Example usage for com.liferay.portal.kernel.xml Document getRootElement

List of usage examples for com.liferay.portal.kernel.xml Document getRootElement

Introduction

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

Prototype

public Element getRootElement();

Source Link

Usage

From source file:com.acs.DDMXSD.java

License:Open Source License

public String getHTML(PageContext pageContext, String xml, Fields fields, String namespace, String mode,
        boolean readOnly, Locale locale) throws Exception {

    Document document = SAXReaderUtil.read(xml);

    return getHTML(pageContext, document.getRootElement(), fields, namespace, mode, readOnly, locale);
}

From source file:com.acs.DDMXSD.java

License:Open Source License

public JSONArray getJSONArray(Document document) throws JSONException {
    return getJSONArray(document.getRootElement());
}

From source file:com.custom.portal.verify.CustomVerifyDynamicDataMapping.java

License:Open Source License

protected String updateXSD(String xsd) throws Exception {
    Document document = SAXReaderUtil.read(xsd);

    Element rootElement = document.getRootElement();

    List<Element> dynamicElementElements = rootElement.elements("dynamic-element");

    for (Element dynamicElementElement : dynamicElementElements) {
        updateXSDDynamicElement(dynamicElementElement);
    }//  w w w. j  av  a 2  s  .  c  o  m

    return document.asXML();
}

From source file:com.hrportal.service.impl.WebArticleHelperLocalServiceImpl.java

License:Open Source License

public Document generateAssetCategoryHierarchyDocument() {
    Document doc = SAXReaderUtil.createDocument();
    doc.add(SAXReaderUtil.createElement("v"));
    Element vocabulariesElem = doc.getRootElement();
    ServiceContext sc = ServiceContextThreadLocal.getServiceContext();
    HashMap<String, Element> map = new HashMap<String, Element>();

    try {/*  w  ww .  j a v  a2 s .c  o m*/
        //         Group globalGroup = GroupLocalServiceUtil.getCompanyGroup(sc.getCompanyId());
        List<AssetVocabulary> vocabularies = AssetVocabularyLocalServiceUtil
                .getCompanyVocabularies(sc.getCompanyId());

        for (AssetVocabulary vocab : vocabularies) {
            Element vocabElem = generateAssetVocabularyElement(vocab);
            vocabulariesElem.add(vocabElem);
            map.put("v".concat(String.valueOf(vocab.getVocabularyId())), vocabElem);
        }

        List<AssetCategory> catList = AssetCategoryLocalServiceUtil.getCategories();

        for (AssetCategory cat : catList) {
            Element catElem = generateAssetCategoryElement(cat);
            map.put(String.valueOf(cat.getCategoryId()), catElem);
        }

        for (AssetCategory cat : catList) {
            Element catElem = map.get(String.valueOf(cat.getCategoryId()));
            Element vocabElem = map.get("v".concat(String.valueOf(cat.getVocabularyId())));
            Element parentCatElem = map.get(String.valueOf(cat.getParentCategoryId()));

            if (parentCatElem != null) {
                parentCatElem.add(catElem);
            } else {
                vocabElem.add(catElem);
            }
        }
    } catch (Exception e) {
        _log.error("", e);
    }

    return doc;
}

From source file:com.liferay.application.list.deploy.hot.LegacyPortletPanelAppHotDeployListener.java

License:Open Source License

protected List<Dictionary<String, Object>> getPropertiesList(HotDeployEvent hotDeployEvent)
        throws DocumentException, IOException {

    ServletContext servletContext = hotDeployEvent.getServletContext();

    String xml = _http.URLtoString(servletContext.getResource("/WEB-INF/liferay-portlet.xml"));

    if (xml == null) {
        return Collections.emptyList();
    }//w  w  w .j av a2s  . com

    List<Dictionary<String, Object>> propertiesList = new ArrayList<>();

    Document document = UnsecureSAXReaderUtil.read(xml, true);

    Element rootElement = document.getRootElement();

    Iterator<Element> iterator = rootElement.elementIterator("portlet");

    while (iterator.hasNext()) {
        Element portletElement = iterator.next();

        String controlPanelEntryCategory = portletElement.elementText("control-panel-entry-category");

        if (Validator.isNull(controlPanelEntryCategory)) {
            continue;
        }

        controlPanelEntryCategory = PortletCategoryUtil.getPortletCategoryKey(controlPanelEntryCategory);

        Dictionary<String, Object> properties = new HashMapDictionary<>();

        String portletName = portletElement.elementText("portlet-name");

        String portletId = getPortletId(hotDeployEvent.getServletContextName(), portletName);

        properties.put("panel.app.portlet.id", portletId);

        properties.put("panel.category.key", controlPanelEntryCategory);

        String controlPanelEntryWeight = portletElement.elementText("control-panel-entry-weight");

        if (Validator.isNotNull(controlPanelEntryWeight)) {
            int panelAppOrder = (int) Math.ceil(GetterUtil.getDouble(controlPanelEntryWeight) * 100);

            properties.put("panel.app.order", panelAppOrder);
        }

        propertiesList.add(properties);
    }

    return propertiesList;
}

From source file:com.liferay.asset.publisher.internal.util.AssetPublisherHelperImpl.java

License:Open Source License

@Override
public List<AssetEntry> getAssetEntries(PortletRequest portletRequest, PortletPreferences portletPreferences,
        PermissionChecker permissionChecker, long[] groupIds, boolean deleteMissingAssetEntries,
        boolean checkPermission, boolean includeNonVisibleAssets, int type) throws Exception {

    String[] assetEntryXmls = portletPreferences.getValues("assetEntryXml", new String[0]);

    List<AssetEntry> assetEntries = new ArrayList<>();

    List<String> missingAssetEntryUuids = new ArrayList<>();

    for (String assetEntryXml : assetEntryXmls) {
        Document document = SAXReaderUtil.read(assetEntryXml);

        Element rootElement = document.getRootElement();

        String assetEntryUuid = rootElement.elementText("asset-entry-uuid");

        String assetEntryType = rootElement.elementText("asset-entry-type");

        AssetRendererFactory<?> assetRendererFactory = AssetRendererFactoryRegistryUtil
                .getAssetRendererFactoryByClassName(assetEntryType);

        String portletId = assetRendererFactory.getPortletId();

        AssetEntry assetEntry = null;/*  w  ww  . jav  a2s  .c  om*/

        for (long groupId : groupIds) {
            Group group = _groupLocalService.fetchGroup(groupId);

            if (group.isStagingGroup() && !group.isStagedPortlet(portletId)) {

                groupId = group.getLiveGroupId();
            }

            assetEntry = _assetEntryLocalService.fetchEntry(groupId, assetEntryUuid);

            if (assetEntry != null) {
                break;
            }
        }

        if (assetEntry == null) {
            if (deleteMissingAssetEntries) {
                missingAssetEntryUuids.add(assetEntryUuid);
            }

            continue;
        }

        if (!assetEntry.isVisible() && !includeNonVisibleAssets) {
            continue;
        }

        assetRendererFactory = AssetRendererFactoryRegistryUtil
                .getAssetRendererFactoryByClassName(assetEntry.getClassName());

        AssetRenderer<?> assetRenderer = assetRendererFactory.getAssetRenderer(assetEntry.getClassPK(), type);

        if (!assetRendererFactory.isActive(permissionChecker.getCompanyId())) {

            if (deleteMissingAssetEntries) {
                missingAssetEntryUuids.add(assetEntryUuid);
            }

            continue;
        }

        if (checkPermission) {
            if (!assetRenderer.isDisplayable() && !includeNonVisibleAssets) {

                continue;
            } else if (!assetRenderer.hasViewPermission(permissionChecker)) {
                assetRenderer = assetRendererFactory.getAssetRenderer(assetEntry.getClassPK(),
                        AssetRendererFactory.TYPE_LATEST_APPROVED);

                if (!assetRenderer.hasViewPermission(permissionChecker)) {
                    continue;
                }
            }
        }

        assetEntries.add(assetEntry);
    }

    if (deleteMissingAssetEntries) {
        _removeAndStoreSelection(missingAssetEntryUuids, portletPreferences);

        if (!missingAssetEntryUuids.isEmpty()) {
            SessionMessages.add(portletRequest, "deletedMissingAssetEntries", missingAssetEntryUuids);
        }
    }

    return assetEntries;
}

From source file:com.liferay.asset.publisher.internal.util.AssetPublisherHelperImpl.java

License:Open Source License

private void _removeAndStoreSelection(List<String> assetEntryUuids, PortletPreferences portletPreferences)
        throws Exception {

    if (assetEntryUuids.isEmpty()) {
        return;/*from www  . jav a 2s  . com*/
    }

    String[] assetEntryXmls = portletPreferences.getValues("assetEntryXml", new String[0]);

    List<String> assetEntryXmlsList = ListUtil.fromArray(assetEntryXmls);

    Iterator<String> itr = assetEntryXmlsList.iterator();

    while (itr.hasNext()) {
        String assetEntryXml = itr.next();

        Document document = SAXReaderUtil.read(assetEntryXml);

        Element rootElement = document.getRootElement();

        String assetEntryUuid = rootElement.elementText("asset-entry-uuid");

        if (assetEntryUuids.contains(assetEntryUuid)) {
            itr.remove();
        }
    }

    portletPreferences.setValues("assetEntryXml",
            assetEntryXmlsList.toArray(new String[assetEntryXmlsList.size()]));

    portletPreferences.store();
}

From source file:com.liferay.asset.publisher.web.upgrade.v1_0_0.UpgradePortletPreferences.java

License:Open Source License

protected void upgradeUuids(String[] assetEntryXmls) throws Exception {
    for (int i = 0; i < assetEntryXmls.length; i++) {
        String assetEntry = assetEntryXmls[i];

        Document document = _saxReader.read(assetEntry);

        Element rootElement = document.getRootElement();

        Element assetTypeElementUuid = rootElement.element("asset-entry-uuid");

        if (assetTypeElementUuid == null) {
            continue;
        }//from  ww  w. j  a v a 2  s  .  co  m

        String journalArticleResourceUuid = getJournalArticleResourceUuid(
                assetTypeElementUuid.getStringValue());

        if (journalArticleResourceUuid == null) {
            continue;
        }

        rootElement.remove(assetTypeElementUuid);

        assetTypeElementUuid.setText(journalArticleResourceUuid);

        rootElement.add(assetTypeElementUuid);

        document.setRootElement(rootElement);

        assetEntryXmls[i] = document.formattedString(StringPool.BLANK);
    }
}

From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java

License:Open Source License

public static List<AssetEntry> getAssetEntries(PortletRequest portletRequest,
        PortletPreferences portletPreferences, PermissionChecker permissionChecker, long[] groupIds,
        boolean deleteMissingAssetEntries, boolean checkPermission, boolean includeNonVisibleAssets, int type)
        throws Exception {

    String[] assetEntryXmls = portletPreferences.getValues("assetEntryXml", new String[0]);

    List<AssetEntry> assetEntries = new ArrayList<>();

    List<String> missingAssetEntryUuids = new ArrayList<>();

    for (String assetEntryXml : assetEntryXmls) {
        Document document = SAXReaderUtil.read(assetEntryXml);

        Element rootElement = document.getRootElement();

        String assetEntryUuid = rootElement.elementText("asset-entry-uuid");

        String assetEntryType = rootElement.elementText("asset-entry-type");

        AssetRendererFactory<?> assetRendererFactory = AssetRendererFactoryRegistryUtil
                .getAssetRendererFactoryByClassName(assetEntryType);

        String portletId = assetRendererFactory.getPortletId();

        AssetEntry assetEntry = null;/*from w  ww. j  a v a  2 s. c  o  m*/

        for (long groupId : groupIds) {
            Group group = _groupLocalService.fetchGroup(groupId);

            if (group.isStagingGroup() && !group.isStagedPortlet(portletId)) {

                groupId = group.getLiveGroupId();
            }

            assetEntry = _assetEntryLocalService.fetchEntry(groupId, assetEntryUuid);

            if (assetEntry != null) {
                break;
            }
        }

        if (assetEntry == null) {
            if (deleteMissingAssetEntries) {
                missingAssetEntryUuids.add(assetEntryUuid);
            }

            continue;
        }

        if (!assetEntry.isVisible() && !includeNonVisibleAssets) {
            continue;
        }

        assetRendererFactory = AssetRendererFactoryRegistryUtil
                .getAssetRendererFactoryByClassName(assetEntry.getClassName());

        AssetRenderer<?> assetRenderer = assetRendererFactory.getAssetRenderer(assetEntry.getClassPK(), type);

        if (!assetRendererFactory.isActive(permissionChecker.getCompanyId())) {

            if (deleteMissingAssetEntries) {
                missingAssetEntryUuids.add(assetEntryUuid);
            }

            continue;
        }

        if (checkPermission) {
            if (!assetRenderer.isDisplayable() && !includeNonVisibleAssets) {

                continue;
            } else if (!assetRenderer.hasViewPermission(permissionChecker)) {
                assetRenderer = assetRendererFactory.getAssetRenderer(assetEntry.getClassPK(),
                        AssetRendererFactory.TYPE_LATEST_APPROVED);

                if (!assetRenderer.hasViewPermission(permissionChecker)) {
                    continue;
                }
            }
        }

        assetEntries.add(assetEntry);
    }

    if (deleteMissingAssetEntries) {
        removeAndStoreSelection(missingAssetEntryUuids, portletPreferences);

        if (!missingAssetEntryUuids.isEmpty()) {
            SessionMessages.add(portletRequest, "deletedMissingAssetEntries", missingAssetEntryUuids);
        }
    }

    return assetEntries;
}

From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java

License:Open Source License

public static void removeAndStoreSelection(List<String> assetEntryUuids, PortletPreferences portletPreferences)
        throws Exception {

    if (assetEntryUuids.isEmpty()) {
        return;//from  www  .  j  a  v a 2s.  c om
    }

    String[] assetEntryXmls = portletPreferences.getValues("assetEntryXml", new String[0]);

    List<String> assetEntryXmlsList = ListUtil.fromArray(assetEntryXmls);

    Iterator<String> itr = assetEntryXmlsList.iterator();

    while (itr.hasNext()) {
        String assetEntryXml = itr.next();

        Document document = SAXReaderUtil.read(assetEntryXml);

        Element rootElement = document.getRootElement();

        String assetEntryUuid = rootElement.elementText("asset-entry-uuid");

        if (assetEntryUuids.contains(assetEntryUuid)) {
            itr.remove();
        }
    }

    portletPreferences.setValues("assetEntryXml",
            assetEntryXmlsList.toArray(new String[assetEntryXmlsList.size()]));

    portletPreferences.store();
}