List of usage examples for org.dom4j Element elementIterator
Iterator<Element> elementIterator();
From source file:com.qagen.osfe.core.loaders.BeanLoader.java
License:Apache License
/** * Pass One - instantiate all classes// w ww . j av a 2 s . c o m */ private void loadBeansIntoBeanMap(Map<String, Object> beanMap, Element parent) { final Iterator categoryIterator = parent.elementIterator(); while (categoryIterator.hasNext()) { final Element category = (Element) categoryIterator.next(); final Iterator it = category.elementIterator(ELEMENT.bean.name()); while (it.hasNext()) { final Element element = (Element) it.next(); final String name = DomReader.getRequiredValue(element, ATTRIBUTE.name.getToken()); final String value = DomReader.getRequiredValue(element, ATTRIBUTE.className.getToken()); final Object clazz = loadClass(element, value); beanMap.put(name, clazz); } } }
From source file:com.qagen.osfe.core.loaders.BeanLoader.java
License:Apache License
/** * Pass Two - inject references to other classes *//*from w ww . j a v a 2 s.com*/ private void loadBeanReferences(Map<String, Object> beanMap, Element parent) { final Iterator categoryIterator = parent.elementIterator(); while (categoryIterator.hasNext()) { final Element category = (Element) categoryIterator.next(); final Iterator it = category.elementIterator(ELEMENT.bean.name()); while (it.hasNext()) { final Element element = (Element) it.next(); final String name = DomReader.getValue(element, ATTRIBUTE.name.getToken()); final Object bean = beanMap.get(name); injectReferences(bean, element, beanMap); injectProperties(bean, element); } } }
From source file:com.qagen.osfe.core.loaders.ComponentLoader.java
License:Apache License
/** * Contains the instructions for parsing data from child elements within * the parent element. If the element is complex, other loaders should * be used within this method to parse different sub elements. * * @param parent container of child element to parse. *//* w ww.j ava 2 s .c om*/ public void load(Element parent) { list = new ArrayList<Property>(); name = parent.attributeValue(ATTRIBUTE.name.name()); final Iterator it = parent.elementIterator(); while (it.hasNext()) { final Element element = (Element) it.next(); final String name = element.getName(); switch (ELEMENT.valueOf(name)) { case feedId: list.add(new Property(ELEMENT.feedId.name(), null)); break; case delimiter: list.add(new Property(ELEMENT.delimiter.name(), null)); break; case lineCount: addPropertyWithFormat(element, list); break; case sequenceNumber: addSequenceNumber(element, list); break; case separator: addPropertyWithValue(element, list); break; case literal: addPropertyWithValue(element, list); break; case timestamp: addPropertyWithFormat(element, list); break; } } }
From source file:com.qagen.osfe.core.loaders.EventPhasesLoader.java
License:Apache License
public void load(Element parent) { map = new HashMap<String, List<PhaseInfo>>(); batchSize = Integer.parseInt(parent.attributeValue(ATTRIBUTE.batchSize.name())); context.setBatchSize(batchSize);/*from ww w . j a va 2 s. c om*/ final Iterator it = parent.elementIterator(); while (it.hasNext()) { final Element element = (Element) it.next(); final String name = element.getName(); final PhasesLoader phaseLoader = new PhasesLoader(parent, name); map.put(name, phaseLoader.getList()); } }
From source file:com.sammyun.util.XmlHelper.java
License:Open Source License
/** * ?XMLDto(?XML?)//from w w w . ja v a 2s . c om * * @param pStrXml ?XML * @return outDto Dto */ public static final Dto parseXml2DtoBasedNode(String pStrXml) { Dto outDto = new BaseDto(); String strTitle = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; Document document = null; try { if (pStrXml.indexOf("<?xml") < 0) pStrXml = strTitle + pStrXml; document = DocumentHelper.parseText(pStrXml); } catch (DocumentException e) { logger.error( "==??:==\nXML??XML DOM?!" + "\n?:"); e.printStackTrace(); } if (document != null) { // ? Element elNode = document.getRootElement(); // ??Dto for (Iterator it = elNode.elementIterator(); it.hasNext();) { Element leaf = (Element) it.next(); outDto.put(leaf.getName().toLowerCase(), leaf.getData()); } } return outDto; }
From source file:com.sammyun.util.XmlHelper.java
License:Open Source License
/** * ?XMLDto(?XML?)/*ww w .j a v a2 s . co m*/ * * @param pStrXml ?XML * @param pXPath ("//paralist/row" paralistrowxPath) * @return outDto Dto */ public static final Dto parseXml2DtoBasedNode(String pStrXml, String pXPath) { Dto outDto = new BaseDto(); String strTitle = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; Document document = null; try { if (pStrXml.indexOf("<?xml") < 0) pStrXml = strTitle + pStrXml; document = DocumentHelper.parseText(pStrXml); } catch (DocumentException e) { logger.error( "==??:==\nXML??XML DOM?!" + "\n?:"); e.printStackTrace(); } if (document != null) { // ? Element elNode = document.getRootElement(); // ??Dto for (Iterator it = elNode.elementIterator(); it.hasNext();) { Element leaf = (Element) it.next(); outDto.put(leaf.getName().toLowerCase(), leaf.getData()); } } return outDto; }
From source file:com.sammyun.util.XmlHelper.java
License:Open Source License
/** * XMLList(XML?)//from w ww.jav a 2s . com * * @param pStrXml ?XML? * @return list List */ public static final List parseXml2List(String pStrXml) { List lst = new ArrayList(); String strTitle = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; Document document = null; try { if (pStrXml.indexOf("<?xml") < 0) pStrXml = strTitle + pStrXml; document = DocumentHelper.parseText(pStrXml); } catch (DocumentException e) { logger.error( "==??:==\nXML??XML DOM?!" + "\n?:"); e.printStackTrace(); } if (document != null) { // ? Element elRoot = document.getRootElement(); // ?? Iterator elIt = elRoot.elementIterator(); while (elIt.hasNext()) { Element el = (Element) elIt.next(); Iterator attrIt = el.attributeIterator(); Dto dto = new BaseDto(); while (attrIt.hasNext()) { Attribute attribute = (Attribute) attrIt.next(); dto.put(attribute.getName().toLowerCase(), attribute.getData()); } lst.add(dto); } } return lst; }
From source file:com.seer.datacruncher.utils.generic.StreamsUtils.java
License:Open Source License
/** * Recursive method that parses all xml childs. * /* w ww . j av a2 s. co m*/ * @param elem - current dom element. * @param xmlTextNodes - text node list */ private static void getXmlChilds(Element elem, List<Element> xmlTextNodes) { for (@SuppressWarnings("unchecked") Iterator<Element> i = elem.elementIterator(); i.hasNext();) { Element el = i.next(); if (el.isTextOnly()) { xmlTextNodes.add(el); } else { getXmlChilds(el, xmlTextNodes); } } }
From source file:com.shlaunch.weixin.local.web.WeixinController.java
License:Open Source License
/** * parse?,map//from ww w . j av a 2 s . c om * * @param request * @return * @throws IOException * @throws DocumentException */ private Map<String, Object> parseInputStream(HttpServletRequest request) throws IOException, DocumentException { Map<String, Object> elementMap = null; ServletInputStream inputStream = request.getInputStream(); if (null != inputStream) { String postStr = this.readStreamParameter(inputStream); Document document = null; try { document = DocumentHelper.parseText(postStr); } catch (Exception e) { logger.debug(e); e.printStackTrace(); } if (null != document) { elementMap = new HashMap<String, Object>(); Element rootElm = document.getRootElement(); for (Iterator<Element> iterator = rootElm.elementIterator(); iterator.hasNext();) { Element element = iterator.next(); String name = element.getName(); Object data = element.getData(); elementMap.put(name, data); } } } return elementMap; }
From source file:com.stgmastek.core.util.XMLUtil.java
License:Open Source License
/** * Returns the response data object// w ww. j a v a 2s .c o m * * @param responseString * The response string. * * @return List of Element instances from data tag. * * @throws Exception */ public static List<org.w3c.dom.Element> getData(String responseString) throws Exception { DocumentFactory factory = new org.dom4j.dom.DOMDocumentFactory(); SAXReader reader = new SAXReader(factory); List<org.w3c.dom.Element> elements = new ArrayList<org.w3c.dom.Element>(); try { Document responseDocument = reader.read(new StringReader(responseString)); org.dom4j.Node dataNode = responseDocument.selectSingleNode(DATA_XPATH); if ((dataNode != null) && (dataNode.getNodeType() == Node.ELEMENT_NODE)) { Element dataElement = (Element) dataNode; for (Iterator<?> nodeIterator = dataElement.elementIterator(); nodeIterator.hasNext();) { Element objectNode = (Element) nodeIterator.next(); elements.add(DOMNodeHelper.asDOMElement(objectNode)); } } } catch (DocumentException e) { throw new Exception("Invalid response", e); } return elements; }