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

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

Introduction

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

Prototype

public String elementText(String name);

Source Link

Usage

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 ww .j a  va  2  s .  co m*/

    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;/*from www  . j av  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.internal.util.AssetPublisherHelperImpl.java

License:Open Source License

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

    if (assetEntryUuids.isEmpty()) {
        return;/* w ww .  j  ava2s  .co m*/
    }

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

    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.calendar.web.internal.upgrade.v1_1_0.UpgradePortalPreferences.java

License:Open Source License

protected void populatePreferenceNamesMap(String preferences) throws Exception {

    Document document = SAXReaderUtil.read(preferences);

    Element rootElement = document.getRootElement();

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

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

        String preferenceName = preferenceElement.elementText("name");

        String newPreferenceName = null;

        if (!_preferenceNamesMap.containsKey(preferenceName)) {
            newPreferenceName = getNewPreferenceName(preferenceName);
        }/*from   w  w  w.j a  v  a  2  s.com*/

        if (newPreferenceName != null) {
            _preferenceNamesMap.put(preferenceName, newPreferenceName);
        }
    }
}

From source file:com.liferay.calendar.web.upgrade.v1_1_0.test.UpgradePortalPreferencesTest.java

License:Open Source License

protected String getPreference(String preferencesXML, String namespace, String name) throws DocumentException {

    String value = null;//w w w. ja v  a2  s  .  c  o m

    Document document = SAXReaderUtil.read(preferencesXML);

    Element rootElement = document.getRootElement();

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

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

        String preferenceName = preferenceElement.elementText("name");

        if (preferenceName.equals(namespace + "#" + name)) {
            value = preferenceElement.elementText("value");
        }
    }

    return value;
}

From source file:com.liferay.document.library.internal.instance.lifecycle.AddDefaultDocumentLibraryStructuresPortalInstanceLifecycleListener.java

License:Open Source License

protected void addDLRawMetadataStructures(long userId, long groupId, ServiceContext serviceContext)
        throws Exception {

    Locale locale = _portal.getSiteDefaultLocale(groupId);

    String xsd = buildDLRawMetadataXML(RawMetadataProcessorUtil.getFields(), locale);

    Document document = UnsecureSAXReaderUtil.read(new StringReader(xsd));

    Element rootElement = document.getRootElement();

    List<Element> structureElements = rootElement.elements("structure");

    for (Element structureElement : structureElements) {
        String name = structureElement.elementText("name");
        String description = structureElement.elementText("description");

        Element structureElementRootElement = structureElement.element("root");

        String structureElementRootXML = structureElementRootElement.asXML();

        DDMStructure ddmStructure = _ddmStructureLocalService.fetchStructure(groupId,
                _portal.getClassNameId(RawMetadataProcessor.class), name);

        DDMForm ddmForm = _ddmFormXSDDeserializer.deserialize(structureElementRootXML);

        if (ddmStructure != null) {
            ddmStructure.setDDMForm(ddmForm);

            _ddmStructureLocalService.updateDDMStructure(ddmStructure);
        } else {//from   w w w  . j  a v  a  2 s  .c o m
            Map<Locale, String> nameMap = new HashMap<>();

            nameMap.put(locale, name);

            Map<Locale, String> descriptionMap = new HashMap<>();

            descriptionMap.put(locale, description);

            DDMFormLayout ddmFormLayout = _ddm.getDefaultDDMFormLayout(ddmForm);

            _ddmStructureLocalService.addStructure(userId, groupId,
                    DDMStructureConstants.DEFAULT_PARENT_STRUCTURE_ID,
                    _portal.getClassNameId(RawMetadataProcessor.class), name, nameMap, descriptionMap, ddmForm,
                    ddmFormLayout, StorageType.JSON.toString(), DDMStructureConstants.TYPE_DEFAULT,
                    serviceContext);
        }
    }
}

From source file:com.liferay.dynamic.data.mapping.internal.util.DefaultDDMStructureHelperImpl.java

License:Open Source License

@Override
public void addDDMStructures(long userId, long groupId, long classNameId, ClassLoader classLoader,
        String fileName, ServiceContext serviceContext) throws Exception {

    Locale locale = _portal.getSiteDefaultLocale(groupId);

    List<Element> structureElements = getDDMStructures(classLoader, fileName, locale);

    for (Element structureElement : structureElements) {
        boolean dynamicStructure = GetterUtil.getBoolean(structureElement.elementText("dynamic-structure"));

        if (dynamicStructure) {
            continue;
        }/* w  w  w  .j av a  2s . com*/

        String name = structureElement.elementText("name");

        String description = structureElement.elementText("description");

        String ddmStructureKey = name;

        DDMStructure ddmStructure = _ddmStructureLocalService.fetchStructure(groupId, classNameId,
                ddmStructureKey);

        if (ddmStructure != null) {
            continue;
        }

        if (name.equals(DLFileEntryTypeConstants.NAME_IG_IMAGE)
                && !UpgradeProcessUtil.isCreateIGImageDocumentType()) {

            continue;
        }

        String ddmTemplateKey = name;

        Map<Locale, String> nameMap = new HashMap<>();
        Map<Locale, String> descriptionMap = new HashMap<>();

        for (Locale curLocale : LanguageUtil.getAvailableLocales(groupId)) {
            nameMap.put(curLocale, LanguageUtil.get(curLocale, name));
            descriptionMap.put(curLocale, LanguageUtil.get(curLocale, description));
        }

        DDMForm ddmForm = getDDMForm(structureElement, locale);

        DDMFormLayout ddmFormLayout = getDDMFormLayout(structureElement, ddmForm);

        serviceContext.setAttribute("status", WorkflowConstants.STATUS_APPROVED);

        ddmStructure = _ddmStructureLocalService.addStructure(userId, groupId,
                DDMStructureConstants.DEFAULT_PARENT_STRUCTURE_ID, classNameId, ddmStructureKey, nameMap,
                descriptionMap, ddmForm, ddmFormLayout, StorageType.JSON.toString(),
                DDMStructureConstants.TYPE_DEFAULT, serviceContext);

        Element templateElement = structureElement.element("template");

        if (templateElement == null) {
            continue;
        }

        String templateFileName = templateElement.elementText("file-name");

        String script = StringUtil.read(classLoader,
                FileUtil.getPath(fileName) + StringPool.SLASH + templateFileName);

        boolean cacheable = GetterUtil.getBoolean(templateElement.elementText("cacheable"));

        _ddmTemplateLocalService.addTemplate(userId, groupId, _portal.getClassNameId(DDMStructure.class),
                ddmStructure.getStructureId(), ddmStructure.getClassNameId(), ddmTemplateKey, nameMap, null,
                DDMTemplateConstants.TEMPLATE_TYPE_DISPLAY, DDMTemplateConstants.TEMPLATE_MODE_CREATE,
                TemplateConstants.LANG_TYPE_FTL, script, cacheable, false, StringPool.BLANK, null,
                serviceContext);
    }
}

From source file:com.liferay.dynamic.data.mapping.internal.util.DefaultDDMStructureHelperImpl.java

License:Open Source License

@Override
public String getDynamicDDMStructureDefinition(ClassLoader classLoader, String fileName,
        String dynamicDDMStructureName, Locale locale) throws Exception {

    List<Element> structureElements = getDDMStructures(classLoader, fileName, locale);

    for (Element structureElement : structureElements) {
        boolean dynamicStructure = GetterUtil.getBoolean(structureElement.elementText("dynamic-structure"));

        if (!dynamicStructure) {
            continue;
        }//from www. jav  a2  s . c o m

        String name = structureElement.elementText("name");

        if (!name.equals(dynamicDDMStructureName)) {
            continue;
        }

        Element structureElementRootElement = structureElement.element("root");

        return structureElementRootElement.asXML();
    }

    return null;
}