View Javadoc

1   /*
2    *  Java HTML Tidy - JTidy
3    *  HTML parser and pretty printer
4    *
5    *  Copyright (c) 1998-2000 World Wide Web Consortium (Massachusetts
6    *  Institute of Technology, Institut National de Recherche en
7    *  Informatique et en Automatique, Keio University). All Rights
8    *  Reserved.
9    *
10   *  Contributing Author(s):
11   *
12   *     Dave Raggett <dsr@w3.org>
13   *     Andy Quick <ac.quick@sympatico.ca> (translation to Java)
14   *     Gary L Peskin <garyp@firstech.com> (Java development)
15   *     Sami Lempinen <sami@lempinen.net> (release management)
16   *     Fabrizio Giustina <fgiust at users.sourceforge.net>
17   *
18   *  The contributing author(s) would like to thank all those who
19   *  helped with testing, bug fixes, and patience.  This wouldn't
20   *  have been possible without all of you.
21   *
22   *  COPYRIGHT NOTICE:
23   * 
24   *  This software and documentation is provided "as is," and
25   *  the copyright holders and contributing author(s) make no
26   *  representations or warranties, express or implied, including
27   *  but not limited to, warranties of merchantability or fitness
28   *  for any particular purpose or that the use of the software or
29   *  documentation will not infringe any third party patents,
30   *  copyrights, trademarks or other rights. 
31   *
32   *  The copyright holders and contributing author(s) will not be
33   *  liable for any direct, indirect, special or consequential damages
34   *  arising out of any use of the software or documentation, even if
35   *  advised of the possibility of such damage.
36   *
37   *  Permission is hereby granted to use, copy, modify, and distribute
38   *  this source code, or portions hereof, documentation and executables,
39   *  for any purpose, without fee, subject to the following restrictions:
40   *
41   *  1. The origin of this source code must not be misrepresented.
42   *  2. Altered versions must be plainly marked as such and must
43   *     not be misrepresented as being the original source.
44   *  3. This Copyright notice may not be removed or altered from any
45   *     source or altered source distribution.
46   * 
47   *  The copyright holders and contributing author(s) specifically
48   *  permit, without fee, and encourage the use of this source code
49   *  as a component for supporting the Hypertext Markup Language in
50   *  commercial products. If you use this source code in a product,
51   *  acknowledgment is not required but would be appreciated.
52   *
53   */
54  package org.w3c.tidy;
55  
56  import org.w3c.dom.DOMException;
57  
58  
59  /**
60   * Tidy implementation of org.w3c.dom.NamedNodeMap.
61   * @author Dave Raggett <a href="mailto:dsr@w3.org">dsr@w3.org </a>
62   * @author Andy Quick <a href="mailto:ac.quick@sympatico.ca">ac.quick@sympatico.ca </a> (translation to Java)
63   * @author Fabrizio Giustina
64   * @version $Revision: 779 $ ($Author: fgiust $)
65   */
66  public class DOMAttrMapImpl implements org.w3c.dom.NamedNodeMap
67  {
68  
69      /**
70       * wrapped org.w3c.tidy.AttVal.
71       */
72      private AttVal first;
73  
74      /**
75       * instantiates a new DOMAttrMapImpl for the given AttVal.
76       * @param firstAttVal wrapped AttVal
77       */
78      protected DOMAttrMapImpl(AttVal firstAttVal)
79      {
80          this.first = firstAttVal;
81      }
82  
83      /**
84       * @see org.w3c.dom.NamedNodeMap#getNamedItem(java.lang.String)
85       */
86      public org.w3c.dom.Node getNamedItem(String name)
87      {
88          AttVal att = this.first;
89          while (att != null)
90          {
91              if (att.attribute.equals(name))
92              {
93                  break;
94              }
95              att = att.next;
96          }
97          if (att != null)
98          {
99              return att.getAdapter();
100         }
101 
102         return null;
103     }
104 
105     /**
106      * @see org.w3c.dom.NamedNodeMap#item
107      */
108     public org.w3c.dom.Node item(int index)
109     {
110         int i = 0;
111         AttVal att = this.first;
112         while (att != null)
113         {
114             if (i >= index)
115             {
116                 break;
117             }
118             i++;
119             att = att.next;
120         }
121         if (att != null)
122         {
123             return att.getAdapter();
124         }
125 
126         return null;
127     }
128 
129     /**
130      * @see org.w3c.dom.NamedNodeMap#getLength
131      */
132     public int getLength()
133     {
134         int len = 0;
135         AttVal att = this.first;
136         while (att != null)
137         {
138             len++;
139             att = att.next;
140         }
141         return len;
142     }
143 
144     /**
145      * @todo DOM level 2 setNamedItem() Not implemented. Throws NOT_SUPPORTED_ERR.
146      * @see org.w3c.dom.NamedNodeMap#setNamedItem
147      */
148     public org.w3c.dom.Node setNamedItem(org.w3c.dom.Node arg) throws DOMException
149     {
150         throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "DOM method not supported");
151     }
152 
153     /**
154      * @see org.w3c.dom.NamedNodeMap#removeNamedItem
155      */
156     public org.w3c.dom.Node removeNamedItem(String name) throws DOMException
157     {
158         AttVal att = this.first;
159         AttVal previous = null;
160 
161         while (att != null)
162         {
163             if (att.attribute.equals(name))
164             {
165                 if (previous == null)
166                 {
167                     this.first = att.getNext();
168                 }
169                 else
170                 {
171                     previous.setNext(att.getNext());
172                 }
173 
174                 break;
175             }
176             previous = att;
177             att = att.next;
178         }
179 
180         if (att != null)
181         {
182             return att.getAdapter();
183         }
184 
185         throw new DOMException(DOMException.NOT_FOUND_ERR, "Named item " + name + "Not found");
186     }
187 
188     /**
189      * Not supported, returns <code>DOMException.NOT_SUPPORTED_ERR</code>.
190      * @see org.w3c.dom.NamedNodeMap#getNamedItemNS(java.lang.String, java.lang.String)
191      */
192     public org.w3c.dom.Node getNamedItemNS(String namespaceURI, String localName)
193     {
194         // NOT_SUPPORTED_ERR: May be raised if the implementation does not support the feature "XML" and the language
195         // exposed through the Document does not support XML Namespaces (such as HTML 4.01).
196         throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "DOM method not supported");
197     }
198 
199     /**
200      * Not supported, returns <code>DOMException.NOT_SUPPORTED_ERR</code>.
201      * @see org.w3c.dom.NamedNodeMap#setNamedItemNS(org.w3c.dom.Node)
202      */
203     public org.w3c.dom.Node setNamedItemNS(org.w3c.dom.Node arg) throws org.w3c.dom.DOMException
204     {
205         // NOT_SUPPORTED_ERR: May be raised if the implementation does not support the feature "XML" and the language
206         // exposed through the Document does not support XML Namespaces (such as HTML 4.01).
207         throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "DOM method not supported");
208     }
209 
210     /**
211      * Not supported, returns <code>DOMException.NOT_SUPPORTED_ERR</code>.
212      * @see org.w3c.dom.NamedNodeMap#removeNamedItemNS(java.lang.String, java.lang.String)
213      */
214     public org.w3c.dom.Node removeNamedItemNS(String namespaceURI, String localName) throws org.w3c.dom.DOMException
215     {
216         // NOT_SUPPORTED_ERR: May be raised if the implementation does not support the feature "XML" and the language
217         // exposed through the Document does not support XML Namespaces (such as HTML 4.01).
218         throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "DOM method not supported");
219     }
220 
221 }