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.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 {//  ww  w  .j  a va  2s  .com
        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 void reconfigProcessDefinition(JbpmContext jbpmContext, Document doc) {
    Element root = doc.getRootElement();
    String processName = root.attributeValue("name");
    String className = null;/* w  ww.  j a va 2s .co 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.export.MxJbpmProcessExporter.java

License:Apache License

public void addElement(Document doc, Map<String, Object> context) {
    Element root = doc.getRootElement();
    GraphSession graphSession = null;/*  w  w w  .  ja v  a2s .co  m*/
    JbpmContext jbpmContext = null;
    try {
        jbpmContext = ProcessContainer.getContainer().createJbpmContext();
        graphSession = jbpmContext.getGraphSession();
        List<ProcessDefinition> processDefinitions = graphSession.findLatestProcessDefinitions();
        if (processDefinitions != null && processDefinitions.size() > 0) {
            Element element = root.addElement("processes");
            Iterator<ProcessDefinition> iterator = processDefinitions.iterator();
            while (iterator.hasNext()) {
                ProcessDefinition pd = iterator.next();
                Element elem = element.addElement("process");
                elem.addAttribute("name", pd.getName());
                elem.addAttribute("description", pd.getDescription());
            }
        }
    } catch (Exception ex) {
        if (LogUtils.isDebug()) {
            ex.printStackTrace();
        }
    } finally {
        Context.close(jbpmContext);
    }

    Element jbpmCfgTemplate = root.addElement("jbpm-cfg-template");

    String configPath = SystemProperties.getConfigRootPath();
    String path = configPath + "/conf/jbpm/template";
    java.io.File directory = new java.io.File(path);
    String[] filelist = directory.list();
    InputStream inputStream = null;
    SAXReader xmlReader = new SAXReader();
    for (int i = 0; i < filelist.length; i++) {
        String filename = directory.getAbsolutePath() + "/" + filelist[i];
        File file = new File(filename);
        if (file.isFile() && file.getName().endsWith(".xml")) {
            try {
                inputStream = new FileInputStream(file);
                Document doc2x = xmlReader.read(inputStream);
                Element root2x = doc2x.getRootElement();
                List<?> elements = root2x.elements("action-definition");
                Iterator<?> iterator = elements.iterator();
                while (iterator.hasNext()) {
                    Element elem = (Element) iterator.next();
                    elem.setParent(jbpmCfgTemplate);
                    elem.setDocument(doc);
                    jbpmCfgTemplate.add(elem);
                }
                inputStream.close();
                inputStream = null;
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }
    }
}

From source file:com.glaf.jbpm.xml.JpdlXmlReader.java

License:Apache License

public List<String> getTaskNames(InputStream inputStream) {
    List<String> taskNames = new ArrayList<String>();
    SAXReader xmlReader = new SAXReader();
    Document doc = null;/*  www.  j a v a  2 s .c om*/
    try {
        doc = xmlReader.read(inputStream);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    Element root = doc.getRootElement();
    List<?> rows = root.elements("task-node");
    Iterator<?> iterator = rows.iterator();
    while (iterator.hasNext()) {
        Element element = (Element) iterator.next();
        List<?> tasks = element.elements("task");
        Iterator<?> iter = tasks.iterator();
        while (iter.hasNext()) {
            Element elem = (Element) iter.next();
            String taskName = elem.attributeValue("name");
            if (taskNames.contains(taskName)) {
                throw new RuntimeException("task name '" + taskName + "' is exists.");
            }
            taskNames.add(taskName);
        }
    }

    return taskNames;
}

From source file:com.glaf.jbpm.xml.JpdlXmlReader.java

License:Apache License

public void checkTaskNames(Document doc) {
    List<String> taskNames = new ArrayList<String>();
    Element root = doc.getRootElement();
    List<?> rows = root.elements("task-node");
    Iterator<?> iterator = rows.iterator();
    while (iterator.hasNext()) {
        Element element = (Element) iterator.next();
        List<?> tasks = element.elements("task");
        Iterator<?> iter = tasks.iterator();
        while (iter.hasNext()) {
            Element elem = (Element) iter.next();
            String taskName = elem.attributeValue("name");
            if (taskNames.contains(taskName)) {
                throw new RuntimeException("task name '" + taskName + "' is exists.");
            }/*from w w  w  .jav  a2s .  co  m*/
            taskNames.add(taskName);
        }
    }
}

From source file:com.glaf.jbpm.xml.JpdlXmlReader.java

License:Apache License

public List<Todo> read(InputStream inputStream) {
    List<Todo> todoList = new java.util.ArrayList<Todo>();
    SAXReader xmlReader = new SAXReader();
    int sortNo = 1;
    try {/* www  . ja va2 s .  c o  m*/
        Document doc = xmlReader.read(inputStream);
        Element root = doc.getRootElement();
        String processName = root.attributeValue("name");
        String moduleName = root.elementText("description");
        List<?> rows = root.elements("task-node");
        Iterator<?> iterator = rows.iterator();
        while (iterator.hasNext()) {
            Element element = (Element) iterator.next();
            List<?> tasks = element.elements("task");
            Iterator<?> iter = tasks.iterator();
            while (iter.hasNext()) {
                Element elem = (Element) iter.next();
                String taskName = elem.attributeValue("name");
                if (taskName.startsWith("task55")) {
                    continue;
                }
                Todo model = new Todo();
                model.setSortNo(sortNo++);
                model.setProcessName(processName);
                model.setModuleName(moduleName);
                model.setTitle(moduleName + " " + elem.attributeValue("description") + "??");
                model.setContent(moduleName + " " + elem.attributeValue("description") + "??");
                model.setCode(processName + "_" + taskName);
                model.setTaskName(taskName);
                model.setProvider("jbpm");
                model.setLinkType(processName + "_" + taskName);
                String detail_url = conf.get("jbpm_task_detail_url");
                String list_url = conf.get("jbpm_task_url");
                model.setLink(detail_url + "&rowId=#{rowId}&x_method=view&app_name=" + processName);
                model.setListLink(list_url + "&taskType=running&app_name=" + processName);
                model.setLimitDay(2);
                model.setXa(6);
                model.setXb(6);
                todoList.add(model);
            }
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    return todoList;
}

From source file:com.glaf.mail.MxMailHelper.java

License:Apache License

public Map<String, String> getAttributes(String attribute) {
    Map<String, String> dataMap = new java.util.HashMap<String, String>();
    StringReader stringReader = new StringReader(attribute);
    SAXReader xmlReader = new SAXReader();
    try {/*w  w  w.  j av  a 2s  .c o m*/
        Document doc = xmlReader.read(stringReader);
        Element root = doc.getRootElement();
        List<?> elements = root.elements("element");
        if (elements != null && elements.size() > 0) {
            Iterator<?> iterator = elements.iterator();
            while (iterator.hasNext()) {
                Element element = (Element) iterator.next();
                String name = element.attributeValue("name");
                String value = element.attributeValue("value");
                if (StringUtils.isEmpty(value)) {
                    value = element.getStringValue();
                }
                dataMap.put(name, value);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return dataMap;
}

From source file:com.glaf.mail.xml.MailXmlReader.java

License:Apache License

protected Map<String, Object> readProperties(Element element) {
    Map<String, Object> properties = new java.util.HashMap<String, Object>();
    Element propsElement = element.element("properties");
    if (propsElement != null) {
        List<?> rows = propsElement.elements("property");
        Iterator<?> iter = rows.iterator();
        while (iter.hasNext()) {
            Element elem = (Element) iter.next();
            String name = elem.attributeValue("name");
            String value = elem.attributeValue("value");
            if (StringUtils.isEmpty(value)) {
                value = elem.getStringValue();
            }/*w w w  .  ja  v  a  2 s . co m*/
            properties.put(name, value);
        }
    }
    return properties;
}

From source file:com.glaf.template.TemplateReader.java

License:Apache License

@SuppressWarnings("unchecked")
public Map<String, Template> getTemplates(InputStream inputStream) {
    Map<String, Template> dataMap = new java.util.HashMap<String, Template>();
    Element root = this.getRootElement(inputStream);
    List<?> templates = root.elements("template");
    if (templates != null && templates.size() > 0) {
        Iterator<?> iterator = templates.iterator();
        while (iterator.hasNext()) {
            Element element = (Element) iterator.next();
            Template template = new Template();

            List<Element> elems = element.elements();
            if (elems != null && !elems.isEmpty()) {
                Map<String, Object> rowMap = new java.util.HashMap<String, Object>();
                for (Element em : elems) {
                    rowMap.put(em.getName(), em.getStringValue());
                }//  w  w w .  ja v  a  2  s. com
                Tools.populate(template, rowMap);
            }

            String text = element.elementText("text");
            String name = element.elementText("name");
            String title = element.elementText("title");
            String templateId = element.attributeValue("id");
            String dataFile = element.elementText("dataFile");
            String moduleId = element.elementText("moduleId");
            String moduleName = element.elementText("moduleName");
            String callbackUrl = element.elementText("callbackUrl");
            String description = element.elementText("description");
            String language = element.elementText("language");
            String objectId = element.elementText("objectId");
            String objectValue = element.elementText("objectValue");
            String _fileType = element.elementText("fileType");

            template.setLanguage(language);

            int fileType = 0;
            if (StringUtils.isNumeric(_fileType)) {
                fileType = Integer.parseInt(_fileType);
            }
            if (dataFile.endsWith(".java")) {
                fileType = 50;
            } else if (dataFile.endsWith(".jsp")) {
                fileType = 51;
            } else if (dataFile.endsWith(".ftl")) {
                fileType = 52;
                template.setLanguage("freemarker");
            } else if (dataFile.endsWith(".vm")) {
                fileType = 54;
                template.setLanguage("velocity");
            } else if (dataFile.endsWith(".xml")) {
                fileType = 60;
            } else if (dataFile.endsWith(".htm") || dataFile.endsWith(".html")) {
                fileType = 80;
            }

            template.setTemplateType(FileUtils.getFileExt(dataFile));

            if (StringUtils.isEmpty(text)) {
                String filename = SystemProperties.getConfigRootPath() + dataFile;
                File file = new File(filename);
                template.setLastModified(file.lastModified());
                template.setFileSize(file.length());
                byte[] data = FileUtils.getBytes(file);
                template.setData(data);
            }
            if (template.getData() == null || template.getFileSize() == 0) {
                throw new RuntimeException(" template content is null ");
            }

            template.setContent(text);
            template.setDataFile(dataFile);
            template.setTitle(title);
            template.setName(name);
            if (StringUtils.isNotEmpty(name)) {
                template.setName(name);
            } else {
                template.setName(title);
            }
            template.setFileType(fileType);
            template.setCallbackUrl(callbackUrl);
            template.setDescription(description);
            template.setTemplateId(templateId);

            template.setModuleId(moduleId);
            template.setModuleName(moduleName);
            template.setObjectId(objectId);
            template.setObjectValue(objectValue);

            dataMap.put(templateId, template);
        }
    }

    return dataMap;
}

From source file:com.glaf.template.TemplateReader.java

License:Apache License

@SuppressWarnings("unchecked")
public List<Template> readTemplates(InputStream inputStream) {
    List<Template> templates = new java.util.ArrayList<Template>();
    Element root = this.getRootElement(inputStream);
    List<Element> elements = root.elements("template");
    if (elements != null && !elements.isEmpty()) {
        for (Element element : elements) {
            Template tpl = new Template();
            tpl.setTemplateId(element.attributeValue("id"));
            tpl.setName(element.attributeValue("name"));
            tpl.setDescription(element.attributeValue("description"));
            List<Element> elems = element.elements();
            if (elems != null && !elems.isEmpty()) {
                Map<String, Object> dataMap = new java.util.HashMap<String, Object>();
                for (Element em : elems) {
                    dataMap.put(em.getName(), em.getStringValue());
                }/*w w  w. ja  v a  2  s  .c  o m*/
                Tools.populate(tpl, dataMap);
            }
            if (StringUtils.isEmpty(tpl.getContent())) {
                if (StringUtils.isNotEmpty(tpl.getDataFile())) {
                    String filename = SystemProperties.getConfigRootPath() + "/" + tpl.getDataFile();
                    try {
                        tpl.setContent(FileUtils.readFile(filename));
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
            templates.add(tpl);
        }
    }

    return templates;
}