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

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

Introduction

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

Prototype

public Element addAttribute(String name, String value);

Source Link

Usage

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  ww . j a  v  a  2  s.  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 exportThreadFlag(PortletDataContext portletDataContext, Element threadFlagsElement,
        MBThreadFlag threadFlag) throws Exception {

    String path = getThreadFlagPath(portletDataContext, threadFlag);

    if (!portletDataContext.isPathNotProcessed(path)) {
        return;//w  w  w . j ava  2s . c  o  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);
        }/*  w w w  .  j a va  2 s  . c  om*/

        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

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

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

    Document document = SAXReaderUtil.createDocument();

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

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

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

    List<PollsQuestion> questions = PollsQuestionUtil.findByGroupId(portletDataContext.getScopeGroupId());

    for (PollsQuestion question : questions) {
        exportQuestion(portletDataContext, questionsElement, choicesElement, votesElement, question);
    }// w w  w . j  av  a2  s  . c  o  m

    return document.formattedString();
}

From source file:com.liferay.portlet.rss.lar.RSSPortletDataHandlerImpl.java

License:Open Source License

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

    String[] footerArticleValues = portletPreferences.getValues("footerArticleValues",
            new String[] { "0", "" });
    String[] headerArticleValues = portletPreferences.getValues("headerArticleValues",
            new String[] { "0", "" });

    String footerArticleId = footerArticleValues[1];
    String headerArticleId = headerArticleValues[1];

    if (Validator.isNull(footerArticleId) && Validator.isNull(headerArticleId)) {

        if (_log.isWarnEnabled()) {
            _log.warn("No article ids found in preferences of portlet " + portletId);
        }/*from w ww .  j av a 2  s. com*/

        return StringPool.BLANK;
    }

    long footerArticleGroupId = GetterUtil.getLong(footerArticleValues[0]);
    long headerArticleGroupId = GetterUtil.getLong(headerArticleValues[0]);

    if ((footerArticleGroupId <= 0) && (headerArticleGroupId <= 0)) {
        if (_log.isWarnEnabled()) {
            _log.warn("No group ids found in preferences of portlet " + portletId);
        }

        return StringPool.BLANK;
    }

    List<JournalArticle> articles = new ArrayList<JournalArticle>(2);

    JournalArticle footerArticle = null;

    try {
        footerArticle = JournalArticleLocalServiceUtil.getLatestArticle(footerArticleGroupId, footerArticleId,
                WorkflowConstants.STATUS_APPROVED);

        articles.add(footerArticle);
    } catch (NoSuchArticleException nsae) {
        if (_log.isWarnEnabled()) {
            _log.warn("No approved article found with group id " + footerArticleGroupId + " and article id "
                    + footerArticleId);
        }
    }

    JournalArticle headerArticle = null;

    try {
        headerArticle = JournalArticleLocalServiceUtil.getLatestArticle(headerArticleGroupId, headerArticleId,
                WorkflowConstants.STATUS_APPROVED);

        articles.add(headerArticle);
    } catch (NoSuchArticleException nsae) {
        if (_log.isWarnEnabled()) {
            _log.warn("No approved article found with group id " + headerArticleGroupId + " and article id "
                    + headerArticleId);
        }
    }

    if ((footerArticle == null) && (headerArticle == null)) {
        return StringPool.BLANK;
    }

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("journal-content-data");

    Element dlFileEntryTypesElement = rootElement.addElement("dl-file-entry-types");
    Element dlFoldersElement = rootElement.addElement("dl-folders");
    Element dlFilesElement = rootElement.addElement("dl-file-entries");
    Element dlFileRanksElement = rootElement.addElement("dl-file-ranks");

    for (JournalArticle article : articles) {
        String path = JournalPortletDataHandlerImpl.getArticlePath(portletDataContext, article);

        Element articleElement = null;

        if (article == footerArticle) {
            articleElement = rootElement.addElement("footer-article");
        } else {
            articleElement = rootElement.addElement("header-article");
        }

        articleElement.addAttribute("path", path);

        JournalPortletDataHandlerImpl.exportArticle(portletDataContext, rootElement, rootElement, rootElement,
                dlFileEntryTypesElement, dlFoldersElement, dlFilesElement, dlFileRanksElement, article, false);
    }

    return document.formattedString();
}

From source file:com.liferay.portlet.softwarecatalog.service.impl.SCProductEntryLocalServiceImpl.java

License:Open Source License

protected void populatePluginPackageElement(Element el, SCProductEntry productEntry,
        SCProductVersion productVersion, String baseImageURL) throws SystemException {

    DocUtil.add(el, "name", productEntry.getName());

    String moduleId = ModuleId.toString(productEntry.getRepoGroupId(), productEntry.getRepoArtifactId(),
            productVersion.getVersion(), "war");

    DocUtil.add(el, "module-id", moduleId);

    DocUtil.add(el, "modified-date", Time.getRFC822(productVersion.getModifiedDate()));

    Element typesEl = el.addElement("types");

    DocUtil.add(typesEl, "type", productEntry.getType());

    Element tagsEl = el.addElement("tags");

    String[] tags = StringUtil.split(productEntry.getTags());

    for (int i = 0; i < tags.length; i++) {
        DocUtil.add(tagsEl, "tag", tags[i]);
    }//from   w  w w . ja v a2  s.c  om

    DocUtil.add(el, "short-description", productEntry.getShortDescription());

    if (Validator.isNotNull(productEntry.getLongDescription())) {
        DocUtil.add(el, "long-description", productEntry.getLongDescription());
    }

    if (Validator.isNotNull(productVersion.getChangeLog())) {
        DocUtil.add(el, "change-log", productVersion.getChangeLog());
    }

    if (Validator.isNotNull(productVersion.getDirectDownloadURL())) {
        DocUtil.add(el, "download-url", productVersion.getDirectDownloadURL());
    }

    DocUtil.add(el, "author", productEntry.getAuthor());

    Element screenshotsEl = el.addElement("screenshots");

    for (SCProductScreenshot screenshot : productEntry.getScreenshots()) {
        long thumbnailId = screenshot.getThumbnailId();
        long fullImageId = screenshot.getFullImageId();

        Element screenshotEl = screenshotsEl.addElement("screenshot");

        DocUtil.add(screenshotEl, "thumbnail-url", baseImageURL + "?img_id=" + thumbnailId + "&t="
                + WebServerServletTokenUtil.getToken(thumbnailId));
        DocUtil.add(screenshotEl, "large-image-url", baseImageURL + "?img_id=" + fullImageId + "&t="
                + WebServerServletTokenUtil.getToken(fullImageId));
    }

    Element licensesEl = el.addElement("licenses");

    for (SCLicense license : productEntry.getLicenses()) {
        Element licenseEl = licensesEl.addElement("license");

        licenseEl.addText(license.getName());
        licenseEl.addAttribute("osi-approved", String.valueOf(license.isOpenSource()));
    }

    Element liferayVersionsEl = el.addElement("liferay-versions");

    for (SCFrameworkVersion frameworkVersion : productVersion.getFrameworkVersions()) {

        DocUtil.add(liferayVersionsEl, "liferay-version", frameworkVersion.getName());
    }
}

From source file:com.liferay.portlet.softwarecatalog.service.impl.SCProductEntryLocalServiceImpl.java

License:Open Source License

protected void populateSettingsElement(Element el, Properties repoSettings) {

    if (repoSettings == null) {
        return;/*from w w  w.j  a  va 2  s . co m*/
    }

    for (Map.Entry<Object, Object> entry : repoSettings.entrySet()) {
        String name = (String) entry.getKey();
        String value = (String) entry.getValue();

        Element settingEl = el.addElement("setting");

        settingEl.addAttribute("name", name);
        settingEl.addAttribute("value", value);
    }
}

From source file:com.liferay.portlet.wiki.lar.WikiDisplayPortletDataHandlerImpl.java

License:Open Source License

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

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

    if (nodeId <= 0) {
        if (_log.isWarnEnabled()) {
            _log.warn("No node id found in preferences of portlet " + portletId);
        }//from ww w  .  j a va  2  s. com

        return StringPool.BLANK;
    }

    String title = portletPreferences.getValue("title", null);

    if (title == null) {
        if (_log.isWarnEnabled()) {
            _log.warn("No title found in preferences of portlet " + portletId);
        }

        return StringPool.BLANK;
    }

    WikiNode node = null;

    try {
        node = WikiNodeUtil.findByPrimaryKey(nodeId);
    } catch (NoSuchNodeException nsne) {
        if (_log.isWarnEnabled()) {
            _log.warn(nsne, nsne);
        }

        return StringPool.BLANK;
    }

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

    Document document = SAXReaderUtil.createDocument();

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

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

    Element nodesElement = rootElement.addElement("nodes");
    Element pagesElement = rootElement.addElement("pages");

    WikiPortletDataHandlerImpl.exportNode(portletDataContext, nodesElement, pagesElement, node);

    return document.formattedString();
}

From source file:com.liferay.portlet.wiki.lar.WikiPortletDataHandlerImpl.java

License:Open Source License

protected static void exportPage(PortletDataContext portletDataContext, Element nodesElement,
        Element pagesElement, Element dlFileEntryTypesElement, Element dlFoldersElement,
        Element dlFileEntriesElement, Element dlFileRanksElement, WikiPage page, boolean checkDateRange)
        throws Exception {

    if (!portletDataContext.isWithinDateRange(page.getModifiedDate())) {
        return;//  w ww . jav a  2 s  . co m
    }

    String path = getPagePath(portletDataContext, page);

    // Clone this page to make sure changes to its content are never
    // persisted

    page = (WikiPage) page.clone();

    Element pageElement = (Element) pagesElement.selectSingleNode("//page[@path='".concat(path).concat("']"));

    if (portletDataContext.isPathNotProcessed(path)) {
        if (pageElement == null) {
            pageElement = pagesElement.addElement("page");
        }

        String content = JournalPortletDataHandlerImpl.exportReferencedContent(portletDataContext,
                dlFileEntryTypesElement, dlFoldersElement, dlFileEntriesElement, dlFileRanksElement,
                pageElement, page.getContent());

        page.setContent(content);

        String imagePath = getPageImagePath(portletDataContext, page);

        pageElement.addAttribute("image-path", imagePath);

        if (portletDataContext.getBooleanParameter(_NAMESPACE, "attachments") && page.isHead()) {

            String[] attachmentsFiles = page.getAttachmentsFiles();

            for (int i = 0; i < attachmentsFiles.length; i++) {
                String attachment = attachmentsFiles[i];

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

                int pos = attachment.lastIndexOf(StringPool.SLASH);

                String name = attachment.substring(pos + 1);

                attachmentElement.addAttribute("name", name);

                String binPath = getPageAttachementBinPath(portletDataContext, page, i);

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

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

                portletDataContext.addZipEntry(binPath, bytes);
            }

            page.setAttachmentsDir(page.getAttachmentsDir());
        }

        portletDataContext.addClassedModel(pageElement, path, page, _NAMESPACE);
    }

    exportNode(portletDataContext, nodesElement, page.getNodeId());
}

From source file:com.liferay.portlet.wiki.lar.WikiPortletDataHandlerImpl.java

License:Open Source License

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

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

    Document document = SAXReaderUtil.createDocument();

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

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

    Element nodesElement = rootElement.addElement("nodes");
    Element pagesElement = rootElement.addElement("pages");

    List<WikiNode> nodes = WikiNodeUtil.findByGroupId(portletDataContext.getScopeGroupId());

    for (WikiNode node : nodes) {
        exportNode(portletDataContext, nodesElement, pagesElement, node);
    }/*  ww  w.  j a v  a2s. c  om*/

    return document.formattedString();
}