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.polls.lar.PollsPortletDataHandlerImpl.java

License:Open Source License

protected static void exportVote(PortletDataContext portletDataContext, Element questionsElement,
        PollsVote vote) throws Exception {

    String path = getVotePath(portletDataContext, vote);

    if (!portletDataContext.isPathNotProcessed(path)) {
        return;/*from   w  ww .  jav a  2  s. com*/
    }

    Element voteElement = questionsElement.addElement("vote");

    portletDataContext.addClassedModel(voteElement, path, vote, _NAMESPACE);
}

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);
    }/*from w w w. j  av a  2s. c om*/

    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);
        }//  w w w  . j  a v a  2  s .  co m

        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

public String getRepositoryXML(long groupId, String version, String baseImageURL, Date oldestDate,
        int maxNumOfVersions, Properties repoSettings) throws SystemException {

    Document doc = SAXReaderUtil.createDocument();

    doc.setXMLEncoding(StringPool.UTF8);

    Element root = doc.addElement("plugin-repository");

    Element settingsEl = root.addElement("settings");

    populateSettingsElement(settingsEl, repoSettings);

    List<SCProductEntry> productEntries = scProductEntryPersistence.findByGroupId(groupId);

    for (SCProductEntry productEntry : productEntries) {
        if (Validator.isNull(productEntry.getRepoGroupId())
                || Validator.isNull(productEntry.getRepoArtifactId())) {

            continue;
        }/*from www .  ja  v a2s  .  c  om*/

        List<SCProductVersion> productVersions = scProductVersionPersistence
                .findByProductEntryId(productEntry.getProductEntryId());

        for (int i = 0; i < productVersions.size(); i++) {
            SCProductVersion productVersion = productVersions.get(i);

            if ((maxNumOfVersions > 0) && (maxNumOfVersions < (i + 1))) {
                break;
            }

            if (!productVersion.isRepoStoreArtifact()) {
                continue;
            }

            if ((oldestDate != null) && (oldestDate.after(productVersion.getModifiedDate()))) {

                continue;
            }

            if (Validator.isNotNull(version)
                    && !isVersionSupported(version, productVersion.getFrameworkVersions())) {

                continue;
            }

            Element el = root.addElement("plugin-package");

            populatePluginPackageElement(el, productEntry, productVersion, baseImageURL);
        }
    }

    return doc.asXML();
}

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 ww  w.  j  a v  a  2 s.  c  o m

    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;/*w  w  w . j  a va  2  s  . c o  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  av a2 s  . c om*/

        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

public static void exportNode(PortletDataContext portletDataContext, Element nodesElement, Element pagesElement,
        WikiNode node) throws Exception {

    if (portletDataContext.isWithinDateRange(node.getModifiedDate())) {
        String path = getNodePath(portletDataContext, node);

        if (portletDataContext.isPathNotProcessed(path)) {
            Element nodeElement = nodesElement.addElement("node");

            portletDataContext.addClassedModel(nodeElement, path, node, _NAMESPACE);
        }/* w  w  w.j  a  va 2 s  .  c  o  m*/
    }

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

    List<WikiPage> pages = WikiPageUtil.findByN_S(node.getNodeId(), WorkflowConstants.STATUS_APPROVED,
            QueryUtil.ALL_POS, QueryUtil.ALL_POS, new PageVersionComparator(true));

    for (WikiPage page : pages) {
        exportPage(portletDataContext, nodesElement, pagesElement, dlFileEntryTypesElement, dlFoldersElement,
                dlFileEntriesElement, dlFileRanksElement, page, true);
    }
}

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

License:Open Source License

protected static void exportNode(PortletDataContext portletDataContext, Element nodesElement, long nodeId)
        throws Exception {

    if (!portletDataContext.hasDateRange()) {
        return;/*from   w  w w  .j  a va  2 s  .c  o m*/
    }

    WikiNode node = WikiNodeUtil.findByPrimaryKey(nodeId);

    String path = getNodePath(portletDataContext, node);

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

    Element nodeElement = nodesElement.addElement("node");

    portletDataContext.addClassedModel(nodeElement, path, node, _NAMESPACE);
}

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;/*from ww  w  .  j a va  2 s .  c om*/
    }

    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());
}