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

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

Introduction

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

Prototype

public String attributeValue(String name);

Source Link

Usage

From source file:com.acs.DDMXSD.java

License:Open Source License

public JSONArray getJSONArray(Element element) throws JSONException {
    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    Document document = element.getDocument();

    String defaultLocale = LocalizationUtil.getDefaultLocale(document.asXML());

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

    for (Element dynamicElementElement : dynamicElementElements) {
        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
        JSONObject localizationMapJSONObject = JSONFactoryUtil.createJSONObject();

        List<Element> metadataElements = dynamicElementElement.elements("meta-data");

        for (Element metadataElement : metadataElements) {
            if (metadataElement == null) {
                continue;
            }/*from   w w w .  java  2  s .  co  m*/

            String locale = metadataElement.attributeValue("locale");

            JSONObject localeMap = JSONFactoryUtil.createJSONObject();

            localizationMapJSONObject.put(locale, localeMap);

            for (Element metadataEntryElement : metadataElement.elements()) {

                String attributeName = metadataEntryElement.attributeValue("name");
                String attributeValue = metadataEntryElement.getText();

                localeMap.put(attributeName, attributeValue);

                if (defaultLocale.equals(locale)) {
                    jsonObject.put(attributeName, attributeValue);
                }
            }
        }

        jsonObject.put("localizationMap", localizationMapJSONObject);

        for (Attribute attribute : dynamicElementElement.attributes()) {
            jsonObject.put(attribute.getName(), attribute.getValue());
        }

        jsonObject.put("id", dynamicElementElement.attributeValue("name"));

        JSONArray hiddenAttributesJSONArray = JSONFactoryUtil.createJSONArray();

        String type = jsonObject.getString("type");

        if (type.equals(_TYPE_CHECKBOX)) {
            hiddenAttributesJSONArray.put("required");
        }

        if (type.equals(_TYPE_DDM_FILEUPLOAD)) {
            hiddenAttributesJSONArray.put("predefinedValue");
        }

        hiddenAttributesJSONArray.put("readOnly");

        jsonObject.put("hiddenAttributes", hiddenAttributesJSONArray);

        String key = "fields";

        if (type.equals(_TYPE_RADIO) || type.equals(_TYPE_SELECT)) {
            key = "options";

            String predefinedValue = jsonObject.getString("predefinedValue");

            jsonObject.put("predefinedValue", JSONFactoryUtil.createJSONArray(predefinedValue));
        }

        jsonObject.put(key, getJSONArray(dynamicElementElement));

        jsonArray.put(jsonObject);
    }

    return jsonArray;
}

From source file:com.acs.DDMXSD.java

License:Open Source License

protected Map<String, Object> getFieldContext(Element dynamicElementElement, Locale locale) {

    Document document = dynamicElementElement.getDocument();

    String[] availableLocales = LocalizationUtil.getAvailableLocales(document.asXML());

    String defaultLanguageId = LocalizationUtil.getDefaultLocale(document.asXML());

    String languageId = LocaleUtil.toLanguageId(locale);

    if (!ArrayUtil.contains(availableLocales, languageId)) {
        languageId = defaultLanguageId;// ww  w  . j a v  a2s  . c  o m
    }

    Element metadataElement = (Element) dynamicElementElement
            .selectSingleNode("meta-data[@locale='" + languageId + "']");

    Map<String, Object> field = new HashMap<String, Object>();

    if (metadataElement != null) {
        for (Element metadataEntry : metadataElement.elements()) {
            field.put(metadataEntry.attributeValue("name"), metadataEntry.getText());
        }
    }

    for (Attribute attribute : dynamicElementElement.attributes()) {
        field.put(attribute.getName(), attribute.getValue());
    }

    return field;
}

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

License:Open Source License

protected boolean hasDefaultMetadataElement(Element dynamicElementElement, String defaultLanguageId) {

    List<Element> metadataElements = dynamicElementElement.elements("meta-data");

    for (Element metadataElement : metadataElements) {
        String languageId = metadataElement.attributeValue("locale");

        if (languageId.equals(defaultLanguageId)) {
            return true;
        }/*from   w ww  .jav a  2  s . c  om*/
    }

    return false;
}

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

License:Open Source License

protected void updateXSDDynamicElement(Element element) {
    String dataType = element.attributeValue("dataType");

    if (Validator.equals(dataType, "file-upload")) {
        element.addAttribute("dataType", "document-library");
        element.addAttribute("type", "ddm-documentlibrary");
    }/*w  w  w. jav a2 s  .c  o  m*/

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

    for (Element dynamicElementElement : dynamicElementElements) {
        updateXSDDynamicElement(dynamicElementElement);
    }
}

From source file:com.liferay.adaptive.media.blogs.internal.exportimport.content.processor.AdaptiveMediaEmbeddedReferenceSetFactory.java

License:Open Source License

public AdaptiveMediaEmbeddedReferenceSet create(PortletDataContext portletDataContext,
        StagedModel stagedModel) {/*from w  w w . j  av a 2  s.  c  o  m*/

    Map<String, Long> embeddedReferences = new HashMap<>();

    List<Element> referenceElements = portletDataContext.getReferenceElements(stagedModel, DLFileEntry.class);

    for (Element referenceElement : referenceElements) {
        long classPK = GetterUtil.getLong(referenceElement.attributeValue("class-pk"));

        Element referenceDataElement = portletDataContext.getReferenceDataElement(stagedModel,
                DLFileEntry.class, classPK);

        long groupId = GetterUtil.getLong(referenceElement.attributeValue("group-id"));

        String path = null;

        if (referenceDataElement != null) {
            path = referenceDataElement.attributeValue("path");
        }

        if (Validator.isNull(path)) {
            String className = referenceElement.attributeValue("class-name");

            path = ExportImportPathUtil.getModelPath(groupId, className, classPK);
        }

        embeddedReferences.put(path, classPK);
    }

    return new AdaptiveMediaEmbeddedReferenceSet(portletDataContext, stagedModel, embeddedReferences);
}

From source file:com.liferay.adaptive.media.blogs.internal.exportimport.content.processor.AMEmbeddedReferenceSetFactory.java

License:Open Source License

public AMEmbeddedReferenceSet create(PortletDataContext portletDataContext, StagedModel stagedModel) {

    Map<String, Long> embeddedReferences = new HashMap<>();

    List<Element> referenceElements = portletDataContext.getReferenceElements(stagedModel, DLFileEntry.class);

    for (Element referenceElement : referenceElements) {
        long classPK = GetterUtil.getLong(referenceElement.attributeValue("class-pk"));

        Element referenceDataElement = portletDataContext.getReferenceDataElement(stagedModel,
                DLFileEntry.class, classPK);

        long groupId = GetterUtil.getLong(referenceElement.attributeValue("group-id"));

        String path = null;//w w w  .  jav a 2 s  .co m

        if (referenceDataElement != null) {
            path = referenceDataElement.attributeValue("path");
        }

        if (Validator.isNull(path)) {
            String className = referenceElement.attributeValue("class-name");

            path = ExportImportPathUtil.getModelPath(groupId, className, classPK);
        }

        embeddedReferences.put(path, classPK);
    }

    return new AMEmbeddedReferenceSet(portletDataContext, stagedModel, embeddedReferences);
}

From source file:com.liferay.asset.categories.admin.web.internal.exportimport.data.handler.AssetCategoryStagedModelDataHandler.java

License:Open Source License

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, AssetCategory category)
        throws Exception {

    long userId = portletDataContext.getUserId(category.getUserUuid());

    Map<Long, Long> vocabularyIds = (Map<Long, Long>) portletDataContext
            .getNewPrimaryKeysMap(AssetVocabulary.class);

    long vocabularyId = MapUtil.getLong(vocabularyIds, category.getVocabularyId(), category.getVocabularyId());

    Map<Long, Long> categoryIds = (Map<Long, Long>) portletDataContext
            .getNewPrimaryKeysMap(AssetCategory.class);

    long parentCategoryId = MapUtil.getLong(categoryIds, category.getParentCategoryId(),
            category.getParentCategoryId());

    Element categoryElement = portletDataContext.getImportDataElement(category);

    List<Element> propertyElements = categoryElement.elements("property");

    String[] properties = new String[propertyElements.size()];

    for (int i = 0; i < propertyElements.size(); i++) {
        Element propertyElement = propertyElements.get(i);

        String key = propertyElement.attributeValue("key");
        String value = propertyElement.attributeValue("value");

        properties[i] = key.concat(AssetCategoryConstants.PROPERTY_KEY_VALUE_SEPARATOR).concat(value);
    }/*from   w w  w  .j a  v  a  2s .  co  m*/

    ServiceContext serviceContext = createServiceContext(portletDataContext, category);

    AssetCategory importedCategory = null;

    AssetCategory existingCategory = fetchStagedModelByUuidAndGroupId(category.getUuid(),
            portletDataContext.getScopeGroupId());

    if (existingCategory == null) {
        String name = getCategoryName(null, portletDataContext.getScopeGroupId(), parentCategoryId,
                category.getName(), vocabularyId, 2);

        serviceContext.setUuid(category.getUuid());

        importedCategory = _assetCategoryLocalService.addCategory(userId, portletDataContext.getScopeGroupId(),
                parentCategoryId, getCategoryTitleMap(portletDataContext.getScopeGroupId(), category, name),
                category.getDescriptionMap(), vocabularyId, properties, serviceContext);
    } else {
        String name = getCategoryName(category.getUuid(), portletDataContext.getScopeGroupId(),
                parentCategoryId, category.getName(), vocabularyId, 2);

        importedCategory = _assetCategoryLocalService.updateCategory(userId, existingCategory.getCategoryId(),
                parentCategoryId, getCategoryTitleMap(portletDataContext.getScopeGroupId(), category, name),
                category.getDescriptionMap(), vocabularyId, properties, serviceContext);
    }

    categoryIds.put(category.getCategoryId(), importedCategory.getCategoryId());

    Map<String, String> categoryUuids = (Map<String, String>) portletDataContext
            .getNewPrimaryKeysMap(AssetCategory.class + ".uuid");

    categoryUuids.put(category.getUuid(), importedCategory.getUuid());

    portletDataContext.importPermissions(AssetCategory.class, category.getCategoryId(),
            importedCategory.getCategoryId());
}

From source file:com.liferay.asset.categories.admin.web.internal.exportimport.data.handler.AssetVocabularyStagedModelDataHandler.java

License:Open Source License

protected JSONObject getImportSettingsMetadataJSONObject(PortletDataContext portletDataContext,
        Element vocabularyElement) throws PortalException {

    String settingsMetadataPath = vocabularyElement.attributeValue(_SETTINGS_METADATA);

    String serializedSettingsMetadata = portletDataContext.getZipEntryAsString(settingsMetadataPath);

    return _jsonFactory.createJSONObject(serializedSettingsMetadata);
}

From source file:com.liferay.asset.publisher.web.internal.exportimport.portlet.preferences.processor.AssetPublisherExportImportPortletPreferencesProcessor.java

License:Open Source License

@Override
protected Long getImportPortletPreferencesNewValue(PortletDataContext portletDataContext, Class<?> clazz,
        long companyGroupId, Map<Long, Long> primaryKeys, String portletPreferencesOldValue) throws Exception {

    if (Validator.isNumber(portletPreferencesOldValue)) {
        long oldPrimaryKey = GetterUtil.getLong(portletPreferencesOldValue);

        return MapUtil.getLong(primaryKeys, oldPrimaryKey, oldPrimaryKey);
    }/*from   w  w  w  . j  a va2  s. com*/

    String className = clazz.getName();

    String[] oldValues = StringUtil.split(portletPreferencesOldValue, StringPool.POUND);

    String uuid = oldValues[0];

    long groupId = portletDataContext.getScopeGroupId();

    if (oldValues.length > 1) {
        Map<Long, Long> groupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Group.class);

        groupId = MapUtil.getLong(groupIds, GetterUtil.getLong(oldValues[1]), groupId);
    }

    if (className.equals(AssetCategory.class.getName())) {
        AssetCategory assetCategory = _assetCategoryLocalService.fetchAssetCategoryByUuidAndGroupId(uuid,
                groupId);

        if (assetCategory != null) {
            return assetCategory.getCategoryId();
        }
    } else if (className.equals(AssetVocabulary.class.getName())) {
        AssetVocabulary assetVocabulary = _assetVocabularyLocalService
                .fetchAssetVocabularyByUuidAndGroupId(uuid, groupId);

        if (assetVocabulary != null) {
            return assetVocabulary.getVocabularyId();
        }
    } else if (className.equals(DDMStructure.class.getName())) {
        DDMStructure ddmStructure = _ddmStructureLocalService.fetchDDMStructureByUuidAndGroupId(uuid, groupId);

        if (ddmStructure == null) {
            Map<String, String> structureUuids = (Map<String, String>) portletDataContext
                    .getNewPrimaryKeysMap(DDMStructure.class + ".ddmStructureUuid");

            String defaultStructureUuid = MapUtil.getString(structureUuids, uuid, uuid);

            ddmStructure = _ddmStructureLocalService.fetchDDMStructureByUuidAndGroupId(defaultStructureUuid,
                    groupId);
        }

        if (ddmStructure != null) {
            return ddmStructure.getStructureId();
        }
    } else if (className.equals(DLFileEntryType.class.getName())) {
        DLFileEntryType dlFileEntryType = _dlFileEntryTypeLocalService
                .fetchDLFileEntryTypeByUuidAndGroupId(uuid, groupId);

        if (dlFileEntryType == null) {
            Element rootElement = portletDataContext.getImportDataRootElement();

            Element element = portletDataContext.getReferenceElement(rootElement, clazz, companyGroupId, uuid,
                    PortletDataContext.REFERENCE_TYPE_DEPENDENCY);

            if (element != null) {
                String fileEntryTypeKey = element.attributeValue("file-entry-type-key");

                boolean preloaded = GetterUtil.getBoolean(element.attributeValue("preloaded"));

                if (preloaded) {
                    dlFileEntryType = _dlFileEntryTypeLocalService.fetchFileEntryType(companyGroupId,
                            fileEntryTypeKey);
                }
            }
        }

        if (dlFileEntryType != null) {
            return dlFileEntryType.getFileEntryTypeId();
        }
    }

    return null;
}

From source file:com.liferay.asset.publisher.web.internal.exportimport.portlet.preferences.processor.AssetPublisherExportImportPortletPreferencesProcessor.java

License:Open Source License

protected void importLayoutReferences(PortletDataContext portletDataContext) throws PortletDataException {

    Element importDataRootElement = portletDataContext.getImportDataRootElement();

    Element referencesElement = importDataRootElement.element("references");

    if (referencesElement == null) {
        return;//from w ww. ja  v a  2  s . co  m
    }

    List<Element> referenceElements = referencesElement.elements();

    for (Element referenceElement : referenceElements) {
        String className = referenceElement.attributeValue("class-name");

        if (!className.equals(Layout.class.getName())) {
            continue;
        }

        long classPK = GetterUtil.getLong(referenceElement.attributeValue("class-pk"));

        StagedModelDataHandlerUtil.importReferenceStagedModel(portletDataContext, className, classPK);
    }
}