List of usage examples for com.liferay.portal.kernel.xml Element getText
@Override
public String getText();
From source file:com.liferay.wiki.importer.impl.mediawiki.MediaWikiImporter.java
License:Open Source License
protected List<String> readSpecialNamespaces(Element root) throws ImportFilesException { List<String> namespaces = new ArrayList<>(); Element siteinfoElement = root.element("siteinfo"); if (siteinfoElement == null) { throw new ImportFilesException("Invalid pages XML file"); }//from w w w .j a v a2 s .c o m Element namespacesElement = siteinfoElement.element("namespaces"); List<Element> namespaceElements = namespacesElement.elements("namespace"); for (Element namespaceElement : namespaceElements) { Attribute attribute = namespaceElement.attribute("key"); String value = attribute.getValue(); if (!value.equals("0")) { namespaces.add(namespaceElement.getText()); } } return namespaces; }
From source file:com.playtech.portal.platform.portlet.orgsettings.lar.OrgSettingsDataHandler.java
/** * Parses single string with data into xml document and saves settings from it. * Internal method, access 'protected' only for licensees * * @param companyId whose settings are changed * @param groupId is id of organization * @param data single string with data to import * @throws DocumentException//from w ww .j a va 2s. c o m */ protected void invokeImportData(PortletDataContext context, final long companyId, final long groupId, final String data) throws DocumentException { Document doc = SAXReaderUtil.read(data); Element expandoRoot = doc.getRootElement(); Map<String, String> properties = new HashMap(); Map<String, String> articleIds = (Map<String, String>) context .getNewPrimaryKeysMap(JournalArticle.class + ".articleId"); for (Iterator<Element> iterator = expandoRoot.elementIterator(ELEM_EXPANDO); iterator.hasNext();) { Element expandoEl = iterator.next(); Element nameEl = expandoEl.element(ELEM_NAME); String propertyName = nameEl.getText(); String type = nameEl.attributeValue(ATTR_TYPE); Element valueEl = expandoEl.element(ELEM_VALUE); try { String primVal = addPrimitiveWrapper(articleIds, type, valueEl); if (log.isDebugEnabled()) { log.debug("Import {} = {} ", propertyName, primVal); } properties.put(propertyName, primVal); } catch (Exception e) { log.error(e.getMessage()); } } getPropertiesService().setAllPartitionPropertiesMap(companyId, PartitionNames.GROUP, groupId, properties); doLookupServiceImport(doc, context, companyId, groupId, data); }
From source file:com.playtech.portal.platform.portlet.orgsettings.lar.OrgSettingsDataHandler.java
protected String addPrimitiveWrapper(Map<String, String> articleIds, String className, Element element) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {//from ww w.jav a 2s .c o m String primVal = element.getText(); if (articleIds.containsKey(primVal)) { primVal = articleIds.get(primVal); } Class<?> aClass = Class.forName(className); if (log.isDebugEnabled()) { log.debug("class = " + aClass + "; primVal = " + primVal); } if (aClass.equals(String.class)) { return primVal; } else { Method valueOf = aClass.getMethod("valueOf", String.class); return (String) valueOf.invoke(null, primVal); } }
From source file:it.smc.calendar.sync.caldav.methods.ProppatchMethodImpl.java
License:Open Source License
protected Set<QName> processInstructions(WebDAVRequest webDAVRequest) throws InvalidRequestException, LockException { try {/* ww w. j av a2s. c o m*/ Set<QName> newProps = new HashSet<QName>(); WebDAVProps webDavProps = getStoredProperties(webDAVRequest); Document document = CalDAVRequestThreadLocal.getRequestDocument(); if (Validator.isNull(document)) { return newProps; } Element rootElement = document.getRootElement(); List<Element> instructionElements = rootElement.elements(); for (Element instructionElement : instructionElements) { List<Element> propElements = instructionElement.elements(); if (propElements.size() != 1) { throw new InvalidRequestException( "There should only be one <prop /> per set or remove " + "instruction."); } Element propElement = propElements.get(0); if (!propElement.getName().equals("prop") || !propElement.getNamespaceURI().equals(WebDAVUtil.DAV_URI.getURI())) { throw new InvalidRequestException("Invalid <prop /> element " + propElement); } List<Element> customPropElements = propElement.elements(); for (Element customPropElement : customPropElements) { String name = customPropElement.getName(); String prefix = customPropElement.getNamespacePrefix(); String uri = customPropElement.getNamespaceURI(); String text = customPropElement.getText(); Namespace namespace = WebDAVUtil.createNamespace(prefix, uri); if (instructionElement.getName().equals("set")) { if (Validator.isNull(text)) { webDavProps.addProp(name, prefix, uri); } else { webDavProps.addProp(name, prefix, uri, text); } newProps.add(SAXReaderUtil.createQName(customPropElement.getName(), namespace)); } else if (instructionElement.getName().equals("remove")) { webDavProps.removeProp(name, prefix, uri); } else { throw new InvalidRequestException( "Instead of set/remove instruction, received " + instructionElement); } } } WebDAVPropsLocalServiceUtil.storeWebDAVProps(webDavProps); return newProps; } catch (LockException le) { throw le; } catch (Exception e) { throw new InvalidRequestException(e); } }
From source file:org.xcolab.portlets.search.Indexer.java
License:Open Source License
private static void _getIndexableContent(StringBuilder sb, Element root) throws Exception { for (Element el : root.elements()) { String elType = el.attributeValue("type", StringPool.BLANK); if (elType.equals("text") || elType.equals("text_box") || elType.equals("text_area")) { for (Element dynamicContent : el.elements("dynamic-content")) { String text = dynamicContent.getText(); sb.append(text);/*from www . j av a 2s . c o m*/ sb.append(StringPool.SPACE); } } else if (el.getName().equals("static-content")) { String text = el.getText(); sb.append(text); sb.append(StringPool.SPACE); } _getIndexableContent(sb, el); } }