KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > xpdl > XMLUtil


1 package org.enhydra.shark.xpdl;
2
3 import java.io.ByteArrayInputStream JavaDoc;
4 import java.io.ByteArrayOutputStream JavaDoc;
5 import java.io.File JavaDoc;
6 import java.io.FileInputStream JavaDoc;
7 import java.io.FileOutputStream JavaDoc;
8 import java.io.ObjectInputStream JavaDoc;
9 import java.io.ObjectOutputStream JavaDoc;
10 import java.io.OutputStream JavaDoc;
11 import java.io.StringReader JavaDoc;
12 import java.net.URL JavaDoc;
13 import java.util.ArrayList JavaDoc;
14 import java.util.Calendar JavaDoc;
15 import java.util.Collection JavaDoc;
16 import java.util.GregorianCalendar JavaDoc;
17 import java.util.HashMap JavaDoc;
18 import java.util.HashSet JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.Map JavaDoc;
22 import java.util.MissingResourceException JavaDoc;
23 import java.util.Properties JavaDoc;
24 import java.util.ResourceBundle JavaDoc;
25 import java.util.Set JavaDoc;
26
27 import javax.xml.parsers.DocumentBuilder JavaDoc;
28 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
29 import javax.xml.transform.Transformer JavaDoc;
30 import javax.xml.transform.TransformerFactory JavaDoc;
31 import javax.xml.transform.dom.DOMSource JavaDoc;
32 import javax.xml.transform.stream.StreamResult JavaDoc;
33
34 import org.apache.xerces.util.XMLChar;
35 import org.enhydra.shark.xpdl.elements.Activities;
36 import org.enhydra.shark.xpdl.elements.Activity;
37 import org.enhydra.shark.xpdl.elements.ActivitySet;
38 import org.enhydra.shark.xpdl.elements.ActivitySets;
39 import org.enhydra.shark.xpdl.elements.ActualParameter;
40 import org.enhydra.shark.xpdl.elements.ActualParameters;
41 import org.enhydra.shark.xpdl.elements.BasicType;
42 import org.enhydra.shark.xpdl.elements.BlockActivity;
43 import org.enhydra.shark.xpdl.elements.Condition;
44 import org.enhydra.shark.xpdl.elements.DataType;
45 import org.enhydra.shark.xpdl.elements.DataTypes;
46 import org.enhydra.shark.xpdl.elements.Deadlines;
47 import org.enhydra.shark.xpdl.elements.DeclaredType;
48 import org.enhydra.shark.xpdl.elements.EnumerationType;
49 import org.enhydra.shark.xpdl.elements.EnumerationValue;
50 import org.enhydra.shark.xpdl.elements.ExtendedAttribute;
51 import org.enhydra.shark.xpdl.elements.ExtendedAttributes;
52 import org.enhydra.shark.xpdl.elements.FinishMode;
53 import org.enhydra.shark.xpdl.elements.FormalParameter;
54 import org.enhydra.shark.xpdl.elements.FormalParameters;
55 import org.enhydra.shark.xpdl.elements.Join;
56 import org.enhydra.shark.xpdl.elements.Manual;
57 import org.enhydra.shark.xpdl.elements.Namespace;
58 import org.enhydra.shark.xpdl.elements.Namespaces;
59 import org.enhydra.shark.xpdl.elements.Package;
60 import org.enhydra.shark.xpdl.elements.RedefinableHeader;
61 import org.enhydra.shark.xpdl.elements.Responsible;
62 import org.enhydra.shark.xpdl.elements.Responsibles;
63 import org.enhydra.shark.xpdl.elements.SchemaType;
64 import org.enhydra.shark.xpdl.elements.Split;
65 import org.enhydra.shark.xpdl.elements.StartMode;
66 import org.enhydra.shark.xpdl.elements.SubFlow;
67 import org.enhydra.shark.xpdl.elements.Tools;
68 import org.enhydra.shark.xpdl.elements.Transition;
69 import org.enhydra.shark.xpdl.elements.TransitionRef;
70 import org.enhydra.shark.xpdl.elements.TransitionRefs;
71 import org.enhydra.shark.xpdl.elements.TransitionRestriction;
72 import org.enhydra.shark.xpdl.elements.TransitionRestrictions;
73 import org.enhydra.shark.xpdl.elements.Transitions;
74 import org.enhydra.shark.xpdl.elements.WorkflowProcess;
75 import org.w3c.dom.Attr JavaDoc;
76 import org.w3c.dom.Document JavaDoc;
77 import org.w3c.dom.Element JavaDoc;
78 import org.w3c.dom.NamedNodeMap JavaDoc;
79 import org.w3c.dom.Node JavaDoc;
80 import org.w3c.dom.NodeList JavaDoc;
81 import org.xml.sax.InputSource JavaDoc;
82
83 /**
84  * Class with utilities to read/write XPDLs from/to XML.
85  *
86  * @author Sasa Bojanic
87  */

88 public class XMLUtil {
89
90    public final static String JavaDoc XMLNS = "http://www.wfmc.org/2002/XPDL1.0";
91    public final static String JavaDoc XMLNS_XPDL = "http://www.wfmc.org/2002/XPDL1.0";
92    public final static String JavaDoc XMLNS_XSI = "http://www.w3.org/2001/XMLSchema-instance";
93    public final static String JavaDoc XSI_SCHEMA_LOCATION = "http://www.wfmc.org/2002/XPDL1.0 http://wfmc.org/standards/docs/TC-1025_schema_10_xpdl.xsd";
94
95    private static ResourceBundle JavaDoc defaultResources;
96    private static ResourceBundle JavaDoc choosenResources;
97    private static Properties JavaDoc properties;
98
99    public static void setDefaultResources (ResourceBundle JavaDoc defaultR) {
100       defaultResources=defaultR;
101    }
102
103    public static void setChoosenResources (ResourceBundle JavaDoc choosenR) {
104       choosenResources=choosenR;
105    }
106
107    public static void setProperties (Properties JavaDoc props) {
108       properties=props;
109    }
110
111    /**
112     * Gets a resource string from the resource bundle.<p> Resource bundle
113     * represents the <i>property file</i>. For example, if property file
114     * contains something like this:<BR><CENTER>menubar=file edit help</CENTER>
115     * method call getLanguageDependentString("menubar") will give the string
116     * <i>file edit help</i> as a result. <BR> This method reads information
117     * from property file. If can't find desired resource, returns <b>null</b>.
118     * @param nm name of the resource to fetch.
119     * @return String value of named resource.
120     */

121    public static String JavaDoc getLanguageDependentString(String JavaDoc nm) {
122       String JavaDoc str;
123       try {
124          str=choosenResources.getString(nm);
125       } catch (MissingResourceException JavaDoc mre) {
126          try {
127             str=defaultResources.getString(nm);
128          } catch (MissingResourceException JavaDoc mre1) {
129             str = null;
130          } catch (NullPointerException JavaDoc npe) {
131             str=null;
132          }
133       } catch (NullPointerException JavaDoc npe) {
134          /*ResourceBundle orig=ResourceBundle.
135           getBundle("org.enhydra.shark.xpdl.resources.SharkXPDL",new Locale(""));*/

136          ResourceBundle JavaDoc orig=ResourceBundle.
137             getBundle("org.enhydra.shark.xpdl.resources.SharkXPDL");
138          try {
139             str=orig.getString(nm);
140          } catch (Exception JavaDoc ex) {
141             str=null;
142          }
143       }
144       return str;
145    }
146
147    /**
148     * Gets the url from a resource string.
149     * @param key the string key to the url in the properties.
150     * @return the resource location.
151     * @see java.lang.Class#getResource
152     */

153    public static URL JavaDoc getResource(String JavaDoc key) {
154       try {
155          String JavaDoc name=properties.getProperty(key);
156          if (name != null) {
157             URL JavaDoc url = XMLUtil.class.getClassLoader().getResource(name);
158             return url;
159          }
160       } catch (Exception JavaDoc ex) {}
161       return null;
162    }
163
164    /**
165     * Determines the number of string toFind within string toSearch.
166     */

167    public static int howManyStringsWithinString (String JavaDoc toSearch,String JavaDoc toFind) {
168       try {
169          int startAt=0;
170          int howMany=0;
171
172          int fnd;
173          while ((fnd=toSearch.indexOf(toFind,startAt))!=-1) {
174             howMany++;
175             startAt=(fnd+toFind.length());
176          }
177          return howMany;
178       } catch (Exception JavaDoc ex) {
179          return -1;
180       }
181    }
182
183    public static String JavaDoc getCanonicalPath (String JavaDoc relpath,String JavaDoc basedir,boolean canBeDirectory) {
184       File JavaDoc f=new File JavaDoc(relpath);
185       if (!f.isAbsolute()) {
186          f=f.getAbsoluteFile();
187          if (!f.exists()) {
188             f=new File JavaDoc(XMLUtil.createPath(basedir,relpath));
189          }
190       }
191       if (!f.exists() || (f.isDirectory() && !canBeDirectory)) {
192          System.err.println("The file "+f.getAbsolutePath()+" does not exist");
193          return null;
194       } else {
195          return getCanonicalPath(f);
196       }
197    }
198
199    public static String JavaDoc getCanonicalPath (String JavaDoc path, boolean canBeDirectory) {
200       File JavaDoc f=new File JavaDoc(path);
201       if (!f.isAbsolute()) {
202          f=new File JavaDoc(System.getProperty("user.dir")+File.separator+path);
203       }
204       if (!f.exists() || (f.isDirectory() && !canBeDirectory)) {
205          System.err.println("The file "+f.getAbsolutePath()+" does not exist");
206          return null;
207       } else {
208          return getCanonicalPath(f);
209       }
210    }
211
212    private static String JavaDoc getCanonicalPath (File JavaDoc f) {
213       try {
214          return f.getCanonicalPath();
215       } catch (Exception JavaDoc ex) {
216          return f.getAbsolutePath();
217       }
218    }
219
220    private static boolean logging=false;
221
222    public static void fromXML (Element JavaDoc node,Package JavaDoc pkg) {
223 // long t1,t2;
224
// t1=System.currentTimeMillis();
225
NamedNodeMap JavaDoc attribs=node.getAttributes();
226       Namespaces nss=pkg.getNamespaces();
227       for (int i=0; i<attribs.getLength(); i++) {
228          Node JavaDoc n=attribs.item(i);
229          String JavaDoc nn=n.getNodeName();
230          if (nn.startsWith("xmlns:") && !nn.equals("xmlns:xsi")) {
231             Namespace ns=(Namespace)nss.generateNewElement();
232             ns.setName(nn.substring(6,nn.length()));
233             fromXML(n,(XMLAttribute)ns.get("location"));
234             nss.add(ns);
235          }
236       }
237       fromXML(node,(XMLComplexElement)pkg);
238 // t2=System.currentTimeMillis();
239
// System.out.println("MFXML="+(t2-t1));
240
}
241
242    public static void fromXML (Node JavaDoc node,XMLCollection cel) {
243       if ( node == null || !node.hasChildNodes()) return;
244       String JavaDoc nameSpacePrefix=getNameSpacePrefix(node);
245
246       XMLElement newOne=cel.generateNewElement();
247       String JavaDoc elName=newOne.toName();
248
249       NodeList JavaDoc children = node.getChildNodes();
250       int lng=children.getLength();
251 if (logging) System.out.println("FROMXML for "+cel.toName()+", c="+cel.getClass().getName());
252       for (int i = 0; i<lng; i++) {
253          Node JavaDoc child=children.item(i);
254          if (child.getNodeName().equals(nameSpacePrefix+elName)) {
255             //System.out.println("I="+i);
256
newOne = cel.generateNewElement();
257             //System.out.println("Now the collection element of collection "+node.getNodeName()+" will be processed");
258
if (newOne instanceof XMLComplexElement) {
259                fromXML(children.item(i),(XMLComplexElement)newOne);
260             } else {
261                fromXML(children.item(i),(XMLSimpleElement)newOne);
262             }
263             cel.add(newOne);
264          } else {
265             //System.err.println("Something's wrong with collection "+elName+" parsing - c="+cel.getClass().getName()+" !");
266
}
267       }
268       //System.out.println("The length of collection "+name+" after importing is"+size());
269
}
270
271    public static void fromXML (Node JavaDoc node,XMLComplexElement cel) {
272       if ( node == null || (!node.hasChildNodes() && !node.hasAttributes())) return;
273
274       String JavaDoc nameSpacePrefix=node.getPrefix();
275       if (nameSpacePrefix!=null) {
276          nameSpacePrefix+=":";
277       } else {
278          nameSpacePrefix="";
279       }
280 if (logging) System.out.println("FROMXML for "+cel.toName()+", c="+cel.getClass().getName());
281
282       if ( node.hasAttributes() ) {
283          NamedNodeMap JavaDoc attribs = node.getAttributes();
284          for ( int i = 0; i < attribs.getLength(); ++i ) {
285             Node JavaDoc attrib = ( Node JavaDoc ) attribs.item( i );
286             try {
287 //System.out.println("Getting attrib "+attrib.getNodeName());
288
fromXML(attrib,(XMLAttribute)cel.get( attrib.getNodeName() ));
289             } catch ( NullPointerException JavaDoc npe ) {
290                /*System.err.println("Processing attributes for "+ cel.toName()
291                                +" element having problems with "
292                                + attrib.getNodeName()+" attribute\n"
293                                + attrib.getNodeValue().trim());*/

294             }
295          }
296       }
297       // getting elements
298
if (node.hasChildNodes()) {
299          // Specific code for handling Condition element - we don't support Xpression element
300
if (cel instanceof Condition) {
301             String JavaDoc newVal=node.getChildNodes().item(0).getNodeValue();
302             if (newVal!=null) {
303                cel.setValue(newVal);
304             }
305          }
306          // Specific code for handling SchemaType element
307
if (cel instanceof SchemaType) {
308             NodeList JavaDoc nl=node.getChildNodes();
309             for (int j=0; j<nl.getLength(); j++) {
310                Node JavaDoc sn=nl.item(j);
311                if (sn instanceof Element JavaDoc) {
312                   cel.setValue(XMLUtil.getContent(sn,true));
313                   break;
314                }
315             }
316          }
317          // Specific code for handling ExtendedAttribute element
318
if (cel instanceof ExtendedAttribute) {
319             cel.setValue(XMLUtil.getChildNodesContent(node));
320          }
321          Iterator JavaDoc it=cel.getXMLElements().iterator();
322          while (it.hasNext()) {
323             XMLElement el=(XMLElement)it.next();
324             String JavaDoc elName=el.toName();
325             if (el instanceof XMLComplexElement) {
326                Node JavaDoc child = getChildByName(node,nameSpacePrefix+elName);
327                fromXML(child, (XMLComplexElement)el);
328             // Specific case if element is Deadlines
329
} else if (el instanceof Deadlines) {
330                fromXML(node, (XMLCollection)el);
331             } else if (el instanceof XMLCollection) {
332                Node JavaDoc child = getChildByName(node,nameSpacePrefix+elName);
333                fromXML(child, (XMLCollection)el);
334             } else if (el instanceof XMLComplexChoice) {
335                fromXML(node, (XMLComplexChoice)el);
336             } else if (el instanceof XMLSimpleElement) {
337                Node JavaDoc child = getChildByName(node,nameSpacePrefix+elName);
338                fromXML(child,(XMLSimpleElement)el);
339             }
340          }
341       }
342    }
343
344    public static void fromXML (Node JavaDoc node,XMLComplexChoice el) {
345       String JavaDoc nameSpacePrefix=getNameSpacePrefix(node);
346       List JavaDoc ch=el.getChoices();
347 if (logging) System.out.println("FROMXML for "+el.toName()+", c="+el.getClass().getName());
348       for (int i=0; i<ch.size(); i++) {
349          XMLElement chc=(XMLElement)ch.get(i);
350          String JavaDoc chname=chc.toName();
351          // Specific code for handling Tools
352
if (chname.equals("Tools")) {
353             chname="Tool";
354          }
355          Node JavaDoc child = getChildByName(node,nameSpacePrefix+chname);
356          if (child!=null) {
357             if (chc instanceof XMLComplexElement) {
358                fromXML(child,(XMLComplexElement)chc);
359             } else { // it is XMLCollection
360
// Specific code for handling Tools
361
if (chc instanceof Tools) {
362                   fromXML(node, (XMLCollection)chc);
363                } else {
364                   fromXML(child, (XMLCollection)chc);
365                }
366             }
367             el.setChoosen(chc);
368             break;
369          }
370       }
371    }
372
373    public static void fromXML (Node JavaDoc node,XMLSimpleElement el) {
374       fromXMLBasic(node, el);
375    }
376
377    public static void fromXML (Node JavaDoc node,XMLAttribute el) {
378       fromXMLBasic(node,el);
379    }
380
381    public static void fromXMLBasic (Node JavaDoc node,XMLElement el) {
382       if (node!=null) {
383 if (logging) System.out.println("FROMXML for "+el.toName()+", c="+el.getClass().getName());
384          String JavaDoc newVal;
385          if (node.hasChildNodes()) {
386             newVal=node.getChildNodes().item(0).getNodeValue();
387 if (logging) System.out.println("11111");
388             // should never happen
389
} else {
390 if (logging) System.out.println("22222");
391             newVal=node.getNodeValue();
392          }
393 if (logging) System.out.println("NV="+newVal);
394
395          if (newVal!=null) {
396             el.setValue(newVal);
397          }
398       }
399    }
400
401
402    public static void toXML (Document JavaDoc parent,Package JavaDoc pkg) {
403       Node JavaDoc node = ((Document JavaDoc) parent).createElement(pkg.toName());
404       ((Element JavaDoc) node).setAttribute("xmlns", XMLNS);
405       //((Element) node).setAttribute("xmlns:xpdl", XMLNS_XPDL);
406
// save additional namespaces
407
Iterator JavaDoc itNs=pkg.getNamespaces().toElements().iterator();
408       while (itNs.hasNext()) {
409          Namespace ns=(Namespace)itNs.next();
410          ((Element JavaDoc) node).setAttribute("xmlns:"+ns.getName(),
411                                        ns.getLocation());
412       }
413       ((Element JavaDoc) node).setAttribute("xmlns:xsi", XMLNS_XSI);
414       ((Element JavaDoc) node).setAttribute("xsi:schemaLocation", XSI_SCHEMA_LOCATION);
415
416       toXML(node,(XMLComplexElement)pkg);
417       parent.appendChild( node );
418    }
419
420    public static void toXML (Node JavaDoc parent,XMLCollection cel) {
421       if (!cel.isEmpty() || cel.isRequired()) {
422          if (parent!=null) {
423             String JavaDoc elName=cel.toName();
424             Node JavaDoc node = parent;
425             // Specific code for handling Deadlines and Tools
426
if (!(elName.equals("Deadlines") || elName.equals("Tools"))) {
427                node=(parent.getOwnerDocument()).createElement(elName);
428             }
429             for (Iterator JavaDoc it = cel.toElements().iterator(); it.hasNext();) {
430                XMLElement el=(XMLElement)it.next();
431                if (el instanceof XMLSimpleElement) {
432                   toXML(node,(XMLSimpleElement)el);
433                } else {
434                   toXML(node,(XMLComplexElement)el);
435                }
436             }
437             // If Deadlines or Tools are handled, node==parent
438
if (node!=parent) {
439                parent.appendChild(node);
440             }
441          }
442       }
443    }
444
445    public static void toXML (Node JavaDoc parent,XMLComplexElement cel) {
446       if ( cel.isEmpty() && !cel.isRequired() )
447          return;
448       if ( parent != null ) {
449 if (logging) System.out.println("TOXML for "+cel.toName()+", c="+cel.getClass().getName());
450          Node JavaDoc node=parent;
451          // Specific code for handling Package
452
if (!(cel instanceof Package JavaDoc)) {
453             node = ( parent.getOwnerDocument() ).createElement( cel.toName() );
454          }
455          if (cel.toValue()!=null && cel.toValue().length()>0) {
456             // Specific code for handling Condition
457
if (cel instanceof Condition) {
458                if (!cel.toValue().equals("")) {
459                   Node JavaDoc textNode=node.getOwnerDocument().createTextNode(cel.toValue());
460                   node.appendChild(textNode);
461                }
462             }
463             // Specific code for handling SchemaType
464
if (cel instanceof SchemaType) {
465                Node JavaDoc schema=XMLUtil.parseSchemaNode(cel.toValue(), false);
466                if (schema!=null) {
467                   node.appendChild(node.getOwnerDocument().importNode(schema,true));
468                }
469             }
470             // Specific code for handling ExtendedAttribute
471
if (cel instanceof ExtendedAttribute) {
472                try {
473                   Node JavaDoc n=XMLUtil.parseExtendedAttributeContent(cel.toValue());
474                   NodeList JavaDoc nl=n.getChildNodes();
475                   for (int i=0; i<nl.getLength(); i++) {
476                      node.appendChild(parent.getOwnerDocument().importNode(nl.item(i),true));
477                   }
478                } catch (Exception JavaDoc ex) {}
479             }
480          }
481          for ( Iterator JavaDoc it = cel.toElements().iterator(); it.hasNext(); ) {
482             XMLElement el = ( XMLElement ) it.next();
483             if (el instanceof XMLComplexElement) {
484                toXML(node, (XMLComplexElement)el);
485             } else if (el instanceof XMLCollection) {
486                toXML(node, (XMLCollection)el);
487             } else if (el instanceof XMLComplexChoice) {
488                toXML(node, (XMLComplexChoice)el);
489             } else if (el instanceof XMLSimpleElement) {
490                toXML(node,(XMLSimpleElement)el);
491             } else { // it's XMLAttribute
492
toXML(node,(XMLAttribute)el);
493             }
494          }
495          // If Package is handled, parent==node
496
if (node!=parent) {
497             parent.appendChild( node );
498          }
499       }
500    }
501
502    public static void toXML (Node JavaDoc parent,XMLComplexChoice el) {
503       XMLElement choosen=el.getChoosen();
504       if (choosen!=null) {
505          if (choosen instanceof XMLComplexElement) {
506             toXML(parent,(XMLComplexElement)choosen);
507          } else {
508             toXML(parent,(XMLCollection)choosen);
509          }
510       }
511    }
512
513    public static void toXML (Node JavaDoc parent,XMLSimpleElement el) {
514       if (!el.isEmpty() || el.isRequired()) {
515          if (parent!=null) {
516             Node JavaDoc node = (parent.getOwnerDocument()).createElement(el.toName());
517             node.appendChild(parent.getOwnerDocument().createTextNode(el.toValue().trim()));
518             parent.appendChild(node);
519          }
520       }
521    }
522
523    public static void toXML (Node JavaDoc parent,XMLAttribute el) {
524       if (!el.isEmpty() || el.isRequired()) {
525          if (parent!=null) {
526             Attr JavaDoc node = (parent.getOwnerDocument()).createAttribute(el.toName());
527             node.setValue(el.toValue().trim());
528             ((Element JavaDoc) parent).setAttributeNode(node);
529          }
530       }
531    }
532
533    public static String JavaDoc getNameSpacePrefix (Node JavaDoc node) {
534       String JavaDoc nameSpacePrefix=node.getPrefix();
535       if (nameSpacePrefix!=null) {
536          nameSpacePrefix+=":";
537       } else {
538          nameSpacePrefix="";
539       }
540       return nameSpacePrefix;
541    }
542
543    public static Node JavaDoc getChildByName(Node JavaDoc parent,String JavaDoc childName) {
544       NodeList JavaDoc children = parent.getChildNodes();
545       for (int i = 0; i < children.getLength(); ++i) {
546          Node JavaDoc child = (Node JavaDoc) children.item(i);
547          if (child.getNodeName().equals(childName)) {
548             return child;
549          }
550       }
551       return null;
552    }
553
554    public static String JavaDoc getId (Node JavaDoc node) {
555       try {
556          NamedNodeMap JavaDoc nnm=node.getAttributes();
557          Node JavaDoc attrib=nnm.getNamedItem("Id");
558          Object JavaDoc ID;
559          if (attrib.hasChildNodes()) {
560             ID=attrib.getChildNodes().item(0).getNodeValue();
561          } else {
562             ID=attrib.getNodeValue();
563          }
564          return ID.toString();
565       } catch (Exception JavaDoc ex) {
566          return "";
567       }
568    }
569
570    public static String JavaDoc getContent (Node JavaDoc node,boolean omitXMLDeclaration) {
571       try {
572          ByteArrayOutputStream JavaDoc baos=new ByteArrayOutputStream JavaDoc();
573
574          // Use a Transformer for output
575
TransformerFactory JavaDoc tFactory =
576             TransformerFactory.newInstance();
577          Transformer JavaDoc transformer = tFactory.newTransformer();
578          transformer.setOutputProperty("indent","yes");
579          transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","4");
580          transformer.setOutputProperty("encoding","UTF-8");
581          if (omitXMLDeclaration) {
582             transformer.setOutputProperty("omit-xml-declaration","yes");
583          }
584
585          DOMSource JavaDoc source = new DOMSource JavaDoc(node);
586          StreamResult JavaDoc result = new StreamResult JavaDoc(baos);
587          transformer.transform(source,result);
588
589          String JavaDoc cont=baos.toString("UTF8");
590
591          baos.close();
592          return cont;
593       } catch (Exception JavaDoc ex) {
594          return "";
595       }
596    }
597
598    public static String JavaDoc getChildNodesContent (Node JavaDoc node) {
599       String JavaDoc txt="";
600       if (node!=null) {
601          if (node.hasChildNodes()) {
602             txt=XMLUtil.getContent(node,true);
603             try {
604                Node JavaDoc fc=node.getFirstChild();
605                String JavaDoc fcnc=XMLUtil.getContent(fc,true);
606                String JavaDoc closedTag="</"+node.getNodeName()+">";
607                if (fcnc.trim().length()>0) {
608                   fcnc=fcnc.trim();
609                }
610
611                int i1,i2;
612                i1=txt.indexOf(fcnc);
613                i2=txt.lastIndexOf(closedTag);
614                txt=txt.substring(i1,i2).trim();
615             } catch (Exception JavaDoc ex) {
616                NodeList JavaDoc nl=node.getChildNodes();
617                txt="";
618                try {
619                   for (int i=0; i<nl.getLength(); i++) {
620                      Node JavaDoc sn=nl.item(i);
621                      if (sn instanceof Element JavaDoc) {
622                         txt+=XMLUtil.getContent(sn,true);
623                      } else {
624                         String JavaDoc nv=sn.getNodeValue();
625                         // trim only the begining of the string
626
if (i>0) {
627                            txt+=nv.substring(1);
628                         } else if (i==0 && nv.trim().length()==0) {
629                            continue;
630                         } else {
631                            txt+=nv;
632                         }
633                      }
634                   }
635                } catch (Exception JavaDoc ex2){}
636             }
637          }
638       }
639       return txt;
640    }
641
642    public static String JavaDoc getShortClassName (String JavaDoc fullClassName) {
643       int lastDot=fullClassName.lastIndexOf(".");
644       if (lastDot>=0) {
645          return fullClassName.substring(lastDot+1,fullClassName.length());
646       }
647       return fullClassName;
648    }
649
650    public static String JavaDoc getExternalPackageId (String JavaDoc extPkgHref) {
651 // System.out.println("EPID1="+extPkgHref);
652
int indBSL=extPkgHref.lastIndexOf("\\");
653       int indSL=extPkgHref.lastIndexOf("/");
654       i