Example usage for com.liferay.portal.kernel.util Constants VIEW

List of usage examples for com.liferay.portal.kernel.util Constants VIEW

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util Constants VIEW.

Prototype

String VIEW

To view the source code for com.liferay.portal.kernel.util Constants VIEW.

Click Source Link

Usage

From source file:com.beorn.onlinepayment.shopping.action.BtopSelectPaymentMethodAction.java

License:Open Source License

@Override
public void processAction(PortletConfig portletConfig, ActionRequest actionRequest,
        ActionResponse actionResponse) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long orderId = ParamUtil.getLong(actionRequest, "orderId");
    long paymentMethodId = ParamUtil.getLong(actionRequest, "methodId");

    OrderTransaction orderTransaction = OrderTransactionLocalServiceUtil.getOrderTransaction(orderId);

    PaymentAppSender paymentAppSender = PaymentAppUtil.getPaymentAppSender();

    HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);

    String remoteIp = request.getRemoteAddr();
    String forwardedForIp = StringUtil.extractFirst(request.getHeader("X-Forwarded-For"),
            StringPool.COMMA_AND_SPACE);
    if (forwardedForIp != null)
        remoteIp = forwardedForIp;//w  ww. ja va2s  . c  o  m

    String countryCode = paymentAppSender.geolocalizeIp(remoteIp);

    LiferayPortletURL returnURL = PortletURLFactoryUtil.create(actionRequest, "34", themeDisplay.getPlid(),
            PortletRequest.ACTION_PHASE);
    returnURL.setWindowState(LiferayWindowState.NORMAL);
    returnURL.setParameter("struts_action", "/shopping/checkout");
    returnURL.setParameter(Constants.CMD, Constants.VIEW);
    returnURL.setParameter("orderId", String.valueOf(orderId));

    String backUrl = returnURL.toString();
    String successUrl = returnURL.toString();
    String errorUrl = returnURL.toString();

    String paymentUrl = paymentAppSender.getPaymentUrl(orderTransaction.getTransactionId(), paymentMethodId,
            themeDisplay.getLanguageId(), countryCode, backUrl, successUrl, errorUrl);

    actionResponse.sendRedirect(paymentUrl);
}

From source file:com.blogspot.jmelon.portlet.quiz.controller.QuizViewController.java

License:Open Source License

@ResourceMapping("submitQuiz")
public String submitQuiz(ResourceRequest request, ResourceResponse response, Model model,
        @RequestParam(PARAM_ANSWERS) String answersParam)
        throws UnsupportedEncodingException, IOException, ReadOnlyException {
    LOGGER.debug("received ansers: {}", answersParam);

    if (StringUtils.hasText(answersParam)) {

        List<Integer> answers = new LinkedList<Integer>();
        for (String answer : answersParam.split(",")) {
            answers.add(Integer.parseInt(answer));
        }/*from w  w  w  .ja  v  a 2  s.  co m*/

        String resolution = RESOLUTION_SUCCESS;

        PortletPreferences portletPrefs = request.getPreferences();
        String prefsJson = portletPrefs.getValue(QUIZ_PREFS, BLANK);

        ObjectMapper om = new ObjectMapper();
        QuizPrefs quizPrefs = om.readValue(prefsJson, QuizPrefs.class);

        // count points
        int points = 0;
        final List<QuizQuestion> allQuestions = quizPrefs.getAllQuestions();
        for (int i = 0; i < allQuestions.size(); i++) {
            final QuizQuestion quizQuestion = allQuestions.get(i);
            final Integer answerIndex = answers.get(i);

            if (quizQuestion.getAnswers().size() > answerIndex) {
                points += quizQuestion.getAnswers().get(answerIndex).getPoints();
            } else {
                resolution = RESOLUTION_FAILED;
                break;
            }
        }

        // get result content
        if (RESOLUTION_SUCCESS.equals(resolution)) {
            // TODO assure sorting while saving prefs
            List<QuizResult> allResults = quizPrefs.getResults();
            Collections.sort(allResults, new QuizResultsComparator());

            QuizResult result = getFinalResultFromPoints(points, allResults);
            ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

            long groupId = getGroupId(result, themeDisplay);
            String articleId = result.getResultArticleId();
            String templateId = result.getResultTemplateId();
            String language = request.getLocale().getLanguage();
            String content;
            if (templateId == null) {
                content = JournalContentUtil.getContent(groupId, articleId, Constants.VIEW, language,
                        themeDisplay);
            } else {
                content = JournalContentUtil.getContent(groupId, articleId, templateId, Constants.VIEW,
                        language, themeDisplay);
            }

            model.addAttribute(ATTR_CONTENT, content);
        }

        model.addAttribute(ATTR_RESOLUTION, resolution);
    } else {
        LOGGER.warn("Received empty answers list");
        model.addAttribute(ATTR_RESOLUTION, RESOLUTION_FAILED);
    }
    return JSON_VIEW;
}

From source file:com.liferay.dynamic.data.lists.web.internal.template.DDLDisplayTemplateTransformer.java

License:Open Source License

public String transform() throws Exception {
    Transformer transformer = TransformerHolder.getTransformer();

    Map<String, Object> contextObjects = new HashMap<>();

    contextObjects.put(DDLConstants.RESERVED_DDM_STRUCTURE_ID, _recordSet.getDDMStructureId());
    contextObjects.put(DDLConstants.RESERVED_DDM_TEMPLATE_ID, _ddmTemplateId);
    contextObjects.put(DDLConstants.RESERVED_RECORD_SET_DESCRIPTION,
            _recordSet.getDescription(_themeDisplay.getLocale()));
    contextObjects.put(DDLConstants.RESERVED_RECORD_SET_ID, _recordSet.getRecordSetId());
    contextObjects.put(DDLConstants.RESERVED_RECORD_SET_NAME, _recordSet.getName(_themeDisplay.getLocale()));
    contextObjects.put(TemplateConstants.TEMPLATE_ID, _ddmTemplateId);

    String viewMode = Constants.VIEW;

    if (_renderRequest != null) {
        viewMode = ParamUtil.getString(_renderRequest, "viewMode", Constants.VIEW);
    }//from ww  w .ja  v  a  2s  .c  om

    contextObjects.put("viewMode", viewMode);

    DDMTemplate ddmTemplate = DDMTemplateLocalServiceUtil.getTemplate(_ddmTemplateId);

    contextObjects.put(TemplateConstants.CLASS_NAME_ID, ddmTemplate.getClassNameId());

    TemplateManager templateManager = TemplateManagerUtil.getTemplateManager(ddmTemplate.getLanguage());

    TemplateHandler templateHandler = TemplateHandlerRegistryUtil
            .getTemplateHandler(DDLRecordSet.class.getName());

    templateManager.addContextObjects(contextObjects, templateHandler.getCustomContextObjects());

    templateManager.addTaglibSupport(contextObjects, PortalUtil.getHttpServletRequest(_renderRequest),
            _themeDisplay.getResponse());

    return transformer.transform(_themeDisplay, contextObjects, ddmTemplate.getScript(),
            ddmTemplate.getLanguage(), new UnsyncStringWriter());
}

From source file:com.liferay.journal.search.JournalArticleIndexer.java

License:Open Source License

protected String getDDMContentSummary(Document document, Locale snippetLocale, PortletRequest portletRequest,
        PortletResponse portletResponse) {

    String content = StringPool.BLANK;

    if ((portletRequest == null) || (portletResponse == null)) {
        return content;
    }/*  w ww  .j a v  a2 s. c  om*/

    try {
        String articleId = document.get(Field.ARTICLE_ID);
        long groupId = GetterUtil.getLong(document.get(Field.GROUP_ID));
        double version = GetterUtil.getDouble(document.get(Field.VERSION));
        PortletRequestModel portletRequestModel = new PortletRequestModel(portletRequest, portletResponse);
        ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

        JournalArticleDisplay articleDisplay = _journalContent.getDisplay(groupId, articleId, version, null,
                Constants.VIEW, LocaleUtil.toLanguageId(snippetLocale), 1, portletRequestModel, themeDisplay);

        content = articleDisplay.getDescription();

        content = HtmlUtil.replaceNewLine(content);

        if (Validator.isNull(content)) {
            content = HtmlUtil.extractText(articleDisplay.getContent());
        }
    } catch (Exception e) {
        if (_log.isDebugEnabled()) {
            _log.debug(e, e);
        }
    }

    return content;
}

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

@Override
public boolean isRenderable(JournalArticle article, PortletRequestModel portletRequestModel,
        ThemeDisplay themeDisplay) {// w  w w. j  ava 2 s  .  c  o  m

    try {
        getArticleDisplay(article, null, Constants.VIEW, article.getDefaultLanguageId(), 0, portletRequestModel,
                themeDisplay, true);
    } catch (Exception e) {
        return false;
    }

    return true;
}

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

protected void notifySubscribers(long userId, JournalArticle article, String action,
        ServiceContext serviceContext) throws PortalException {

    String portletId = PortletProviderUtil.getPortletId(JournalArticle.class.getName(),
            PortletProvider.Action.EDIT);

    String articleURL = PortalUtil.getControlPanelFullURL(article.getGroupId(), portletId, null);

    if (!article.isApproved() || Validator.isNull(articleURL)) {
        return;//  w ww .j  a v a 2  s.c o  m
    }

    JournalGroupServiceConfiguration journalGroupServiceConfiguration = getJournalGroupServiceConfiguration(
            article.getGroupId());

    String articleTitle = article.getTitle(serviceContext.getLanguageId());

    articleURL = buildArticleURL(articleURL, article.getGroupId(), article.getFolderId(),
            article.getArticleId());

    if (action.equals("add") && journalGroupServiceConfiguration.emailArticleAddedEnabled()) {
    } else if (action.equals("move_to")
            && journalGroupServiceConfiguration.emailArticleMovedToFolderEnabled()) {
    } else if (action.equals("move_from")
            && journalGroupServiceConfiguration.emailArticleMovedFromFolderEnabled()) {
    } else if (action.equals("update") && journalGroupServiceConfiguration.emailArticleUpdatedEnabled()) {
    } else {
        return;
    }

    String fromName = journalGroupServiceConfiguration.emailFromName();
    String fromAddress = journalGroupServiceConfiguration.emailFromAddress();

    Map<Locale, String> localizedSubjectMap = null;
    Map<Locale, String> localizedBodyMap = null;

    int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY;

    if (action.equals("add")) {
        localizedSubjectMap = LocalizationUtil
                .getMap(journalGroupServiceConfiguration.emailArticleAddedSubject());
        localizedBodyMap = LocalizationUtil.getMap(journalGroupServiceConfiguration.emailArticleAddedBody());
    } else if (action.equals("move_to")) {
        localizedSubjectMap = LocalizationUtil
                .getMap(journalGroupServiceConfiguration.emailArticleMovedToFolderSubject());
        localizedBodyMap = LocalizationUtil
                .getMap(journalGroupServiceConfiguration.emailArticleMovedToFolderBody());

        notificationType = JournalArticleConstants.NOTIFICATION_TYPE_MOVE_ENTRY_TO_FOLDER;
    } else if (action.equals("move_from")) {
        localizedSubjectMap = LocalizationUtil
                .getMap(journalGroupServiceConfiguration.emailArticleMovedFromFolderSubject());
        localizedBodyMap = LocalizationUtil
                .getMap(journalGroupServiceConfiguration.emailArticleMovedFromFolderBody());

        notificationType = JournalArticleConstants.NOTIFICATION_TYPE_MOVE_ENTRY_FROM_FOLDER;
    } else if (action.equals("update")) {
        localizedSubjectMap = LocalizationUtil
                .getMap(journalGroupServiceConfiguration.emailArticleUpdatedSubject());
        localizedBodyMap = LocalizationUtil.getMap(journalGroupServiceConfiguration.emailArticleUpdatedBody());

        notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY;
    }

    String articleContent = StringPool.BLANK;
    String articleDiffs = StringPool.BLANK;

    JournalArticle previousApprovedArticle = getPreviousApprovedArticle(article);

    try {
        PortletRequestModel portletRequestModel = new PortletRequestModel(
                serviceContext.getLiferayPortletRequest(), serviceContext.getLiferayPortletResponse());

        JournalArticleDisplay articleDisplay = getArticleDisplay(article, null, Constants.VIEW,
                LocaleUtil.toLanguageId(LocaleUtil.getSiteDefault()), 1, portletRequestModel,
                serviceContext.getThemeDisplay());

        articleContent = articleDisplay.getContent();

        articleDiffs = JournalUtil.diffHtml(article.getGroupId(), article.getArticleId(),
                previousApprovedArticle.getVersion(), article.getVersion(),
                LocaleUtil.toLanguageId(LocaleUtil.getSiteDefault()), portletRequestModel,
                serviceContext.getThemeDisplay());
    } catch (Exception e) {
    }

    SubscriptionSender subscriptionSender = new GroupSubscriptionCheckSubscriptionSender(
            JournalPermission.RESOURCE_NAME);

    subscriptionSender.setClassName(article.getModelClassName());
    subscriptionSender.setClassPK(article.getId());
    subscriptionSender.setCompanyId(article.getCompanyId());
    subscriptionSender.setContextAttribute("[$ARTICLE_CONTENT$]", articleContent, false);
    subscriptionSender.setContextAttribute("[$ARTICLE_DIFFS$]", DiffHtmlUtil.replaceStyles(articleDiffs),
            false);

    JournalFolder folder = article.getFolder();

    subscriptionSender.setContextAttributes("[$ARTICLE_ID$]", article.getArticleId(), "[$ARTICLE_TITLE$]",
            articleTitle, "[$ARTICLE_URL$]", articleURL, "[$ARTICLE_VERSION$]", article.getVersion(),
            "[$FOLDER_NAME$]", folder.getName());

    subscriptionSender.setContextCreatorUserPrefix("ARTICLE");
    subscriptionSender.setCreatorUserId(article.getUserId());
    subscriptionSender.setCurrentUserId(userId);
    subscriptionSender.setEntryTitle(articleTitle);
    subscriptionSender.setEntryURL(articleURL);
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setLocalizedBodyMap(localizedBodyMap);
    subscriptionSender.setLocalizedSubjectMap(localizedSubjectMap);
    subscriptionSender.setMailId("journal_article", article.getId());
    subscriptionSender.setNotificationType(notificationType);
    subscriptionSender.setPortletId(portletId);
    subscriptionSender.setReplyToAddress(fromAddress);
    subscriptionSender.setScopeGroupId(article.getGroupId());
    subscriptionSender.setServiceContext(serviceContext);

    subscriptionSender.addPersistedSubscribers(JournalFolder.class.getName(), article.getGroupId());

    if (folder != null) {
        subscriptionSender.addPersistedSubscribers(JournalFolder.class.getName(), folder.getFolderId());

        for (Long ancestorFolderId : folder.getAncestorFolderIds()) {
            subscriptionSender.addPersistedSubscribers(JournalFolder.class.getName(), ancestorFolderId);
        }
    }

    DDMStructure ddmStructure = ddmStructureLocalService.getStructure(article.getGroupId(),
            classNameLocalService.getClassNameId(JournalArticle.class), article.getDDMStructureKey(), true);

    subscriptionSender.addPersistedSubscribers(DDMStructure.class.getName(), ddmStructure.getStructureId());

    subscriptionSender.addPersistedSubscribers(JournalArticle.class.getName(), article.getResourcePrimKey());

    subscriptionSender.flushNotificationsAsync();
}

From source file:com.liferay.journal.taglib.servlet.taglib.JournalArticleTag.java

License:Open Source License

@Override
public int doStartTag() throws JspException {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    PortletRequest portletRequest = (PortletRequest) request.getAttribute(JavaConstants.JAVAX_PORTLET_REQUEST);
    PortletResponse portletResponse = (PortletResponse) request
            .getAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE);

    PortletRequestModel portletRequestModel = new PortletRequestModel(portletRequest, portletResponse);

    _article = JournalArticleLocalServiceUtil.fetchLatestArticle(_groupId, _articleId,
            WorkflowConstants.STATUS_APPROVED);

    try {//from  w w  w. j  av  a 2s .c  om
        _articleDisplay = JournalArticleLocalServiceUtil.getArticleDisplay(_article.getGroupId(),
                _article.getArticleId(), _article.getVersion(), _ddmTemplateKey, Constants.VIEW,
                getLanguageId(), 1, portletRequestModel, themeDisplay);
    } catch (PortalException pe) {
        if (_log.isDebugEnabled()) {
            _log.debug("Unable to get journal article display", pe);
        }

        return SKIP_BODY;
    }

    return super.doStartTag();
}

From source file:com.liferay.journal.transformer.JournalTransformer.java

License:Open Source License

protected String doTransform(ThemeDisplay themeDisplay, Map<String, Object> contextObjects,
        Map<String, String> tokens, String viewMode, String languageId, Document document,
        PortletRequestModel portletRequestModel, String script, String langType, boolean propagateException)
        throws Exception {

    // Setup listeners

    if (_log.isDebugEnabled()) {
        _log.debug("Language " + languageId);
    }//from   w  w  w  .  ja v a2  s.c om

    if (Validator.isNull(viewMode)) {
        viewMode = Constants.VIEW;
    }

    if (_logTokens.isDebugEnabled()) {
        String tokensString = PropertiesUtil.list(tokens);

        _logTokens.debug(tokensString);
    }

    if (_logTransformBefore.isDebugEnabled()) {
        _logTransformBefore.debug(document);
    }

    List<TransformerListener> transformerListeners = JournalTransformerListenerRegistryUtil
            .getTransformerListeners();

    for (TransformerListener transformerListener : transformerListeners) {

        // Modify XML

        if (_logXmlBeforeListener.isDebugEnabled()) {
            _logXmlBeforeListener.debug(document);
        }

        if (transformerListener != null) {
            document = transformerListener.onXml(document, languageId, tokens);

            if (_logXmlAfterListener.isDebugEnabled()) {
                _logXmlAfterListener.debug(document);
            }
        }

        // Modify script

        if (_logScriptBeforeListener.isDebugEnabled()) {
            _logScriptBeforeListener.debug(script);
        }

        if (transformerListener != null) {
            script = transformerListener.onScript(script, document, languageId, tokens);

            if (_logScriptAfterListener.isDebugEnabled()) {
                _logScriptAfterListener.debug(script);
            }
        }
    }

    // Transform

    String output = null;

    if (Validator.isNull(langType)) {
        output = LocalizationUtil.getLocalization(document.asXML(), languageId);
    } else {
        long companyId = 0;
        long companyGroupId = 0;
        long articleGroupId = 0;
        long classNameId = 0;

        if (tokens != null) {
            companyId = GetterUtil.getLong(tokens.get("company_id"));
            companyGroupId = GetterUtil.getLong(tokens.get("company_group_id"));
            articleGroupId = GetterUtil.getLong(tokens.get("article_group_id"));
            classNameId = GetterUtil.getLong(tokens.get(TemplateConstants.CLASS_NAME_ID));
        }

        long scopeGroupId = 0;
        long siteGroupId = 0;

        if (themeDisplay != null) {
            companyId = themeDisplay.getCompanyId();
            companyGroupId = themeDisplay.getCompanyGroupId();
            scopeGroupId = themeDisplay.getScopeGroupId();
            siteGroupId = themeDisplay.getSiteGroupId();
        }

        String templateId = tokens.get("template_id");

        templateId = getTemplateId(templateId, companyId, companyGroupId, articleGroupId);

        Template template = getTemplate(templateId, tokens, languageId, document, script, langType);

        if (contextObjects != null) {
            template.putAll(contextObjects);
        }

        UnsyncStringWriter unsyncStringWriter = new UnsyncStringWriter();

        try {
            if (document != null) {
                Element rootElement = document.getRootElement();

                List<TemplateNode> templateNodes = getTemplateNodes(themeDisplay, rootElement,
                        Long.valueOf(tokens.get("ddm_structure_id")));

                if (templateNodes != null) {
                    for (TemplateNode templateNode : templateNodes) {
                        template.put(templateNode.getName(), templateNode);
                    }
                }

                if (portletRequestModel != null) {
                    template.put("request", portletRequestModel.toMap());

                    if (langType.equals(TemplateConstants.LANG_TYPE_XSL)) {
                        Document requestDocument = SAXReaderUtil.read(portletRequestModel.toXML());

                        Element requestElement = requestDocument.getRootElement();

                        template.put("xmlRequest", requestElement.asXML());
                    }
                } else {
                    Element requestElement = rootElement.element("request");

                    template.put("request", insertRequestVariables(requestElement));

                    if (langType.equals(TemplateConstants.LANG_TYPE_XSL)) {
                        template.put("xmlRequest", requestElement.asXML());
                    }
                }
            }

            template.put("articleGroupId", articleGroupId);
            template.put("company", getCompany(themeDisplay, companyId));
            template.put("companyId", companyId);
            template.put("device", getDevice(themeDisplay));

            String templatesPath = getTemplatesPath(companyId, articleGroupId, classNameId);

            Locale locale = LocaleUtil.fromLanguageId(languageId);

            template.put("locale", locale);

            template.put("permissionChecker", PermissionThreadLocal.getPermissionChecker());
            template.put("randomNamespace", StringUtil.randomId() + StringPool.UNDERLINE);
            template.put("scopeGroupId", scopeGroupId);
            template.put("siteGroupId", siteGroupId);
            template.put("templatesPath", templatesPath);
            template.put("viewMode", viewMode);

            if (themeDisplay != null) {
                TemplateManager templateManager = TemplateManagerUtil.getTemplateManager(langType);

                HttpServletRequest request = themeDisplay.getRequest();

                templateManager.addTaglibSupport(template, request, themeDisplay.getResponse());
                templateManager.addTaglibTheme(template, "taglibLiferay", request,
                        new PipingServletResponse(themeDisplay.getResponse(), unsyncStringWriter));
            }

            // Deprecated variables

            template.put("groupId", articleGroupId);
            template.put("journalTemplatesPath", templatesPath);

            mergeTemplate(template, unsyncStringWriter, propagateException);
        } catch (Exception e) {
            if (e instanceof DocumentException) {
                throw new TransformException("Unable to read XML document", e);
            } else if (e instanceof IOException) {
                throw new TransformException("Error reading template", e);
            } else if (e instanceof TransformException) {
                throw (TransformException) e;
            } else {
                throw new TransformException("Unhandled exception", e);
            }
        }

        output = unsyncStringWriter.toString();
    }

    // Postprocess output

    for (TransformerListener transformerListener : transformerListeners) {

        // Modify output

        if (_logOutputBeforeListener.isDebugEnabled()) {
            _logOutputBeforeListener.debug(output);
        }

        output = transformerListener.onOutput(output, languageId, tokens);

        if (_logOutputAfterListener.isDebugEnabled()) {
            _logOutputAfterListener.debug(output);
        }
    }

    if (_logTransfromAfter.isDebugEnabled()) {
        _logTransfromAfter.debug(output);
    }

    return output;
}

From source file:com.liferay.journal.transformer.test.JournalTransformerTest.java

License:Open Source License

@Test
public void testContentTransformerListener() throws Exception {
    DDMForm ddmForm = new DDMForm();

    ddmForm.addAvailableLocale(LocaleUtil.US);
    ddmForm.addDDMFormField(DDMFormTestUtil.createTextDDMFormField("link", false, false, false));
    ddmForm.addDDMFormField(DDMFormTestUtil.createTextDDMFormField("name", false, false, false));
    ddmForm.setDefaultLocale(LocaleUtil.US);

    _ddmStructure = DDMStructureTestUtil.addStructure(JournalArticle.class.getName(), ddmForm);

    String xsl = "$name.getData()";

    _ddmTemplate = DDMTemplateTestUtil.addTemplate(_ddmStructure.getStructureId(),
            PortalUtil.getClassNameId(JournalArticle.class), TemplateConstants.LANG_TYPE_VM, xsl);

    String xml = DDMStructureTestUtil.getSampleStructuredContent("Joe Bloggs");

    _article = JournalTestUtil.addArticleWithXMLContent(xml, _ddmStructure.getStructureKey(),
            _ddmTemplate.getTemplateKey());

    Map<String, String> tokens = getTokens();

    String content = JournalUtil.transform(null, tokens, Constants.VIEW, "en_US",
            UnsecureSAXReaderUtil.read(xml), null, xsl, TemplateConstants.LANG_TYPE_VM);

    Assert.assertEquals("Joe Bloggs", content);

    Document document = UnsecureSAXReaderUtil.read(xml);

    Element element = (Element) document.selectSingleNode("//dynamic-content");

    element.setText("[@" + _article.getArticleId() + ";name@]");

    content = JournalUtil.transform(null, tokens, Constants.VIEW, "en_US", document, null, xsl,
            TemplateConstants.LANG_TYPE_VM);

    Assert.assertEquals("Joe Bloggs", content);
}

From source file:com.liferay.journal.transformer.test.JournalTransformerTest.java

License:Open Source License

@Test
public void testLocaleTransformerListener() throws Exception {
    Map<String, String> tokens = getTokens();

    Map<Locale, String> contents = new HashMap<>();

    contents.put(LocaleUtil.BRAZIL, "Joao da Silva");
    contents.put(LocaleUtil.US, "Joe Bloggs");

    String xml = DDMStructureTestUtil.getSampleStructuredContent(contents,
            LanguageUtil.getLanguageId(LocaleUtil.US));

    String script = "$name.getData()";

    String content = JournalUtil.transform(null, tokens, Constants.VIEW, "en_US",
            UnsecureSAXReaderUtil.read(xml), null, script, TemplateConstants.LANG_TYPE_VM);

    Assert.assertEquals("Joe Bloggs", content);

    content = JournalUtil.transform(null, tokens, Constants.VIEW, "pt_BR", UnsecureSAXReaderUtil.read(xml),
            null, script, TemplateConstants.LANG_TYPE_VM);

    Assert.assertEquals("Joao da Silva", content);

    content = JournalUtil.transform(null, tokens, Constants.VIEW, "fr_CA", UnsecureSAXReaderUtil.read(xml),
            null, script, TemplateConstants.LANG_TYPE_VM);

    Assert.assertEquals("Joe Bloggs", content);
}