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.ibm.cognos.ReportObject.java

License:Open Source License

public Document getPackages(CRNConnect connection, String sPath) {
    Document oDom = null;
    Element packagesElement;//from w  ww  . j a  v  a  2s .c  o  m
    try {
        com.cognos.developer.schemas.bibus._3.BaseClass oBase[];
        oBase = connection.getCMService()
                .query(new SearchPathMultipleObject(sPath), new PropEnum[] { PropEnum.defaultName,
                        PropEnum.source, PropEnum.dispatcherPath, PropEnum.searchPath }, new Sort[] {},
                        new QueryOptions());
        packagesElement = DocumentHelper.createElement("packages");
        oDom = DocumentHelper.createDocument(packagesElement);
        for (int i = 0; i < oBase.length; i++) {
            if (oBase[i].getClass().getName().toString()
                    .equals("com.cognos.developer.schemas.bibus._3._package")) {
                Element oElement = DocumentHelper.createElement("package");
                String oBaseName = oBase[i].getDefaultName().getValue();
                String oBaseSearchPath = oBase[i].getSearchPath().getValue();
                oElement.addElement("name").setText(oBaseName);
                oElement.addElement("searchPath").setText(oBaseSearchPath);
                oDom.getRootElement().add(oElement);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return oDom;
}

From source file:com.iflytek.edu.cloud.frame.support.jdbc.CustomSQL.java

License:Apache License

protected void read(InputStream is) {

    if (is == null)
        return;/*from   ww  w .j  av a 2 s  .  co m*/

    Document document;
    try {
        document = saxReader.read(is);
    } catch (DocumentException e) {
        throw new RuntimeException(e.getMessage(), e);
    }

    Element rootElement = document.getRootElement();

    for (Object sqlObj : rootElement.elements("sql")) {
        Element sqlElement = (Element) sqlObj;
        String id = sqlElement.attributeValue("id");
        String tempateType = sqlElement.attributeValue("tempateType");

        if ("simple".equals(tempateType) || "httl".equals(tempateType)) {
            String content = transform(sqlElement.getText());

            SQLBean bean = new SQLBean();
            bean.setTempateType(tempateType);
            bean.setContent(content);

            try {
                Template template = engine.parseTemplate(content);
                bean.setTemplate(template);
                _sqlPool.put(id, bean);
            } catch (ParseException e) {
                throw new RuntimeException(e.getMessage(), e);
            }
        } else {
            logger.warn("{}  tempateType  {} ??simplehttl", id,
                    tempateType);
        }
    }
}

From source file:com.iflytek.edu.cloud.frame.utils.ErrorMsgParser.java

License:Apache License

public static String getErrorCode(MockHttpServletResponse response) {
    try {/*from www  .j a v  a  2 s  . c  o m*/
        SAXReader saxReader = new SAXReader();
        Document document = saxReader.read(new ByteArrayInputStream(response.getContentAsByteArray()));
        Element rootElement = document.getRootElement();
        return rootElement.element("code").getText();
    } catch (DocumentException e) {
        return null;
    }
}

From source file:com.iih5.smartorm.kit.SqlXmlKit.java

License:Apache License

private void init(File dataDir) {
    try {//from  w w  w .j a  va2s  .co m
        List<File> files = new ArrayList<File>();
        listDirectory(dataDir, files);
        for (File file : files) {
            if (file.getName().contains(".xml")) {
                SAXReader reader = new SAXReader();
                Document document = reader.read(file);
                Element xmlRoot = document.getRootElement();
                for (Object e : xmlRoot.elements("class")) {
                    Map<String, String> methods = new HashMap<String, String>();
                    Element clasz = (Element) e;
                    for (Object ebj : clasz.elements("sql")) {
                        Element sql = (Element) ebj;
                        methods.put(sql.attribute("method").getValue(), sql.getText());
                    }
                    resourcesMap.put(clasz.attributeValue("name"), methods);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.iisigroup.cap.utils.CapXmlUtil.java

License:Open Source License

/**
 * XML?JSON//from ww  w. j  a v a  2s.co  m
 * 
 * @param xmlString
 *            xmlString
 * @return jsonObject
 */
public static JSONObject convertXmlStringToJson(String xmlString) {
    try {
        Document document = DocumentHelper.parseText(xmlString);
        Element root = document.getRootElement();
        return travelXML(root);
    } catch (DocumentException e) {
        throw new CapMessageException(e, CapXmlUtil.class);
    }
}

From source file:com.ischool.weixin.tool.MessageUtil.java

License:Open Source License

public static Map<String, String> parseXml(HttpServletRequest request) throws Exception {
    // ?HashMap// w w w.j a  v  a 2  s .  co m
    Map<String, String> map = new HashMap<String, String>();

    // request??
    InputStream inputStream = request.getInputStream();
    // ??
    SAXReader reader = new SAXReader();
    Document document = reader.read(inputStream);
    // xml
    Element root = document.getRootElement();
    // ?
    @SuppressWarnings("unchecked")
    List<Element> elementList = root.elements();

    // ???
    for (Element e : elementList) {
        map.put(e.getName(), e.getText());
    }
    // ?
    inputStream.close();
    inputStream = null;

    return map;
}

From source file:com.itfsw.mybatis.generator.plugins.utils.enhanced.TemplateCommentGenerator.java

License:Apache License

/**
 * /*from   w  w w. ja  v a  2 s . c o  m*/
 * @param templatePath ?
 * @param useForDefault Comment??
 */
public TemplateCommentGenerator(String templatePath, boolean useForDefault) {
    try {
        Document doc = null;
        if (useForDefault) {
            InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(templatePath);
            doc = new SAXReader().read(inputStream);
            inputStream.close();
        } else {
            File file = new File(templatePath);
            if (file.exists()) {
                doc = new SAXReader().read(file);
            } else {
                logger.error("?:" + templatePath);
            }
        }

        // ??comment 
        if (doc != null) {
            for (EnumNode node : EnumNode.values()) {
                Element element = doc.getRootElement().elementByID(node.value());
                if (element != null) {
                    Configuration cfg = new Configuration(Configuration.VERSION_2_3_26);
                    // ?
                    Template template = new Template(node.value(), element.getText(), cfg);
                    templates.put(node, template);
                }
            }
        }
    } catch (Exception e) {
        logger.error("?XML??", e);
    }
}

From source file:com.jaspersoft.jasperserver.export.ImporterImpl.java

License:Open Source License

protected void process() {
    Document indexDocument = readIndexDocument();
    Element indexRoot = indexDocument.getRootElement();

    Properties properties = new Properties();
    for (Iterator it = indexRoot.elementIterator(getPropertyElementName()); it.hasNext();) {
        Element propElement = (Element) it.next();
        String propKey = propElement.attribute(getPropertyNameAttribute()).getValue();
        Attribute valueAttr = propElement.attribute(getPropertyValueAttribute());
        String value = valueAttr == null ? null : valueAttr.getValue();
        properties.setProperty(propKey, value);
    }/* www  .j a v  a  2s .  c o  m*/
    input.propertiesRead(properties);

    Attributes contextAttributes = createContextAttributes();
    contextAttributes.setAttribute("sourceJsVersion", properties.getProperty(VERSION_ATTR));
    contextAttributes.setAttribute("targetJsVersion", super.getJsVersion());

    for (Iterator it = indexRoot.elementIterator(getIndexModuleElementName()); it.hasNext();) {
        if (Thread.interrupted()) {
            throw new RuntimeException("Cancelled");
        }
        Element moduleElement = (Element) it.next();
        String moduleId = moduleElement.attribute(getIndexModuleIdAttributeName()).getValue();
        ImporterModule module = getModuleRegister().getImporterModule(moduleId);
        if (module == null) {
            throw new JSException("jsexception.import.module.not.found", new Object[] { moduleId });
        }

        commandOut.debug("Invoking module " + module);

        contextAttributes.setAttribute("appContext", this.task.getApplicationContext());
        ModuleContextImpl moduleContext = new ModuleContextImpl(moduleElement, contextAttributes);
        module.init(moduleContext);

        List<String> messages = new ArrayList<String>();
        ImportRunMonitor.start();
        try {
            List<String> moduleMessages = module.process();
            if (moduleMessages != null) {
                messages.addAll(moduleMessages);
            }
        } finally {
            ImportRunMonitor.stop();
            for (String message : messages) {
                commandOut.info(message);
            }
        }
    }
}

From source file:com.jfaker.framework.flow.web.ProcessController.java

License:Apache License

/**
 * ???/*from  www .  j av  a2  s .  c om*/
 */
public void getProcessTaskInfo() {
    Process process = engine.process().getProcessById(getPara(PARA_PROCESSID));
    //Process process = engine.process().getProcessById("23e85c95caf74a9eaef8cc9df9594448");
    String flowId = this.getPara("flowId");
    String flowName = this.getPara("flowName");
    setAttr("process", process);
    if (process.getDBContent() != null) {
        try {
            String content = new String(process.getDBContent(), "UTF-8");
            System.out.println(new String(process.getDBContent(), "UTF-8"));
            Document document = DocumentHelper.parseText(content);
            Element rootEle = document.getRootElement();
            List taskNodes = rootEle.elements("task");
            List<Object> list = new ArrayList<Object>();
            Map map = null;
            for (Iterator it = taskNodes.iterator(); it.hasNext();) {
                map = new HashMap();
                Element elm = (Element) it.next();
                map.put("processId", process.getId());
                map.put("processName", process.getName());
                map.put("SUB_FLOW_ID", flowId);
                map.put("FLOW_NAME", flowName);
                map.put("tacheCode", elm.attribute("name").getText());
                map.put("tachName", elm.attribute("displayName").getText());
                list.add(map);

            }
            setAttr("tacheList", list);
            renderJson(list);
            //renderJson(JSONArray.fromObject(list).toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:com.jfinal.ext.weixin.msg.InMsgParaser.java

License:Apache License

/**
 * ?/*  www.j a  va 2  s .  c  o  m*/
 * 1text ?
 * 2image ?
 * 3voice ?
 * 4video ?
 * 5location ???
 * 6link ?
 * 7event 
 */
private static InMsg doParse(String xml) throws DocumentException {
    Document doc = DocumentHelper.parseText(xml);
    Element root = doc.getRootElement();
    String toUserName = root.elementText("ToUserName");
    String fromUserName = root.elementText("FromUserName");
    Integer createTime = Integer.parseInt(root.elementText("CreateTime"));
    String msgType = root.elementText("MsgType");
    if ("text".equals(msgType))
        return parseInTextMsg(root, toUserName, fromUserName, createTime, msgType);
    if ("image".equals(msgType))
        return parseInImageMsg(root, toUserName, fromUserName, createTime, msgType);
    if ("voice".equals(msgType))
        return parseInVoiceMsg(root, toUserName, fromUserName, createTime, msgType);
    if ("video".equals(msgType))
        return parseInVideoMsg(root, toUserName, fromUserName, createTime, msgType);
    if ("location".equals(msgType))
        return parseInLocationMsg(root, toUserName, fromUserName, createTime, msgType);
    if ("link".equals(msgType))
        return parseInLinkMsg(root, toUserName, fromUserName, createTime, msgType);
    if ("event".equals(msgType))
        return parseInEvent(root, toUserName, fromUserName, createTime, msgType);
    throw new RuntimeException("???");
}