Search in sources :

Example 1 with MenuElement

use of org.javlo.navigation.MenuElement in project javlo by Javlo.

the class AbstractOrderComponent method sendConfirmationEmail.

protected void sendConfirmationEmail(ContentContext ctx, Basket basket) throws Exception {
    /**
     * send email *
     */
    String subject = getData().getProperty("mail.subject");
    if (subject == null) {
        subject = "Transaction confirmed : " + ctx.getGlobalContext().getContextKey();
    }
    String email = null;
    String mailingPage = getData().getProperty("mail.page");
    String pageURL = "error:no link.";
    if (mailingPage != null) {
        MenuElement page = ContentService.getInstance(ctx.getGlobalContext()).getNavigation(ctx).searchChildFromName(mailingPage);
        if (page == null) {
            logger.warning("page not found : " + mailingPage);
        }
        Map<String, String> params = new HashMap<String, String>();
        params.put("body", getConfirmationEmail(ctx, basket));
        params.put("total", basket.getTotalString(ctx, true));
        params.put("totalHVAT", basket.getTotalString(ctx, false));
        params.put("VAT", basket.getVAT(ctx));
        params.put("userReduction", StringHelper.renderDoubleAsPercentage(basket.getUserReduction()).replace("%", "&#37;"));
        params.put("communication", basket.getStructutedCommunication());
        params.put("firstName", StringHelper.toHTMLAttribute(basket.getFirstName()));
        params.put("lastName", StringHelper.toHTMLAttribute(basket.getLastName()));
        params.put("basketSize", "" + basket.getSize());
        params.put("basketId", "" + basket.getId());
        params.put("invoiceHash", basket.getInvoiceHash());
        /**
         * customer *
         */
        params.put("customerFirstName", StringHelper.toHTMLAttribute(basket.getCustomerFirstName()));
        params.put("customerLastName", StringHelper.toHTMLAttribute(basket.getCustomerLastName()));
        params.put("customerEmail", StringHelper.toHTMLAttribute(basket.getCustomerEmail()));
        params.put("customerPhone", StringHelper.toHTMLAttribute(basket.getCustomerPhone()));
        params.put("deliveryDate", StringHelper.renderDate(basket.getDeliveryDate()));
        if (basket.getDeliveryDate() != null) {
            params.put("deliveryDay", StringHelper.renderDay(basket.getDeliveryDate(), ctx.getRequestContentLanguage()));
        }
        params.put("deliveryTime", StringHelper.renderTime(basket.getDeliveryDate()));
        params.put("deliveryInstructions", basket.getDeliveryInstructions());
        params.put("giftMessage", StringHelper.toHTMLAttribute(basket.getGiftMessage()));
        params.put("giftSender", StringHelper.toHTMLAttribute(basket.getGiftSender()));
        params.put("giftReceiver", StringHelper.toHTMLAttribute(basket.getGiftReceiver()));
        String basketTable = URLEncoder.encode(renderBasket(ctx, basket), ContentContext.CHARACTER_ENCODING);
        params.put("basketTable", basketTable);
        params.put("address", StringHelper.toHTMLAttribute(basket.getAddress()));
        params.put("city", StringHelper.toHTMLAttribute(basket.getCity()));
        params.put("zip", basket.getZip());
        params.put("postcode", basket.getZip());
        params.put("phone", basket.getContactPhone());
        params.put("country", StringHelper.toHTMLAttribute(new Locale(ctx.getRequestContentLanguage(), basket.getCountry()).getDisplayCountry(ctx.getLocale())));
        params.put("currencyCode", "" + basket.getCurrencyCode());
        if (basket.getOrganization() != null && basket.getOrganization().trim().length() > 0) {
            params.put("organization", basket.getOrganization());
        }
        double delivery = basket.getDelivery(ctx, true);
        params.put("delivery", Basket.renderPrice(ctx, delivery, basket.getCurrencyCode()));
        double deliveryHVAT = basket.getDelivery(ctx, false);
        params.put("deliveryHVAT", Basket.renderPrice(ctx, deliveryHVAT, basket.getCurrencyCode()));
        if (basket.getVATNumber() != null && basket.getVATNumber().trim().length() > 0) {
            params.put("vat", basket.getVATNumber());
        }
        if (page != null) {
            try {
                params.putAll(new ReadOnlyPropertiesMap(getData()));
                pageURL = URLHelper.createURL(ctx.getContextForAbsoluteURL().getContextWithOtherRenderMode(ContentContext.PAGE_MODE), page.getPath(), params);
                email = NetHelper.readPageForMailing(new URL(pageURL));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    InternetAddress bcc = null;
    String bccString = getData().getProperty("mail.bcc");
    if (bccString != null && StringHelper.isMail(bccString)) {
        bcc = new InternetAddress(bccString);
    }
    // InternetAddress from;
    // String fromString = getData().getProperty("mail.from");
    // if( fromString != null && StringHelper.isMail(fromString)) {
    // from = new InternetAddress(fromString);
    // } else {
    // from = new InternetAddress(ctx.getGlobalContext().getAdministratorEmail());
    // }
    InternetAddress from = new InternetAddress(ctx.getGlobalContext().getAdministratorEmail());
    InternetAddress to = new InternetAddress(basket.getRealEmail());
    if (email == null) {
        email = getConfirmationEmail(ctx, basket);
        NetHelper.sendMail(ctx.getGlobalContext(), from, to, null, bcc, subject, email, null, false);
    } else {
        NetHelper.sendMail(ctx.getGlobalContext(), from, to, null, bcc, subject, email, getConfirmationEmail(ctx, basket), true);
    }
}
Also used : Locale(java.util.Locale) InternetAddress(javax.mail.internet.InternetAddress) ReadOnlyPropertiesMap(org.javlo.utils.ReadOnlyPropertiesMap) HashMap(java.util.HashMap) MenuElement(org.javlo.navigation.MenuElement) URL(java.net.URL) IOException(java.io.IOException) ResourceNotFoundException(org.javlo.exception.ResourceNotFoundException)

Example 2 with MenuElement

use of org.javlo.navigation.MenuElement in project javlo by Javlo.

the class AbstractVisualComponent method getEmptyCode.

/*
	 * public String getContentTimeCache(ContentContext ctx) { return
	 * viewTimeCache.get(getContentCacheKey(ctx)); }
	 */
protected String getEmptyCode(ContentContext ctx) throws Exception {
    if ((ctx.getRenderMode() == ContentContext.PREVIEW_MODE)) {
        GlobalContext globalContext = ctx.getGlobalContext();
        EditContext editCtx = EditContext.getInstance(globalContext, ctx.getRequest().getSession());
        if (editCtx.isPreviewEditionMode() && !ctx.isPreviewOnly()) {
            MenuElement currentPage = ctx.getCurrentPage();
            if (currentPage.equals(getPage())) {
                // not edit component
                String prefix = "";
                String suffix = "";
                if (!isWrapped(ctx)) {
                    prefix = getForcedPrefixViewXHTMLCode(ctx);
                    suffix = getForcedSuffixViewXHTMLCode(ctx);
                }
                return (prefix + "<div " + getPrefixCssClass(ctx, "pc_empty-component") + getSpecialPreviewCssId(ctx) + ">" + getEmptyXHTMLCode(ctx) + "</div>" + suffix);
            }
        }
    }
    return null;
}
Also used : GlobalContext(org.javlo.context.GlobalContext) EditContext(org.javlo.context.EditContext) MenuElement(org.javlo.navigation.MenuElement)

Example 3 with MenuElement

use of org.javlo.navigation.MenuElement in project javlo by Javlo.

the class ComponentFactory method getAllDynamicComponents.

public static List<DynamicComponent> getAllDynamicComponents(ContentContext ctx) throws Exception {
    ContentContext noAreaCtx = ctx.getContextWithArea(null);
    List<DynamicComponent> outComps = new LinkedList<DynamicComponent>();
    ContentService content = ContentService.getInstance(ctx.getGlobalContext());
    MenuElement root = content.getNavigation(noAreaCtx);
    ContentElementList pageContent = root.getContent(noAreaCtx);
    /*
		 * while (pageContent.hasNext(noAreaCtx)) { IContentVisualComponent comp
		 * = pageContent.next(noAreaCtx); if (comp instanceof DynamicComponent)
		 * { outComps.add((DynamicComponent)comp); } }
		 */
    for (MenuElement page : root.getAllChildrenList()) {
        pageContent = page.getContent(noAreaCtx);
        while (pageContent.hasNext(noAreaCtx)) {
            IContentVisualComponent comp = pageContent.next(noAreaCtx);
            if (comp instanceof DynamicComponent) {
                outComps.add((DynamicComponent) comp);
            }
        }
    }
    return outComps;
}
Also used : DynamicComponent(org.javlo.component.dynamic.DynamicComponent) ContentService(org.javlo.service.ContentService) ContentContext(org.javlo.context.ContentContext) MenuElement(org.javlo.navigation.MenuElement) LinkedList(java.util.LinkedList)

Example 4 with MenuElement

use of org.javlo.navigation.MenuElement in project javlo by Javlo.

the class ComponentFactory method getDynamicComponents.

public static DynamicComponent getDynamicComponents(ContentContext ctx, String type) throws Exception {
    ContentContext noAreaCtx = ctx.getContextWithArea(null);
    ContentService content = ContentService.getInstance(ctx.getGlobalContext());
    MenuElement root = content.getNavigation(noAreaCtx);
    ContentElementList pageContent = root.getContent(noAreaCtx);
    for (MenuElement page : root.getAllChildrenList()) {
        pageContent = page.getContent(noAreaCtx);
        while (pageContent.hasNext(noAreaCtx)) {
            IContentVisualComponent comp = pageContent.next(noAreaCtx);
            if (comp instanceof DynamicComponent && comp.getType().equals(type)) {
                return (DynamicComponent) comp;
            }
        }
    }
    return null;
}
Also used : DynamicComponent(org.javlo.component.dynamic.DynamicComponent) ContentService(org.javlo.service.ContentService) ContentContext(org.javlo.context.ContentContext) MenuElement(org.javlo.navigation.MenuElement)

Example 5 with MenuElement

use of org.javlo.navigation.MenuElement in project javlo by Javlo.

the class ProductComponent method prepareView.

@Override
public void prepareView(ContentContext ctx) throws Exception {
    super.prepareView(ctx);
    ctx.getRequest().setAttribute("productName", getName());
    String action;
    if (getBasketPage().trim().length() > 0) {
        ContentService content = ContentService.getInstance(ctx.getRequest());
        MenuElement page = content.getNavigation(ctx).searchChildFromName(getBasketPage());
        if (page != null) {
            action = URLHelper.createURL(ctx, page);
        } else {
            action = URLHelper.createURL(ctx);
        }
    } else {
        action = URLHelper.createURL(ctx);
    }
    ProductComponent refComp = (ProductComponent) getReferenceComponent(ctx);
    if (refComp != null) {
        ctx.getRequest().setAttribute("action", action);
        ctx.getRequest().setAttribute("price", refComp.getPrice());
        ctx.getRequest().setAttribute("priceDisplay", StringHelper.renderDouble(refComp.getPrice(), 2));
        ctx.getRequest().setAttribute("currency", refComp.getCurrency());
        ctx.getRequest().setAttribute("currencyDisplay", getCurrencyHtml(refComp.getCurrency()));
        if (!StringHelper.isEmpty(getDescription())) {
            ctx.getRequest().setAttribute("description", XHTMLHelper.textToXHTML(getDescription()));
        }
        ctx.getRequest().setAttribute("virtualStock", getVirtualStock(ctx));
        ctx.getRequest().setAttribute("offset", refComp.getOffset(ctx));
        if (!StringHelper.isEmpty(refComp.getSpecialLink())) {
            String link = refComp.getSpecialLink();
            link = XHTMLHelper.replaceJSTLData(ctx, link);
            link = XHTMLHelper.replaceLinks(ctx, link);
            ctx.getRequest().setAttribute("specialLink", link);
        }
    }
}
Also used : ContentService(org.javlo.service.ContentService) MenuElement(org.javlo.navigation.MenuElement)

Aggregations

MenuElement (org.javlo.navigation.MenuElement)333 ContentService (org.javlo.service.ContentService)136 GlobalContext (org.javlo.context.GlobalContext)102 LinkedList (java.util.LinkedList)74 ContentContext (org.javlo.context.ContentContext)73 IContentVisualComponent (org.javlo.component.core.IContentVisualComponent)64 GenericMessage (org.javlo.message.GenericMessage)55 ContentElementList (org.javlo.component.core.ContentElementList)38 I18nAccess (org.javlo.i18n.I18nAccess)38 PersistenceService (org.javlo.service.PersistenceService)38 HashMap (java.util.HashMap)36 Date (java.util.Date)33 IOException (java.io.IOException)29 ComponentBean (org.javlo.component.core.ComponentBean)28 NavigationService (org.javlo.service.NavigationService)25 PrintWriter (java.io.PrintWriter)23 StringWriter (java.io.StringWriter)20 Calendar (java.util.Calendar)20 HashSet (java.util.HashSet)19 ByteArrayOutputStream (java.io.ByteArrayOutputStream)18