Example usage for org.dom4j Element elementIterator

List of usage examples for org.dom4j Element elementIterator

Introduction

In this page you can find the example usage for org.dom4j Element elementIterator.

Prototype

Iterator<Element> elementIterator();

Source Link

Document

Returns an iterator over all this elements child elements.

Usage

From source file:com.hihsoft.sso.systempublic.servlet.HihSoftInitDBServlet.java

License:Apache License

/**
 * xml,"import"?xml/*from   w w  w  .ja  v a2 s  . com*/
 * 
 * @param file
 */
@SuppressWarnings("deprecation")
private void loadFile(File file) throws Exception {
    XmlParseUtil xmlUtil = new XmlParseUtil();
    Document doc = xmlUtil.readXml(file);
    Element root = doc.getRootElement();
    Iterator<?> it = root.elementIterator();
    String path = file.getPath();
    String fileseparate = System.getProperty("file.separator");
    String dir = path.substring(0, path.lastIndexOf(fileseparate));
    Element el = null;
    String isLoad = null;
    String type = null;
    String resource = null;
    File file1 = null;
    Document doc1 = null;
    while (it.hasNext()) {
        el = (Element) it.next();
        isLoad = el.attributeValue("isLoad");
        type = el.attributeValue("type");
        resource = el.attributeValue("resource");
        // "import",xml?
        if (el.getName().equals("import") && isLoad != null && isLoad.equals("true")) {
            file1 = new FileSystemResource(dir + fileseparate + resource).getFile();
            if (file1.isDirectory()) {
                readFile(file1);
            } else {
                doc1 = xmlUtil.readXml(file1);
                // ?
                if (el.getName().equals("import") && isLoad != null && isLoad.equals("true") && type != null
                        && type.equals("framework")) {
                    initDB(doc1);
                    el.setAttributeValue("isLoad", "false");
                    doc1.getRootElement().element("models").setAttributeValue("isLoad", "false");
                    xmlUtil.writeXml(doc1, file1);

                }
            }
        } else if (el.getName().equals("models")) {
            initDB(doc);
            doc.getRootElement().element("models").setAttributeValue("isLoad", "false");
            // xmlUtil.writeXml(doc1, file1);
        }
        xmlUtil.writeXml(doc, file);
    }
    initFrameworkService.saveOrUpdateInitFramework();
}

From source file:com.hyron.poscafe.util.ConfigurationWithWildcard.java

License:Open Source License

private void parseSessionFactory(Element sfNode, String name) {
    Iterator elements = sfNode.elementIterator();
    while (elements.hasNext()) {
        Element subelement = (Element) elements.next();
        String subelementName = subelement.getName();
        if ("mapping".equals(subelementName)) {
            parseMappingElement(subelement, name);
        } else if ("class-cache".equals(subelementName)) {
            String className = subelement.attributeValue("class");
            Attribute regionNode = subelement.attribute("region");
            final String region = (regionNode == null) ? className : regionNode.getValue();
            boolean includeLazy = !"non-lazy".equals(subelement.attributeValue("include"));
            setCacheConcurrencyStrategy(className, subelement.attributeValue("usage"), region, includeLazy);
        } else if ("collection-cache".equals(subelementName)) {
            String role = subelement.attributeValue("collection");
            Attribute regionNode = subelement.attribute("region");
            final String region = (regionNode == null) ? role : regionNode.getValue();
            setCollectionCacheConcurrencyStrategy(role, subelement.attributeValue("usage"), region);
        } else if ("listener".equals(subelementName)) {
            parseListener(subelement);//from w w  w.j  a v  a 2  s.  c o  m
        } else if ("event".equals(subelementName)) {
            parseEvent(subelement);
        }
    }
}

From source file:com.hyron.poscafe.util.ConfigurationWithWildcard.java

License:Open Source License

private void parseSecurity(Element secNode) {
    String contextId = secNode.attributeValue("context");
    setProperty(Environment.JACC_CONTEXTID, contextId);
    log.info("JACC contextID: " + contextId);
    JACCConfiguration jcfg = new JACCConfiguration(contextId);
    Iterator grantElements = secNode.elementIterator();
    while (grantElements.hasNext()) {
        Element grantElement = (Element) grantElements.next();
        String elementName = grantElement.getName();
        if ("grant".equals(elementName)) {
            jcfg.addPermission(grantElement.attributeValue("role"), grantElement.attributeValue("entity-name"),
                    grantElement.attributeValue("actions"));
        }//from   ww  w .j  av a  2s . c  o  m
    }
}

From source file:com.jinglingtec.ijiazu.util.CCPRestSmsSDK.java

License:Open Source License

/**
 * @param xml/*from w w w .j  a  v a 2  s  .  c  om*/
 *
 * @return Map
 *
 * @description xml??map
 */
private HashMap<String, Object> xmlToMap(String xml) {
    HashMap<String, Object> map = new HashMap<String, Object>();
    Document doc = null;
    try {
        doc = DocumentHelper.parseText(xml); // XML
        Element rootElt = doc.getRootElement(); // ?
        HashMap<String, Object> hashMap2 = new HashMap<String, Object>();
        for (Iterator i = rootElt.elementIterator(); i.hasNext();) {
            Element e = (Element) i.next();
            if ("statusCode".equals(e.getName()) || "statusMsg".equals(e.getName())) {
                map.put(e.getName(), e.getText());
            } else {
                if ("SubAccount".equals(e.getName()) || "totalCount".equals(e.getName())
                        || "token".equals(e.getName()) || "downUrl".equals(e.getName())) {
                    if (!"SubAccount".equals(e.getName())) {
                        hashMap2.put(e.getName(), e.getText());
                    } else {
                        ArrayList<HashMap<String, Object>> arrayList = new ArrayList<HashMap<String, Object>>();
                        HashMap<String, Object> hashMap3 = new HashMap<String, Object>();
                        for (Iterator i2 = e.elementIterator(); i2.hasNext();) {
                            Element e2 = (Element) i2.next();
                            hashMap3.put(e2.getName(), e2.getText());
                            arrayList.add(hashMap3);
                        }
                        hashMap2.put("SubAccount", arrayList);
                    }
                    map.put("data", hashMap2);
                } else {

                    HashMap<String, Object> hashMap3 = new HashMap<String, Object>();
                    for (Iterator i2 = e.elementIterator(); i2.hasNext();) {
                        Element e2 = (Element) i2.next();
                        // hashMap2.put(e2.getName(),e2.getText());
                        hashMap3.put(e2.getName(), e2.getText());
                    }
                    if (hashMap3.size() != 0) {
                        hashMap2.put(e.getName(), hashMap3);
                    } else {
                        hashMap2.put(e.getName(), e.getText());
                    }
                    map.put("data", hashMap2);
                }
            }
        }
    } catch (DocumentException e) {
        e.printStackTrace();
        LoggerUtil.error(e.getMessage());
    } catch (Exception e) {
        LoggerUtil.error(e.getMessage());
        e.printStackTrace();
    }
    return map;
}

From source file:com.jiusit.onePurchase.pay.Pay.java

License:Open Source License

public static Map<String, String> xml2Map(String xml) {
    Map<String, String> map = new HashMap<String, String>();
    try {/*from   w  ww  .  j a v  a  2 s.  c  om*/
        Document document = DocumentHelper.parseText(xml);
        Element root = document.getRootElement();
        for (Iterator it = root.elementIterator(); it.hasNext();) {
            Element element = (Element) it.next();
            map.put(element.getName(), element.getTextTrim());
        }
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return map;
}

From source file:com.kingmed.dp.mail.util.XMLHandler.java

@SuppressWarnings("rawtypes")
public static Map<String, String> transXmltoMapForSpec(String xmlInfo) throws DocumentException {
    Document doc = DocumentHelper.parseText(xmlInfo); // xml
    Map<String, String> map = new HashMap<String, String>();
    Element rootElt = doc.getRootElement();
    Iterator iter = rootElt.elementIterator();
    while (iter.hasNext()) {
        Element dataElement = (Element) iter.next();
        map.put(dataElement.getName(), dataElement.getText());
    }//from   w w  w  . j ava  2  s. co m
    Element e = (Element) (rootElt.element("specimen").elements().get(0));
    map.put("specimen", e.asXML());
    return map;
}

From source file:com.kingmed.dp.mail.util.XMLHandler.java

public static Map<String, Object> transXmltoMapForReport(String xmlInfo) throws DocumentException {
    Document doc = DocumentHelper.parseText(xmlInfo); // xml
    Map<String, Object> map = new HashMap<String, Object>();
    Element rootElt = doc.getRootElement();
    @SuppressWarnings("rawtypes")
    Iterator iter = rootElt.elementIterator();
    while (iter.hasNext()) {
        Element dataElement = (Element) iter.next();
        map.put(dataElement.getName(), dataElement.getText());
    }/*from w w w . ja  v a  2 s. co  m*/
    /*
    Element e = (Element) (rootElt.element("Data"));
    String data = "";
    if (e != null) {
    data = ((Element) e.elements().get(0)).asXML();
    map.put("Data", "<Data>" + data + "</Data>");
    } else {
    data = xmlInfo;
    map.put("Data", data);
    }
    */
    return map;
}

From source file:com.kingmed.dp.mail.util.XMLHandler.java

public static Map<String, String> transSimpleXmltoMap(String xmlInfo) throws DocumentException {
    Document doc = DocumentHelper.parseText(xmlInfo); // xml
    Map<String, String> map = new HashMap<String, String>();
    Element rootElt = doc.getRootElement();
    @SuppressWarnings("rawtypes")
    Iterator iter = rootElt.elementIterator();
    while (iter.hasNext()) {
        Element dataElement = (Element) iter.next();
        map.put(dataElement.getName(), dataElement.getText());
    }/*from ww w.  ja  v a  2  s .co m*/
    return map;
}

From source file:com.kingmed.yuyt.util.XMLHandler.java

public static Map<String, String> transXmltoMapForSpec(String xmlInfo) throws DocumentException {
    Document doc = DocumentHelper.parseText(xmlInfo); // xml
    Map<String, String> map = new HashMap<String, String>();
    Element rootElt = doc.getRootElement();
    Iterator iter = rootElt.elementIterator();
    while (iter.hasNext()) {
        Element dataElement = (Element) iter.next();
        map.put(dataElement.getName(), dataElement.getText());
    }/*from   w w  w  .java2  s.  c  om*/
    Element e = (Element) (rootElt.element("specimen").elements().get(0));
    map.put("specimen", e.asXML());
    return map;
}

From source file:com.kingmed.yuyt.util.XMLHandler.java

public static Map<String, Object> transXmltoMapForReport(String xmlInfo) throws DocumentException {
    Document doc = DocumentHelper.parseText(xmlInfo); // xml
    Map<String, Object> map = new HashMap<String, Object>();
    Element rootElt = doc.getRootElement();
    Iterator iter = rootElt.elementIterator();
    while (iter.hasNext()) {
        Element dataElement = (Element) iter.next();
        map.put(dataElement.getName(), dataElement.getText());
    }/*from w  w  w. j  a  va  2s.c o  m*/
    /*
    Element e = (Element) (rootElt.element("Data"));
    String data = "";
    if (e != null) {
    data = ((Element) e.elements().get(0)).asXML();
    map.put("Data", "<Data>" + data + "</Data>");
    } else {
    data = xmlInfo;
    map.put("Data", data);
    }
    */
    return map;
}