List of usage examples for org.dom4j Element attributeValue
String attributeValue(QName qName);
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; }/* w w w . j a v a2 s. com*/ 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.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 {/*from w w w . jav a 2s. co 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
public void processElement(String systemName, Element root, Map<String, Object> params) { /**/*from w w w .j a v a2 s. c o 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.XmlBuilder.java
License:Apache License
@SuppressWarnings({ "unchecked", "rawtypes" }) protected void processForEachNode(Element element, Map<String, DatasetModel> dataSetMap, Map<String, Object> myDataMap, String systemName, Map<String, Object> params) { //LOG.debug("---------------------processForEachNode-----------------------"); Element parent = element.getParent(); String dsId = element.attributeValue("DataSetId"); if (StringUtils.isNotEmpty(dsId)) { if (myDataMap != null && !myDataMap.isEmpty()) { params.putAll(myDataMap);/*from w w w.ja v a 2s. c o m*/ } DatasetModel dsm = dataSetMap.get(dsId); String sql = dsm.getSql(); String queryId = dsm.getQueryId(); List<Map<String, Object>> 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("#1 rows:" + rows.size()); } if (rows != null && !rows.isEmpty()) { int sortNo = 0; List<?> elements = element.elements(); if (elements != null && elements.size() == 1) { Element elem = (Element) elements.get(0); LOG.debug("name:" + elem.getName()); for (Map<String, Object> dataMap : rows) { sortNo = sortNo + 1; dataMap.put("sortNo", sortNo); Element e = elem.createCopy(); 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); } } if (e.isTextOnly()) { String value = e.getStringValue(); if (StringUtils.contains(value, "#{") && StringUtils.contains(value, "}")) { String text = QueryUtils.replaceBlankParas(value, dataMap); e.setText(text); } } List<?> attrs = e.attributes(); Iterator<?> iter = attrs.iterator(); while (iter.hasNext()) { Attribute attr = (Attribute) iter.next(); String value = attr.getValue(); if (StringUtils.contains(value, "#{") && StringUtils.contains(value, "}")) { String text = QueryUtils.replaceBlankParas(value, dataMap); attr.setValue(text); } } e.setParent(null); parent.add(e); } } } } parent.remove(element); }
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 {//from w w w.j a v a2s. co 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); } }
From source file:com.glaf.core.xml.XmlBuilder.java
License:Apache License
protected void processTextNode(Element element, Map<String, DatasetModel> dataSetMap, Map<String, Object> dataMap, String systemName, Map<String, Object> params) { //LOG.debug("---------------------processTextNode-----------------------"); if (StringUtils.equals(element.getName(), "foreach")) { this.processForEachNode(element, dataSetMap, dataMap, systemName, params); return;//from www . jav a 2 s. c o m } String dsId = element.attributeValue("DataSetId"); if (StringUtils.isNotEmpty(dsId)) { if (dataMap != null && !dataMap.isEmpty()) { params.putAll(dataMap); } this.processNode(element, dataSetMap, systemName, params); return; } if (element.isTextOnly()) { String value = element.getStringValue(); if (StringUtils.contains(value, "#{") && StringUtils.contains(value, "}")) { String text = QueryUtils.replaceBlankParas(value, dataMap); element.setText(text); } } List<?> attrs = element.attributes(); Iterator<?> iter = attrs.iterator(); while (iter.hasNext()) { Attribute attr = (Attribute) iter.next(); String value = attr.getValue(); if (StringUtils.contains(value, "#{") && StringUtils.contains(value, "}")) { String text = QueryUtils.replaceBlankParas(value, dataMap); attr.setValue(text); } } List<?> elements = element.elements(); Iterator<?> iterator = elements.iterator(); while (iterator.hasNext()) { Element elem = (Element) iterator.next(); if (StringUtils.equals(elem.getName(), "foreach")) { this.processForEachNode(elem, dataSetMap, dataMap, systemName, params); } else { String dsId2 = elem.attributeValue("DataSetId"); if (StringUtils.isNotEmpty(dsId2)) { if (dataMap != null && !dataMap.isEmpty()) { params.putAll(dataMap); } this.processNode(elem, dataSetMap, systemName, params); } else { this.processTextNode(elem, dataSetMap, dataMap, systemName, params); } } } }
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 . jav a2 s.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.XmlMappingReader.java
License:Apache License
protected void readField(Element elem, ColumnModel field) { field.setName(elem.attributeValue("name")); field.setType(elem.attributeValue("type")); field.setColumnName(elem.attributeValue("column")); field.setTitle(elem.attributeValue("title")); field.setSecondTitle(elem.attributeValue("secondTitle")); field.setTrimType(elem.attributeValue("trimType")); field.setValueExpression(elem.attributeValue("valueExpression")); field.setFormat(elem.attributeValue("format")); field.setCurrency(elem.attributeValue("currency")); /**/*from w w w .j ava 2s . c o m*/ * ??? */ if ("true".equals(elem.attributeValue("temporary"))) { field.setTemporary(true); } /** * */ if ("true".equals(elem.attributeValue("required"))) { field.setRequired(true); } String length = elem.attributeValue("length"); if (StringUtils.isNumeric(length)) { field.setLength(Integer.parseInt(length)); } String precision = elem.attributeValue("precision"); if (StringUtils.isNumeric(precision)) { field.setPrecision(Integer.parseInt(precision)); } String decimal = elem.attributeValue("decimal"); if (StringUtils.isNumeric(decimal)) { field.setDecimal(Integer.parseInt(decimal)); } String position = elem.attributeValue("position"); if (StringUtils.isNumeric(position)) { field.setPosition(Integer.parseInt(position)); } }
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 ww . j a v a2 s.co 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; }