List of usage examples for org.dom4j Element addElement
Element addElement(String name);
Element
node with the given name to this branch and returns a reference to the new node. From source file:com.flaptor.hounder.searcher.XmlResults.java
License:Apache License
private static Element createAndAddElement(org.apache.lucene.document.Document doc, Element parent) { Element item = parent.addElement("result"); for (Iterator iter = doc.getFields().iterator(); iter.hasNext();) { Field f = (Field) iter.next(); item.addElement(f.name()).addText(f.stringValue()); }/* ww w. j a v a 2 s .co m*/ return item; }
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()); }/* ww w . j av a 2s .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.activiti.spring.SpringProcessEngineConfigurationBean.java
License:Apache License
@Override protected void initSqlSessionFactory() { logger.info("-------------------------------------------"); logger.info("-------------initSqlSessionFactory()-------"); logger.info("sqlSessionFactory:" + sqlSessionFactory); logger.info("transactionFactory:" + transactionFactory); if (sqlSessionFactory == null) { InputStream inputStream = null; try {//from www. j av a 2s.c o m if (configLocation != null) { logger.info("mybatis config:" + this.configLocation.getFile().getAbsolutePath()); inputStream = this.configLocation.getInputStream(); } else { Resource resource = new ClassPathResource("com/glaf/activiti/activiti.mybatis.conf.xml"); inputStream = resource.getInputStream(); } if (!ObjectUtils.isEmpty(this.mapperLocations)) { SAXReader xmlReader = new SAXReader(); EntityResolver entityResolver = new XMLMapperEntityResolver(); xmlReader.setEntityResolver(entityResolver); Document doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); Element mappers = root.element("mappers"); if (mappers != null) { java.util.List<?> list = mappers.elements(); Collection<String> files = new HashSet<String>(); if (list != null && !list.isEmpty()) { Iterator<?> iterator = list.iterator(); while (iterator.hasNext()) { Element elem = (Element) iterator.next(); if (elem.attributeValue("resource") != null) { String file = elem.attributeValue("resource"); files.add(file); } else if (elem.attributeValue("url") != null) { String file = elem.attributeValue("url"); files.add(file); } } } for (Resource mapperLocation : this.mapperLocations) { if (mapperLocation == null) { continue; } String url = mapperLocation.getURL().toString(); // logger.debug("find mapper:" + url); if (!files.contains(url)) { Element element = mappers.addElement("mapper"); element.addAttribute("url", url); } } } IOUtils.closeStream(inputStream); byte[] bytes = Dom4jUtils.getBytesFromPrettyDocument(doc); inputStream = new ByteArrayInputStream(bytes); } // update the jdbc parameters to the configured ones... Environment environment = new Environment("default", transactionFactory, dataSource); Reader reader = new InputStreamReader(inputStream); Properties properties = new Properties(); properties.put("prefix", databaseTablePrefix); if (databaseType != null) { properties.put("limitBefore", DbSqlSessionFactory.databaseSpecificLimitBeforeStatements.get(databaseType)); properties.put("limitAfter", DbSqlSessionFactory.databaseSpecificLimitAfterStatements.get(databaseType)); properties.put("limitBetween", DbSqlSessionFactory.databaseSpecificLimitBetweenStatements.get(databaseType)); properties.put("orderBy", DbSqlSessionFactory.databaseSpecificOrderByStatements.get(databaseType)); } XMLConfigBuilder parser = new XMLConfigBuilder(reader, "", properties); Configuration configuration = parser.getConfiguration(); configuration.setEnvironment(environment); configuration.getTypeHandlerRegistry().register(VariableType.class, JdbcType.VARCHAR, new IbatisVariableTypeHandler()); configuration = parser.parse(); sqlSessionFactory = new DefaultSqlSessionFactory(configuration); } catch (Exception e) { throw new ActivitiException("Error while building ibatis SqlSessionFactory: " + e.getMessage(), e); } finally { IoUtil.closeSilently(inputStream); } } }
From source file:com.glaf.core.xml.XmlWriter.java
License:Apache License
public Document write(List<ClassDefinition> rows) { Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("mapping"); for (ClassDefinition classDefinition : rows) { Element element = root.addElement("entity"); element.addAttribute("name", classDefinition.getEntityName()); element.addAttribute("package", classDefinition.getPackageName()); element.addAttribute("moduleName", classDefinition.getModuleName()); element.addAttribute("table", classDefinition.getTableName()); element.addAttribute("title", classDefinition.getTitle()); element.addAttribute("englishTitle", classDefinition.getEnglishTitle()); FieldDefinition idField = classDefinition.getIdField(); if (idField != null) { Element idElement = element.addElement("id"); idElement.addAttribute("name", idField.getName()); idElement.addAttribute("column", idField.getColumnName()); idElement.addAttribute("type", idField.getType()); idElement.addAttribute("title", idField.getTitle()); idElement.addAttribute("englishTitle", idField.getEnglishTitle()); if (idField.getLength() > 0) { idElement.addAttribute("length", String.valueOf(idField.getLength())); }/* w w w .j a va2 s. c o m*/ } Map<String, FieldDefinition> fields = classDefinition.getFields(); Set<Entry<String, FieldDefinition>> entrySet = fields.entrySet(); for (Entry<String, FieldDefinition> entry : entrySet) { String name = entry.getKey(); FieldDefinition field = entry.getValue(); if (idField != null && StringUtils.equalsIgnoreCase(idField.getColumnName(), field.getColumnName())) { continue; } Element elem = element.addElement("property"); elem.addAttribute("name", name); elem.addAttribute("column", field.getColumnName()); elem.addAttribute("type", field.getType()); elem.addAttribute("title", field.getTitle()); elem.addAttribute("englishTitle", field.getEnglishTitle()); if (StringUtils.equals(field.getType(), "String") && field.getLength() > 0) { elem.addAttribute("length", String.valueOf(field.getLength())); } if (field.isUnique()) { elem.addAttribute("unique", String.valueOf(field.isUnique())); } if (field.isSearchable()) { elem.addAttribute("searchable", String.valueOf(field.isSearchable())); } if (!field.isNullable()) { elem.addAttribute("nullable", String.valueOf(field.isNullable())); } if (field.isEditable()) { elem.addAttribute("editable", String.valueOf(field.isEditable())); } if (field.getDisplayType() > 0) { elem.addAttribute("displayType", String.valueOf(field.getDisplayType())); } } } return doc; }
From source file:com.glaf.dts.util.XmlWriter.java
License:Apache License
public Document write(List<DataTransfer> rows) { Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("mapping"); for (DataTransfer dataTransfer : rows) { Element element = root.addElement("entity"); element.addAttribute("name", dataTransfer.getEntityName()); element.addAttribute("package", dataTransfer.getPackageName()); element.addAttribute("entityName", dataTransfer.getEntityName()); element.addAttribute("className", dataTransfer.getClassName()); element.addAttribute("table", dataTransfer.getTableName()); element.addAttribute("title", dataTransfer.getTitle()); element.addAttribute("englishTitle", dataTransfer.getEnglishTitle()); element.addAttribute("parseType", dataTransfer.getParseType()); element.addAttribute("parseClass", dataTransfer.getParseClass()); element.addAttribute("filePrefix", dataTransfer.getFilePrefix()); element.addAttribute("aggregationKeys", dataTransfer.getAggregationKeys()); element.addAttribute("deleteFetch", dataTransfer.getDeleteFetch()); element.addAttribute("insertOnly", dataTransfer.getInsertOnly()); element.addAttribute("primaryKey", dataTransfer.getPrimaryKey()); element.addAttribute("queryIds", dataTransfer.getQueryIds()); element.addAttribute("split", dataTransfer.getSplit()); element.addAttribute("stopWord", dataTransfer.getStopWord()); element.addAttribute("temporaryFlag", dataTransfer.getTemporaryFlag()); element.addAttribute("batchSize", String.valueOf(dataTransfer.getBatchSize())); element.addAttribute("startRow", String.valueOf(dataTransfer.getStartRow())); element.addAttribute("stopSkipRow", String.valueOf(dataTransfer.getStopSkipRow())); element.addAttribute("systemFlag", dataTransfer.getSystemFlag()); ColumnDefinition idField = dataTransfer.getIdColumn(); if (idField != null) { Element idElement = element.addElement("id"); idElement.addAttribute("name", idField.getName()); idElement.addAttribute("column", idField.getColumnName()); idElement.addAttribute("type", idField.getType()); idElement.addAttribute("title", idField.getTitle()); idElement.addAttribute("englishTitle", idField.getEnglishTitle()); if (idField.getLength() > 0) { idElement.addAttribute("length", String.valueOf(idField.getLength())); }/* w w w . j ava 2 s. c o m*/ if (idField.getValueExpression() != null) { idElement.addAttribute("valueExpression", idField.getValueExpression()); } } List<ColumnDefinition> columns = dataTransfer.getColumns(); for (ColumnDefinition field : columns) { if (idField != null && StringUtils.equalsIgnoreCase(idField.getColumnName(), field.getColumnName())) { continue; } Element elem = element.addElement("property"); elem.addAttribute("name", field.getName()); elem.addAttribute("column", field.getColumnName()); elem.addAttribute("type", field.getType()); if (field.getTitle() != null) { elem.addAttribute("title", field.getTitle()); } if (field.getEnglishTitle() != null) { elem.addAttribute("englishTitle", field.getEnglishTitle()); } if (field.getValueExpression() != null) { elem.addAttribute("valueExpression", field.getValueExpression()); } if (field.getLength() > 0) { elem.addAttribute("length", String.valueOf(field.getLength())); } if (field.getPosition() != null && field.getPosition() > 0) { elem.addAttribute("position", String.valueOf(field.getPosition())); } if (field.getPrecision() > 0) { elem.addAttribute("precision", String.valueOf(field.getPrecision())); } if (field.isUnique()) { elem.addAttribute("unique", String.valueOf(field.isUnique())); } if (field.isSearchable()) { elem.addAttribute("searchable", String.valueOf(field.isSearchable())); } if (!field.isNullable()) { elem.addAttribute("nullable", String.valueOf(field.isNullable())); } if (field.isEditable()) { elem.addAttribute("editable", String.valueOf(field.isEditable())); } elem.addAttribute("displayType", String.valueOf(field.getDisplayType())); } } return doc; }
From source file:com.glaf.jbpm.config.JbpmExtensionWriter.java
License:Apache License
public Document write(List<Extension> extensions) { Document doc = DocumentHelper.createDocument(); if (extensions != null && extensions.size() > 0) { Element root = doc.addElement("bpm-cfg"); Iterator<Extension> iterator = extensions.iterator(); while (iterator.hasNext()) { Extension extension = iterator.next(); if (root.attribute("type") == null && extension.getType() != null) { root.addAttribute("type", extension.getType()); }/*from w ww .jav a2s. 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<ExtensionField> iter = extension.getFields().values().iterator(); while (iter.hasNext()) { ExtensionField 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<ExtensionParam> iter = extension.getParams().iterator(); while (iter.hasNext()) { ExtensionParam 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.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. j a v a 2 s . 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;//from w ww .ja v a2 s . c o 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 void convert(File dir) { if (!(dir.exists() || dir.isDirectory())) { return;//from www . jav a 2s.c o m } String[] filelist = dir.list(); for (int i = 0; i < filelist.length; i++) { String filename = dir.getAbsolutePath() + "/" + filelist[i]; java.io.File file = new java.io.File(filename); if (file.isDirectory()) { this.convert(file); } else if (file.isFile() && file.getName().equals("processdefinition.xml")) { List<Todo> todoList = null; try { todoList = this.read(new FileInputStream(file)); } catch (FileNotFoundException ex) { ex.printStackTrace(); } if (todoList != null && todoList.size() > 0) { index = index + 100; Document doc = DocumentHelper.createDocument(); doc.setXMLEncoding("GBK"); Element root = doc.addElement("rows"); Iterator<Todo> iter = todoList.iterator(); while (iter.hasNext()) { Todo todo = (Todo) iter.next(); Map<String, Object> dataMap = Tools.getDataMap(todo); dataMap.remove("id"); dataMap.remove("locked"); dataMap.remove("configFlag"); dataMap.remove("versionNo"); Element row = root.addElement("row"); row.addAttribute("id", String.valueOf(index++)); Set<Entry<String, Object>> entrySet = dataMap.entrySet(); for (Entry<String, Object> entry : entrySet) { String key = entry.getKey(); Object value = entry.getValue(); if (value != null && !(value instanceof Map<?, ?>) && !(value instanceof Set<?>) && !(value instanceof Collection<?>)) { Element elem = row.addElement("property"); elem.addAttribute("name", key); if (key.equals("link") || key.equals("listLink")) { elem.addCDATA(sp + " " + value.toString()); } else { elem.addAttribute("value", value.toString()); } } } } filename = dir.getAbsolutePath() + "/" + "todo.xml"; Dom4jUtils.savePrettyDoument(doc, filename, "GBK"); doc = null; root = null; } } } }
From source file:com.globalsight.cxe.adapter.msoffice.ExcelRepairer.java
License:Apache License
private void repairExcelSharedStrings() throws Exception { File f = new File(path + "/xl/sharedStrings.xml"); if (!f.exists()) return;/*from w w w . ja v a 2 s . c o m*/ String content = FileUtil.readFile(f, "utf-8"); XmlParser parser = new XmlParser(); org.dom4j.Document document = parser.parseXml(content); Element element = document.getRootElement(); List<Element> rs = getElementByName(element, "r"); for (Element r : rs) { @SuppressWarnings("rawtypes") List els = r.content(); StringBuffer sb = new StringBuffer(); Element wt = null; List<DefaultText> texts = new ArrayList<DefaultText>(); for (Object el : els) { if (el instanceof DefaultText) { DefaultText text = (DefaultText) el; String s = text.getStringValue(); if ("\n".equals(s)) continue; texts.add(text); sb.append(text.getStringValue()); } else if (el instanceof Element) { Element elm = (Element) el; if ("t".equals(elm.getName())) { wt = elm; sb.append(elm.getStringValue()); } } } if (wt == null) { wt = r.addElement("t"); wt.addAttribute("xml:space", "preserve"); } if (sb.length() == 0) sb.append(" "); wt.clearContent(); wt.addText(sb.toString()); for (DefaultText text : texts) { r.remove(text); } } Writer fileWriter = new OutputStreamWriter(new FileOutputStream(f), "UTF-8"); XMLWriter xmlWriter = new XMLWriter(fileWriter); xmlWriter.write(document); xmlWriter.close(); }