List of usage examples for com.liferay.portal.kernel.xml Element elements
public List<Element> elements(String name);
From source file:com.acs.DDMXSD.java
License:Open Source License
public String getHTML(PageContext pageContext, Element element, Fields fields, String namespace, String mode, boolean readOnly, Locale locale) throws Exception { StringBundler sb = new StringBundler(); HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); String portletId = PortalUtil.getPortletId(request); String portletNamespace = PortalUtil.getPortletNamespace(portletId); List<Element> dynamicElementElements = element.elements("dynamic-element"); for (Element dynamicElementElement : dynamicElementElements) { FreeMarkerContext freeMarkerContext = getFreeMarkerContext(dynamicElementElement, locale); freeMarkerContext.put("portletNamespace", portletNamespace); freeMarkerContext.put("namespace", namespace); if (fields != null) { freeMarkerContext.put("fields", fields); }/*from w w w.ja va 2 s . c o m*/ Map<String, Object> field = (Map<String, Object>) freeMarkerContext.get("fieldStructure"); String childrenHTML = getHTML(pageContext, dynamicElementElement, fields, namespace, mode, readOnly, locale); field.put("children", childrenHTML); String fieldNamespace = dynamicElementElement.attributeValue("fieldNamespace", _DEFAULT_NAMESPACE); String url = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); url = url.substring(0, url.lastIndexOf('/')); String defaultResourcePath = url + "/" + _TPL_DEFAULT_PATH; boolean fieldReadOnly = GetterUtil.getBoolean(field.get("readOnly")); if ((fieldReadOnly && Validator.isNotNull(mode) && mode.equalsIgnoreCase(DDMTemplateConstants.TEMPLATE_MODE_EDIT)) || readOnly) { fieldNamespace = _DEFAULT_READ_ONLY_NAMESPACE; defaultResourcePath = _TPL_DEFAULT_READ_ONLY_PATH; } String type = dynamicElementElement.attributeValue("type"); String templateName = StringUtil.replaceFirst(type, fieldNamespace.concat(StringPool.DASH), StringPool.BLANK); StringBundler resourcePath = new StringBundler(5); resourcePath.append(_TPL_PATH); resourcePath.append(fieldNamespace.toLowerCase()); resourcePath.append(CharPool.SLASH); resourcePath.append(templateName); resourcePath.append(_TPL_EXT); sb.append(processFTL(pageContext, freeMarkerContext, resourcePath.toString(), defaultResourcePath)); } return sb.toString(); }
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 ww w .ja va 2 s.c o 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.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 . j ava2 s. c om*/ } return false; }
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); }//from w w w. ja v a2 s.com return document.asXML(); }
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. j a va 2 s . com List<Element> dynamicElementElements = element.elements("dynamic-element"); for (Element dynamicElementElement : dynamicElementElements) { updateXSDDynamicElement(dynamicElementElement); } }
From source file:com.liferay.adaptive.media.journal.web.internal.exportimport.content.processor.AMJournalArticleContentHTMLReplacer.java
License:Open Source License
public String replace(String content, Replace replace) throws Exception { try {/*from w w w. jav a 2 s .co m*/ Document document = SAXReaderUtil.read(content); XPath xPath = SAXReaderUtil.createXPath("//dynamic-element[@type='text_area']"); List<Node> ddmJournalArticleNodes = xPath.selectNodes(document); for (Node ddmJournalArticleNode : ddmJournalArticleNodes) { Element ddmJournalArticleElement = (Element) ddmJournalArticleNode; List<Element> dynamicContentElements = ddmJournalArticleElement.elements("dynamic-content"); for (Element dynamicContentElement : dynamicContentElements) { String replacedHtml = replace.apply(dynamicContentElement.getStringValue()); dynamicContentElement.clearContent(); dynamicContentElement.addCDATA(replacedHtml); } } return document.asXML(); } catch (DocumentException de) { if (_log.isDebugEnabled()) { _log.debug("Invalid content:\n" + content); } return content; } }
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); }/* w w w.j av a 2 s . c o 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.publisher.web.internal.exportimport.portlet.preferences.processor.AssetPublisherExportImportPortletPreferencesProcessor.java
License:Open Source License
protected void updateImportScopeIds(PortletDataContext portletDataContext, PortletPreferences portletPreferences, String key, long companyGroupId, long plid) throws Exception { String[] oldValues = portletPreferences.getValues(key, null); if (oldValues == null) { return;//w w w. j a v a2 s .c om } StagedModelDataHandler<StagedGroup> stagedModelDataHandler = (StagedModelDataHandler<StagedGroup>) StagedModelDataHandlerRegistryUtil .getStagedModelDataHandler(StagedGroup.class.getName()); Element rootElement = portletDataContext.getImportDataRootElement(); Element groupIdMappingsElement = rootElement.element("group-id-mappings"); for (Element groupIdMappingElement : groupIdMappingsElement.elements("group-id-mapping")) { stagedModelDataHandler.importMissingReference(portletDataContext, groupIdMappingElement); } Map<Long, Long> groupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Group.class); Layout layout = _layoutLocalService.getLayout(plid); String companyGroupScopeId = AssetPublisherUtil.SCOPE_ID_GROUP_PREFIX + companyGroupId; List<String> newValues = new ArrayList<>(oldValues.length); for (String oldValue : oldValues) { String newValue = StringUtil.replace(oldValue, "[$COMPANY_GROUP_SCOPE_ID$]", companyGroupScopeId); if (Validator.isNumber(oldValue) && groupIds.containsKey(Long.valueOf(oldValue))) { Group group = _groupLocalService.fetchGroup(groupIds.get(Long.valueOf(oldValue))); if (group != null) { newValue = AssetPublisherUtil.getScopeId(group, portletDataContext.getScopeGroupId()); } } if (Validator.isNumber(newValue)) { if (_log.isInfoEnabled()) { _log.info(StringBundler.concat("Ignoring group ", newValue, " because it cannot ", "be converted to scope")); } continue; } try { if (!assetPublisherWebUtil.isScopeIdSelectable(PermissionThreadLocal.getPermissionChecker(), newValue, companyGroupId, layout, false)) { continue; } newValues.add(newValue); } catch (NoSuchGroupException nsge) { if (_log.isInfoEnabled()) { _log.info(StringBundler.concat("Ignoring scope ", newValue, " because the ", "referenced group was not found"), nsge); } } catch (NoSuchLayoutException nsle) { if (_log.isInfoEnabled()) { _log.info(StringBundler.concat("Ignoring scope ", newValue, " because the ", "referenced layout was not found"), nsle); } } catch (PrincipalException pe) { if (_log.isInfoEnabled()) { _log.info(StringBundler.concat("Ignoring scope ", newValue, " because the ", "referenced parent group no longer allows sharing ", "content with child sites"), pe); } } } portletPreferences.setValues(key, newValues.toArray(new String[newValues.size()])); }
From source file:com.liferay.calendar.lar.CalendarPortletDataHandlerImpl.java
License:Open Source License
@Override protected PortletPreferences doImportData(PortletDataContext portletDataContext, String portletId, PortletPreferences portletPreferences, String data) throws Exception { portletDataContext.importPermissions("com.liferay.portlet.calendar", portletDataContext.getSourceGroupId(), portletDataContext.getScopeGroupId()); Document document = SAXReaderUtil.read(data); Element rootElement = document.getRootElement(); Element calendarResourcesElement = rootElement.element("calendar-resources"); List<Element> calendarResourceElements = calendarResourcesElement.elements("calendar-resource"); for (Element calendarResourceElement : calendarResourceElements) { importCalendarResource(portletDataContext, calendarResourceElement); }/*from w w w . j a va 2 s .c o m*/ Element calendarsElement = rootElement.element("calendars"); List<Element> calendarElements = calendarsElement.elements("calendar"); for (Element calendarElement : calendarElements) { importCalendar(portletDataContext, calendarElement); } if (portletDataContext.getBooleanParameter(_NAMESPACE, "bookings")) { Element calendarBookingsElement = rootElement.element("calendar-bookings"); List<Element> calendarBookingElements = calendarBookingsElement.elements("calendar-booking"); for (Element calendarBookingElement : calendarBookingElements) { importCalendarBooking(portletDataContext, calendarBookingElement); } } return portletPreferences; }
From source file:com.liferay.customsql.CustomSQL.java
License:Open Source License
protected void read(ClassLoader classLoader, String source) throws Exception { InputStream is = classLoader.getResourceAsStream(source); if (is == null) { return;/*from www. j a v a 2 s .c o m*/ } if (_log.isDebugEnabled()) { _log.debug("Loading " + source); } Document document = SAXReaderUtil.read(is); Element rootElement = document.getRootElement(); for (Element sqlElement : rootElement.elements("sql")) { String file = sqlElement.attributeValue("file"); if (Validator.isNotNull(file)) { read(classLoader, file); } else { String id = sqlElement.attributeValue("id"); String content = transform(sqlElement.getText()); content = replaceIsNull(content); _sqlPool.put(id, content); } } }