List of usage examples for org.dom4j Element attributes
List<Attribute> attributes();
From source file:com.devoteam.srit.xmlloader.core.utils.XMLElementDefaultParser.java
License:Open Source License
public List<Element> replace(Element element, ParameterPool parameterPool) throws Exception { List<Element> list = new LinkedList<Element>(); Element newElement = element.createCopy(); list.add(newElement);// www.jav a 2 s . c o m List<Attribute> attributes = newElement.attributes(); for (Attribute attribute : attributes) { String value = attribute.getValue(); LinkedList<String> parsedValue = parameterPool.parse(value); if (parsedValue.size() != 1) { throw new ExecutionException("Invalid size of variables in attribute " + value); } attribute.setValue(parsedValue.getFirst()); } return list; }
From source file:com.devoteam.srit.xmlloader.core.utils.XMLElementRTPFLOWParser.java
License:Open Source License
public List<Element> replace(Element element, ParameterPool parameterPool) throws Exception { List<Element> result = new LinkedList(); //do classic replacement of attribute and save it in result Element newElement = element.createCopy(); result.add(newElement);// ww w .j a v a 2s . c om List<Attribute> attributes = newElement.attributes(); for (Attribute attribute : attributes) { if (!attribute.getName().equalsIgnoreCase("timestamp") && !attribute.getName().equalsIgnoreCase("seqnum") && !attribute.getName().equalsIgnoreCase("deltaTime") && !attribute.getName().equalsIgnoreCase("mark")) { String value = attribute.getValue(); LinkedList<String> parsedValue = parameterPool.parse(value); if (parsedValue.size() != 1) { throw new ExecutionException("Invalid size of variables in attribute " + value); } attribute.setValue(parsedValue.getFirst()); } } return result; }
From source file:com.devoteam.srit.xmlloader.core.utils.XMLTree.java
License:Open Source License
private void listMatchingElements(Element element, String regex, boolean recurse) { ///*from w ww. j a va2 s . c om*/ // First check attributes // List<Attribute> namedNodeMap = element.attributes(); if (null != namedNodeMap) { for (Attribute attribute : namedNodeMap) { String value = attribute.getValue(); if (Utils.containsRegex(value, regex)) { if (false == elementsMap.containsKey(element)) { elementsMap.put(element, null); elementsOrder.addFirst(element); } } } } // // Then check text // if (Utils.containsRegex(element.getText(), regex)) { if (false == elementsMap.containsKey(element)) { elementsMap.put(element, null); elementsOrder.addFirst(element); } } // // Finally elements // if (recurse) { List<Element> childrens = element.elements(); for (Element child : childrens) { listMatchingElements(child, regex, recurse); } } }
From source file:com.doculibre.constellio.utils.xml.SolrShemaXmlReader.java
License:Open Source License
private static Map<String, Map<String, String>> readFields(Document schemaDocument, Boolean readDynamicFields, Boolean checkTypes) {//w w w .ja v a 2 s. c o m Map<String, Map<String, String>> returnList = new HashMap<String, Map<String, String>>(); //AnalyzerClassServices analyzerClassServices = ConstellioSpringUtils.getAnalyzerClassServices(); FieldTypeServices fieldTypeServices = ConstellioSpringUtils.getFieldTypeServices(); if (schemaDocument != null) { Element fieldsElement = schemaDocument.getRootElement().element("fields"); List<Element> fieldElements; if (readDynamicFields) { fieldElements = fieldsElement.elements("dynamicField"); } else { fieldElements = fieldsElement.elements("field"); } for (Iterator<Element> it = fieldElements.iterator(); it.hasNext();) { Element fieldElement = it.next(); if (checkTypes) { /*String analyzerClassName = fieldElement.attributeValue("analyzer"); if (analyzerClassName != null) { AnalyzerClass analyzerClass = analyzerClassServices.get(analyzerClassName); if (analyzerClass == null) { throw new RuntimeException("New Analyzers must be defined throught Constellio Interface"); } }*/ String typeName = fieldElement.attributeValue("type"); if (typeName == null) { throw new RuntimeException("A Field must have a type"); } FieldType fieldType = fieldTypeServices.get(typeName); if (fieldType == null) { throw new RuntimeException( "New Field type " + typeName + " must be defined throught Constellio Interface"); } } String fieldName = fieldElement.attributeValue("name"); if (fieldName == null) { throw new RuntimeException("A Field must have a name"); } List<Attribute> attributes = fieldElement.attributes(); Map<String, String> attributesToMap = new HashMap<String, String>(); for (Attribute att : attributes) { if (!att.getQualifiedName().equals("name")) { attributesToMap.put(att.getQualifiedName(), att.getValue()); } } returnList.put(fieldName, attributesToMap); } } return returnList; }
From source file:com.dtolabs.shared.resources.ResourceXMLParser.java
License:Apache License
/** * Parse the DOM attributes as properties for the particular entity node type * * @param ent Entity object//from w w w .j av a2s.co m * @param node entity DOM node * * @throws ResourceXMLParserException if the DOM node is an unexpected tag name */ private void parseEntProperties(final Entity ent, final Node node) throws ResourceXMLParserException { if (null == entityProperties.get(node.getName())) { throw new ResourceXMLParserException( "Unexpected entity declaration: " + node.getName() + ": " + reportNodeErrorLocation(node)); } final Element node1 = (Element) node; //load all element attributes as properties for (final Object o : node1.attributes()) { final Attribute attr = (Attribute) o; ent.properties.setProperty(attr.getName(), attr.getStringValue()); } }
From source file:com.example.sample.pMainActivity.java
License:Apache License
public void listNodes(Element node) { System.out.println("" + node.getName()); List<Attribute> list = node.attributes(); for (Attribute attr : list) { Log.d(TAG, "listNodes: " + attr.getText() + "-----" + attr.getName() + "---" + attr.getValue()); }/*from w ww .j av a 2s . c o m*/ if (!(node.getTextTrim().equals(""))) { Log.d(TAG, "getText: " + node.getText()); node.setText("getText: "); saveDocument(document); Log.d(TAG, "saveDocument: " + node.getText()); } Iterator<Element> it = node.elementIterator(); while (it.hasNext()) { Element e = it.next(); listNodes(e); } }
From source file:com.github.megatronking.svg.applet.graphics.VdTree.java
License:Apache License
private void parseTree(Element currentNode, VdGroup currentGroup) { List<?> childrenNodes = currentNode.elements(); int length = childrenNodes.size(); for (int i = 0; i < length; i++) { Element child = (Element) childrenNodes.get(i); if (child.getNodeType() == Element.ELEMENT_NODE) { if (SHAPE_GROUP.equals(child.getName())) { VdGroup newGroup = parseGroupAttributes(child.attributes()); currentGroup.add(newGroup); parseTree(child, newGroup); } else if (SHAPE_PATH.equals(child.getName())) { VdPath newPath = parsePathAttributes(child.attributes()); currentGroup.add(newPath); }/*from ww w . j a va 2s . co m*/ } } }
From source file:com.github.megatronking.svg.applet.graphics.VdTree.java
License:Apache License
private void parseRootNode(Element rootNode) { if (rootNode.attributeCount() != 0) { parseSize(rootNode.attributes()); } }
From source file:com.glaf.core.xml.XmlBuilder.java
License:Apache License
public void processElement(String systemName, Element root, Map<String, Object> params) { /**/* w w w . j a v a2s . co m*/ * ?? */ Map<String, DatasetModel> dataSetMap = new HashMap<String, DatasetModel>(); List<?> elements = root.elements("DataSet"); Iterator<?> iterator = elements.iterator(); while (iterator.hasNext()) { Element element = (Element) iterator.next(); String id = element.attributeValue("id"); String sql = element.attributeValue("sql"); String queryId = element.attributeValue("queryId"); String title = element.attributeValue("title"); String single = element.attributeValue("single"); String splits = element.attributeValue("splits"); String foreachPerRow = element.attributeValue("foreachPerRow"); if (sql == null) { sql = element.elementText("sql"); } DatasetModel dsm = new DatasetModel(); dsm.setId(id); dsm.setSql(sql); dsm.setQueryId(queryId); dsm.setTitle(title); if (StringUtils.equalsIgnoreCase(single, "true")) { dsm.setSingle(true); } if (StringUtils.equalsIgnoreCase(foreachPerRow, "true")) { dsm.setForeachPerRow(true); } if (StringUtils.isNotEmpty(splits)) { dsm.setSplitList(StringTools.split(splits)); } List<?> attrs = element.attributes(); if (attrs != null && !attrs.isEmpty()) { Iterator<?> iter = attrs.iterator(); while (iter.hasNext()) { Attribute attr = (Attribute) iter.next(); dsm.addAttribute(attr.getName(), attr.getStringValue()); } } List<?> providers = element.elements("FieldConverter"); if (providers != null && !providers.isEmpty()) { Iterator<?> iter = providers.iterator(); while (iter.hasNext()) { Element elem = (Element) iter.next(); String fromName = elem.attributeValue("fromName"); String toName = elem.attributeValue("toName"); String provider = elem.attributeValue("provider"); FieldController c = new FieldController(); c.setFromName(fromName); c.setToName(toName); c.setProvider(provider); dsm.addController(c); } } dataSetMap.put(dsm.getId(), dsm); } elements = root.elements(); iterator = elements.iterator(); while (iterator.hasNext()) { Element element = (Element) iterator.next(); if (StringUtils.equals(element.getName(), "DataSet")) { continue; } this.processNode(element, dataSetMap, systemName, params); } elements = root.elements("DataSet"); iterator = elements.iterator(); while (iterator.hasNext()) { Element element = (Element) iterator.next(); root.remove(element); } }
From source file:com.glaf.core.xml.XmlBuilder.java
License:Apache License
protected void processTextNode(Element element, Map<String, DatasetModel> dataSetMap, Map<String, Object> dataMap, String systemName, Map<String, Object> params) { //LOG.debug("---------------------processTextNode-----------------------"); if (StringUtils.equals(element.getName(), "foreach")) { this.processForEachNode(element, dataSetMap, dataMap, systemName, params); return;//from w w w .j a va 2s . c o m } String dsId = element.attributeValue("DataSetId"); if (StringUtils.isNotEmpty(dsId)) { if (dataMap != null && !dataMap.isEmpty()) { params.putAll(dataMap); } this.processNode(element, dataSetMap, systemName, params); return; } if (element.isTextOnly()) { String value = element.getStringValue(); if (StringUtils.contains(value, "#{") && StringUtils.contains(value, "}")) { String text = QueryUtils.replaceBlankParas(value, dataMap); element.setText(text); } } List<?> attrs = element.attributes(); Iterator<?> iter = attrs.iterator(); while (iter.hasNext()) { Attribute attr = (Attribute) iter.next(); String value = attr.getValue(); if (StringUtils.contains(value, "#{") && StringUtils.contains(value, "}")) { String text = QueryUtils.replaceBlankParas(value, dataMap); attr.setValue(text); } } List<?> elements = element.elements(); Iterator<?> iterator = elements.iterator(); while (iterator.hasNext()) { Element elem = (Element) iterator.next(); if (StringUtils.equals(elem.getName(), "foreach")) { this.processForEachNode(elem, dataSetMap, dataMap, systemName, params); } else { String dsId2 = elem.attributeValue("DataSetId"); if (StringUtils.isNotEmpty(dsId2)) { if (dataMap != null && !dataMap.isEmpty()) { params.putAll(dataMap); } this.processNode(elem, dataSetMap, systemName, params); } else { this.processTextNode(elem, dataSetMap, dataMap, systemName, params); } } } }