List of usage examples for com.liferay.portal.kernel.xml Attribute setValue
public void setValue(String value);
From source file:com.liferay.google.apps.connector.GGroupManagerImpl.java
License:Open Source License
@Override public void updateDescription(String emailAddress, String description) throws GoogleAppsException { Document document = getDocument(getGroupURL(emailAddress)); if (hasError(document)) { if (_log.isInfoEnabled()) { _log.info(getErrorMessage(document)); }/*from w w w . j a v a2s .c o m*/ return; } Element atomEntryElement = document.getRootElement(); List<Element> appsPropertyElements = atomEntryElement.elements(getAppsQName("property")); for (Element appsPropertyElement : appsPropertyElements) { String name = appsPropertyElement.attributeValue("name"); if (name.equals("description")) { Attribute valueAttribute = appsPropertyElement.attribute("value"); valueAttribute.setValue(description); } } submitUpdate(getGroupURL(emailAddress), document); }
From source file:com.liferay.journal.transformer.test.JournalTransformerTest.java
License:Open Source License
@Test public void testLocaleTransformerListenerNestedFieldWithNoTranslation() throws Exception { Map<String, String> tokens = getTokens(); Map<Locale, String> contents = new HashMap<>(); contents.put(LocaleUtil.US, "Joe Bloggs"); String xml = DDMStructureTestUtil.getSampleStructuredContent(contents, LanguageUtil.getLanguageId(LocaleUtil.US)); Document document = UnsecureSAXReaderUtil.read(xml); Element rootElement = document.getRootElement(); Attribute availableLocalesAttribute = rootElement.attribute("available-locales"); availableLocalesAttribute.setValue("en_US,pt_BR"); Element dynamicElement = (Element) document.selectSingleNode("//dynamic-element"); dynamicElement.addElement("nestedElement"); String script = "$name.getData()"; String content = JournalUtil.transform(null, tokens, Constants.VIEW, "en_US", document, null, script, TemplateConstants.LANG_TYPE_VM); Assert.assertEquals("Joe Bloggs", content); content = JournalUtil.transform(null, tokens, Constants.VIEW, "pt_BR", document, null, script, TemplateConstants.LANG_TYPE_VM); Assert.assertEquals("Joe Bloggs", content); }
From source file:com.liferay.journal.util.impl.JournalUtil.java
License:Open Source License
public static String prepareLocalizedContentForImport(String content, Locale defaultImportLocale) throws LocaleException { try {// w w w. j av a 2s.c om Document oldDocument = SAXReaderUtil.read(content); Document newDocument = SAXReaderUtil.read(content); Element newRootElement = newDocument.getRootElement(); Attribute availableLocalesAttribute = newRootElement.attribute("available-locales"); if (availableLocalesAttribute == null) { newRootElement = newRootElement.addAttribute("available-locales", StringPool.BLANK); availableLocalesAttribute = newRootElement.attribute("available-locales"); } String defaultImportLanguageId = LocaleUtil.toLanguageId(defaultImportLocale); if (!StringUtil.contains(availableLocalesAttribute.getValue(), defaultImportLanguageId)) { if (Validator.isNull(availableLocalesAttribute.getValue())) { availableLocalesAttribute.setValue(defaultImportLanguageId); } else { availableLocalesAttribute.setValue( availableLocalesAttribute.getValue() + StringPool.COMMA + defaultImportLanguageId); } _mergeArticleContentUpdate(oldDocument, newRootElement, LocaleUtil.toLanguageId(defaultImportLocale)); content = XMLUtil.formatXML(newDocument); } Attribute defaultLocaleAttribute = newRootElement.attribute("default-locale"); if (defaultLocaleAttribute == null) { newRootElement = newRootElement.addAttribute("default-locale", StringPool.BLANK); defaultLocaleAttribute = newRootElement.attribute("default-locale"); } Locale defaultContentLocale = LocaleUtil.fromLanguageId(defaultLocaleAttribute.getValue()); if (!LocaleUtil.equals(defaultContentLocale, defaultImportLocale)) { defaultLocaleAttribute.setValue(defaultImportLanguageId); content = XMLUtil.formatXML(newDocument); } } catch (Exception e) { throw new LocaleException(LocaleException.TYPE_CONTENT, "The locale " + defaultImportLocale + " is not available"); } return content; }
From source file:com.liferay.journal.util.impl.JournalUtil.java
License:Open Source License
private static void _mergeArticleContentUpdate(Element curElement, Element newElement, String defaultLocale) { Attribute curTypeAttribute = curElement.attribute("type"); Attribute newTypeAttribute = newElement.attribute("type"); curTypeAttribute.setValue(newTypeAttribute.getValue()); Attribute curIndexTypeAttribute = curElement.attribute("index-type"); Attribute newIndexTypeAttribute = newElement.attribute("index-type"); if (newIndexTypeAttribute != null) { if (curIndexTypeAttribute == null) { curElement.addAttribute("index-type", newIndexTypeAttribute.getValue()); } else {/* w ww .j av a2s . co m*/ curIndexTypeAttribute.setValue(newIndexTypeAttribute.getValue()); } } List<Element> elements = newElement.elements("dynamic-content"); if ((elements == null) || elements.isEmpty()) { return; } Element newContentElement = elements.get(0); String newLanguageId = newContentElement.attributeValue("language-id"); String newValue = newContentElement.getText(); String indexType = newElement.attributeValue("index-type"); if (Validator.isNotNull(indexType)) { curElement.addAttribute("index-type", indexType); } List<Element> curContentElements = curElement.elements("dynamic-content"); if (Validator.isNull(newLanguageId)) { for (Element curContentElement : curContentElements) { curContentElement.detach(); } Element curContentElement = SAXReaderUtil.createElement("dynamic-content"); if (newContentElement.element("option") != null) { _addElementOptions(curContentElement, newContentElement); } else { curContentElement.addCDATA(newValue); } curElement.add(curContentElement); } else { boolean alreadyExists = false; for (Element curContentElement : curContentElements) { String curLanguageId = curContentElement.attributeValue("language-id"); if (newLanguageId.equals(curLanguageId)) { alreadyExists = true; curContentElement.clearContent(); if (newContentElement.element("option") != null) { _addElementOptions(curContentElement, newContentElement); } else { curContentElement.addCDATA(newValue); } break; } } if (!alreadyExists) { Element curContentElement = curContentElements.get(0); String curLanguageId = curContentElement.attributeValue("language-id"); if (Validator.isNull(curLanguageId)) { if (newLanguageId.equals(defaultLocale)) { curContentElement.clearContent(); if (newContentElement.element("option") != null) { _addElementOptions(curContentElement, newContentElement); } else { curContentElement.addCDATA(newValue); } } else { curElement.add(newContentElement.createCopy()); } curContentElement.addAttribute("language-id", defaultLocale); } else { curElement.add(newContentElement.createCopy()); } } } }
From source file:com.liferay.portlet.journal.util.JournalUtil.java
License:Open Source License
private static void _mergeArticleContentUpdate(Element curElement, Element newElement, String defaultLocale) { Attribute curTypeAttribute = curElement.attribute("type"); Attribute newTypeAttribute = newElement.attribute("type"); curTypeAttribute.setValue(newTypeAttribute.getValue()); Attribute curIndexTypeAttribute = curElement.attribute("index-type"); Attribute newIndexTypeAttribute = newElement.attribute("index-type"); if (newIndexTypeAttribute != null) { if (curIndexTypeAttribute == null) { curElement.addAttribute("index-type", newIndexTypeAttribute.getValue()); } else {//w w w .j av a2 s. co m curIndexTypeAttribute.setValue(newIndexTypeAttribute.getValue()); } } Element newContentElement = newElement.elements("dynamic-content").get(0); String newLanguageId = newContentElement.attributeValue("language-id"); String newValue = newContentElement.getText(); String indexType = newElement.attributeValue("index-type"); if (Validator.isNotNull(indexType)) { curElement.addAttribute("index-type", indexType); } List<Element> curContentElements = curElement.elements("dynamic-content"); if (Validator.isNull(newLanguageId)) { for (Element curContentElement : curContentElements) { curContentElement.detach(); } Element curContentElement = SAXReaderUtil.createElement("dynamic-content"); if (newContentElement.element("option") != null) { _addElementOptions(curContentElement, newContentElement); } else { curContentElement.addCDATA(newValue); } curElement.add(curContentElement); } else { boolean alreadyExists = false; for (Element curContentElement : curContentElements) { String curLanguageId = curContentElement.attributeValue("language-id"); if (newLanguageId.equals(curLanguageId)) { alreadyExists = true; curContentElement.clearContent(); if (newContentElement.element("option") != null) { _addElementOptions(curContentElement, newContentElement); } else { curContentElement.addCDATA(newValue); } break; } } if (!alreadyExists) { Element curContentElement = curContentElements.get(0); String curLanguageId = curContentElement.attributeValue("language-id"); if (Validator.isNull(curLanguageId)) { if (newLanguageId.equals(defaultLocale)) { curContentElement.clearContent(); if (newContentElement.element("option") != null) { _addElementOptions(curContentElement, newContentElement); } else { curContentElement.addCDATA(newValue); } } else { curElement.add(newContentElement.createCopy()); } curContentElement.addAttribute("language-id", defaultLocale); } else { curElement.add(newContentElement.createCopy()); } } } }
From source file:com.liferay.util.ant.Java2WsddTask.java
License:Open Source License
private static String _format(String content) throws Exception { content = HtmlUtil.stripComments(content); Document document = SAXReaderUtil.read(content); Element rootElement = document.getRootElement(); Element serviceElement = rootElement.element("service"); Map<String, Element> arrayMappingElements = new TreeMap<String, Element>(); Map<String, Element> typeMappingElements = new TreeMap<String, Element>(); Map<String, Element> operationElements = new TreeMap<String, Element>(); Map<String, Element> parameterElements = new TreeMap<String, Element>(); for (Element element : serviceElement.elements()) { String elementName = element.getName(); if (elementName.equals("arrayMapping")) { element.detach();//from www. ja va2 s .com arrayMappingElements.put(element.formattedString(), element); } else if (elementName.equals("operation")) { element.detach(); StringBundler sb = new StringBundler(); String name = element.attributeValue("name"); sb.append(name); sb.append("_METHOD_"); for (Element parameterElement : element.elements("parameter")) { String type = parameterElement.attributeValue("type"); sb.append(type); sb.append("_PARAMETER_"); } operationElements.put(sb.toString(), element); } else if (elementName.equals("parameter")) { element.detach(); String name = element.attributeValue("name"); if (name.equals("allowedMethods")) { Attribute valueAttribute = element.attribute("value"); String[] values = StringUtil.split(valueAttribute.getValue(), CharPool.SPACE); Arrays.sort(values); valueAttribute.setValue(StringUtil.merge(values, StringPool.SPACE)); } else if (name.equals("schemaUnqualified")) { Attribute valueAttribute = element.attribute("value"); String[] values = StringUtil.split(valueAttribute.getValue()); Arrays.sort(values); valueAttribute.setValue(StringUtil.merge(values)); } parameterElements.put(name, element); } else if (elementName.equals("typeMapping")) { element.detach(); typeMappingElements.put(element.formattedString(), element); } } _addElements(serviceElement, arrayMappingElements); _addElements(serviceElement, typeMappingElements); _addElements(serviceElement, operationElements); _addElements(serviceElement, parameterElements); content = StringUtil.replace(document.formattedString(), "\"/>", "\" />"); return content; }