Example usage for org.dom4j Element attribute

List of usage examples for org.dom4j Element attribute

Introduction

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

Prototype

Attribute attribute(QName qName);

Source Link

Document

DOCUMENT ME!

Usage

From source file:com.founder.fix.fixflow.core.impl.util.XmlUtil.java

License:Apache License

public static String getElementAttributeValue(Element element, String value) {
    if (element != null)
        return getAttributeValue(element.attribute(value));
    else/* w w  w. j a v a 2  s . c  o m*/
        return "";
}

From source file:com.github.autoprimer3.AutoPrimer3Config.java

License:Open Source License

public LinkedHashSet<String> readTableFile(Document dasXml) throws DocumentException {
    LinkedHashSet<String> tables = new LinkedHashSet<>();
    Element root = dasXml.getRootElement();
    Element gff = root.element("GFF");
    Element segment = gff.element("SEGMENT");
    for (Iterator i = segment.elementIterator("TYPE"); i.hasNext();) {
        Element type = (Element) i.next();
        Attribute id = type.attribute("id");
        tables.add(id.getValue());//w w  w . ja v  a2  s.c o  m
    }
    return tables;
}

From source file:com.github.autoprimer3.AutoPrimer3Config.java

License:Open Source License

public LinkedHashSet<String> readTableFile(Document dasXml, String category) throws DocumentException {
    LinkedHashSet<String> tables = new LinkedHashSet<>();
    Element root = dasXml.getRootElement();
    Element gff = root.element("GFF");
    Element segment = gff.element("SEGMENT");
    for (Iterator i = segment.elementIterator("TYPE"); i.hasNext();) {
        Element type = (Element) i.next();
        Attribute id = type.attribute("id");
        Attribute cat = type.attribute("category");
        if (cat.getValue().equals(category)) {
            tables.add(id.getValue());/*  w w  w. ja v  a2  s  .  c o  m*/
        }
    }
    return tables;
}

From source file:com.github.autoprimer3.GetUcscBuildsAndTables.java

License:Open Source License

public void readDasGenomeXmlDocument() {
    if (dasGenomeXml == null) {
        return;/*w w w  .  j  a v a  2s.c o  m*/
    }
    Element root = dasGenomeXml.getRootElement();
    for (Iterator i = root.elementIterator("DSN"); i.hasNext();) {
        Element dsn = (Element) i.next();
        Element source = dsn.element("SOURCE");
        Attribute build = source.attribute("id");
        Element mapmaster = dsn.element("MAPMASTER");
        Element desc = dsn.element("DESCRIPTION");
        buildToMapMaster.put(build.getValue(), mapmaster.getText());
        buildToDescription.put(build.getValue(), desc.getText());
    }
}

From source file:com.github.autoprimer3.SequenceFromDasUcsc.java

License:Open Source License

SequenceFromDasUcsc() {//get build names and DAS urls
    try {//from   w w w.  j a va  2  s.  c  o m
        SAXReader reader = new SAXReader();
        URL url = new URL("http://genome.ucsc.edu/cgi-bin/das/dsn");//usa    
        //URL url = new URL("http://genome-euro.ucsc.edu/cgi-bin/das/dsn");    
        Document dasXml;
        dasXml = reader.read(url);
        Element root = dasXml.getRootElement();
        for (Iterator i = root.elementIterator("DSN"); i.hasNext();) {
            Element dsn = (Element) i.next();
            Element source = dsn.element("SOURCE");
            Attribute build = source.attribute("id");
            Element mapmaster = dsn.element("MAPMASTER");
            buildToMapMaster.put(build.getValue(), mapmaster.getText());
        }
    } catch (DocumentException | MalformedURLException ex) {
        //TO DO - handle (throw) this error properly
        ex.printStackTrace();
    }
}

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

License:Apache License

public List<ExtensionEntity> readTasks(java.io.InputStream inputStream) {
    List<ExtensionEntity> extensions = new java.util.ArrayList<ExtensionEntity>();
    SAXReader xmlReader = new SAXReader();
    try {//from  w w  w  . j a  v  a 2s  .  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();
            ExtensionEntity extension = new ExtensionEntity();
            extension.setProcessName(element.attributeValue("processName"));
            extension.setTaskName(element.attributeValue("taskName"));
            extension.setType(x_type);
            if (element.elementTextTrim("taskMgmtType") != null) {
                ExtensionFieldEntity extensionField = new ExtensionFieldEntity();
                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)) {
                        ExtensionFieldEntity extensionField = new ExtensionFieldEntity();
                        extensionField.setName(propertyName.trim());
                        extensionField.setValue(propertyValue.trim());
                        extension.addField(extensionField);
                    }
                }
            }
            if (element.elementText("handlers") != null) {
                ExtensionFieldEntity extensionField = new ExtensionFieldEntity();
                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.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  www. ja 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();
            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.extension.xml.ExtensionWriter.java

License:Apache License

public Document write(List<ExtensionEntity> extensions) {
    Document doc = DocumentHelper.createDocument();
    if (extensions != null && extensions.size() > 0) {
        Element root = doc.addElement("bpm-cfg");
        Iterator<ExtensionEntity> iterator = extensions.iterator();
        while (iterator.hasNext()) {
            ExtensionEntity extension = iterator.next();
            if (root.attribute("type") == null && extension.getType() != null) {
                root.addAttribute("type", extension.getType());
            }//from  w w w .  j  a  v a 2 s.  c  o  m
            if (StringUtils.isNotEmpty(extension.getTaskName())) {
                Element element = root.addElement("taskmgr");
                element.addAttribute("processName", extension.getProcessName());
                element.addAttribute("taskName", extension.getTaskName());
                if (extension.getFieldValue("taskMgmtType") != null) {
                    Element elem = element.addElement("taskMgmtType");
                    elem.setText(extension.getFieldValue("taskMgmtType"));
                }
                if (extension.getFieldValue("handlers") != null) {
                    Element elem = element.addElement("handlers");
                    elem.setText(extension.getFieldValue("handlers"));
                }
                if (extension.getFields() != null && extension.getFields().size() > 0) {
                    Element elem = element.addElement("properties");
                    Iterator<ExtensionFieldEntity> iter = extension.getFields().values().iterator();
                    while (iter.hasNext()) {
                        ExtensionFieldEntity field = iter.next();
                        Element e = elem.addElement("property");
                        e.addAttribute("key", field.getName());
                        e.addCDATA(field.getValue());
                    }
                }
            } else if (StringUtils.isNotEmpty(extension.getName())) {
                Element element = root.addElement("action");
                element.addAttribute("processName", extension.getProcessName());
                element.addAttribute("name", extension.getName());
                if (extension.getFieldValue("sql") != null) {
                    Element elem = element.addElement("sql");
                    elem.addCDATA(extension.getFieldValue("sql"));
                }
                if (extension.getFieldValue("handlers") != null) {
                    Element elem = element.addElement("handlers");
                    elem.setText(extension.getFieldValue("handlers"));
                }
                if (extension.getParams() != null && extension.getParams().size() > 0) {
                    Element em = element.addElement("parameters");
                    Iterator<ExtensionParamEntity> iter = extension.getParams().iterator();
                    while (iter.hasNext()) {
                        ExtensionParamEntity param = iter.next();
                        Element e = em.addElement("parameter");
                        e.addAttribute("name", param.getName());
                        e.addAttribute("type", param.getType());
                        e.addCDATA(param.getValue());
                    }
                }
            }
        }
    }
    return doc;
}

From source file:com.glaf.core.todo.util.TodoXmlReader.java

License:Apache License

public List<Todo> read(java.io.InputStream inputStream) {
    List<Todo> todos = new java.util.ArrayList<Todo>();
    SAXReader xmlReader = new SAXReader();
    int sortNo = 1;
    try {/*w ww  .ja v  a 2  s.c  o m*/
        Document doc = xmlReader.read(inputStream);
        Element root = doc.getRootElement();
        List<?> rows = root.elements();
        Iterator<?> iterator = rows.iterator();
        while (iterator.hasNext()) {
            Element element = (Element) iterator.next();
            String id = element.attributeValue("id");
            Map<String, Object> rowMap = new java.util.HashMap<String, Object>();
            rowMap.put("id", id);
            List<?> properties = element.elements("property");
            Iterator<?> iter = properties.iterator();
            while (iter.hasNext()) {
                Element elem = (Element) iter.next();
                String propertyName = elem.attributeValue("name");
                String propertyValue = null;
                if (elem.attribute("value") != null) {
                    propertyValue = elem.attributeValue("value");
                } else {
                    propertyValue = elem.getTextTrim();
                }
                if (StringUtils.isNotEmpty(propertyName) && StringUtils.isNotEmpty(propertyValue)) {
                    rowMap.put(propertyName, propertyValue);
                }
            }

            Todo model = new Todo();
            model.setSortNo(sortNo++);
            Tools.populate(model, rowMap);

            todos.add(model);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new RuntimeException(ex.getMessage());
    }
    return todos;
}

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

License:Apache License

@SuppressWarnings({ "rawtypes", "unchecked" })
protected void processNode(Element element, Map<String, DatasetModel> dataSetMap, String systemName,
        Map<String, Object> params) {
    //LOG.debug("---------------------processNode-----------------------");
    String dsId = element.attributeValue("DataSetId");

    if (StringUtils.isNotEmpty(dsId) && dataSetMap.get(dsId) != null) {
        //LOG.debug(element.getName() + " ds->" + dsId);
        element.remove(element.attribute("DataSetId"));
        Element parent = element.getParent();
        DatasetModel dsm = dataSetMap.get(dsId);
        String sql = dsm.getSql();
        String queryId = dsm.getQueryId();
        boolean single = dsm.isSingle();
        boolean foreachPerRow = dsm.isForeachPerRow();
        List<Map<String, Object>> rows = null;
        List<String> splits = dsm.getSplitList();
        if (foreachPerRow) {
            LOG.debug("sql:" + sql);
            LOG.debug("params:" + params);
            rows = queryHelper.getResultList(systemName, sql, params);
            // ITablePageService tablePageService =
            // ContextFactory.getBean("tablePageService");
            // rows = queryHelper.getResultList(systemName, sql, params);
            // Environment.setCurrentSystemName(systemName);
            // rows = tablePageService.getListData(sql, params);
            LOG.debug("#2 rows:" + rows.size());
        } else {//w ww  .  j ava  2  s. c  o m
            rows = ResultThreadLocal.getResultList(dsId);
            if (rows == null) {
                if (StringUtils.isNotEmpty(queryId)) {
                    Environment.setCurrentSystemName(systemName);
                    List<Object> list = entityService.getList(queryId, params);
                    if (list != null && !list.isEmpty()) {
                        rows = new ArrayList<Map<String, Object>>();
                        for (Object object : list) {
                            if (object instanceof Map) {
                                Map dataMap = (Map) object;
                                rows.add(dataMap);
                            } else {
                                try {
                                    Map dataMap = BeanUtils.describe(object);
                                    rows.add(dataMap);
                                } catch (Exception e) {
                                }
                            }
                        }
                    }
                } else if (StringUtils.isNotEmpty(sql)) {
                    LOG.debug("sql:" + sql);
                    LOG.debug("params:" + params);
                    rows = queryHelper.getResultList(systemName, sql, params);
                    // ITablePageService tablePageService =
                    // ContextFactory.getBean("tablePageService");
                    // rows = queryHelper.getResultList(systemName, sql,
                    // params);
                    // Environment.setCurrentSystemName(systemName);
                    // rows = tablePageService.getListData(sql, params);
                    LOG.debug("#3 rows:" + rows.size());
                }
                ResultThreadLocal.setResultList(dsId, rows);
            }
        }
        if (rows != null && !rows.isEmpty()) {
            if (single) {
                Map<String, Object> dataMap = rows.get(0);
                if (dsm.getControllers() != null && !dsm.getControllers().isEmpty()) {
                    List<FieldController> controllers = dsm.getControllers();
                    for (FieldController c : controllers) {
                        Class<?> x = ClassUtils.classForName(c.getProvider());
                        FieldConverter fp = (FieldConverter) ReflectUtils.newInstance(x);
                        fp.convert(c.getFromName(), c.getToName(), dataMap);
                    }
                }
                this.processTextNode(element, dataSetMap, dataMap, systemName, params);
            } else {
                int sortNo = 0;
                for (Map<String, Object> dataMap : rows) {
                    if (splits != null && !splits.isEmpty()) {
                        int splitCnt = 0;
                        Iterator<String> it = splits.iterator();
                        while (it.hasNext()) {
                            String str = it.next();
                            if (str != null && ObjectUtils.equals(dataMap.get(str), params.get(str))) {
                                splitCnt = splitCnt + 1;
                            } else if (str != null && ObjectUtils.equals(dataMap.get(str.toLowerCase()),
                                    params.get(str.toLowerCase()))) {
                                splitCnt = splitCnt + 1;
                            }
                        }
                        /**
                         * ???
                         */
                        if (splitCnt != splits.size()) {
                            // LOG.debug("dsId="+dsId);
                            // LOG.debug("params:"+params );
                            // LOG.debug(dataMap + " ???");
                            continue;
                        }
                    }
                    sortNo = sortNo + 1;
                    dataMap.put("sortNo", sortNo);
                    if (dsm.getControllers() != null && !dsm.getControllers().isEmpty()) {
                        List<FieldController> controllers = dsm.getControllers();
                        for (FieldController c : controllers) {
                            Class<?> x = ClassUtils.classForName(c.getProvider());
                            FieldConverter fp = (FieldConverter) ReflectUtils.newInstance(x);
                            fp.convert(c.getFromName(), c.getToName(), dataMap);
                        }
                    }

                    Element e = element.createCopy();
                    this.processTextNode(e, dataSetMap, dataMap, systemName, params);
                    parent.add(e);

                }
                parent.remove(element);
            }
        } else {
            parent.remove(element);
        }
    } else {
        this.processTextNode(element, dataSetMap, null, systemName, params);
    }
}