List of usage examples for org.dom4j Element getTextTrim
String getTextTrim();
From source file:com.finderbots.miner2.pinterest.AnalyzeHtml.java
License:Apache License
private String getTextFromNode(Node node) { String attributeValue = null; if (node.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) node; attributeValue = e.getTextTrim(); }/*ww w .j av a 2s . c o m*/ return (attributeValue == null ? "" : attributeValue); }
From source file:com.glaf.activiti.extension.xml.ExtensionReader.java
License:Apache License
public List<ExtensionEntity> readTasks(java.io.InputStream inputStream) { List<ExtensionEntity> extensions = new java.util.ArrayList<ExtensionEntity>(); SAXReader xmlReader = new SAXReader(); try {/*from w w w .ja v a2s. com*/ Document doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); String x_type = root.attributeValue("type"); List<?> rows = root.elements("taskmgr"); Iterator<?> iterator = rows.iterator(); while (iterator.hasNext()) { Element element = (Element) iterator.next(); ExtensionEntity extension = new ExtensionEntity(); extension.setProcessName(element.attributeValue("processName")); extension.setTaskName(element.attributeValue("taskName")); extension.setType(x_type); if (element.elementTextTrim("taskMgmtType") != null) { ExtensionFieldEntity extensionField = new ExtensionFieldEntity(); extensionField.setName("taskMgmtType"); extensionField.setValue(element.elementTextTrim("taskMgmtType")); extension.addField(extensionField); } Element propertiesE = element.element("properties"); if (propertiesE != null) { List<?> properties = propertiesE.elements("property"); Iterator<?> iter = properties.iterator(); while (iter.hasNext()) { Element elem = (Element) iter.next(); String propertyName = elem.attributeValue("key"); String propertyValue = null; if (elem.attribute("value") != null) { propertyValue = elem.attributeValue("value"); } else { propertyValue = elem.getTextTrim(); } if (StringUtils.isNotEmpty(propertyName) && StringUtils.isNotEmpty(propertyValue)) { ExtensionFieldEntity extensionField = new ExtensionFieldEntity(); extensionField.setName(propertyName.trim()); extensionField.setValue(propertyValue.trim()); extension.addField(extensionField); } } } if (element.elementText("handlers") != null) { ExtensionFieldEntity extensionField = new ExtensionFieldEntity(); extensionField.setName("handlers"); extensionField.setValue(element.elementTextTrim("handlers")); extension.addField(extensionField); } extensions.add(extension); } } catch (Exception ex) { throw new RuntimeException(ex); } return extensions; }
From source file:com.glaf.activiti.extension.xml.ExtensionReader.java
License:Apache License
public List<ExtensionEntity> readActions(java.io.InputStream inputStream) { List<ExtensionEntity> extensions = new java.util.ArrayList<ExtensionEntity>(); SAXReader xmlReader = new SAXReader(); try {//from w w w . jav a 2 s. c o m Document doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); String x_type = root.attributeValue("type"); List<?> actions = root.elements("action"); Iterator<?> iter = actions.iterator(); while (iter.hasNext()) { Element element = (Element) iter.next(); ExtensionEntity extension = new ExtensionEntity(); extension.setProcessName(element.attributeValue("processName")); extension.setTaskName(element.attributeValue("taskName")); extension.setName(element.attributeValue("name")); extension.setType(x_type); extension.setDescription(element.elementTextTrim("description")); Iterator<?> it99 = element.elementIterator(); while (it99.hasNext()) { Element elem = (Element) it99.next(); String propertyName = elem.getName(); String propertyValue = elem.getTextTrim(); if (StringUtils.isNotEmpty(propertyValue)) { ExtensionFieldEntity extensionField = new ExtensionFieldEntity(); extensionField.setName(propertyName.trim()); extensionField.setValue(propertyValue.trim()); extension.addField(extensionField); } } if (element.elementText("sql") != null) { ExtensionFieldEntity extensionField = new ExtensionFieldEntity(); extensionField.setName("sql"); extensionField.setValue(element.elementTextTrim("sql")); extension.addField(extensionField); } if (element.elementText("handlers") != null) { ExtensionFieldEntity extensionField = new ExtensionFieldEntity(); extensionField.setName("handlers"); extensionField.setValue(element.elementTextTrim("handlers")); extension.addField(extensionField); } Element parametersE = element.element("parameters"); if (parametersE != null) { List<?> parameters = parametersE.elements("parameter"); Iterator<?> it = parameters.iterator(); while (it.hasNext()) { Element elem = (Element) it.next(); String propertyName = elem.attributeValue("name"); String type = elem.attributeValue("type"); String propertyValue = null; if (elem.attribute("value") != null) { propertyValue = elem.attributeValue("value"); } else { propertyValue = elem.getTextTrim(); } if (StringUtils.isNotEmpty(propertyName) && StringUtils.isNotEmpty(propertyValue)) { ExtensionParamEntity extensionParam = new ExtensionParamEntity(); extensionParam.setName(propertyName.trim()); extensionParam.setValue(propertyValue.trim()); extensionParam.setType(type); extension.addParam(extensionParam); } } } extensions.add(extension); } } catch (Exception ex) { throw new RuntimeException(ex); } return extensions; }
From source file:com.glaf.core.todo.util.TodoXmlReader.java
License:Apache License
public List<Todo> read(java.io.InputStream inputStream) { List<Todo> todos = new java.util.ArrayList<Todo>(); SAXReader xmlReader = new SAXReader(); int sortNo = 1; try {/*from www .ja v a2s . c o m*/ Document doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); List<?> rows = root.elements(); Iterator<?> iterator = rows.iterator(); while (iterator.hasNext()) { Element element = (Element) iterator.next(); String id = element.attributeValue("id"); Map<String, Object> rowMap = new java.util.HashMap<String, Object>(); rowMap.put("id", id); List<?> properties = element.elements("property"); Iterator<?> iter = properties.iterator(); while (iter.hasNext()) { Element elem = (Element) iter.next(); String propertyName = elem.attributeValue("name"); String propertyValue = null; if (elem.attribute("value") != null) { propertyValue = elem.attributeValue("value"); } else { propertyValue = elem.getTextTrim(); } if (StringUtils.isNotEmpty(propertyName) && StringUtils.isNotEmpty(propertyValue)) { rowMap.put(propertyName, propertyValue); } } Todo model = new Todo(); model.setSortNo(sortNo++); Tools.populate(model, rowMap); todos.add(model); } } catch (Exception ex) { ex.printStackTrace(); throw new RuntimeException(ex.getMessage()); } return todos; }
From source file:com.glaf.jbpm.config.JbpmExtensionReader.java
License:Apache License
public List<Extension> readTasks(java.io.InputStream inputStream) { List<Extension> extensions = new java.util.ArrayList<Extension>(); SAXReader xmlReader = new SAXReader(); try {//ww w . ja v a 2s. c o m Document doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); String x_type = root.attributeValue("type"); List<?> rows = root.elements("taskmgr"); Iterator<?> iterator = rows.iterator(); while (iterator.hasNext()) { Element element = (Element) iterator.next(); Extension extension = new Extension(); extension.setProcessName(element.attributeValue("processName")); extension.setTaskName(element.attributeValue("taskName")); extension.setType(x_type); if (element.elementTextTrim("taskMgmtType") != null) { ExtensionField extensionField = new ExtensionField(); extensionField.setName("taskMgmtType"); extensionField.setValue(element.elementTextTrim("taskMgmtType")); extension.addField(extensionField); } Element propertiesE = element.element("properties"); if (propertiesE != null) { List<?> properties = propertiesE.elements("property"); Iterator<?> iter = properties.iterator(); while (iter.hasNext()) { Element elem = (Element) iter.next(); String propertyName = elem.attributeValue("key"); String propertyValue = null; if (elem.attribute("value") != null) { propertyValue = elem.attributeValue("value"); } else { propertyValue = elem.getTextTrim(); } if (StringUtils.isNotEmpty(propertyName) && StringUtils.isNotEmpty(propertyValue)) { ExtensionField extensionField = new ExtensionField(); extensionField.setName(propertyName.trim()); extensionField.setValue(propertyValue.trim()); extension.addField(extensionField); } } } if (element.elementText("handlers") != null) { ExtensionField extensionField = new ExtensionField(); extensionField.setName("handlers"); extensionField.setValue(element.elementTextTrim("handlers")); extension.addField(extensionField); } extensions.add(extension); } } catch (Exception ex) { throw new RuntimeException(ex); } return extensions; }
From source file:com.glaf.jbpm.config.JbpmExtensionReader.java
License:Apache License
public List<Extension> readActions(java.io.InputStream inputStream) { List<Extension> extensions = new java.util.ArrayList<Extension>(); SAXReader xmlReader = new SAXReader(); try {/*from w ww.jav a 2 s . c o m*/ Document doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); String x_type = root.attributeValue("type"); List<?> actions = root.elements("action"); Iterator<?> iter = actions.iterator(); while (iter.hasNext()) { Element element = (Element) iter.next(); Extension extension = new Extension(); extension.setProcessName(element.attributeValue("processName")); extension.setTaskName(element.attributeValue("taskName")); extension.setName(element.attributeValue("name")); extension.setType(x_type); extension.setDescription(element.elementTextTrim("description")); Iterator<?> it99 = element.elementIterator(); while (it99.hasNext()) { Element elem = (Element) it99.next(); String propertyName = elem.getName(); String propertyValue = elem.getTextTrim(); if (StringUtils.isNotEmpty(propertyValue)) { ExtensionField extensionField = new ExtensionField(); extensionField.setName(propertyName.trim()); extensionField.setValue(propertyValue.trim()); extension.addField(extensionField); } } if (element.elementText("sql") != null) { ExtensionField extensionField = new ExtensionField(); extensionField.setName("sql"); extensionField.setValue(element.elementTextTrim("sql")); extension.addField(extensionField); } if (element.elementText("handlers") != null) { ExtensionField extensionField = new ExtensionField(); extensionField.setName("handlers"); extensionField.setValue(element.elementTextTrim("handlers")); extension.addField(extensionField); } Element parametersE = element.element("parameters"); if (parametersE != null) { List<?> parameters = parametersE.elements("parameter"); Iterator<?> it = parameters.iterator(); while (it.hasNext()) { Element elem = (Element) it.next(); String propertyName = elem.attributeValue("name"); String type = elem.attributeValue("type"); String propertyValue = null; if (elem.attribute("value") != null) { propertyValue = elem.attributeValue("value"); } else { propertyValue = elem.getTextTrim(); } if (StringUtils.isNotEmpty(propertyName) && StringUtils.isNotEmpty(propertyValue)) { ExtensionParam extensionParam = new ExtensionParam(); extensionParam.setName(propertyName.trim()); extensionParam.setValue(propertyValue.trim()); extensionParam.setType(type); extension.addParam(extensionParam); } } } extensions.add(extension); } } catch (Exception ex) { throw new RuntimeException(ex); } return extensions; }
From source file:com.glaf.jbpm.util.CustomFieldInstantiator.java
License:Apache License
public static Object getValue(Class<?> type, Element propertyElement) { Object value = null;//from www . j a va 2 s. c o m if (type == String.class) { value = propertyElement.getText(); } else if ((type == Integer.class) || (type == int.class)) { value = Integer.parseInt(propertyElement.getTextTrim()); } else if ((type == Long.class) || (type == long.class)) { value = Long.parseLong(propertyElement.getTextTrim()); } else if ((type == Float.class) || (type == float.class)) { value = new Float(propertyElement.getTextTrim()); } else if ((type == Double.class) || (type == double.class)) { value = Double.parseDouble(propertyElement.getTextTrim()); } else if ((type == Boolean.class) || (type == boolean.class)) { value = Boolean.valueOf(propertyElement.getTextTrim()); } else if ((type == Character.class) || (type == char.class)) { value = Character.valueOf(propertyElement.getTextTrim().charAt(0)); } else if ((type == Short.class) || (type == short.class)) { value = Short.valueOf(propertyElement.getTextTrim()); } else if ((type == Byte.class) || (type == byte.class)) { value = Byte.valueOf(propertyElement.getTextTrim()); } else if (type.isAssignableFrom(java.util.Date.class)) { value = DateUtils.toDate(propertyElement.getTextTrim()); } else if (type.isAssignableFrom(List.class)) { value = getCollectionValue(propertyElement, new java.util.ArrayList<Object>()); } else if (type.isAssignableFrom(Set.class)) { value = getCollectionValue(propertyElement, new LinkedHashSet<Object>()); } else if (type.isAssignableFrom(Collection.class)) { value = getCollectionValue(propertyElement, new java.util.ArrayList<Object>()); } else if (type.isAssignableFrom(Map.class)) { value = getMapValue(propertyElement, new LinkedHashMap<Object, Object>()); } else if (type == Element.class) { value = propertyElement; } else { try { Constructor<?> constructor = type.getConstructor(new Class[] { String.class }); if ((propertyElement.isTextOnly()) && (constructor != null)) { value = constructor.newInstance(new Object[] { propertyElement.getTextTrim() }); } } catch (Exception ex) { logger.error("couldn't parse the bean property value '" + propertyElement.asXML() + "' to a '" + type.getName() + "'"); throw new RuntimeException(ex); } } return value; }
From source file:com.globalsight.connector.mindtouch.util.MindTouchHelper.java
License:Apache License
/** * Return an XML like//from w w w.jav a 2s .co m * "<tags><tag value=\"title1\"/><tag value=\"title2\"/></tags>". * * @param tagsXml * @return String * @throws DocumentException */ @SuppressWarnings("rawtypes") private String getTagTitlesXml(String tagsXml) throws DocumentException { StringBuffer titles = new StringBuffer(); titles.append("<tags>"); Document doc = getDocument(tagsXml); List titleNodes = doc.selectNodes("//title"); Iterator it = titleNodes.iterator(); String title = null; while (it.hasNext()) { Element titleNode = (Element) it.next(); title = titleNode.getTextTrim(); if (title != null && title.length() > 0) { title = StringUtil.replace(title, "&", "&"); title = StringUtil.replace(title, "<", "<"); title = StringUtil.replace(title, ">", ">"); titles.append("<tag value=\"").append(title).append("\"/>"); } } titles.append("</tags>"); return titles.toString(); }
From source file:com.globalsight.connector.mindtouch.util.MindTouchHelper.java
License:Apache License
/** * Return an XML like//from ww w . j ava 2 s .c om * "<properties><property name="name1"><contents type="text/plain">yes</contents></property><property name="name2"/></properties>" * * @param propertiesXml * @return String * @throws DocumentException */ @SuppressWarnings("rawtypes") private String getPropertiesContentsXml(String propertiesXml, HashMap<String, String> etagMap) throws DocumentException { StringBuffer titles = new StringBuffer(); titles.append("<properties>"); Document doc = getDocument(propertiesXml); List propertyNodes = doc.selectNodes("//property"); Iterator it = propertyNodes.iterator(); String name = null; String content = null; while (it.hasNext()) { Element propertyNode = (Element) it.next(); name = propertyNode.attributeValue("name"); Element contentNode = (Element) propertyNode.selectSingleNode("contents"); content = contentNode.getTextTrim(); if (content != null && content.length() > 0) { content = StringUtil.replace(content, "&", "&"); content = StringUtil.replace(content, "<", "<"); content = StringUtil.replace(content, ">", ">"); titles.append("<property name=\"").append(name).append("\" etag=\"").append(etagMap.get(name)) .append("\"><contents type=\"text/plain; charset=UTF-8\">").append(content) .append("</contents></property>"); } } titles.append("</properties>"); return titles.toString(); }
From source file:com.haulmont.cuba.desktop.theme.impl.DesktopThemeLoaderImpl.java
License:Apache License
private void loadThemeFromXml(DesktopThemeImpl theme, Resource resource) throws IOException { log.info("Loading theme file " + resource.getURL()); Document doc = readXmlDocument(resource); final Element rootElement = doc.getRootElement(); for (Element element : (List<Element>) rootElement.elements()) { String elementName = element.getName(); if ("lookAndFeel".equals(elementName)) { String lookAndFeel = element.getTextTrim(); if (StringUtils.isNotEmpty(lookAndFeel)) { theme.setLookAndFeel(lookAndFeel); }// w w w .j av a 2s . c o m } else if ("ui-defaults".equals(elementName)) { loadUIDefaults(theme.getUiDefaults(), element); } else if ("layout".equals(elementName)) { loadLayoutSettings(theme, element); } else if ("style".equals(elementName)) { DesktopStyle style = loadStyle(element); theme.addStyle(style); } else if ("include".equals(elementName)) { includeThemeFile(theme, element, resource); } else if ("class".equals(elementName)) { // ignore it } else { log.error("Unknown tag: " + elementName); } } }