Example usage for org.dom4j Element elements

List of usage examples for org.dom4j Element elements

Introduction

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

Prototype

List<Element> elements(QName qName);

Source Link

Document

Returns the elements contained in this element with the given fully qualified name.

Usage

From source file:com.glaf.activiti.extension.xml.ExtensionReader.java

License:Apache License

public List<ExtensionEntity> readActions(java.io.InputStream inputStream) {
    List<ExtensionEntity> extensions = new java.util.ArrayList<ExtensionEntity>();
    SAXReader xmlReader = new SAXReader();
    try {/*from w  w  w  .ja va  2s . c o m*/
        Document doc = xmlReader.read(inputStream);
        Element root = doc.getRootElement();
        String x_type = root.attributeValue("type");
        List<?> actions = root.elements("action");
        Iterator<?> iter = actions.iterator();
        while (iter.hasNext()) {
            Element element = (Element) iter.next();
            ExtensionEntity extension = new ExtensionEntity();
            extension.setProcessName(element.attributeValue("processName"));
            extension.setTaskName(element.attributeValue("taskName"));
            extension.setName(element.attributeValue("name"));
            extension.setType(x_type);
            extension.setDescription(element.elementTextTrim("description"));
            Iterator<?> it99 = element.elementIterator();
            while (it99.hasNext()) {
                Element elem = (Element) it99.next();
                String propertyName = elem.getName();
                String propertyValue = elem.getTextTrim();
                if (StringUtils.isNotEmpty(propertyValue)) {
                    ExtensionFieldEntity extensionField = new ExtensionFieldEntity();
                    extensionField.setName(propertyName.trim());
                    extensionField.setValue(propertyValue.trim());
                    extension.addField(extensionField);
                }
            }
            if (element.elementText("sql") != null) {
                ExtensionFieldEntity extensionField = new ExtensionFieldEntity();
                extensionField.setName("sql");
                extensionField.setValue(element.elementTextTrim("sql"));
                extension.addField(extensionField);

            }
            if (element.elementText("handlers") != null) {
                ExtensionFieldEntity extensionField = new ExtensionFieldEntity();
                extensionField.setName("handlers");
                extensionField.setValue(element.elementTextTrim("handlers"));
                extension.addField(extensionField);
            }

            Element parametersE = element.element("parameters");
            if (parametersE != null) {
                List<?> parameters = parametersE.elements("parameter");
                Iterator<?> it = parameters.iterator();
                while (it.hasNext()) {
                    Element elem = (Element) it.next();
                    String propertyName = elem.attributeValue("name");
                    String type = elem.attributeValue("type");
                    String propertyValue = null;
                    if (elem.attribute("value") != null) {
                        propertyValue = elem.attributeValue("value");
                    } else {
                        propertyValue = elem.getTextTrim();
                    }
                    if (StringUtils.isNotEmpty(propertyName) && StringUtils.isNotEmpty(propertyValue)) {
                        ExtensionParamEntity extensionParam = new ExtensionParamEntity();
                        extensionParam.setName(propertyName.trim());
                        extensionParam.setValue(propertyValue.trim());
                        extensionParam.setType(type);
                        extension.addParam(extensionParam);
                    }
                }
            }

            extensions.add(extension);
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    return extensions;
}

From source file:com.glaf.activiti.xml.BpmnXmlReader.java

License:Apache License

public List<ActivityInfo> read(Element root, String processDefinitionKey) {
    List<ActivityInfo> activities = new java.util.ArrayList<ActivityInfo>();
    Element element = root.element("BPMNDiagram");
    if (element != null) {
        List<?> elements = element.elements("BPMNPlane");
        if (elements != null && !elements.isEmpty()) {
            Iterator<?> iterator = elements.iterator();
            while (iterator.hasNext()) {
                Element elem = (Element) iterator.next();
                String attr = elem.attributeValue("bpmnElement");
                if (StringUtils.equals(attr, processDefinitionKey)) {
                    List<?> elems = elem.elements("BPMNShape");
                    if (elems != null && !elems.isEmpty()) {
                        Iterator<?> iter = elems.iterator();
                        while (iter.hasNext()) {
                            Element em = (Element) iter.next();
                            Element e = em.element("Bounds");
                            if (e != null) {
                                ActivityInfo info = new ActivityInfo();
                                info.setActivityId(em.attributeValue("bpmnElement"));
                                ActivityCoordinates coord = new ActivityCoordinates();
                                coord.setHeight(Double.valueOf(e.attributeValue("height")));
                                coord.setWidth(Double.valueOf(e.attributeValue("width")));
                                coord.setX(Double.valueOf(e.attributeValue("x")));
                                coord.setY(Double.valueOf(e.attributeValue("y")));
                                info.setCoordinates(coord);
                                activities.add(info);
                            }/*from w w  w . ja  v  a 2  s  . c  o m*/
                        }
                    }
                }
            }
        }
    }

    return activities;
}

From source file:com.glaf.activiti.xml.BpmnXmlReader.java

License:Apache License

public List<UserTask> readUserTasks(Element root, String processDefinitionKey) {
    List<UserTask> tasks = new java.util.ArrayList<UserTask>();
    List<?> elements = root.elements("process");
    if (elements != null && !elements.isEmpty()) {
        Iterator<?> iterator = elements.iterator();
        while (iterator.hasNext()) {
            Element elem = (Element) iterator.next();
            String pid = elem.attributeValue("id");
            if (!StringUtils.equals(processDefinitionKey, pid)) {
                continue;
            }//from  w  ww  .jav a2  s  . c  om
            List<?> elems = elem.elements("userTask");
            if (elems != null && !elems.isEmpty()) {
                Iterator<?> iter = elems.iterator();
                while (iter.hasNext()) {
                    Element em = (Element) iter.next();
                    UserTask task = new UserTask();
                    task.setId(em.attributeValue("id"));
                    task.setName(em.attributeValue("name"));
                    tasks.add(task);
                }
            }
        }
    }

    return tasks;
}

From source file:com.glaf.core.xml.MimeMappingReader.java

License:Apache License

public Map<String, String> read(InputStream inputStream) {
    Map<String, String> mapping = new HashMap<String, String>();
    SAXReader xmlReader = new SAXReader();
    try {//from w  w w .  j  a  v a 2  s  .co  m
        Document doc = xmlReader.read(inputStream);
        Element root = doc.getRootElement();
        List<?> elements = root.elements("mime-mapping");
        for (int i = 0; i < elements.size(); i++) {
            Element element = (Element) elements.get(i);
            mapping.put(element.elementTextTrim("extension"), element.elementTextTrim("mime-type"));
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new RuntimeException(ex);
    }
    return mapping;
}

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  ava  2 s.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.XmlMappingReader.java

License:Apache License

public TableModel read(java.io.InputStream inputStream) {
    TableModel tableModel = new TableModel();
    SAXReader xmlReader = new SAXReader();
    try {/*w w  w.  jav  a2  s.  com*/
        Document doc = xmlReader.read(inputStream);
        Element root = doc.getRootElement();
        Element element = root.element("entity");
        if (element != null) {
            tableModel.setEntityName(element.attributeValue("name"));
            tableModel.setPrimaryKey(element.attributeValue("primaryKey"));
            tableModel.setTableName(element.attributeValue("table"));
            tableModel.setTitle(element.attributeValue("title"));
            tableModel.setStopWord(element.attributeValue("stopWord"));
            tableModel.setPackageName(element.attributeValue("package"));
            tableModel.setEnglishTitle(element.attributeValue("englishTitle"));
            tableModel.setFilePrefix(element.attributeValue("filePrefix"));
            tableModel.setParseType(element.attributeValue("parseType"));
            tableModel.setParseClass(element.attributeValue("parseClass"));
            tableModel.setAggregationKey(element.attributeValue("aggregationKeys"));
            tableModel.setSplit(element.attributeValue("split"));
            if (StringUtils.equals(element.attributeValue("insertOnly"), "true")) {
                tableModel.setInsertOnly(true);
            }

            String startRow = element.attributeValue("startRow");
            if (StringUtils.isNumeric(startRow)) {
                tableModel.setStartRow(Integer.parseInt(startRow));
            }
            String stopSkipRow = element.attributeValue("stopSkipRow");
            if (StringUtils.isNumeric(stopSkipRow)) {
                tableModel.setStopSkipRow(Integer.parseInt(stopSkipRow));
            }

            String minLength = element.attributeValue("minLength");
            if (StringUtils.isNumeric(minLength)) {
                tableModel.setMinLength(Integer.parseInt(minLength));
            }

            String batchSize = element.attributeValue("batchSize");
            if (StringUtils.isNumeric(batchSize)) {
                tableModel.setBatchSize(Integer.parseInt(batchSize));
            }

            List<?> excludes = element.elements("excludes");
            if (excludes != null && excludes.size() > 0) {
                Iterator<?> iterator = excludes.iterator();
                while (iterator.hasNext()) {
                    Element elem = (Element) iterator.next();
                    tableModel.addExclude(elem.getStringValue());
                }
            }

            List<?> rows = element.elements("property");
            if (rows != null && rows.size() > 0) {
                Iterator<?> iterator = rows.iterator();
                while (iterator.hasNext()) {
                    Element elem = (Element) iterator.next();
                    ColumnModel field = new ColumnModel();
                    this.readField(elem, field);
                    tableModel.addColumn(field);
                    if (StringUtils.equals(tableModel.getPrimaryKey(), field.getColumnName())) {
                        tableModel.setIdColumn(field);
                    }
                }
            }

            Element idElem = element.element("id");
            if (idElem != null) {
                ColumnModel idField = new ColumnModel();
                this.readField(idElem, idField);
                tableModel.setIdColumn(idField);
            }
        }

    } catch (Exception ex) {
        ex.printStackTrace();
        throw new RuntimeException(ex);
    }

    return tableModel;
}

From source file:com.glaf.core.xml.XmlReader.java

License:Apache License

public SysDataTable getSysDataTable(java.io.InputStream inputStream) {
    SysDataTable dataTable = new SysDataTable();
    SAXReader xmlReader = new SAXReader();
    try {//from ww  w  .j  a  v a2s  .c o m
        Document doc = xmlReader.read(inputStream);
        Element root = doc.getRootElement();
        Element element = root.element("entity");
        if (element != null) {
            dataTable.setServiceKey(element.attributeValue("name"));
            dataTable.setTablename(element.attributeValue("table"));
            dataTable.setTitle(element.attributeValue("title"));

            Element idElement = element.element("id");
            if (idElement != null) {
                SysDataField idField = new SysDataField();

                List<?> attrs = idElement.attributes();
                if (attrs != null && !attrs.isEmpty()) {
                    Map<String, Object> dataMap = new java.util.HashMap<String, Object>();
                    Iterator<?> iter = attrs.iterator();
                    while (iter.hasNext()) {
                        Attribute attr = (Attribute) iter.next();
                        dataMap.put(attr.getName(), attr.getStringValue());
                    }
                    Tools.populate(idField, dataMap);
                }

                idField.setPrimaryKey("Y");
                idField.setName(idElement.attributeValue("name"));
                idField.setColumnName(idElement.attributeValue("column"));
                idField.setTitle(idElement.attributeValue("title"));
                idField.setDataType(idElement.attributeValue("type"));
                dataTable.addField(idField);
            }

            List<?> props = element.elements("property");
            if (props != null && props.size() > 0) {
                Iterator<?> iterator = props.iterator();
                while (iterator.hasNext()) {
                    Element elem = (Element) iterator.next();
                    SysDataField field = new SysDataField();

                    List<?> attrs = elem.attributes();
                    if (attrs != null && !attrs.isEmpty()) {
                        Map<String, Object> dataMap = new java.util.HashMap<String, Object>();
                        Iterator<?> iter = attrs.iterator();
                        while (iter.hasNext()) {
                            Attribute attr = (Attribute) iter.next();
                            dataMap.put(attr.getName(), attr.getStringValue());
                        }
                        Tools.populate(field, dataMap);
                    }

                    field.setName(elem.attributeValue("name"));
                    field.setColumnName(elem.attributeValue("column"));
                    field.setTitle(elem.attributeValue("title"));
                    field.setDataType(elem.attributeValue("type"));
                    dataTable.addField(field);
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new RuntimeException(ex);
    }
    return dataTable;
}

From source file:com.glaf.core.xml.XmlReader.java

License:Apache License

public TableDefinition read(java.io.InputStream inputStream) {
    TableDefinition tableDefinition = new TableDefinition();
    SAXReader xmlReader = new SAXReader();
    try {//from  ww w . j  av a 2 s .  c o  m
        Document doc = xmlReader.read(inputStream);
        Element root = doc.getRootElement();
        Element element = root.element("entity");
        if (element != null) {
            List<?> attrs = element.attributes();
            if (attrs != null && !attrs.isEmpty()) {
                Map<String, Object> dataMap = new java.util.HashMap<String, Object>();
                Iterator<?> iter = attrs.iterator();
                while (iter.hasNext()) {
                    Attribute attr = (Attribute) iter.next();
                    dataMap.put(attr.getName(), attr.getStringValue());
                }
                Tools.populate(tableDefinition, dataMap);
            }

            tableDefinition.setEntityName(element.attributeValue("name"));
            tableDefinition.setPackageName(element.attributeValue("package"));
            tableDefinition.setTableName(element.attributeValue("table"));
            tableDefinition.setTitle(element.attributeValue("title"));
            tableDefinition.setEnglishTitle(element.attributeValue("englishTitle"));

            if (StringUtils.equals("true", element.attributeValue("jbpmSupport"))) {
                tableDefinition.setJbpmSupport(true);
            }
            if (StringUtils.equals("true", element.attributeValue("treeSupport"))) {
                tableDefinition.setTreeSupport(true);
            }

            tableDefinition.setAggregationKeys(element.attributeValue("aggregationKeys"));

            tableDefinition.setModuleName(element.attributeValue("moduleName"));

            String primaryKey = element.attributeValue("primaryKey");

            List<?> rows = element.elements("property");
            if (rows != null && rows.size() > 0) {
                Iterator<?> iterator = rows.iterator();
                while (iterator.hasNext()) {
                    Element elem = (Element) iterator.next();
                    ColumnDefinition field = new ColumnDefinition();
                    this.read(elem, field);
                    if (primaryKey != null && StringUtils.equals(primaryKey, field.getColumnName())) {
                        tableDefinition.setIdColumn(field);
                    } else {
                        tableDefinition.addColumn(field);
                    }
                }
            }

            Element idElem = element.element("id");
            if (idElem != null) {
                ColumnDefinition idField = new ColumnDefinition();
                this.read(idElem, idField);
                tableDefinition.setIdColumn(idField);
            }
        }

    } catch (Exception ex) {
        ex.printStackTrace();
        throw new RuntimeException(ex);
    }

    return tableDefinition;
}

From source file:com.glaf.dts.util.XmlReader.java

License:Apache License

public DataTransfer read(java.io.InputStream inputStream) {
    DataTransfer tableModel = new DataTransfer();
    SAXReader xmlReader = new SAXReader();
    try {//from  w w  w . j a  v  a2  s .c om
        Document doc = xmlReader.read(inputStream);
        Element root = doc.getRootElement();
        Element element = root.element("entity");
        if (element != null) {
            List<?> attrs = element.attributes();
            if (attrs != null && !attrs.isEmpty()) {
                Map<String, Object> dataMap = new java.util.HashMap<String, Object>();
                Iterator<?> iter = attrs.iterator();
                while (iter.hasNext()) {
                    Attribute attr = (Attribute) iter.next();
                    dataMap.put(attr.getName(), attr.getStringValue());
                    tableModel.addProperty(attr.getName(), attr.getStringValue());
                }
                Tools.populate(tableModel, dataMap);
            }

            tableModel.setEntityName(element.attributeValue("name"));
            tableModel.setPrimaryKey(element.attributeValue("primaryKey"));
            tableModel.setTableName(element.attributeValue("table"));
            tableModel.setTitle(element.attributeValue("title"));
            tableModel.setStopWord(element.attributeValue("stopWord"));
            tableModel.setPackageName(element.attributeValue("package"));
            tableModel.setEnglishTitle(element.attributeValue("englishTitle"));
            tableModel.setFilePrefix(element.attributeValue("filePrefix"));
            tableModel.setParseType(element.attributeValue("parseType"));
            tableModel.setParseClass(element.attributeValue("parseClass"));
            tableModel.setAggregationKeys(element.attributeValue("aggregationKeys"));
            tableModel.setSplit(element.attributeValue("split"));
            if (StringUtils.equals(element.attributeValue("insertOnly"), "true")) {
                tableModel.setInsertOnly("true");
            }

            String startRow = element.attributeValue("startRow");
            if (StringUtils.isNotEmpty(startRow) && StringUtils.isNumeric(startRow)) {
                tableModel.setStartRow(Integer.parseInt(startRow));
            }

            String stopSkipRow = element.attributeValue("stopSkipRow");
            if (StringUtils.isNotEmpty(stopSkipRow) && StringUtils.isNumeric(stopSkipRow)) {
                tableModel.setStopSkipRow(Integer.parseInt(stopSkipRow));
            }

            String batchSize = element.attributeValue("batchSize");
            if (StringUtils.isNotEmpty(batchSize) && StringUtils.isNumeric(batchSize)) {
                tableModel.setBatchSize(Integer.parseInt(batchSize));
            }

            List<?> excludes = element.elements("excludes");
            if (excludes != null && excludes.size() > 0) {
                Iterator<?> iterator = excludes.iterator();
                while (iterator.hasNext()) {
                    Element elem = (Element) iterator.next();
                    tableModel.addExclude(elem.getStringValue());
                }
            }

            List<?> rows = element.elements("property");
            if (rows != null && rows.size() > 0) {
                Iterator<?> iterator = rows.iterator();
                while (iterator.hasNext()) {
                    Element elem = (Element) iterator.next();
                    ColumnDefinition field = new ColumnDefinition();
                    this.readField(elem, field);
                    tableModel.addColumn(field);
                    if (StringUtils.equalsIgnoreCase(tableModel.getPrimaryKey(), field.getColumnName())) {
                        tableModel.setIdColumn(field);
                    }
                }
            }
        }

    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    return tableModel;
}

From source file:com.glaf.jbpm.config.JbpmExtensionReader.java

License:Apache License

public List<Extension> readTasks(java.io.InputStream inputStream) {
    List<Extension> extensions = new java.util.ArrayList<Extension>();
    SAXReader xmlReader = new SAXReader();
    try {//from w  w  w  .  j  ava 2 s.  c o m
        Document doc = xmlReader.read(inputStream);
        Element root = doc.getRootElement();
        String x_type = root.attributeValue("type");
        List<?> rows = root.elements("taskmgr");
        Iterator<?> iterator = rows.iterator();
        while (iterator.hasNext()) {
            Element element = (Element) iterator.next();
            Extension extension = new Extension();
            extension.setProcessName(element.attributeValue("processName"));
            extension.setTaskName(element.attributeValue("taskName"));
            extension.setType(x_type);
            if (element.elementTextTrim("taskMgmtType") != null) {
                ExtensionField extensionField = new ExtensionField();
                extensionField.setName("taskMgmtType");
                extensionField.setValue(element.elementTextTrim("taskMgmtType"));
                extension.addField(extensionField);
            }
            Element propertiesE = element.element("properties");
            if (propertiesE != null) {
                List<?> properties = propertiesE.elements("property");
                Iterator<?> iter = properties.iterator();
                while (iter.hasNext()) {
                    Element elem = (Element) iter.next();
                    String propertyName = elem.attributeValue("key");
                    String propertyValue = null;
                    if (elem.attribute("value") != null) {
                        propertyValue = elem.attributeValue("value");
                    } else {
                        propertyValue = elem.getTextTrim();
                    }
                    if (StringUtils.isNotEmpty(propertyName) && StringUtils.isNotEmpty(propertyValue)) {
                        ExtensionField extensionField = new ExtensionField();
                        extensionField.setName(propertyName.trim());
                        extensionField.setValue(propertyValue.trim());
                        extension.addField(extensionField);
                    }
                }
            }
            if (element.elementText("handlers") != null) {
                ExtensionField extensionField = new ExtensionField();
                extensionField.setName("handlers");
                extensionField.setValue(element.elementTextTrim("handlers"));
                extension.addField(extensionField);
            }
            extensions.add(extension);
        }

    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    return extensions;
}