1 package org.jbpm.jpdl.xml; 2 3 import java.io.*; 4 5 import java.util.HashMap ; 6 7 import junit.framework.*; 8 9 import org.dom4j.*; 10 11 import org.jbpm.graph.def.*; 12 13 public class AbstractXmlTestCase extends TestCase { 14 15 17 static Element toXmlAndParse(ProcessDefinition processDefinition, String xpathExpression) throws Exception { 18 Element element = toXmlAndParse(processDefinition); 19 return (Element) element.selectSingleNode(xpathExpression); 20 } 21 22 static Element toXmlAndParse(ProcessDefinition processDefinition, String xpathExpression, String namespace) throws Exception { 23 Element element = toXmlAndParseWithNamespace(processDefinition); 24 XPath xpath = DocumentHelper.createXPath(xpathExpression); 25 HashMap m = new HashMap (); 26 m.put("", namespace); 27 28 xpath.setNamespaceURIs( m ); 29 30 return (Element) xpath.selectSingleNode( element ); 31 } 32 33 static Element toXmlAndParse(ProcessDefinition processDefinition) throws Exception { 34 StringWriter stringWriter = new StringWriter(); 35 JpdlXmlWriter jpdlWriter = new JpdlXmlWriter(stringWriter); 36 jpdlWriter.write( processDefinition ); 37 String xml = stringWriter.toString(); 38 return DocumentHelper.parseText( xml ).getRootElement(); 39 } 40 41 static Element toXmlAndParseWithNamespace(ProcessDefinition processDefinition) throws Exception { 42 StringWriter stringWriter = new StringWriter(); 43 JpdlXmlWriter jpdlWriter = new JpdlXmlWriter(stringWriter); 44 jpdlWriter.setUseNamespace( true ); 45 jpdlWriter.write( processDefinition ); 46 String xml = stringWriter.toString(); 47 return DocumentHelper.parseText( xml ).getRootElement(); 48 } 49 50 static void printXml(ProcessDefinition processDefinition) { 51 StringWriter stringWriter = new StringWriter(); 52 JpdlXmlWriter jpdlWriter = new JpdlXmlWriter(stringWriter); 53 jpdlWriter.write( processDefinition ); 54 System.out.println( stringWriter.toString() ); 55 } 56 } 57 | Popular Tags |