View Javadoc
1   /*
2    * (C) Copyright Keith Visco 1998, 1999  All rights reserved.
3    *
4    * The contents of this file are released under an Open Source
5    * Definition (OSD) compliant license; you may not use this file
6    * execpt in compliance with the license. Please see license.txt,
7    * distributed with this file. You may also obtain a copy of the
8    * license at http://www.clc-marketing.com/xslp/license.txt
9    *
10   * The program is provided "as is" without any warranty express or
11   * implied, including the warranty of non-infringement and the implied
12   * warranties of merchantibility and fitness for a particular purpose.
13   * The Copyright owner will not be liable for any damages suffered by
14   * you as a result of using the Program. In no event will the Copyright
15   * owner be liable for any special, indirect or consequential damages or
16   * lost profits even if the Copyright owner has been advised of the
17   * possibility of their occurrence.
18   *
19   * The orginal source for this file is XSL:P
20   *
21   * $Id$
22   */
23  package org.exolab.castor.xml.util;
24  
25  import org.w3c.dom.Attr;
26  import org.w3c.dom.NamedNodeMap;
27  import org.xml.sax.AttributeList;
28  
29  /**
30   * A class which implements AttributeList by "wrapping" a DOM NamedNodeMap.
31   * XSLReader when reading an XSLT stylsheet.
32   *
33   * @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
34   * @version $Revision$ $Date: 2003-03-03 00:05:44 -0700 (Mon, 03 Mar 2003) $
35   */
36  public class AttributeListWrapper implements AttributeList {
37  
38      NamedNodeMap _map = null;
39  
40      public AttributeListWrapper(NamedNodeMap namedNodeMap) {
41          _map = namedNodeMap;
42      } //-- AtrributeListWrapper
43  
44      //-----------------------------/
45      //- org.xml.sax.AttributeList -/
46      //-----------------------------/
47  
48      /**
49       * Returns the number of attributes in the list.
50       *
51       * @return The number of attributes in the list.
52       */
53      public int getLength() {
54          if (_map == null) {
55              return 0;
56          }
57          return _map.getLength();
58      } //-- getLength
59  
60      /**
61       * Returns the name of the attribute at the given index.
62       *
63       * @param i The position of the attribute in the list.
64       * @return The attribute name as a string, or null if there is no attribute
65       *         at that position.
66       */
67      public String getName(final int i) {
68          if (_map != null) {
69              Attr attr = (Attr) _map.item(i);
70              return attr.getName();
71          }
72          return null;
73      } //-- getName
74  
75      /**
76       * Returns the type of the attribute at the specified index.
77       *
78       * @param i The position of the attribute in the list.
79       * @return The attribute type as a string ("NMTOKEN" for an enumeration, and
80       *         "CDATA" if no declaration was read), or null if there is no
81       *         attribute at that position. <br/><b>Note:</b> Not supported,
82       *         will simply return null.
83       */
84      public String getType(final int i) {
85          return null;
86      } //-- getType
87  
88      /**
89       * Return the value of the attribute at the specified index
90       *
91       * @param i The position of the attribute in the list.
92       * @return The attribute value as a string, or null if there is no attribute
93       *         at that position.
94       */
95      public String getValue(final int i) {
96          if (_map != null) {
97              Attr attr = (Attr) _map.item(i);
98              return attr.getValue();
99          }
100         return null;
101     } //-- getValue
102 
103     /**
104      * Return the type of the attribute with the given name.
105      *
106      * @param name The attribute name.
107      * @return The attribute type as a string ("NMTOKEN" for an enumeration, and
108      *         "CDATA" if no declaration was read). <br/><b>Note:</b> Not
109      *         supported, will simply return null.
110      */
111     public String getType(final String name) {
112         return null;
113     } //-- getType
114 
115     /**
116      * Get the value of an attribute (by name).
117      *
118      * @param name The attribute name.
119      * @see org.xml.sax.AttributeList#getValue(java.lang.String)
120      */
121     public String getValue(final String name) {
122         if (_map != null) {
123             Attr attr = (Attr) _map.getNamedItem(name);
124             if (attr != null) {
125                 return attr.getValue();
126             }
127         }
128         return null;
129     } //-- getValue
130 
131 } //-- AttributeListWrapper