1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLHelper.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package com
.sun
.star
.filter
.config
.tools
.utils
;
33 //_______________________________________________
39 //_______________________________________________
42 * It provides some constant values and some static helper routines
43 * which are neccessary to work with a xml file - especialy
44 * the filter configuration.
48 public class XMLHelper
50 //___________________________________________
53 /** its a possible value of the xml attribute "oor:type" and identify an integer type. */
54 public static final java
.lang
.String XMLTYPE_INTEGER
= "xs:int";
56 /** its a possible value of the xml attribute "oor:type" and identify an boolean type. */
57 public static final java
.lang
.String XMLTYPE_BOOLEAN
= "xs:boolean";
59 /** its a possible value of the xml attribute "oor:type" and identify an string type. */
60 public static final java
.lang
.String XMLTYPE_STRING
= "xs:string";
62 /** its a possible value of the xml attribute "oor:type" and identify an string list type. */
63 public static final java
.lang
.String XMLTYPE_STRINGLIST
= "oor:string-list";
65 /** its a xml attribute, which specify a property name. */
66 public static final java
.lang
.String XMLATTRIB_OOR_NAME
= "oor:name";
68 /** its a xml attribute, which specify a property type. */
69 public static final java
.lang
.String XMLATTRIB_OOR_TYPE
= "oor:type";
71 /** its a xml attribute, which specify a list separator. */
72 public static final java
.lang
.String XMLATTRIB_OOR_SEPARATOR
= "oor:separator";
74 /** its a xml attribute, which specify a localized value. */
75 public static final java
.lang
.String XMLATTRIB_OOR_LOCALIZED
= "oor:localized";
77 /** its a xml attribute, which specify a merge operation for cfg layering. */
78 public static final java
.lang
.String XMLATTRIB_OOR_OP
= "oor:op";
80 /** can be used as value for XMLATTRIB_OOR_OP. */
81 public static final java
.lang
.String XMLATTRIB_OP_REPLACE
= "replace";
83 /** its a xml attribute, which specify a locale value. */
84 public static final java
.lang
.String XMLATTRIB_XML_LANG
= "xml:lang";
86 /** its the tag name of a <value ...> entry. */
87 public static final java
.lang
.String XMLTAG_VALUE
= "value";
89 /** its the tag name of a <prop ...> entry. */
90 public static final java
.lang
.String XMLTAG_PROP
= "prop";
92 /** its the tag name of a <node ...> entry. */
93 public static final java
.lang
.String XMLTAG_NODE
= "node";
95 //___________________________________________
98 /** a static list of all possible separators, which can be used for configuration type string-list. */
99 private static final java
.lang
.String
[] DELIMS
= {" ", ",", ";", ".", ":", "-", "_", "#", "'", "+", "*", "~", "=", "?"};
101 /** index of the default separator inside list DELIMS.
102 * Its neccessary to know such default separator; because it can
103 * be supressed as xml attribute of the corresponding value tag. */
104 private static final int DEFAULT_SEPARATOR
= 0;
106 //___________________________________________
108 /** analyze the structures of the given XML node and
109 * return a property set of all found sub nodes.
111 * Such properties are organized as [name, value] pairs.
112 * The type of a xml node will be detected automaticly.
113 * Following types are supported:
114 * xs:int => java.lang.Integer
115 * xs:bool => java.lang.Boolean
116 * xs:string => java.lang.String
117 * oor:string-list => java.util.LinkedList[java.lang.String]
118 * oor:set => java.util.Vector[java.lang.Object]
119 * oor:localized => java.util.HashMap[java.lang.Object]
122 * points directly to the xml node, where we should analyze
123 * the children nodes.
125 * @return [java.util.HashMap]
126 * contains every node name as key and its string(!) as value.
128 public static java
.util
.HashMap
convertNodeToPropSet(org
.w3c
.dom
.Node aNode
)
129 throws java
.lang
.Exception
131 java
.util
.HashMap aPropSet
= new java
.util
.HashMap();
133 // get all child nodes, which seems to be properties
134 java
.util
.Vector lChildNodes
= XMLHelper
.extractChildNodesByTagName(aNode
, XMLTAG_PROP
);
135 java
.util
.Enumeration en1
= lChildNodes
.elements();
136 while(en1
.hasMoreElements())
138 org
.w3c
.dom
.Node aChildNode
= (org
.w3c
.dom
.Node
)en1
.nextElement();
141 java
.lang
.String sChildName
= XMLHelper
.extractNodeAttribByName(aChildNode
, XMLATTRIB_OOR_NAME
);
142 if (sChildName
== null)
143 throw new java
.io
.IOException("unsupported format: could not extract child node name");
145 // read its type info
146 java
.lang
.String sChildType
= XMLHelper
.extractNodeAttribByName(aChildNode
, XMLATTRIB_OOR_TYPE
);
147 if (sChildType
== null)
150 * If an xml tag has no type information set ... we can restore it
151 * by analyzing the already readed tag name :-)
152 * Not very nice - but it can help to read stripped xml files too. */
153 sChildType
= XMLHelper
.getTypeForTag(sChildName
);
154 if (sChildType
== null)
155 throw new java
.io
.IOException("unsupported format: could not extract child node type");
158 // read its value(s?)
159 java
.util
.Vector lChildValues
= XMLHelper
.extractChildNodesByTagName(aChildNode
, XMLTAG_VALUE
);
160 java
.util
.Enumeration en2
= lChildValues
.elements();
162 java
.lang
.Object aValue
= null;
163 while(en2
.hasMoreElements())
165 org
.w3c
.dom
.Node aValueNode
= (org
.w3c
.dom
.Node
)en2
.nextElement();
166 java
.lang
.String sChildLocale
= XMLHelper
.extractNodeAttribByName(aValueNode
, XMLATTRIB_XML_LANG
);
167 boolean bLocalized
= (sChildLocale
!= null);
171 if (sChildType
.equals(XMLTYPE_INTEGER
))
173 if (!bLocalized
&& nValue
> 1)
174 throw new java
.io
.IOException("unsupported format: more then one value for non localized but atomic type detected");
175 java
.lang
.String sData
= ((org
.w3c
.dom
.CharacterData
)aValueNode
.getFirstChild()).getData();
176 aValue
= new java
.lang
.Integer(sData
);
179 if (sChildType
.equals(XMLTYPE_BOOLEAN
))
181 if (!bLocalized
&& nValue
> 1)
182 throw new java
.io
.IOException("unsupported format: more then one value for non localized but atomic type detected");
183 java
.lang
.String sData
= ((org
.w3c
.dom
.CharacterData
)aValueNode
.getFirstChild()).getData();
184 aValue
= new java
.lang
.Boolean(sData
);
187 if (sChildType
.equals(XMLTYPE_STRING
))
189 if (!bLocalized
&& nValue
> 1)
190 throw new java
.io
.IOException("unsupported format: more then one value for non localized but atomic type detected");
192 java
.lang
.String sData
= ((org
.w3c
.dom
.CharacterData
)aValueNode
.getFirstChild()).getData();
194 java
.util
.HashMap lLocalized
= null;
198 aValue
= new java
.util
.HashMap();
199 lLocalized
= (java
.util
.HashMap
)aValue
;
200 lLocalized
.put(sChildLocale
, sData
);
206 if (sChildType
.equals(XMLTYPE_STRINGLIST
))
208 if (!bLocalized
&& nValue
> 1)
209 throw new java
.io
.IOException("unsupported format: more then one value for non localized but atomic type detected");
211 java
.lang
.String sSeparator
= XMLHelper
.extractNodeAttribByName(aChildNode
, XMLATTRIB_OOR_SEPARATOR
);
212 if (sSeparator
== null)
215 java
.lang
.String sData
= ((org
.w3c
.dom
.CharacterData
)aValueNode
.getFirstChild()).getData();
216 sData
= sData
.replace('\t', ' ');
217 sData
= sData
.replace('\n', ' ');
218 java
.util
.StringTokenizer aTokenizer
= new java
.util
.StringTokenizer(sData
, sSeparator
);
219 java
.util
.Vector lList
= new java
.util
.Vector();
220 while(aTokenizer
.hasMoreTokens())
222 java
.lang
.String sToken
= (java
.lang
.String
)aTokenizer
.nextToken();
224 if (sToken
.length() < 1)
231 aPropSet
.put(sChildName
, aValue
);
238 //___________________________________________
240 private static java
.lang
.String
getTypeForTag(java
.lang
.String sTag
)
242 java
.lang
.String sType
= null;
245 (sTag
.equals(Cache
.PROPNAME_DATA
)) ||
246 (sTag
.equals(Cache
.PROPNAME_NAME
)) ||
247 (sTag
.equals(Cache
.PROPNAME_UINAME
)) ||
248 (sTag
.equals(Cache
.PROPNAME_MEDIATYPE
)) ||
249 (sTag
.equals(Cache
.PROPNAME_CLIPBOARDFORMAT
)) ||
250 (sTag
.equals(Cache
.PROPNAME_PREFERREDFILTER
)) ||
251 (sTag
.equals(Cache
.PROPNAME_DETECTSERVICE
)) ||
252 (sTag
.equals(Cache
.PROPNAME_FRAMELOADER
)) ||
253 (sTag
.equals(Cache
.PROPNAME_CONTENTHANDLER
)) ||
254 (sTag
.equals(Cache
.PROPNAME_DOCUMENTSERVICE
)) ||
255 (sTag
.equals(Cache
.PROPNAME_FILTERSERVICE
)) ||
256 (sTag
.equals(Cache
.PROPNAME_TEMPLATENAME
)) ||
257 (sTag
.equals(Cache
.PROPNAME_TYPE
)) ||
258 (sTag
.equals(Cache
.PROPNAME_UICOMPONENT
))
260 sType
= XMLTYPE_STRING
;
263 (sTag
.equals(Cache
.PROPNAME_PREFERRED
)) ||
264 (sTag
.equals("Installed" ))
266 sType
= XMLTYPE_BOOLEAN
;
269 (sTag
.equals(Cache
.PROPNAME_UIORDER
)) ||
270 (sTag
.equals(Cache
.PROPNAME_DOCUMENTICONID
)) ||
271 (sTag
.equals(Cache
.PROPNAME_FILEFORMATVERSION
))
273 sType
= XMLTYPE_INTEGER
;
276 (sTag
.equals(Cache
.PROPNAME_URLPATTERN
)) ||
277 (sTag
.equals(Cache
.PROPNAME_EXTENSIONS
)) ||
278 (sTag
.equals(Cache
.PROPNAME_USERDATA
)) ||
279 (sTag
.equals(Cache
.PROPNAME_FLAGS
)) ||
280 (sTag
.equals(Cache
.PROPNAME_TYPES
))
282 sType
= XMLTYPE_STRINGLIST
;
285 System
.err
.println("getTypeForTag("+sTag
+") = "+sType
);
290 //___________________________________________
292 /** return a xml representation of the given property set.
295 * a set of <name,value> pairs, which should be translated to xml
297 * @return [java.lang.String]
298 * the xml string representation.
300 * @throws [java.lang.Exception]
301 * if anything during convertion fill fail.
303 public static java
.lang
.String
convertPropSetToXML(java
.util
.HashMap aPropSet
,
305 throws java
.lang
.Exception
307 java
.lang
.StringBuffer sXML
= new java
.lang
.StringBuffer(256);
309 java
.util
.Iterator it1
= aPropSet
.keySet().iterator();
312 java
.lang
.String sProp
= (java
.lang
.String
)it1
.next();
313 java
.lang
.Object aVal
= aPropSet
.get(sProp
);
315 sProp
= encodeHTMLSigns(sProp
);
317 // is it a simple type?
319 (aVal
instanceof java
.lang
.Integer
) ||
320 (aVal
instanceof java
.lang
.Boolean
) ||
321 (aVal
instanceof java
.lang
.String
)
324 sXML
.append(XMLHelper
.convertSimpleObjectToXML(sProp
, aVal
, nPrettyTabs
));
329 // is it a list value?
330 if (aVal
instanceof java
.util
.Vector
)
332 java
.util
.Vector lVal
= (java
.util
.Vector
)aVal
;
333 sXML
.append(XMLHelper
.convertListToXML(sProp
, lVal
, nPrettyTabs
));
337 // its a localized value?
338 if (aVal
instanceof java
.util
.HashMap
)
340 java
.util
.HashMap lVal
= (java
.util
.HashMap
)aVal
;
341 sXML
.append(XMLHelper
.convertLocalizedValueToXML(sProp
, lVal
, nPrettyTabs
));
346 java
.lang
.StringBuffer sMsg
= new java
.lang
.StringBuffer(256);
347 sMsg
.append("unsupported object type detected.");
348 sMsg
.append("\ttype ? : \""+sProp
+"\" = "+aVal
);
349 sMsg
.append("\tprop set: \""+aPropSet
);
350 throw new java
.lang
.Exception(sMsg
.toString());
353 return sXML
.toString();
356 public static java
.lang
.String
encodeHTMLSigns(java
.lang
.String sValue
)
358 java
.lang
.StringBuffer sSource
= new java
.lang
.StringBuffer(sValue
);
359 java
.lang
.StringBuffer sDestination
= new java
.lang
.StringBuffer(1000 );
361 for (int i
=0; i
<sSource
.length(); ++i
)
363 char c
= sSource
.charAt(i
);
365 sDestination
.append("&");
367 sDestination
.append(c
);
370 java
.lang
.String sReturn
= sDestination
.toString();
371 if (!sReturn
.equals(sValue
))
372 System
.out
.println("encode \""+sValue
+"\" => \""+sReturn
+"\"");
377 //___________________________________________
379 /** return a xml representation of an atomic property.
381 * Atomic property types are e.g. Integer, Boolean, String.
384 * the name of the property.
387 * the value of the property.
390 * count of tab signs for pretty format the xml code :-)
392 * @return [java.lang.String]
393 * the xml string representation.
395 * @throws [java.lang.Exception]
396 * if anything during convertion fill fail.
398 private static java
.lang
.String
convertSimpleObjectToXML(java
.lang
.String sName
,
399 java
.lang
.Object aValue
,
401 throws java
.lang
.Exception
403 java
.lang
.StringBuffer sXML
= new java
.lang
.StringBuffer(256);
404 for (int t
=0; t
<nPrettyTabs
; ++t
)
407 if (aValue
instanceof java
.lang
.Integer
)
409 sXML
.append("<prop "+XMLATTRIB_OOR_NAME
+"=\""+sName
+"\">");
410 sXML
.append("<value>"+aValue
.toString()+"</value>");
411 sXML
.append("</prop>\n");
414 if (aValue
instanceof java
.lang
.Boolean
)
416 sXML
.append("<prop "+XMLATTRIB_OOR_NAME
+"=\""+sName
+"\">");
417 sXML
.append("<value>"+aValue
.toString()+"</value>");
418 sXML
.append("</prop>\n");
421 if (aValue
instanceof java
.lang
.String
)
423 sXML
.append("<prop "+XMLATTRIB_OOR_NAME
+"=\""+sName
+"\"");
424 java
.lang
.String sValue
= (java
.lang
.String
)aValue
;
426 sValue
= encodeHTMLSigns(sValue
);
428 if (sValue
.length() < 1)
432 sXML
.append("><value>"+sValue
+"</value>");
433 sXML
.append("</prop>\n");
438 System
.err
.println("name = "+sName
);
439 System
.err
.println("value = "+aValue
);
440 // ! can be used outside to detect - that it was not a simple type :-)
441 throw new java
.lang
.Exception("not an atomic type.");
444 return sXML
.toString();
447 //___________________________________________
449 /** return a xml representation of a string-list property.
452 * the name of the property.
455 * the value of the property.
458 * count of tab signs for pretty format the xml code :-)
460 * @return [java.lang.String]
461 * the xml string representation.
463 * @throws [java.lang.Exception]
464 * if anything during convertion fill fail.
466 private static java
.lang
.String
convertListToXML(java
.lang
.String sName
,
467 java
.util
.Vector aValue
,
469 throws java
.lang
.Exception
471 java
.lang
.StringBuffer sXML
= new java
.lang
.StringBuffer(256);
473 for (int t
=0; t
<nPrettyTabs
; ++t
)
476 int c
= aValue
.size();
479 sXML
.append("<prop "+XMLATTRIB_OOR_NAME
+"=\""+sName
+"\"/>\n");
480 return sXML
.toString();
483 // step over all list items and add it to a string buffer
484 // Every item will be separated by a default separator "\n" first.
485 // Because "\n" is not a valid separator at all and can`t occure inside
486 // our list items. During we step over all items, we check if our current separator
487 // (we use a list of possible ones!) clash with an item.
488 // If it clash - we step to the next possible separator.
489 // If our list of possible separator values runs out of range we throw
490 // an exception :-) Its better then generating of wrong values
491 // If we found a valid seperator - we use it to replace our "\n" place holder
492 // at the end of the following loop ...
495 java
.lang
.StringBuffer sValBuff
= new java
.lang
.StringBuffer(256);
496 for (int i
=0; i
<c
; ++i
)
498 // get the next list item
499 java
.lang
.Object aItem
= aValue
.get(i
);
500 if (!(aItem
instanceof java
.lang
.String
))
501 throw new java
.lang
.Exception("Current implementation supports string-list only!");
503 java
.lang
.String sValue
= (java
.lang
.String
)aItem
;
505 sValue
= encodeHTMLSigns(sValue
);
507 // append item with default separator, which isn a valid separator at all
508 // But supress adding of the separator if last element is reached.
509 sValBuff
.append(sValue
);
511 sValBuff
.append("\n");
513 // check for delim clash
514 // Attention: An empty (means default) element forbid using
515 // of a whitespace character as separator!
518 if (d
>= DELIMS
.length
)
519 throw new java
.lang
.Exception("No valid separator found for a string list item.");
520 if (sValue
.length() < 1 && DELIMS
[d
].equals(" "))
525 if (sValue
.indexOf(DELIMS
[d
]) != -1)
534 // replace default separator with right one
535 System
.out
.println("TODO: must be adapted to java 1.3 :-(");
537 //TODO_JAVA java.lang.String sListVal = sValBuff.toString().replaceAll("\n", DELIMS[d]);
538 java
.lang
.String sListVal
= null;
540 sXML
.append("<prop "+XMLATTRIB_OOR_NAME
+"=\""+sName
+"\">");
541 if (d
== DEFAULT_SEPARATOR
)
542 sXML
.append("<value>");
544 sXML
.append("<value "+XMLATTRIB_OOR_SEPARATOR
+"=\""+DELIMS
[d
]+"\">");
545 sXML
.append(sListVal
);
546 sXML
.append("</value>");
547 sXML
.append("</prop>\n");
549 return sXML
.toString();
552 //___________________________________________
554 /** return a xml representation of a localized property.
557 * the name of the property.
560 * the value of the property.
563 * count of tab signs for pretty format the xml code :-)
565 * @return [java.lang.String]
566 * the xml string representation.
568 * @throws [java.lang.Exception]
569 * if anything during convertion fill fail.
571 private static java
.lang
.String
convertLocalizedValueToXML(java
.lang
.String sName
,
572 java
.util
.HashMap aValue
,
574 throws java
.lang
.Exception
576 java
.lang
.StringBuffer sXML
= new java
.lang
.StringBuffer(256);
578 int c
= aValue
.size();
580 throw new java
.lang
.Exception("Cant detect type of localized values. Because the given list is empty.");
582 for (int t
=0; t
<nPrettyTabs
; ++t
)
584 // !Our localized values must be formated at a deeper coloum
585 // then its property name!
588 sXML
.append("<prop "+XMLATTRIB_OOR_NAME
+"=\""+sName
+"\">\n");
589 java
.util
.Iterator it
= aValue
.keySet().iterator();
590 // boolean bTypeKnown = false;
593 java
.lang
.String sLocale
= (java
.lang
.String
)it
.next();
594 java
.lang
.Object aLocalizedValue
= aValue
.get(sLocale
);
599 if (aLocalizedValue instanceof java.lang.Integer)
600 sXML.append(" "+XMLATTRIB_OOR_TYPE+"=\""+XMLTYPE_INTEGER+"\">\n");
602 if (aLocalizedValue instanceof java.lang.Boolean)
603 sXML.append(" "+XMLATTRIB_OOR_TYPE+"=\""+XMLTYPE_BOOLEAN+"\">\n");
605 if (aLocalizedValue instanceof java.lang.String)
606 sXML.append(" "+XMLATTRIB_OOR_TYPE+"=\""+XMLTYPE_STRING+"\">\n");
608 throw new java.lang.Exception("Unsupported type for localized value detected.");
611 java
.lang
.String sLocValue
= aLocalizedValue
.toString();
612 java
.lang
.String sValue
= encodeHTMLSigns(sLocValue
);
614 for (int t
=0; t
<nPrettyTabs
; ++t
)
616 sXML
.append("<value "+XMLATTRIB_XML_LANG
+"=\""+sLocale
+"\">"+sValue
+"</value>\n");
619 for (int t
=0; t
<nPrettyTabs
; ++t
)
621 sXML
.append("</prop>\n");
623 return sXML
.toString();
626 //___________________________________________
628 /** returns the value of an attribute of the given node.
630 * If the given node represent an lement node, may it supports some attributes.
631 * Then this method search for an attribute with the specified name and return it's value.
632 * If nothing could be found ... or the given node isn't a suitable node ... it returns null.
635 * the node, which should be analyzed.
638 * name of the attribute, which should be searched.
640 * @return The value of the specified attribute if it could be found at the given node.
641 * Can be null if node doesn't support attributes or the searched one does not exist there.
643 public static java
.lang
.String
extractNodeAttribByName(org
.w3c
.dom
.Node aNode
,
644 java
.lang
.String sAttrib
)
645 throws java
.lang
.Exception
647 // We can get valid attributes for element nodes only!
648 if (aNode
.getNodeType() != org
.w3c
.dom
.Node
.ELEMENT_NODE
)
650 // System.err.println("not an element node");
654 // may it supports attributes in general ... but doesn't have anyone realy.
655 org
.w3c
.dom
.NamedNodeMap lAttribs
= aNode
.getAttributes();
658 // System.err.println("no attributes at all");
662 // step over the attribute list and search for the requested one
663 for (int i
=0; i
<lAttribs
.getLength(); ++i
)
665 org
.w3c
.dom
.Attr aAttrib
= (org
.w3c
.dom
.Attr
)lAttribs
.item(i
);
666 if (aAttrib
.getName().equals(sAttrib
))
668 java
.lang
.String sValue
= aAttrib
.getValue();
673 // the searched attribute was not found!
674 // System.err.println("required attribute \""+sAttrib+"\" does not exist for node ["+aNode.toString()+"]");
678 //___________________________________________
680 /** returns a list of childs, which are ELEMENT_NODES and have the right tag name.
682 * It analyze the list of all possible child nodes. Only ELEMENT_NODES are candidates.
683 * All other ones will be ignored. Further these element nodes are compared by it's tag
684 * names. If it match with the specified value it's added to the return list.
685 * So the return list includes references to the DOM tree nodes only, which are child
686 * element nodes with the right tag name.
689 * provides access to the child nodes, which should be analyzed
692 * the searched tag name.
694 * @return A list of child nodes, which are element nodes and have the right tag name.
696 public static java
.util
.Vector
extractChildNodesByTagName(org
.w3c
.dom
.Node aNode
,
697 java
.lang
.String sTag
)
699 // extract first all ELEMENT_NODES of he given parent
700 // Such nodes only provide tag names.
701 java
.util
.Vector lChilds
= XMLHelper
.extractChildNodesByType(aNode
,org
.w3c
.dom
.Node
.ELEMENT_NODE
);
702 java
.util
.Vector lExtractedChilds
= new java
.util
.Vector(lChilds
.size());
704 // step over the list and search for the right tags using the specified name
705 java
.util
.Enumeration en
= lChilds
.elements();
706 while (en
.hasMoreElements())
708 org
.w3c
.dom
.Node aChild
= (org
.w3c
.dom
.Node
)en
.nextElement();
709 if (aChild
.getNodeName().equals(sTag
))
710 lExtractedChilds
.add(aChild
);
713 // pack(!) and return the list
714 lExtractedChilds
.trimToSize();
715 return lExtractedChilds
;
718 //___________________________________________
720 /** returns a list of childs, which supports the right node type.
722 * It analyze the list of all possible child nodes. If a node represent the right node type
723 * it is added to the return list. Otherwhise it will be ignored.
726 * provides access to the list of possible children nodes.
729 * represent the searched node type.
730 * Possible values are constant fields of a org.w3c.dom.Node - e.g. org.w3c.dom.Node.ELEMENT_NODE.
732 * @return A list of child nodes, which provides the right node type.
734 public static java
.util
.Vector
extractChildNodesByType(org
.w3c
.dom
.Node aNode
,
737 // get list of all possibe childs and reserve enough space for our return list
738 // Attention: A null pointer is not allowed for return! (means lExtractedChilds)
739 org
.w3c
.dom
.NodeList lChilds
= aNode
.getChildNodes();
740 int c
= lChilds
.getLength();
741 java
.util
.Vector lExtractedChilds
= new java
.util
.Vector(c
);
743 // step of these childs and select only needed ones
744 for (int i
=0; i
<c
; ++i
)
746 org
.w3c
.dom
.Node aChild
= lChilds
.item(i
);
747 if (aChild
.getNodeType() == nType
)
748 lExtractedChilds
.add(aChild
);
751 // pack(!) and return the list
752 lExtractedChilds
.trimToSize();
753 return lExtractedChilds
;
756 //___________________________________________
758 /** generates an xml header, using parameters.
761 * number of the xml version.
764 * used file encoding.
767 * name of the configuration root.
770 * name of the configuration package.
772 * @param bLanguagepack
773 * force creation of a special header,
774 * which is needed for language packs only.
776 * @return [java.lang.String]
777 * the generated xml header.
780 public static java
.lang
.String
generateHeader(java
.lang
.String sVersion
,
781 java
.lang
.String sEncoding
,
782 java
.lang
.String sPath
,
783 java
.lang
.String sPackage
,
784 boolean bLanguagePack
)
786 java
.lang
.StringBuffer sHeader
= new java
.lang
.StringBuffer(256);
790 sHeader
.append("<?xml version=\"");
791 sHeader
.append(sVersion
);
792 sHeader
.append("\" encoding=\"");
793 sHeader
.append(sEncoding
);
794 sHeader
.append("\"?>\n");
795 sHeader
.append("<oor:component-data oor:package=\"");
796 sHeader
.append(sPath
);
797 sHeader
.append("\" oor:name=\"");
798 sHeader
.append(sPackage
);
799 sHeader
.append("\" xmlns:install=\"http://openoffice.org/2004/installation\"");
800 sHeader
.append(" xmlns:oor=\"http://openoffice.org/2001/registry\"");
801 sHeader
.append(" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"");
802 sHeader
.append(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n");
806 sHeader
.append("<?xml version=\"");
807 sHeader
.append(sVersion
);
808 sHeader
.append("\" encoding=\"");
809 sHeader
.append(sEncoding
);
810 sHeader
.append("\"?>\n<!DOCTYPE oor:component-data SYSTEM \"../../../../component-update.dtd\">\n");
811 sHeader
.append("<oor:component-data xmlns:oor=\"http://openoffice.org/2001/registry\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" oor:package=\"");
812 sHeader
.append(sPath
);
813 sHeader
.append("\" oor:name=\"");
814 sHeader
.append(sPackage
);
815 sHeader
.append("\">\n");
818 return sHeader
.toString();
821 public static java
.lang
.String
generateFooter()
823 return "</oor:component-data>\n";