List of usage examples for org.dom4j Document getRootElement
Element getRootElement();
From source file:com.glaf.core.util.Dom4jUtils.java
License:Apache License
/** * ??//from w ww .j a va2 s. c om * * @param inputStream * InputStream * @param xpath * String * @return Element * @throws Exception */ public static Element getElementCopy(InputStream inputStream, String xpath) throws Exception { if (xpath == null) { return toElement(inputStream); } SAXReader xmlReader = new SAXReader(); Document doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); Element element = (Element) root.selectSingleNode(xpath); return element; }
From source file:com.glaf.core.util.Dom4jUtils.java
License:Apache License
/** * ???// w w w. j a v a 2 s . c om * * @param inputStream * InputStream * @return Element * @throws Exception */ public static Element toElement(InputStream inputStream) throws Exception { SAXReader xmlReader = new SAXReader(); Document doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); return root; }
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 {/* ww w. ja 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 Document process(String systemName, InputStream inputStream, Map<String, Object> params) { ResultThreadLocal.clear();/* w w w. j a v a 2s.c o m*/ SAXReader xmlReader = new SAXReader(); Document doc = null; try { doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); processElement(systemName, root, params); } catch (Exception ex) { ex.printStackTrace(); throw new RuntimeException(ex); } finally { ResultThreadLocal.clear(); } return doc; }
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 {/*from w w w . j a v a 2s .c o m*/ 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 {/*w w w . j av a 2 s . com*/ 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 {/* w w w . j a v 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 ww w.j av 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()); 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 www . jav a2 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 {/* w w w.ja v a 2s . c om*/ 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; }