KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > util > xml > parser > ParserUtil


1 package org.sapia.util.xml.parser;
2
3
4 // Imports of David Meggison's SAX classes
5
// ---------------------------------------
6
import org.xml.sax.Attributes JavaDoc;
7
8
9 /**
10  * Utility methods used by this parser package.
11  *
12  * @author Jean-Cedric Desrochers
13  * <dl>
14  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
15  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
16  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
17  * </dl>
18  */

19 public class ParserUtil {
20   /**
21    * Utility method that formats the SAX attributes passed in into a string form.
22    *
23    * @return The string form of the SAX attributes passed in.
24    */

25   public static String JavaDoc toStringAtributes(Attributes JavaDoc someAttributes) {
26     StringBuffer JavaDoc aBuffer = new StringBuffer JavaDoc();
27
28     for (int i = 0; i < someAttributes.getLength(); i++) {
29       aBuffer.append("Attribute ").append(i).append(":")
30              .append(" qualifiedName=").append(someAttributes.getQName(i))
31              .append(" namespaceURI=").append(someAttributes.getURI(i))
32              .append(" localName=").append(someAttributes.getLocalName(i))
33              .append(" type=").append(someAttributes.getType(i))
34              .append(" value=").append(someAttributes.getValue(i)).append("\n");
35     }
36
37     return aBuffer.toString();
38   }
39
40   /**
41    * Parses the attributes passed in and extract the xml:base attribute's value.
42    *
43    * @return The value of the xml:base attribute or null if the attribute is not defined.
44    */

45   public static String JavaDoc extractXmlBaseURI(Attributes JavaDoc someAttributes) {
46     String JavaDoc aValue = someAttributes.getValue(XMLDictionnaryIF.QUALIFIED_ELEMENT_XML_BASE);
47
48     if (aValue == null) {
49       aValue = someAttributes.getValue(XMLDictionnaryIF.XML_NAMESPACE_URI,
50           XMLDictionnaryIF.LOCAL_ELEMENT_XML_BASE);
51     }
52
53     return aValue;
54   }
55
56   /**
57    * Parses the attributes passed in and extract the xml:lang attribute's value.
58    *
59    * @return The value of the xml:lang attribute or null if the attribute is not defined.
60    */

61   public static String JavaDoc extractXmlLanguageCode(Attributes JavaDoc someAttributes) {
62     String JavaDoc aValue = someAttributes.getValue(XMLDictionnaryIF.QUALIFIED_ELEMENT_XML_LANG);
63
64     if (aValue == null) {
65       aValue = someAttributes.getValue(XMLDictionnaryIF.XML_NAMESPACE_URI,
66           XMLDictionnaryIF.LOCAL_ELEMENT_XML_LANG);
67     }
68
69     return aValue;
70   }
71
72   /**
73    * Parses the attributes passed in and extract the xml:space attribute's value.
74    *
75    * @return The value of the xml:space attribute or null if the attribute is not defined.
76    */

77   public static String JavaDoc extractXmlSpaceValue(Attributes JavaDoc someAttributes) {
78     String JavaDoc aValue = someAttributes.getValue(XMLDictionnaryIF.QUALIFIED_ELEMENT_XML_SPACE);
79
80     if (aValue == null) {
81       aValue = someAttributes.getValue(XMLDictionnaryIF.XML_NAMESPACE_URI,
82           XMLDictionnaryIF.LOCAL_ELEMENT_XML_SPACE);
83     }
84
85     return aValue;
86   }
87 }
88
Popular Tags