Example usage for com.liferay.portal.kernel.xml Element addElement

List of usage examples for com.liferay.portal.kernel.xml Element addElement

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.xml Element addElement.

Prototype

public Element addElement(QName qName);

Source Link

Usage

From source file:com.liferay.portlet.layoutsadmin.util.SitemapImpl.java

License:Open Source License

protected void addURLElement(Element element, String url, UnicodeProperties typeSettingsProperties,
        Date modifiedDate) {//from w ww.  j  a  v a2 s.  c om

    Element urlElement = element.addElement("url");

    Element locElement = urlElement.addElement("loc");

    locElement.addText(encodeXML(url));

    if (typeSettingsProperties == null) {
        if (Validator.isNotNull(PropsValues.SITES_SITEMAP_DEFAULT_CHANGE_FREQUENCY)) {

            Element changefreqElement = urlElement.addElement("changefreq");

            changefreqElement.addText(PropsValues.SITES_SITEMAP_DEFAULT_CHANGE_FREQUENCY);
        }

        if (Validator.isNotNull(PropsValues.SITES_SITEMAP_DEFAULT_PRIORITY)) {

            Element priorityElement = urlElement.addElement("priority");

            priorityElement.addText(PropsValues.SITES_SITEMAP_DEFAULT_PRIORITY);
        }
    } else {
        String changefreq = typeSettingsProperties.getProperty("sitemap-changefreq");

        if (Validator.isNotNull(changefreq)) {
            Element changefreqElement = urlElement.addElement("changefreq");

            changefreqElement.addText(changefreq);
        } else if (Validator.isNotNull(PropsValues.SITES_SITEMAP_DEFAULT_CHANGE_FREQUENCY)) {

            Element changefreqElement = urlElement.addElement("changefreq");

            changefreqElement.addText(PropsValues.SITES_SITEMAP_DEFAULT_CHANGE_FREQUENCY);
        }

        String priority = typeSettingsProperties.getProperty("sitemap-priority");

        if (Validator.isNotNull(priority)) {
            Element priorityElement = urlElement.addElement("priority");

            priorityElement.addText(priority);
        } else if (Validator.isNotNull(PropsValues.SITES_SITEMAP_DEFAULT_PRIORITY)) {

            Element priorityElement = urlElement.addElement("priority");

            priorityElement.addText(PropsValues.SITES_SITEMAP_DEFAULT_PRIORITY);
        }
    }

    if (modifiedDate != null) {
        Element modifiedDateElement = urlElement.addElement("lastmod");

        DateFormat iso8601DateFormat = DateUtil.getISO8601Format();

        modifiedDateElement.addText(iso8601DateFormat.format(modifiedDate));
    }
}

From source file:com.liferay.portlet.messageboards.lar.MBPortletDataHandlerImpl.java

License:Open Source License

@Override
protected String doExportData(PortletDataContext portletDataContext, String portletId,
        PortletPreferences portletPreferences) throws Exception {

    portletDataContext.addPermissions("com.liferay.portlet.messageboards",
            portletDataContext.getScopeGroupId());

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("message-boards-data");

    rootElement.addAttribute("group-id", String.valueOf(portletDataContext.getScopeGroupId()));

    Element categoriesElement = rootElement.addElement("categories");
    Element messagesElement = rootElement.addElement("messages");
    Element threadFlagsElement = rootElement.addElement("thread-flags");
    Element userBansElement = rootElement.addElement("user-bans");

    List<MBCategory> categories = MBCategoryUtil.findByGroupId(portletDataContext.getScopeGroupId());

    for (MBCategory category : categories) {
        exportCategory(portletDataContext, categoriesElement, messagesElement, threadFlagsElement, category);
    }/*www .j av  a2 s .  c o m*/

    List<MBMessage> messages = MBMessageUtil.findByG_C(portletDataContext.getScopeGroupId(),
            MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID);

    for (MBMessage message : messages) {
        exportMessage(portletDataContext, categoriesElement, messagesElement, threadFlagsElement, message);
    }

    if (portletDataContext.getBooleanParameter(_NAMESPACE, "user-bans")) {
        List<MBBan> bans = MBBanUtil.findByGroupId(portletDataContext.getScopeGroupId());

        for (MBBan ban : bans) {
            exportBan(portletDataContext, userBansElement, ban);
        }
    }

    return document.formattedString();
}

From source file:com.liferay.portlet.messageboards.lar.MBPortletDataHandlerImpl.java

License:Open Source License

protected void exportBan(PortletDataContext portletDataContext, Element userBansElement, MBBan ban)
        throws Exception {

    if (!portletDataContext.isWithinDateRange(ban.getModifiedDate())) {
        return;//from w w w  .j  a v a  2  s  .  c o  m
    }

    String path = getUserBanPath(portletDataContext, ban);

    if (!portletDataContext.isPathNotProcessed(path)) {
        return;
    }

    Element userBanElement = userBansElement.addElement("user-ban");

    ban.setBanUserUuid(ban.getBanUserUuid());

    portletDataContext.addClassedModel(userBanElement, path, ban, _NAMESPACE);
}

From source file:com.liferay.portlet.messageboards.lar.MBPortletDataHandlerImpl.java

License:Open Source License

protected void exportCategory(PortletDataContext portletDataContext, Element categoriesElement,
        Element messagesElement, Element threadFlagsElement, MBCategory category) throws Exception {

    if (portletDataContext.isWithinDateRange(category.getModifiedDate())) {
        exportParentCategory(portletDataContext, categoriesElement, category.getParentCategoryId());

        String path = getCategoryPath(portletDataContext, category);

        if (portletDataContext.isPathNotProcessed(path)) {
            Element categoryElement = categoriesElement.addElement("category");

            portletDataContext.addClassedModel(categoryElement, path, category, _NAMESPACE);
        }/*from w ww .  j  av a 2 s . c  om*/
    }

    List<MBMessage> messages = MBMessageUtil.findByG_C(category.getGroupId(), category.getCategoryId());

    for (MBMessage message : messages) {
        exportMessage(portletDataContext, categoriesElement, messagesElement, threadFlagsElement, message);
    }
}

From source file:com.liferay.portlet.messageboards.lar.MBPortletDataHandlerImpl.java

License:Open Source License

protected void exportMessage(PortletDataContext portletDataContext, Element categoriesElement,
        Element messagesElement, Element threadFlagsElement, MBMessage message) throws Exception {

    if (!portletDataContext.isWithinDateRange(message.getModifiedDate())) {
        return;//from  w  w w. java2s .  c o  m
    }

    if (message.getStatus() != WorkflowConstants.STATUS_APPROVED) {
        return;
    }

    exportParentCategory(portletDataContext, categoriesElement, message.getCategoryId());

    String path = getMessagePath(portletDataContext, message);

    if (!portletDataContext.isPathNotProcessed(path)) {
        return;
    }

    Element messageElement = messagesElement.addElement("message");

    message.setPriority(message.getPriority());

    if (portletDataContext.getBooleanParameter(_NAMESPACE, "attachments") && message.isAttachments()) {

        for (String attachment : message.getAttachmentsFiles()) {
            int pos = attachment.lastIndexOf(CharPool.FORWARD_SLASH);

            String name = attachment.substring(pos + 1);
            String binPath = getMessageAttachementBinPath(portletDataContext, message, name);

            Element attachmentElement = messageElement.addElement("attachment");

            attachmentElement.addAttribute("name", name);
            attachmentElement.addAttribute("bin-path", binPath);

            byte[] bytes = DLStoreUtil.getFileAsBytes(portletDataContext.getCompanyId(),
                    CompanyConstants.SYSTEM, attachment);

            portletDataContext.addZipEntry(binPath, bytes);
        }

        message.setAttachmentsDir(message.getAttachmentsDir());
    }

    if (portletDataContext.getBooleanParameter(_NAMESPACE, "thread-flags")) {

        List<MBThreadFlag> threadFlags = MBThreadFlagUtil.findByThreadId(message.getThreadId());

        for (MBThreadFlag threadFlag : threadFlags) {
            exportThreadFlag(portletDataContext, threadFlagsElement, threadFlag);
        }
    }

    portletDataContext.addClassedModel(messageElement, path, message, _NAMESPACE);
}

From source file:com.liferay.portlet.messageboards.lar.MBPortletDataHandlerImpl.java

License:Open Source License

protected void exportParentCategory(PortletDataContext portletDataContext, Element categoriesElement,
        long categoryId) throws Exception {

    if ((!portletDataContext.hasDateRange()) || (categoryId == MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID)
            || (categoryId == MBCategoryConstants.DISCUSSION_CATEGORY_ID)) {

        return;//  w  ww .j  a  v  a2s.  co m
    }

    MBCategory category = MBCategoryUtil.findByPrimaryKey(categoryId);

    exportParentCategory(portletDataContext, categoriesElement, category.getParentCategoryId());

    String path = getCategoryPath(portletDataContext, category);

    if (portletDataContext.isPathNotProcessed(path)) {
        Element categoryElement = categoriesElement.addElement("category");

        portletDataContext.addClassedModel(categoryElement, path, category, _NAMESPACE);
    }
}

From source file:com.liferay.portlet.messageboards.lar.MBPortletDataHandlerImpl.java

License:Open Source License

protected void exportThreadFlag(PortletDataContext portletDataContext, Element threadFlagsElement,
        MBThreadFlag threadFlag) throws Exception {

    String path = getThreadFlagPath(portletDataContext, threadFlag);

    if (!portletDataContext.isPathNotProcessed(path)) {
        return;//w  w  w.j av  a  2 s  .  co  m
    }

    Element threadFlagElement = threadFlagsElement.addElement("thread-flag");

    MBThread thread = MBThreadLocalServiceUtil.getThread(threadFlag.getThreadId());

    MBMessage rootMessage = MBMessageLocalServiceUtil.getMessage(thread.getRootMessageId());

    threadFlagElement.addAttribute("root-message-uuid", rootMessage.getUuid());

    portletDataContext.addClassedModel(threadFlagElement, path, threadFlag, _NAMESPACE);
}

From source file:com.liferay.portlet.polls.lar.PollsDisplayPortletDataHandlerImpl.java

License:Open Source License

@Override
protected String doExportData(PortletDataContext portletDataContext, String portletId,
        PortletPreferences portletPreferences) throws Exception {

    long questionId = GetterUtil.getLong(portletPreferences.getValue("questionId", StringPool.BLANK));

    if (questionId <= 0) {
        if (_log.isWarnEnabled()) {
            _log.warn("No question id found in preferences of portlet " + portletId);
        }/*from   ww w.  j av a2 s  .co m*/

        return StringPool.BLANK;
    }

    PollsQuestion question = null;

    try {
        question = PollsQuestionUtil.findByPrimaryKey(questionId);
    } catch (NoSuchQuestionException nsqe) {
        if (_log.isWarnEnabled()) {
            _log.warn(nsqe, nsqe);
        }

        return StringPool.BLANK;
    }

    portletDataContext.addPermissions("com.liferay.portlet.polls", portletDataContext.getScopeGroupId());

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("polls-display-data");

    rootElement.addAttribute("group-id", String.valueOf(portletDataContext.getScopeGroupId()));

    Element questionsElement = rootElement.addElement("questions");
    Element choicesElement = rootElement.addElement("choices");
    Element votesElement = rootElement.addElement("votes");

    PollsPortletDataHandlerImpl.exportQuestion(portletDataContext, questionsElement, choicesElement,
            votesElement, question);

    return document.formattedString();
}

From source file:com.liferay.portlet.polls.lar.PollsPortletDataHandlerImpl.java

License:Open Source License

protected static void exportChoice(PortletDataContext portletDataContext, Element questionsElement,
        PollsChoice choice) throws Exception {

    String path = getChoicePath(portletDataContext, choice);

    if (!portletDataContext.isPathNotProcessed(path)) {
        return;//from   ww  w.ja v  a2  s  .  com
    }

    Element choiceElement = questionsElement.addElement("choice");

    portletDataContext.addClassedModel(choiceElement, path, choice, _NAMESPACE);
}

From source file:com.liferay.portlet.polls.lar.PollsPortletDataHandlerImpl.java

License:Open Source License

protected static void exportQuestion(PortletDataContext portletDataContext, Element questionsElement,
        Element choicesElement, Element votesElement, PollsQuestion question) throws Exception {

    if (!portletDataContext.isWithinDateRange(question.getModifiedDate())) {
        return;//from  w ww  .  j a v  a  2 s.c o  m
    }

    String path = getQuestionPath(portletDataContext, question);

    if (!portletDataContext.isPathNotProcessed(path)) {
        return;
    }

    Element questionElement = questionsElement.addElement("question");

    List<PollsChoice> choices = PollsChoiceUtil.findByQuestionId(question.getQuestionId());

    for (PollsChoice choice : choices) {
        exportChoice(portletDataContext, choicesElement, choice);
    }

    if (portletDataContext.getBooleanParameter(_NAMESPACE, "votes")) {
        List<PollsVote> votes = PollsVoteUtil.findByQuestionId(question.getQuestionId());

        for (PollsVote vote : votes) {
            exportVote(portletDataContext, votesElement, vote);
        }
    }

    portletDataContext.addClassedModel(questionElement, path, question, _NAMESPACE);
}