Example usage for com.liferay.portal.kernel.xml SAXReaderUtil createDocument

List of usage examples for com.liferay.portal.kernel.xml SAXReaderUtil createDocument

Introduction

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

Prototype

public static Document createDocument() 

Source Link

Usage

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  . c  o  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

@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  a  va  2  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  . java2  s.c o  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;
        }/*  w w w  .jav a2  s . c  o m*/

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

        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

@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);
    }/*www  .j  a v a2  s .  com*/

    return document.formattedString();
}

From source file:com.liferay.samplehibernate.FoodItemComponentImpl.java

License:Open Source License

public String getXml(List list) {
    Document doc = SAXReaderUtil.createDocument();

    Element root = doc.addElement("result");

    for (Object obj : list) {
        BeanToXMLUtil.addBean(obj, root);
    }/* w  w  w . java  2  s. c  om*/

    return doc.asXML();
}

From source file:com.liferay.wsrp.admin.lar.AdminPortletDataHandlerImpl.java

License:Open Source License

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

    Document document = SAXReaderUtil.createDocument();

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

    if (portletDataContext.getBooleanParameter(_NAMESPACE, "wsrp-producers")) {

        Element wsrpProducersElement = rootElement.addElement("wsrp-producers");

        List<WSRPProducer> wsrpProducers = WSRPProducerLocalServiceUtil
                .getWSRPProducers(portletDataContext.getCompanyId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS);

        for (WSRPProducer wsrpProducer : wsrpProducers) {
            exportWSRPProducer(portletDataContext, wsrpProducersElement, wsrpProducer);
        }//from  w ww.jav a2  s  .  c o  m
    }

    if (portletDataContext.getBooleanParameter(_NAMESPACE, "wsrp-consumers")) {

        Element wsrpConsumersElement = rootElement.addElement("wsrp-consumers");

        List<WSRPConsumer> wsrpConsumers = WSRPConsumerLocalServiceUtil
                .getWSRPConsumers(portletDataContext.getCompanyId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS);

        for (WSRPConsumer wsrpConsumer : wsrpConsumers) {
            exportWSRPConsumer(portletDataContext, wsrpConsumersElement, wsrpConsumer);
        }
    }

    return document.formattedString();
}

From source file:com.playtech.portal.platform.portlet.orgsettings.lar.OrgSettingsDataHandler.java

protected String invokeExportData(final long companyId, final long groupId) throws IOException {
    /*// ww  w  .j a  va 2s  .  c o m
    * <organization-expando-attributes>
    *   <expando>
    *     <name type="java.lang.Boolean etc"> org_x_expando </name>
    *     <value> aa </value>
    *     <value> oo </value>
    *   </expando>
    * </organization-expando-attributes>
    */

    Map<String, String> attributes = getPropertiesService().getAllPartitionPropertiesMap(companyId,
            PartitionNames.GROUP, groupId);

    Document doc = SAXReaderUtil.createDocument();

    Element expandoRoot = doc.addElement(NAMESPACE_EXPANDO);

    for (Map.Entry<String, String> entry : attributes.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();

        Element expando = expandoRoot.addElement(ELEM_EXPANDO);
        Element name = expando.addElement(ELEM_NAME);
        name.addAttribute(ATTR_TYPE, value.getClass().getName());
        name.setText(key);
        expando.addElement(ELEM_VALUE).setText(value);
        log.debug("Exporting expando {}", key);
    }

    doLookupServiceExport(expandoRoot, companyId, groupId);

    return doc.formattedString();
}

From source file:it.smc.calendar.sync.caldav.methods.BasePropMethodImpl.java

License:Open Source License

protected int writeResponseXML(WebDAVRequest webDAVRequest, Set<QName> props) throws Exception {

    WebDAVStorage storage = webDAVRequest.getWebDAVStorage();

    long depth = WebDAVUtil.getDepth(webDAVRequest.getHttpServletRequest());

    Document document = SAXReaderUtil.createDocument();

    Element multistatusElement = SAXReaderUtil.createElement(CalDAVProps.createQName("multistatus"));

    document.setRootElement(multistatusElement);

    Resource resource = storage.getResource(webDAVRequest);

    if (resource != null) {
        addResponse(storage, webDAVRequest, resource, props, multistatusElement, depth);

        String xml = document.formattedString(StringPool.FOUR_SPACES);

        if (_log.isDebugEnabled()) {
            _log.debug("Response XML\n" + xml);
        }//from   ww  w .ja v a  2  s  . co  m

        // Set the status prior to writing the XML

        int status = WebDAVUtil.SC_MULTI_STATUS;

        HttpServletResponse response = webDAVRequest.getHttpServletResponse();

        response.setContentType(ContentTypes.TEXT_XML_UTF8);
        response.setStatus(status);

        try {
            ServletResponseUtil.write(response, xml);

            response.flushBuffer();
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn(e);
            }
        }

        return status;
    } else {
        if (_log.isDebugEnabled()) {
            _log.debug("No resource found for " + storage.getRootPath() + webDAVRequest.getPath());
        }

        return HttpServletResponse.SC_NOT_FOUND;
    }
}