Example usage for org.dom4j Element attributeValue

List of usage examples for org.dom4j Element attributeValue

Introduction

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

Prototype

String attributeValue(QName qName);

Source Link

Document

This returns the attribute value for the attribute with the given fully qualified name or null if there is no such attribute or the empty string if the attribute value is empty.

Usage

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

License:Apache License

protected void read(Element elem, ColumnDefinition field) {
    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());
        }// w w w .j  a va 2s .  c om
        Tools.populate(field, dataMap);
    }

    field.setName(elem.attributeValue("name"));
    field.setMask(elem.attributeValue("mask"));
    field.setTitle(elem.attributeValue("title"));
    field.setEnglishTitle(elem.attributeValue("englishTitle"));
    field.setType(elem.attributeValue("type"));
    field.setDataCode(elem.attributeValue("dataCode"));
    field.setRenderType(elem.attributeValue("renderType"));
    field.setColumnName(elem.attributeValue("column"));
    field.setDataType(FieldType.getFieldType(field.getType()));
    String length = elem.attributeValue("length");
    if (StringUtils.isNumeric(length)) {
        field.setLength(Integer.valueOf(length));
    }
    String maxLength = elem.attributeValue("maxLength");
    if (StringUtils.isNumeric(maxLength)) {
        field.setMaxLength(Integer.valueOf(maxLength));
    }
    String minLength = elem.attributeValue("minLength");
    if (StringUtils.isNumeric(minLength)) {
        field.setMinLength(Integer.valueOf(minLength));
    }
    String displayType = elem.attributeValue("displayType");
    if (StringUtils.isNumeric(displayType)) {
        field.setDisplayType(Integer.valueOf(displayType));
    }
    String sortNo = elem.attributeValue("sortNo");
    if (StringUtils.isNumeric(sortNo)) {
        field.setSortNo(Integer.valueOf(sortNo));
    }
    if (StringUtils.equals(elem.attributeValue("updatable"), "false")) {
        field.setUpdatable(false);
    }
    if (StringUtils.equals(elem.attributeValue("nullable"), "false")) {
        field.setNullable(false);
    }
    if (StringUtils.equals(elem.attributeValue("editable"), "true")) {
        field.setEditable(true);
    }
    if (StringUtils.equals(elem.attributeValue("searchable"), "true")) {
        field.setSearchable(true);
    }
}

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  a v a  2 s .  co 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  ww  w  . j  av a 2 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.dts.util.XmlReader.java

License:Apache License

protected void readField(Element elem, ColumnDefinition field) {
    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());
            field.addProperty(attr.getName(), attr.getStringValue());
        }/*  www. j av  a 2  s . c  o m*/
        Tools.populate(field, dataMap);
    }

    field.setName(elem.attributeValue("name"));
    field.setType(elem.attributeValue("type"));
    field.setColumnName(elem.attributeValue("column"));
    field.setTitle(elem.attributeValue("title"));
    field.setValueExpression(elem.attributeValue("valueExpression"));

    /**
     * 
     */
    if ("true".equals(elem.attributeValue("required"))) {
        field.setRequired(true);
    }

    String length = elem.attributeValue("length");
    if (StringUtils.isNotEmpty(length) && StringUtils.isNumeric(length)) {
        field.setLength(Integer.parseInt(length));
    }

    String nullable = elem.attributeValue("nullable");
    if (StringUtils.isNotEmpty(nullable)) {
        if (StringUtils.equalsIgnoreCase(nullable, "true")) {
            field.setNullable(true);
            field.setNullableField("true");
        } else {
            field.setNullable(false);
            field.setNullableField("false");
        }
    }

    String position = elem.attributeValue("position");
    if (StringUtils.isNotEmpty(position) && StringUtils.isNumeric(position)) {
        field.setPosition(Integer.parseInt(position));
    }

    String precision = elem.attributeValue("precision");
    if (StringUtils.isNotEmpty(precision) && StringUtils.isNumeric(precision)) {
        field.setPrecision(Integer.parseInt(precision));
    }

}

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;
}

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

License:Apache License

public List<Extension> readActions(java.io.InputStream inputStream) {
    List<Extension> extensions = new java.util.ArrayList<Extension>();
    SAXReader xmlReader = new SAXReader();
    try {/*from   ww w . j a  v a2  s  .  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();
            Extension extension = new Extension();
            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)) {
                    ExtensionField extensionField = new ExtensionField();
                    extensionField.setName(propertyName.trim());
                    extensionField.setValue(propertyValue.trim());
                    extension.addField(extensionField);
                }
            }
            if (element.elementText("sql") != null) {
                ExtensionField extensionField = new ExtensionField();
                extensionField.setName("sql");
                extensionField.setValue(element.elementTextTrim("sql"));
                extension.addField(extensionField);

            }
            if (element.elementText("handlers") != null) {
                ExtensionField extensionField = new ExtensionField();
                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)) {
                        ExtensionParam extensionParam = new ExtensionParam();
                        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.jbpm.deploy.MxJbpmProcessDeployer.java

License:Apache License

public ProcessDefinition deploy(JbpmContext jbpmContext, byte[] zipBytes) {
    SAXReader xmlReader = new SAXReader();
    JpdlXmlReader jpdlReader = new JpdlXmlReader();
    Document doc = null;/*w w w.j  av a2s .co  m*/
    InputStream inputStream = null;
    ZipInputStream zipInputStream = null;
    ProcessDefinition processDefinition = null;
    Map<String, byte[]> zipMap = null;
    try {
        zipInputStream = new ZipInputStream(new ByteArrayInputStream(zipBytes));
        zipMap = ZipUtils.getZipBytesMap(zipInputStream);
        zipInputStream.close();
        zipInputStream = null;
        if (zipMap != null) {
            if (zipMap.get("processdefinition.xml") != null) {
                byte[] bytes = zipMap.get("processdefinition.xml");
                inputStream = new ByteArrayInputStream(bytes);
                doc = xmlReader.read(inputStream);
                jpdlReader.checkTaskNames(doc);
                this.reconfigProcessDefinition(jbpmContext, doc);
                Element root = doc.getRootElement();
                String encoding = doc.getXMLEncoding();
                String processName = root.attributeValue("name");

                try {
                    SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault());
                    String ret = formatter.format(new Date());
                    String filename = SystemProperties.getConfigRootPath() + "/deploy/" + processName + ret
                            + ".zip";
                    // ?
                    FileUtils.save(filename, zipBytes);
                } catch (Exception ex) {
                    if (LogUtils.isDebug()) {
                        logger.debug(ex);
                        ex.printStackTrace();
                    }
                }

                byte[] pdBytes = Dom4jUtils.getBytesFromPrettyDocument(doc, encoding);
                zipMap.put("processdefinition.xml", pdBytes);

                // ??
                byte[] newZipBytes = ZipUtils.toZipBytes(zipMap);
                zipInputStream = new ZipInputStream(new ByteArrayInputStream(newZipBytes));
                processDefinition = ProcessDefinition.parseParZipInputStream(zipInputStream);
                jbpmContext.deployProcessDefinition(processDefinition);
                zipInputStream.close();
                zipInputStream = null;

                String processDefinitionId = String.valueOf(processDefinition.getId());

                logger.debug("processDefinitionId:" + processDefinitionId);
                logger.debug("processName:" + processName);
                Map<String, Task> taskMap = processDefinition.getTaskMgmtDefinition().getTasks();
                if (taskMap != null && taskMap.size() > 0) {
                    Iterator<String> iter = taskMap.keySet().iterator();
                    while (iter.hasNext()) {
                        String taskName = iter.next();
                        logger.debug("taskName:" + taskName);
                    }
                }

                try {
                    SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault());
                    String ret = formatter.format(new Date());
                    String filename = SystemProperties.getConfigRootPath() + "/deploy/" + processName + ret
                            + "_repack.zip";
                    // ??
                    FileUtils.save(filename, newZipBytes);
                } catch (Exception ex) {
                    if (LogUtils.isDebug()) {
                        logger.debug(ex);
                    }
                }
            }

            if (zipMap.get("process.cfg.xml") != null) {
                byte[] x_bytes = zipMap.get("process.cfg.xml");
                if (x_bytes != null) {
                    JbpmExtensionReader reader = new JbpmExtensionReader();
                    List<Extension> extensions = reader.readTasks(new ByteArrayInputStream(x_bytes));
                    if (extensions != null && extensions.size() > 0) {

                        JbpmExtensionManager jbpmExtensionManager = ProcessContainer.getContainer()
                                .getJbpmExtensionManager();
                        jbpmExtensionManager.reconfig(jbpmContext, extensions);
                    }
                }
            }
        }
        return processDefinition;
    } catch (Throwable ex) {
        if (LogUtils.isDebug()) {
            logger.debug(ex);
            ex.printStackTrace();
        }
        throw new JbpmException(ex);
    } finally {
        try {
            if (zipInputStream != null) {
                zipInputStream.close();
                zipInputStream = null;
            }
        } catch (Exception ex) {
            if (LogUtils.isDebug()) {
                logger.debug(ex);
            }
        }
        try {
            if (inputStream != null) {
                inputStream.close();
                inputStream = null;
            }
        } catch (Exception ex) {
            if (LogUtils.isDebug()) {
                logger.debug(ex);
            }
        }
    }
}

From source file:com.glaf.jbpm.deploy.MxJbpmProcessDeployer.java

License:Apache License

public void reconfigProcessDefinition(JbpmContext jbpmContext, Document doc) {
    Element root = doc.getRootElement();
    String processName = root.attributeValue("name");
    String className = null;//from w  ww  .  ja  va2s .  c  o  m
    Map<String, String> actionMap = new java.util.HashMap<String, String>();
    List<?> actionList = root.elements("action");
    if (actionList != null && actionList.size() > 0) {
        Iterator<?> iterator = actionList.iterator();
        while (iterator.hasNext()) {
            Element element = (Element) iterator.next();
            String name = element.attributeValue("name");
            String clazz = element.attributeValue("class");
            actionMap.put(name, clazz);
        }
    }

    if (StringUtils.isEmpty(className)) {
        className = CustomProperties.getString(processName + ".jbpm.action.class");
    }

    if (StringUtils.isEmpty(className)) {
        className = CustomProperties.getString("jbpm.action.class");
    }

    if (StringUtils.isEmpty(className)) {
        className = SystemProperties.getString("jbpm.action.class");
    }

    List<?> taskNodeList = root.elements("task-node");
    if (taskNodeList == null || taskNodeList.size() == 0) {
        return;
    }

    Iterator<?> iterator = taskNodeList.iterator();
    while (iterator.hasNext()) {
        Element element = (Element) iterator.next();
        Map<String, String> taskMap = new java.util.HashMap<String, String>();
        List<?> taskList = element.elements("task");
        if (taskList != null && taskList.size() > 0) {
            Iterator<?> iter = taskList.iterator();
            while (iter.hasNext()) {
                Element elem = (Element) iter.next();
                taskMap.put(elem.attributeValue("name"), elem.attributeValue("description"));
            }
        }

        List<?> eventList = element.elements("event");
        if (eventList != null && eventList.size() > 0) {
            Iterator<?> iter = eventList.iterator();
            while (iter.hasNext()) {
                Element elem = (Element) iter.next();
                String eventType = elem.attributeValue("type");
                if (StringUtils.equals(eventType, "node-enter")) {
                    List<?> actionRefList = elem.elements("action");
                    if (actionRefList != null && actionRefList.size() > 0) {
                        Iterator<?> it = actionRefList.iterator();
                        while (it.hasNext()) {
                            Element e = (Element) it.next();
                            String ref = e.attributeValue("ref-name");
                            if (StringUtils.isNotEmpty(ref)) {
                                if (!actionMap.containsKey(ref)) {
                                    Element newAction = root.addElement("action");
                                    newAction.addAttribute("name", ref);
                                    newAction.addAttribute("class", className);
                                    newAction.addElement("extensionName").setText(ref);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:com.glaf.jbpm.util.CustomFieldInstantiator.java

License:Apache License

private static Object getMapValue(Element mapElement, Map<Object, Object> map) {
    Class<?> keyClass = String.class;
    String keyType = mapElement.attributeValue("key-type");
    if (keyType != null) {
        keyClass = ClassLoaderUtil.classForName(keyType);
    }//w  ww  .ja  v a2 s .  c o  m
    Class<?> valueClass = String.class;
    String valueType = mapElement.attributeValue("value-type");
    if (valueType != null) {
        valueClass = ClassLoaderUtil.classForName(valueType);
    }
    Iterator<?> iter = mapElement.elementIterator();
    while (iter.hasNext()) {
        Element element = (Element) iter.next();
        Element keyElement = element.element("key");
        Element valueElement = element.element("value");
        Class<?> clazz = null;
        String className = element.attributeValue("value-type");
        if (className != null) {
            clazz = ClassLoaderUtil.classForName(className);
        }
        if (clazz == null) {
            clazz = valueClass;
        }
        map.put(getValue(keyClass, keyElement), getValue(clazz, valueElement));
    }
    return map;
}

From source file:com.glaf.jbpm.util.CustomFieldInstantiator.java

License:Apache License

private static Object getCollectionValue(Element collectionElement, Collection<Object> collection) {
    Class<?> elementClass = String.class;
    String elementType = collectionElement.attributeValue("element-type");
    if (elementType != null) {
        elementClass = ClassLoaderUtil.classForName(elementType);
    }/*from   ww  w.  j  a  v  a 2  s .  com*/
    Iterator<?> iter = collectionElement.elementIterator();
    while (iter.hasNext()) {
        Element element = (Element) iter.next();
        collection.add(getValue(elementClass, element));
    }
    return collection;
}