List of usage examples for com.liferay.portal.kernel.xml Attribute getValue
public String getValue();
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 www .j av a 2s . 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;// w w w . j av 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.liferay.dynamic.data.mapping.test.util.DDMStructureTestUtil.java
License:Open Source License
protected static Map<String, String> getElementMap(Element element) { Map<String, String> elementMap = new HashMap<>(); // Attributes for (Attribute attribute : element.attributes()) { elementMap.put(attribute.getName(), attribute.getValue()); }/*from w ww .jav a 2s.c o m*/ // Metadata for (Element metadadataElement : element.elements("meta-data")) { String metadataLanguageId = metadadataElement.attributeValue("locale"); for (Element entryElement : metadadataElement.elements("entry")) { String entryName = entryElement.attributeValue("name"); elementMap.put(entryName.concat(metadataLanguageId), entryElement.getText()); } } return elementMap; }
From source file:com.liferay.exportimport.lar.PortletDataContextImpl.java
License:Open Source License
protected ServiceContext createServiceContext(Element element, String path, ClassedModel classedModel, Class<?> clazz) {// w w w. java2 s .c o m ServiceContext serviceContext = new ServiceContext(); // Theme display serviceContext.setCompanyId(getCompanyId()); serviceContext.setScopeGroupId(getScopeGroupId()); // Dates if (classedModel instanceof AuditedModel) { AuditedModel auditedModel = (AuditedModel) classedModel; serviceContext.setUserId(getUserId(auditedModel)); serviceContext.setCreateDate(auditedModel.getCreateDate()); serviceContext.setModifiedDate(auditedModel.getModifiedDate()); } // Permissions if (!MapUtil.getBoolean(_parameterMap, PortletDataHandlerKeys.PERMISSIONS)) { serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); } // Asset if (isResourceMain(classedModel)) { Serializable classPKObj = ExportImportClassedModelUtil.getPrimaryKeyObj(classedModel); long[] assetCategoryIds = getAssetCategoryIds(clazz, classPKObj); serviceContext.setAssetCategoryIds(assetCategoryIds); String[] assetTagNames = getAssetTagNames(clazz, classPKObj); serviceContext.setAssetTagNames(assetTagNames); } if (element != null) { Attribute assetPriorityAttribute = element.attribute("asset-entry-priority"); if (assetPriorityAttribute != null) { double assetPriority = GetterUtil.getDouble(assetPriorityAttribute.getValue()); serviceContext.setAssetPriority(assetPriority); } } // Expando String expandoPath = null; if (element != null) { expandoPath = element.attributeValue("expando-path"); } else { expandoPath = ExportImportPathUtil.getExpandoPath(path); } if (Validator.isNotNull(expandoPath)) { try { Map<String, Serializable> expandoBridgeAttributes = (Map<String, Serializable>) getZipEntryAsObject( expandoPath); if (expandoBridgeAttributes != null) { serviceContext.setExpandoBridgeAttributes(expandoBridgeAttributes); } } catch (Exception e) { if (_log.isDebugEnabled()) { _log.debug(e, e); } } } // Workflow if (classedModel instanceof WorkflowedModel) { WorkflowedModel workflowedModel = (WorkflowedModel) classedModel; if (workflowedModel.getStatus() == WorkflowConstants.STATUS_APPROVED) { serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH); } else if (workflowedModel.getStatus() == WorkflowConstants.STATUS_DRAFT) { serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT); } } return serviceContext; }
From source file:com.liferay.exportimport.lar.ThemeImporter.java
License:Open Source License
public void importTheme(PortletDataContext portletDataContext, LayoutSet layoutSet) throws Exception { boolean importThemeSettings = MapUtil.getBoolean(portletDataContext.getParameterMap(), PortletDataHandlerKeys.THEME_REFERENCE); if (_log.isDebugEnabled()) { _log.debug("Import theme settings " + importThemeSettings); }// ww w . j av a2 s . co m if (!importThemeSettings) { return; } Map<Long, Long> groupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Group.class); long importGroupId = groupIds.get(layoutSet.getGroupId()); Element importDataRootElement = portletDataContext.getImportDataRootElement(); Element headerElement = importDataRootElement.element("header"); String themeId = layoutSet.getThemeId(); String colorSchemeId = layoutSet.getColorSchemeId(); Attribute themeIdAttribute = headerElement.attribute("theme-id"); if (themeIdAttribute != null) { themeId = themeIdAttribute.getValue(); } Attribute colorSchemeIdAttribute = headerElement.attribute("color-scheme-id"); if (colorSchemeIdAttribute != null) { colorSchemeId = colorSchemeIdAttribute.getValue(); } String css = GetterUtil.getString(headerElement.elementText("css")); LayoutSetLocalServiceUtil.updateLookAndFeel(importGroupId, layoutSet.isPrivateLayout(), themeId, colorSchemeId, css); }
From source file:com.liferay.faces.portal.component.inputsearch.internal.InputSearchRenderer.java
License:Open Source License
@Override protected StringBuilder getMarkup(UIComponent uiComponent, StringBuilder markup) throws Exception { //J-//from ww w.j av a 2 s. co m // NOTE: The specified markup looks like the following (HTML comments added for clarity): // // <!-- Opening <div> rendered by html/taglib/ui/input_search/page.jsp --> // <div class="input-append"> // // <!-- Input text field rendered by html/taglib/ui/input_search/page.jsp --> // <input class="search-query span9" id="...:jid42" name="..." placeholder="" type="text" value="" /> // // <!-- Search button rendered by html/taglib/ui/input_search/page.jsp --> // <button class="btn" type="submit">Search</button> // // <!-- HtmlInputText (dynamically added JSF child component) --> // <input type="text" name="...:htmlInputText" /> // // <!-- HtmlCommandButton (dynamically added JSF child component) --> // <input type="submit" name="...:htmlCommandButton" value="" /> // // <!-- Closing </div> rendered by html/taglib/ui/input_search/page.jsp --> // </div> //J+ // Parse the generated markup as an XML document. InputSearch inputSearch = cast(uiComponent); Document document = SAXReaderUtil.read(markup.toString()); Element rootElement = document.getRootElement(); // Locate the first/main input element in the XML document. This is the one that will contain contain the value // that will be submitted in the postback and received by the decode(FacesContext, UIComponent) method). String xpathInput = "//input[contains(@id, '" + uiComponent.getClientId() + "')]"; Element mainInputElement = (Element) rootElement.selectSingleNode(xpathInput); if (mainInputElement != null) { // Copy the value attribute of the InputSearch component to the first input element in the XML document. mainInputElement.attribute("value").setValue((String) inputSearch.getValue()); // Locate the dynamically added HtmlInputText and HtmlCommandButton child components. String xpathInputs = "//input[@type='text']"; List<Node> inputElements = rootElement.selectNodes(xpathInputs); if ((inputElements != null) && (inputElements.size() == 2)) { // Copy each "on" attribute name/value pairs from the HtmlInputText to the first input element in // the XML document. This will enable all of the AjaxBehavior events like keyup/keydown to work. Element htmlInputTextElement = (Element) inputElements.get(1); Iterator<Attribute> attributeIterator = htmlInputTextElement.attributeIterator(); while (attributeIterator.hasNext()) { Attribute attribute = attributeIterator.next(); String attributeName = attribute.getName(); if (attributeName.startsWith("on")) { mainInputElement.addAttribute(attributeName, attribute.getValue()); } } // Remove the HtmlInputText <input> from the XML document so that only one text field is rendered. htmlInputTextElement.getParent().remove(htmlInputTextElement); } } // Locate the HtmlCommandButton in the XML document. List<UIComponent> children = uiComponent.getChildren(); HtmlCommandButton htmlCommandButton = (HtmlCommandButton) children.get(1); String htmlCommandButtonClientId = htmlCommandButton.getClientId(); // Note that if there is an AjaxBehavior, then the rendered HtmlCommandButton can be located in the XML document // via the name attribute. Otherwise it can be located in the XML document via the id attribute. String htmlCommandButtonXPath = "//input[contains(@name,'" + htmlCommandButtonClientId + "') and @type='submit']"; Element htmlCommandButtonElement = (Element) rootElement.selectSingleNode(htmlCommandButtonXPath); if (htmlCommandButtonElement == null) { htmlCommandButtonXPath = "//input[contains(@id,'" + htmlCommandButtonClientId + "') and @type='submit']"; htmlCommandButtonElement = (Element) rootElement.selectSingleNode(htmlCommandButtonXPath); } if (htmlCommandButtonElement != null) { // Locate the <button> element in the XML document that was rendered by page.jsp Element buttonElement = (Element) rootElement.selectSingleNode("//button[@type='submit']"); if (buttonElement != null) { // Copy attributes found on the HtmlCommandButton <input> element to the <button> element that was // rendered by page.jsp Attribute onClickAttr = htmlCommandButtonElement.attribute("onclick"); if (onClickAttr != null) { buttonElement.addAttribute("onclick", onClickAttr.getValue()); } Attribute nameAttr = htmlCommandButtonElement.attribute("name"); if (nameAttr != null) { buttonElement.addAttribute("name", nameAttr.getValue()); } Attribute idAttr = htmlCommandButtonElement.attribute("id"); if (idAttr != null) { buttonElement.addAttribute("id", idAttr.getValue()); } // Remove the HtmlCommandButton <input> from the XML document so that only one button is rendered. htmlCommandButtonElement.getParent().remove(htmlCommandButtonElement); } } // Returned the modified verson of the specified markup. return new StringBuilder(rootElement.asXML()); }
From source file:com.liferay.faces.test.hooks.TestSetupAction.java
License:Open Source License
protected void setupBridgeTCKSite(long companyId, long userId) throws Exception, DocumentException { Group site = getSiteForSetup(companyId, userId, "Bridge TCK"); long groupId = site.getGroupId(); addAllUsersToSite(companyId, groupId); URL configFileURL = getClass().getClassLoader().getResource("pluto-portal-driver-config.xml"); Document document = SAXReaderUtil.read(configFileURL); Element rootElement = document.getRootElement(); Element renderConfigElement = rootElement.element("render-config"); Iterator<Element> pageElementIterator = renderConfigElement.elementIterator("page"); while (pageElementIterator.hasNext()) { Element pageElement = pageElementIterator.next(); Attribute nameAttribute = pageElement.attribute("name"); String pageName = nameAttribute.getValue(); Element portletElement = pageElement.element("portlet"); nameAttribute = portletElement.attribute("name"); String portletName = nameAttribute.getValue(); String liferayPortletName = portletName.replaceAll("-", ""); String liferayPortletId = liferayPortletName + "_WAR_bridgetckmainportlet"; PortalPage portalPage = new PortalPage(pageName, liferayPortletId); setupPrivatePage(companyId, userId, groupId, portalPage); }//from w w w .j a v a 2s. co m setupPrivatePage(companyId, userId, groupId, new PortalPage("Lifecycle Set", "chapter3TestslifecycleTestportlet_WAR_bridgetcklifecyclesetportlet")); setupPrivatePage(companyId, userId, groupId, new PortalPage("Render Policy Always Delegate", "chapter3TestsrenderPolicyTestportlet_WAR_bridgetckrenderpolicy1portlet")); setupPrivatePage(companyId, userId, groupId, new PortalPage("Render Policy Default", "chapter3TestsrenderPolicyTestportlet_WAR_bridgetckrenderpolicy2portlet")); setupPrivatePage(companyId, userId, groupId, new PortalPage("Render Policy Never Delegate", "chapter3TestsrenderPolicyTestportlet_WAR_bridgetckrenderpolicy3portlet")); setupPrivatePage(companyId, userId, groupId, new PortalPage("Render Response Wrapper", "chapter6_2_1TestsusesConfiguredRenderResponseWrapperTestportlet_WAR_bridgetckresponsewrapperportlet")); setupPrivatePage(companyId, userId, groupId, new PortalPage("Resource Response Wrapper", "chapter6_2_1TestsusesConfiguredResourceResponseWrapperTestportlet_WAR_bridgetckresponsewrapperportlet")); }
From source file:com.liferay.google.apps.connector.GHelperUtil.java
License:Open Source License
public static String getErrorMessage(Document document) { Element rootElement = document.getRootElement(); Element errorElement = rootElement.element("error"); List<Attribute> attributes = errorElement.attributes(); StringBundler sb = new StringBundler(attributes.size() * 4 + 1); sb.append(StringPool.OPEN_CURLY_BRACE); for (int i = 0; i < attributes.size(); i++) { Attribute attribute = attributes.get(i); sb.append(attribute.getName());//from w w w . j av a 2s . c om sb.append(StringPool.EQUAL); sb.append(attribute.getValue()); if ((i + 1) <= attributes.size()) { sb.append(StringPool.COMMA_AND_SPACE); } } sb.append(StringPool.CLOSE_CURLY_BRACE); return sb.toString(); }
From source file:com.liferay.journal.internal.util.impl.JournalConverterImpl.java
License:Open Source License
protected void updateJournalXSDDynamicElement(Element element, String defaultLanguageId) { String name = element.attributeValue("name"); String type = element.attributeValue("type"); Element metadataElement = element.element("meta-data"); if (metadataElement == null) { metadataElement = element.addElement("meta-data"); }// w w w. j a va 2 s .c o m if (type.equals("multi-list")) { element.addAttribute("multiple", "true"); } else { Element parentElement = element.getParent(); String parentType = parentElement.attributeValue("type"); if ((parentType != null) && parentType.equals("select")) { metadataElement.addAttribute("locale", defaultLanguageId); addMetadataEntry(metadataElement, "label", decodeURL(name)); removeAttribute(element, "index-type"); element.addAttribute("name", "option" + parentElement.attributeValue("name") + StringUtil.randomString(8)); element.addAttribute("type", "option"); element.addAttribute("value", decodeURL(type)); return; } } String indexType = StringPool.BLANK; Attribute indexTypeAttribute = element.attribute("index-type"); if (indexTypeAttribute != null) { indexType = indexTypeAttribute.getValue(); element.remove(indexTypeAttribute); } element.remove(element.attribute("type")); if (!type.equals("selection_break")) { String dataType = _ddmDataTypes.get(type); if (dataType == null) { dataType = "string"; } element.addAttribute("dataType", dataType); } element.addAttribute("indexType", indexType); String required = "false"; Element requiredElement = fetchMetadataEntry(metadataElement, "name", "required"); if (requiredElement != null) { required = requiredElement.getText(); } element.addAttribute("required", required); element.addAttribute("showLabel", "true"); String newType = _journalTypesToDDMTypes.get(type); if (newType == null) { newType = type; } element.addAttribute("type", newType); if (newType.startsWith("ddm")) { element.addAttribute("fieldNamespace", "ddm"); } metadataElement.addAttribute("locale", defaultLanguageId); List<Element> entryElements = metadataElement.elements(); if (entryElements.isEmpty()) { addMetadataEntry(metadataElement, "label", name); } else { for (Element entryElement : entryElements) { String oldEntryName = entryElement.attributeValue("name"); String newEntryName = _ddmMetadataAttributes.get(oldEntryName); if (newEntryName == null) { metadataElement.remove(entryElement); } else { entryElement.addAttribute("name", newEntryName); } } } if (newType.equals("ddm-date") || newType.equals("ddm-decimal") || newType.equals("ddm-integer") || newType.equals("ddm-link-to-page") || newType.equals("ddm-number") || newType.equals("ddm-text-html") || newType.equals("text") || newType.equals("textarea")) { element.addAttribute("width", "25"); } else if (newType.equals("ddm-image")) { element.addAttribute("fieldNamespace", "ddm"); element.addAttribute("readOnly", "false"); } element.add(metadataElement.detach()); List<Element> dynamicElementElements = element.elements("dynamic-element"); for (Element dynamicElementElement : dynamicElementElements) { updateJournalXSDDynamicElement(dynamicElementElement, defaultLanguageId); } }
From source file:com.liferay.journal.test.util.JournalTestUtil.java
License:Open Source License
private static Map<String, String> _getMap(Element dynamicElementElement) { Map<String, String> map = new HashMap<>(); Element parentElement = dynamicElementElement.getParent(); String parentType = parentElement.attributeValue("type"); // Attributes for (Attribute attribute : dynamicElementElement.attributes()) { // Option element should not contain index type atribute if ((Objects.equals(parentType, "list") || Objects.equals(parentType, "multi-list")) && Objects.equals(attribute.getName(), "index-type")) { continue; }/*from ww w . j ava 2 s . c om*/ map.put(attribute.getName(), attribute.getValue()); } // Metadata Element metadadataElement = dynamicElementElement.element("meta-data"); if (metadadataElement == null) { return map; } List<Element> entryElements = metadadataElement.elements("entry"); for (Element entryElement : entryElements) { map.put(entryElement.attributeValue("name"), entryElement.getText()); } return map; }