Example usage for org.dom4j Document getRootElement

List of usage examples for org.dom4j Document getRootElement

Introduction

In this page you can find the example usage for org.dom4j Document getRootElement.

Prototype

Element getRootElement();

Source Link

Document

Returns the root Element for this document.

Usage

From source file:com.heren.turtle.gear.meta.AbstractService.java

License:Open Source License

protected Map<String, Object> getMessage(String message) throws DocumentException {
    Document document = DocumentHelper.parseText(message);
    Element rootElement = document.getRootElement();
    List elements = rootElement.elements();
    Map<String, Object> result = new HashMap<String, Object>();
    for (Iterator it = elements.iterator(); it.hasNext();) {
        Element subElement = (Element) it.next();
        if (subElement.isTextOnly()) {
            result.put(subElement.getName(), subElement.getTextTrim());
        } else {//  w w w . jav  a2s .c om
            List<String> subList = new ArrayList<String>();
            List subEle = subElement.elements();
            for (Iterator iterator = subEle.iterator(); iterator.hasNext();) {
                Element itemElements = (Element) iterator.next();
                subList.add(itemElements.getTextTrim());
            }
            result.put(subElement.getName(), subList);
        }
    }
    return result;
}

From source file:com.heren.turtle.server.utils.XmlUtils.java

License:Open Source License

/**
 * delete the label of xml that is not use
 *
 * @param message//from  w ww. j  ava2 s  . com
 * @return
 */
public static Map<String, Object> getMessage(String message) throws DocumentException {
    message = replaceWrongPart(message);
    Document document = DocumentHelper.parseText(message);
    Element rootElement = document.getRootElement();
    Element request = rootElement.element("request");
    List elements = request.elements();
    Map<String, Object> result = new HashMap<>();
    for (Object element : elements) {
        Element subElement = (Element) element;
        if (subElement.isTextOnly()) {
            result.put(subElement.getName(), subElement.getTextTrim());
        } else {
            List<String> subList = new ArrayList<>();
            List subEle = subElement.elements();
            for (Object aSubEle : subEle) {
                Element itemElements = (Element) aSubEle;
                subList.add(itemElements.getTextTrim());
            }
            result.put(subElement.getName(), subList);
        }
    }
    return result;
}

From source file:com.heren.turtle.server.utils.XmlUtils.java

License:Open Source License

public static Map<String, Object> getMessageReceiveSample(String message) throws DocumentException {
    message = replaceWrongPart(message);
    Document document = DocumentHelper.parseText(message);
    Element rootElement = document.getRootElement();
    Element request = rootElement.element("request");
    List elements = request.elements();
    Map<String, Object> result = new HashMap<>();
    for (Object element : elements) {
        Element subElement = (Element) element;
        String name = subElement.getName();
        if (name.equalsIgnoreCase("item")) {
            List subElements = subElement.elements();
            for (Object subEle : subElements) {
                Element grantSubElement = (Element) subEle;
                result.put(grantSubElement.getName(), grantSubElement.getTextTrim());
            }/*from   www .  j  a  va2s . c o  m*/
        } else if (subElement.isTextOnly()) {
            result.put(name, subElement.getTextTrim());
        }
    }
    return result;
}

From source file:com.heren.turtle.server.utils.XmlUtils.java

License:Open Source License

public static List<Map<String, Object>> getMessageReceiveSampleContainItems(String message)
        throws DocumentException {
    message = replaceWrongPart(message);
    Document document = DocumentHelper.parseText(message);
    Element rootElement = document.getRootElement();
    Element request = rootElement.element("request");
    Element items = request.element("items");
    List elements = items.elements();
    List<Map<String, Object>> resultList = new ArrayList<>();
    for (Object element : elements) {
        Map<String, Object> result = new HashMap<>();
        Element subElement = (Element) element;
        String name = subElement.getName();
        if (name.equalsIgnoreCase("item")) {
            List subElements = subElement.elements();
            for (Object subEle : subElements) {
                Element grantSubElement = (Element) subEle;
                result.put(grantSubElement.getName(), grantSubElement.getTextTrim());
            }/*from ww  w . j a  va2 s. c o m*/
        } else if (subElement.isTextOnly()) {
            result.put(name, subElement.getTextTrim());
        }
        resultList.add(result);
    }
    return resultList;
}

From source file:com.heren.turtle.server.utils.XmlUtils.java

License:Open Source License

/**
 * delete the label of xml that is not use
 *
 * @param message//from   w ww. ja  v  a  2 s  .c o m
 * @return
 */
public static Map<String, Object> getMessageContainsMap(String message) throws DocumentException {
    message = replaceWrongPart(message);
    Document document = DocumentHelper.parseText(message);
    Element rootElement = document.getRootElement();
    Element request = rootElement.element("request");
    List elements = request.elements();
    Map<String, Object> result = new HashMap<>();
    for (Object element : elements) {
        Element subElement = (Element) element;
        if (subElement.isTextOnly()) {
            result.put(subElement.getName(), subElement.getTextTrim());
        } else {
            List<Map<String, String>> subList = new ArrayList<>();
            List subEle = subElement.elements();
            for (Object aSubEle : subEle) {
                Element itemElements = (Element) aSubEle;
                Map<String, String> subMap = new HashMap<>();
                List grandSubElements = itemElements.elements();
                for (Object grandSubElement : grandSubElements) {
                    Element grandItemElements = (Element) grandSubElement;
                    subMap.put(grandItemElements.getName().trim(), grandItemElements.getTextTrim());
                }
                subList.add(subMap);
            }
            result.put(subElement.getName(), subList);
        }
    }
    return result;
}

From source file:com.hihframework.osplugins.dom4j.XmlParseUtil.java

License:Apache License

/**
 * ?ROOT/*from   ww  w.  j a v  a 2  s. co  m*/
 *
 * @param doc
 *            ?XML
 * @return ROOT?
 */
public Element getRootElement(Document doc) {
    Element rootElement = doc.getRootElement();
    return rootElement;

}

From source file:com.hihframework.osplugins.dom4j.XmlParseUtil.java

License:Apache License

/**
 * ?/*from   w w  w .  ja  v  a  2  s  .c  o  m*/
 *
 * @param document
 *            
 * @param elementName
 *            ?
 * @return ?
 */
public Element FindElement(Document document, String elementName) {
    Element root = document.getRootElement();
    Element element = null;
    for (Iterator<?> i = root.elementIterator(elementName); i.hasNext();) {
        element = (Element) i.next();
    }
    return element;
}

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

License:Apache License

/**
 * xml,"import"?xml/*from   w w  w.  j  a  va2 s . c om*/
 * 
 * @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.hwsoft.util.idcard.IDCardVerifyTools.java

/**
 * ?Nciicl?//  w ww.  j  a  va2s.c om
 *
 * @param backXMl?
 * @return
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static IdCardInfo parseXml(String backXMl, String userName, String idCard) {
    Document doc = null;
    String result_gmsfhm = null;
    String result_xm = null;
    String gmsfhm = null;
    String xm = null;
    String xp = null;
    String errormesage = null;
    IdCardInfo IdCardInfo = null;
    System.out.println("idcard bind Nciic  backInfo:" + backXMl);

    try {
        //XML
        doc = DocumentHelper.parseText(backXMl);

        // ?
        Element rootElt = doc.getRootElement();

        if ("RESPONSE".equalsIgnoreCase(rootElt.getName())) {
            //???
            List<DefaultAttribute> list = rootElt.attributes();

            for (DefaultAttribute e : list) {
                if ("errorcode".equals(e.getName())) {
                    if ("-70".equalsIgnoreCase(e.getValue())) {
                        throw new RuntimeException("?", null);
                    } else if ("-71".equalsIgnoreCase(e.getValue())) {
                        throw new RuntimeException("?", null);
                    } else if ("-72".equalsIgnoreCase(e.getValue())) {
                        throw new RuntimeException("IP ???", null);
                    } else if ("-80".equalsIgnoreCase(e.getValue())) {
                        throw new RuntimeException("??", null);
                    }
                }
            }
        } else if ("ROWS".equalsIgnoreCase(rootElt.getName())) {
            Iterator iterForRow = rootElt.elementIterator("ROW");

            while (iterForRow.hasNext()) {
                Element recordEleForRow = (Element) iterForRow.next();

                //?????
                Iterator itersForInput = recordEleForRow.elementIterator("INPUT");

                while (itersForInput.hasNext()) {
                    Element recordEleForInput = (Element) itersForInput.next();
                    gmsfhm = recordEleForInput.elementTextTrim("gmsfhm");

                    if (!(idCard.equalsIgnoreCase(gmsfhm))) {
                        throw new RuntimeException("?????", null);
                    }

                    xm = recordEleForInput.elementTextTrim("xm");

                    if (!(userName.equalsIgnoreCase(xm))) {
                        throw new RuntimeException("?????", null);
                    }
                }

                //??????
                Iterator itersForOutput = recordEleForRow.elementIterator("OUTPUT");

                while (itersForOutput.hasNext()) {
                    Element recordEleForSubRow = (Element) itersForOutput.next();
                    Iterator itersForItem = recordEleForSubRow.elementIterator("ITEM");

                    while (itersForItem.hasNext()) {
                        Element recordEleForItem = (Element) itersForItem.next();
                        gmsfhm = recordEleForItem.elementTextTrim("gmsfhm");
                        xm = recordEleForItem.elementTextTrim("xm");
                        xp = recordEleForItem.elementTextTrim("xp");
                        errormesage = recordEleForItem.elementTextTrim("errormesage");

                        if (gmsfhm != null) {
                            result_gmsfhm = recordEleForItem.elementTextTrim("result_gmsfhm");
                        }

                        if (xm != null) {
                            result_xm = recordEleForItem.elementTextTrim("result_xm");
                        }

                        if (xp != null) {
                            xp = recordEleForItem.elementTextTrim("xp");
                        }

                        if (errormesage != null) {
                            errormesage = recordEleForItem.elementTextTrim("errormesage");
                            break;
                        }
                    }
                }

                if (null != errormesage) {
                    throw new RuntimeException("??!", null);
                } else {
                    if (!"".equalsIgnoreCase(result_xm)) {
                        throw new RuntimeException("?????", null);
                    }

                    if (!"".equalsIgnoreCase(result_gmsfhm)) {
                        throw new RuntimeException("?????", null);
                    }

                    IdCardInfo = new IdCardInfo();
                    IdCardInfo.setIdCardNumber(idCard);
                    IdCardInfo.setRealName(userName);
                    IdCardInfo.setAvatar(xp);
                }
            }
        }
    } catch (DocumentException e) {
        System.out.println("idcard bind erroinfo:XML??");
    } catch (Exception e) {
        System.out.println("idcard bind erroinfo:XML??");
    }
    return IdCardInfo;
}

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

License:Open Source License

@Override
protected Configuration doConfigure(Document doc) throws HibernateException {

    Element sfNode = doc.getRootElement().element("session-factory");
    String name = sfNode.attributeValue("name");
    if (name != null) {
        Properties props = new Properties();
        props.setProperty(Environment.SESSION_FACTORY_NAME, name);
        addProperties(props);//from  w ww  . ja  v a 2 s . c  om
    }
    addProperties(sfNode);
    parseSessionFactory(sfNode, name);

    Element secNode = doc.getRootElement().element("security");
    if (secNode != null) {
        parseSecurity(secNode);
    }

    log.info("Configured SessionFactory: " + name);
    log.debug("properties: " + getProperties());

    return this;
}