Author: Grid.Qian
Date: 2008-08-21 04:03:25 -0400 (Thu, 21 Aug 2008)
New Revision: 9844
Added:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/util/
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/util/BPMNToUtil.java
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/util/DomXmlWriter.java
Removed:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/translate/DomXmlWriter.java
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/util/B2JUtil.java
Modified:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/action/B2JAction.java
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/translate/BPMN2JPDL.java
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/translate/GraphicalFileGenerator.java
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/translate/TranslateHelper.java
Log:
improve the codes
Modified:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/action/B2JAction.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/action/B2JAction.java 2008-08-21
07:18:04 UTC (rev 9843)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/action/B2JAction.java 2008-08-21
08:03:25 UTC (rev 9844)
@@ -25,7 +25,7 @@
import org.jboss.tools.b2j.translate.BPMN2JPDL;
import org.jboss.tools.b2j.translate.GraphicalFileGenerator;
import org.jboss.tools.b2j.translate.TranslateHelper;
-import org.jboss.tools.b2j.util.B2JUtil;
+import org.jboss.tools.bpmnto.util.BPMNToUtil;
/**
* @author Grid Qian
@@ -46,7 +46,7 @@
.toOSString();
Document bpmnDocument = null;
try {
- bpmnDocument = B2JUtil.parse(bpmnFileParentPath, bpmnFileName);
+ bpmnDocument = BPMNToUtil.parse(bpmnFileParentPath, bpmnFileName);
} catch (Exception e1) {
System.out.println(B2JMessages.Translate_Error_BpmnFile_CanNotRead
+ e1.getMessage());
@@ -60,7 +60,7 @@
.getBpmnDiagramName(bpmnFileName);
Document bpmnDiagramDocument = null;
try {
- bpmnDiagramDocument = B2JUtil.parse(bpmnFileParentPath,
+ bpmnDiagramDocument = BPMNToUtil.parse(bpmnFileParentPath,
bpmnDiagramFileName);
} catch (Exception e1) {
System.out
Modified:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/translate/BPMN2JPDL.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/translate/BPMN2JPDL.java 2008-08-21
07:18:04 UTC (rev 9843)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/translate/BPMN2JPDL.java 2008-08-21
08:03:25 UTC (rev 9844)
@@ -12,7 +12,6 @@
package org.jboss.tools.b2j.translate;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@@ -21,6 +20,8 @@
import org.dom4j.Document;
import org.dom4j.Element;
import org.jboss.tools.bpmnto.*;
+import org.jboss.tools.bpmnto.translate.BPMNTranslator;
+import org.jboss.tools.bpmnto.util.DomXmlWriter;
import org.jboss.tools.b2j.messages.B2JMessages;
/**
@@ -28,37 +29,12 @@
*
* this is a translator for bpmn ->jpdl
*/
-public class BPMN2JPDL {
+public class BPMN2JPDL extends BPMNTranslator{
- String bpmnFileName;
- String rootLocation;
Document bpmnDocument;
- List<String> poolIDList;
List<Document> processDefs = new LinkedList<Document>();
Map<String, Element> map = new HashMap<String, Element>();
- // the warning messages when translate
- List<String> warnings = new ArrayList<String>();
-
- // the error messages when translate
- List<String> errors = new ArrayList<String>();
-
- public List<String> getErrors() {
- return errors;
- }
-
- public void setErrors(List<String> errors) {
- this.errors = errors;
- }
-
- public List<String> getWarnings() {
- return warnings;
- }
-
- public void setWarnings(List<String> warnings) {
- this.warnings = warnings;
- }
-
public Map<String, Element> getMap() {
return map;
}
@@ -77,9 +53,7 @@
public BPMN2JPDL(String bpmnFileName, String bpmnFilePath,
List<String> poolIDList, Document bpmnDocument) {
- this.bpmnFileName = bpmnFileName;
- this.rootLocation = bpmnFilePath;
- this.poolIDList = poolIDList;
+ super(bpmnFileName, bpmnFilePath, poolIDList);
this.bpmnDocument = bpmnDocument;
}
@@ -88,7 +62,7 @@
* definition
*/
public String[] translateToStrings() {
- this.translateDiagram(this.bpmnDocument);
+ this.translateDiagram();
String[] strForProcessDefs = new String[processDefs.size()];
int i = 0;
for (Document def : processDefs) {
@@ -143,7 +117,7 @@
/*
* Translate a bpmn diagram Domument tree to some jpdl process Dom trees
*/
- public void translateDiagram(Document bpmnDocument) {
+ public void translateDiagram() {
// set the namemap = null
TranslateHelper.setNameMap(new HashMap<String, Integer>());
Deleted:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/translate/DomXmlWriter.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/translate/DomXmlWriter.java 2008-08-21
07:18:04 UTC (rev 9843)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/translate/DomXmlWriter.java 2008-08-21
08:03:25 UTC (rev 9844)
@@ -1,115 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-
-package org.jboss.tools.b2j.translate;
-
-import java.io.*;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.dom4j.*;
-import org.dom4j.io.*;
-
-/**
- * @author Grid Qian
- *
- * this is for generating dom element or attribute
- */
-public class DomXmlWriter {
-
- /*
- * map a dom document to a string
- */
- public static String toString(Document document) throws IOException {
- OutputFormat outputFormat = new OutputFormat(" ", true);
- Writer writer = new StringWriter();
- XMLWriter xmlWriter = new XMLWriter(writer, outputFormat);
- xmlWriter.write(document);
- xmlWriter.flush();
- writer.flush();
- return writer.toString();
- }
-
- /*
- * create a dom tree
- */
- public static Document createDomTree(boolean useNamespace, String url,
- String rootElementName) {
- Document document = DocumentHelper.createDocument();
- Element root = null;
-
- if (useNamespace) {
- Namespace jbpmNamespace = new Namespace(null, url);
- root = document.addElement(rootElementName, jbpmNamespace.getURI());
- } else {
- root = document.addElement(rootElementName);
- }
- root.addText(System.getProperty("line.separator"));
-
- return document;
- }
-
- /*
- * add a new element to a dom element
- */
- public static Element addElement(Element element, String elementName) {
- Element newElement = element.addElement(elementName);
- return newElement;
- }
-
- /*
- * add a new element to the location of a dom element
- */
- @SuppressWarnings("unchecked")
- public static Element addElement(Element element, String elementName,
- int location) {
- Element newElement = null;
- if (element.elements(elementName) != null
- && element.elements(elementName).size() > location
- && location >= 0) {
- newElement = DocumentHelper.createElement(elementName);
- element.elements(elementName).add(location, newElement);
- }
- return newElement;
- }
-
- /*
- * add a attribute to a dom element
- */
- public static void addAttribute(Element e, String attributeName,
- String value) {
- if (value != null) {
- e.addAttribute(attributeName, value);
- }
- }
-
- /*
- * get a named element from a element (any depth)
- */
- public static List<Element> getElementsByName(Element element, String name) {
- List<Element> list = new LinkedList<Element>();
- for (Object ele : element.elements()) {
- if (name.equals(((Element) ele).getName())) {
- list.add((Element) ele);
- }
- list.addAll(getElementsByName((Element) ele, name));
- }
- return list;
- }
-
- /*
- * set a element attribute using a same name attribute of other element
- */
- public static void mapAttribute(Element ele, String attrName, Element sourceEle){
- DomXmlWriter.addAttribute(ele, attrName,sourceEle.attributeValue(attrName));
- }
-
-}
Modified:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/translate/GraphicalFileGenerator.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/translate/GraphicalFileGenerator.java 2008-08-21
07:18:04 UTC (rev 9843)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/translate/GraphicalFileGenerator.java 2008-08-21
08:03:25 UTC (rev 9844)
@@ -12,7 +12,6 @@
package org.jboss.tools.b2j.translate;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@@ -21,6 +20,8 @@
import org.dom4j.Document;
import org.dom4j.Element;
import org.jboss.tools.bpmnto.BpmnToPlugin;
+import org.jboss.tools.bpmnto.translate.BPMNTranslator;
+import org.jboss.tools.bpmnto.util.DomXmlWriter;
import org.jboss.tools.b2j.messages.B2JMessages;
/**
@@ -28,40 +29,17 @@
*
* this is a translator for bpmn_diagram to gpd of jpdl
*/
-public class GraphicalFileGenerator {
-
- String rootLocation;
- String bpmnFileName;
+public class GraphicalFileGenerator extends BPMNTranslator{
+
Document document;
// gpd.xml documents list
List<Document> gpdDefs = new LinkedList<Document>();
+
// the pool of gpd.xml name
List<String> gpdPoolNames = new LinkedList<String>();
Map<String, Element> map = new HashMap<String, Element>();
- // the warning messages when translate
- List<String> warnings = new ArrayList<String>();
-
- // the error messages when translate
- List<String> errors = new ArrayList<String>();
-
- public List<String> getErrors() {
- return errors;
- }
-
- public void setErrors(List<String> errors) {
- this.errors = errors;
- }
-
- public List<String> getWarnings() {
- return warnings;
- }
-
- public void setWarnings(List<String> warnings) {
- this.warnings = warnings;
- }
-
public GraphicalFileGenerator(Document bpmnDiagramDocument,
Map<String, Element> map, String rootLocation, String bpmnFileName) {
this.rootLocation = rootLocation;
@@ -74,7 +52,7 @@
* translate a bpmn_diagram document to a gpd document string
*/
public String[] translateToStrings() {
- this.translateDiagram(this.document);
+ this.translateDiagram();
String[] strForProcessDefs = new String[gpdDefs.size()];
int i = 0;
for (Document def : gpdDefs) {
@@ -128,8 +106,8 @@
/*
* translate the graphical bpmn_diagram document
*/
- private void translateDiagram(Document diagramDocument) {
- Element rootElement = diagramDocument.getRootElement();
+ public void translateDiagram() {
+ Element rootElement = document.getRootElement();
List<Element> eleList = DomXmlWriter.getElementsByName(rootElement,
B2JMessages.Gpd_Element_Name);
Modified:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/translate/TranslateHelper.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/translate/TranslateHelper.java 2008-08-21
07:18:04 UTC (rev 9843)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/translate/TranslateHelper.java 2008-08-21
08:03:25 UTC (rev 9844)
@@ -20,7 +20,8 @@
import org.dom4j.Document;
import org.dom4j.Element;
import org.jboss.tools.b2j.messages.B2JMessages;
-import org.jboss.tools.b2j.util.B2JUtil;
+import org.jboss.tools.bpmnto.util.BPMNToUtil;
+import org.jboss.tools.bpmnto.util.DomXmlWriter;
/**
* @author Grid Qian
@@ -59,18 +60,18 @@
public static File[] createFiles(String parentFolder, String bpmnFileName,
String[] strsForGenerate, String[] fileFolders, String fileName)
throws IOException {
- File jpdlFolder = B2JUtil.createFile(parentFolder,
+ File jpdlFolder = BPMNToUtil.createFile(parentFolder,
B2JMessages.Jpdl_Suffix, null);
- File diagramFolder = B2JUtil.createFile(jpdlFolder.getAbsolutePath(),
+ File diagramFolder = BPMNToUtil.createFile(jpdlFolder.getAbsolutePath(),
bpmnFileName, null);
File[] files = new File[strsForGenerate.length];
File processFolder = null;
int i = 0;
for (String str : strsForGenerate) {
- processFolder = B2JUtil.createFile(diagramFolder.getAbsolutePath(),
+ processFolder = BPMNToUtil.createFile(diagramFolder.getAbsolutePath(),
fileFolders[i], null);
- files[i] = B2JUtil.createFile(processFolder.getAbsolutePath(),
+ files[i] = BPMNToUtil.createFile(processFolder.getAbsolutePath(),
fileName, str);
i++;
}
Deleted: workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/util/B2JUtil.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/util/B2JUtil.java 2008-08-21
07:18:04 UTC (rev 9843)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/util/B2JUtil.java 2008-08-21
08:03:25 UTC (rev 9844)
@@ -1,130 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-
-package org.jboss.tools.b2j.util;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintWriter;
-
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import org.dom4j.Document;
-import org.dom4j.io.SAXReader;
-import org.xml.sax.InputSource;
-import org.xml.sax.XMLReader;
-
-/**
- * @author Grid Qian
- *
- * this a util class
- */
-public class B2JUtil {
-
- /*
- * create a file
- */
- public static File createFile(String parentFolder, String fileName,
- String inputStr) throws IOException {
- File child = new File(parentFolder, fileName);
- if (inputStr == null) {
- if (!child.exists()) {
- child.mkdir();
- }
- } else {
- if (!child.exists()) {
- child.createNewFile();
- }
- FileWriter childWriter = new FileWriter(child);
- PrintWriter printFile = new PrintWriter(childWriter);
- printFile.println(inputStr);
- printFile.close();
- childWriter.close();
-
- }
- return child;
- }
-
- /*
- * get a sax input source
- */
- public static InputSource getInputSource(String parentFolder,
- String fileName) throws FileNotFoundException {
- return new InputSource(B2JUtil.getInputStream(parentFolder, fileName));
-
- }
-
- /*
- * get a input stream
- */
- public static InputStream getInputStream(String parentFolder,
- String fileName) throws FileNotFoundException {
- File file = new File(parentFolder, fileName);
- InputStream input = new FileInputStream(file);
- return input;
-
- }
-
- /*
- * parse a file to a dom document
- */
- public static Document parse(String parentFolder, String fileName)
- throws Exception {
- Document document = null;
- SAXReader saxReader = createSaxReader();
- document = saxReader.read(B2JUtil
- .getInputSource(parentFolder, fileName));
- return document;
- }
-
- /*
- * create a sax reader
- */
- public static SAXReader createSaxReader() throws Exception {
- XMLReader xmlReader = createXmlReader();
- SAXReader saxReader = new SAXReader(xmlReader);
- return saxReader;
- }
-
- /*
- * create a sax xml reader
- */
- public static XMLReader createXmlReader() throws Exception {
-
- SAXParser saxParser = createSaxParserFactory().newSAXParser();
- XMLReader xmlReader = saxParser.getXMLReader();
-
- saxParser.setProperty(
- "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
- "http://www.w3.org/2001/XMLSchema");
-
- xmlReader.setFeature(
- "http://apache.org/xml/features/validation/dynamic", true);
-
- return xmlReader;
- }
-
- /*
- * create a sax parser factory
- */
- private static SAXParserFactory createSaxParserFactory() {
- SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
- saxParserFactory.setValidating(true);
- saxParserFactory.setNamespaceAware(true);
- return saxParserFactory;
- }
-
-}
Added:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/util/BPMNToUtil.java
===================================================================
--- workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/util/BPMNToUtil.java
(rev 0)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/util/BPMNToUtil.java 2008-08-21
08:03:25 UTC (rev 9844)
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.bpmnto.util;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.dom4j.Document;
+import org.dom4j.io.SAXReader;
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLReader;
+
+/**
+ * @author Grid Qian
+ *
+ * this a util class
+ */
+public class BPMNToUtil {
+
+ /*
+ * create a file
+ */
+ public static File createFile(String parentFolder, String fileName,
+ String inputStr) throws IOException {
+ File child = new File(parentFolder, fileName);
+ if (inputStr == null) {
+ if (!child.exists()) {
+ child.mkdir();
+ }
+ } else {
+ if (!child.exists()) {
+ child.createNewFile();
+ }
+ FileWriter childWriter = new FileWriter(child);
+ PrintWriter printFile = new PrintWriter(childWriter);
+ printFile.println(inputStr);
+ printFile.close();
+ childWriter.close();
+
+ }
+ return child;
+ }
+
+ /*
+ * get a sax input source
+ */
+ public static InputSource getInputSource(String parentFolder,
+ String fileName) throws FileNotFoundException {
+ return new InputSource(BPMNToUtil.getInputStream(parentFolder, fileName));
+
+ }
+
+ /*
+ * get a input stream
+ */
+ public static InputStream getInputStream(String parentFolder,
+ String fileName) throws FileNotFoundException {
+ File file = new File(parentFolder, fileName);
+ InputStream input = new FileInputStream(file);
+ return input;
+
+ }
+
+ /*
+ * parse a file to a dom document
+ */
+ public static Document parse(String parentFolder, String fileName)
+ throws Exception {
+ Document document = null;
+ SAXReader saxReader = createSaxReader();
+ document = saxReader.read(BPMNToUtil
+ .getInputSource(parentFolder, fileName));
+ return document;
+ }
+
+ /*
+ * create a sax reader
+ */
+ public static SAXReader createSaxReader() throws Exception {
+ XMLReader xmlReader = createXmlReader();
+ SAXReader saxReader = new SAXReader(xmlReader);
+ return saxReader;
+ }
+
+ /*
+ * create a sax xml reader
+ */
+ public static XMLReader createXmlReader() throws Exception {
+
+ SAXParser saxParser = createSaxParserFactory().newSAXParser();
+ XMLReader xmlReader = saxParser.getXMLReader();
+
+ saxParser.setProperty(
+ "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
+ "http://www.w3.org/2001/XMLSchema");
+
+ xmlReader.setFeature(
+ "http://apache.org/xml/features/validation/dynamic", true);
+
+ return xmlReader;
+ }
+
+ /*
+ * create a sax parser factory
+ */
+ private static SAXParserFactory createSaxParserFactory() {
+ SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
+ saxParserFactory.setValidating(true);
+ saxParserFactory.setNamespaceAware(true);
+ return saxParserFactory;
+ }
+
+}
Copied:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/util/DomXmlWriter.java
(from rev 9840,
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/translate/DomXmlWriter.java)
===================================================================
---
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/util/DomXmlWriter.java
(rev 0)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/util/DomXmlWriter.java 2008-08-21
08:03:25 UTC (rev 9844)
@@ -0,0 +1,115 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.bpmnto.util;
+
+import java.io.*;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.dom4j.*;
+import org.dom4j.io.*;
+
+/**
+ * @author Grid Qian
+ *
+ * this is for generating dom element or attribute
+ */
+public class DomXmlWriter {
+
+ /*
+ * map a dom document to a string
+ */
+ public static String toString(Document document) throws IOException {
+ OutputFormat outputFormat = new OutputFormat(" ", true);
+ Writer writer = new StringWriter();
+ XMLWriter xmlWriter = new XMLWriter(writer, outputFormat);
+ xmlWriter.write(document);
+ xmlWriter.flush();
+ writer.flush();
+ return writer.toString();
+ }
+
+ /*
+ * create a dom tree
+ */
+ public static Document createDomTree(boolean useNamespace, String url,
+ String rootElementName) {
+ Document document = DocumentHelper.createDocument();
+ Element root = null;
+
+ if (useNamespace) {
+ Namespace jbpmNamespace = new Namespace(null, url);
+ root = document.addElement(rootElementName, jbpmNamespace.getURI());
+ } else {
+ root = document.addElement(rootElementName);
+ }
+ root.addText(System.getProperty("line.separator"));
+
+ return document;
+ }
+
+ /*
+ * add a new element to a dom element
+ */
+ public static Element addElement(Element element, String elementName) {
+ Element newElement = element.addElement(elementName);
+ return newElement;
+ }
+
+ /*
+ * add a new element to the location of a dom element
+ */
+ @SuppressWarnings("unchecked")
+ public static Element addElement(Element element, String elementName,
+ int location) {
+ Element newElement = null;
+ if (element.elements(elementName) != null
+ && element.elements(elementName).size() > location
+ && location >= 0) {
+ newElement = DocumentHelper.createElement(elementName);
+ element.elements(elementName).add(location, newElement);
+ }
+ return newElement;
+ }
+
+ /*
+ * add a attribute to a dom element
+ */
+ public static void addAttribute(Element e, String attributeName,
+ String value) {
+ if (value != null) {
+ e.addAttribute(attributeName, value);
+ }
+ }
+
+ /*
+ * get a named element from a element (any depth)
+ */
+ public static List<Element> getElementsByName(Element element, String name) {
+ List<Element> list = new LinkedList<Element>();
+ for (Object ele : element.elements()) {
+ if (name.equals(((Element) ele).getName())) {
+ list.add((Element) ele);
+ }
+ list.addAll(getElementsByName((Element) ele, name));
+ }
+ return list;
+ }
+
+ /*
+ * set a element attribute using a same name attribute of other element
+ */
+ public static void mapAttribute(Element ele, String attrName, Element sourceEle){
+ DomXmlWriter.addAttribute(ele, attrName,sourceEle.attributeValue(attrName));
+ }
+
+}