001: /*
002: * Java HTML Tidy - JTidy
003: * HTML parser and pretty printer
004: *
005: * Copyright (c) 1998-2000 World Wide Web Consortium (Massachusetts
006: * Institute of Technology, Institut National de Recherche en
007: * Informatique et en Automatique, Keio University). All Rights
008: * Reserved.
009: *
010: * Contributing Author(s):
011: *
012: * Dave Raggett <dsr@w3.org>
013: * Andy Quick <ac.quick@sympatico.ca> (translation to Java)
014: * Gary L Peskin <garyp@firstech.com> (Java development)
015: * Sami Lempinen <sami@lempinen.net> (release management)
016: * Fabrizio Giustina <fgiust at users.sourceforge.net>
017: *
018: * The contributing author(s) would like to thank all those who
019: * helped with testing, bug fixes, and patience. This wouldn't
020: * have been possible without all of you.
021: *
022: * COPYRIGHT NOTICE:
023: *
024: * This software and documentation is provided "as is," and
025: * the copyright holders and contributing author(s) make no
026: * representations or warranties, express or implied, including
027: * but not limited to, warranties of merchantability or fitness
028: * for any particular purpose or that the use of the software or
029: * documentation will not infringe any third party patents,
030: * copyrights, trademarks or other rights.
031: *
032: * The copyright holders and contributing author(s) will not be
033: * liable for any direct, indirect, special or consequential damages
034: * arising out of any use of the software or documentation, even if
035: * advised of the possibility of such damage.
036: *
037: * Permission is hereby granted to use, copy, modify, and distribute
038: * this source code, or portions hereof, documentation and executables,
039: * for any purpose, without fee, subject to the following restrictions:
040: *
041: * 1. The origin of this source code must not be misrepresented.
042: * 2. Altered versions must be plainly marked as such and must
043: * not be misrepresented as being the original source.
044: * 3. This Copyright notice may not be removed or altered from any
045: * source or altered source distribution.
046: *
047: * The copyright holders and contributing author(s) specifically
048: * permit, without fee, and encourage the use of this source code
049: * as a component for supporting the Hypertext Markup Language in
050: * commercial products. If you use this source code in a product,
051: * acknowledgment is not required but would be appreciated.
052: *
053: */
054: package org.w3c.tidy;
055:
056: import org.w3c.dom.DOMException;
057:
058: /**
059: * Tidy implementation of org.w3c.dom.NamedNodeMap.
060: * @author Dave Raggett <a href="mailto:dsr@w3.org">dsr@w3.org </a>
061: * @author Andy Quick <a href="mailto:ac.quick@sympatico.ca">ac.quick@sympatico.ca </a> (translation to Java)
062: * @author Fabrizio Giustina
063: * @version $Revision: 1.10 $ ($Author: fgiust $)
064: */
065: public class DOMAttrMapImpl implements org.w3c.dom.NamedNodeMap {
066:
067: /**
068: * wrapped org.w3c.tidy.AttVal.
069: */
070: private AttVal first;
071:
072: /**
073: * instantiates a new DOMAttrMapImpl for the given AttVal.
074: * @param firstAttVal wrapped AttVal
075: */
076: protected DOMAttrMapImpl(AttVal firstAttVal) {
077: this .first = firstAttVal;
078: }
079:
080: /**
081: * @see org.w3c.dom.NamedNodeMap#getNamedItem(java.lang.String)
082: */
083: public org.w3c.dom.Node getNamedItem(String name) {
084: AttVal att = this .first;
085: while (att != null) {
086: if (att.attribute.equals(name)) {
087: break;
088: }
089: att = att.next;
090: }
091: if (att != null) {
092: return att.getAdapter();
093: }
094:
095: return null;
096: }
097:
098: /**
099: * @see org.w3c.dom.NamedNodeMap#item
100: */
101: public org.w3c.dom.Node item(int index) {
102: int i = 0;
103: AttVal att = this .first;
104: while (att != null) {
105: if (i >= index) {
106: break;
107: }
108: i++;
109: att = att.next;
110: }
111: if (att != null) {
112: return att.getAdapter();
113: }
114:
115: return null;
116: }
117:
118: /**
119: * @see org.w3c.dom.NamedNodeMap#getLength
120: */
121: public int getLength() {
122: int len = 0;
123: AttVal att = this .first;
124: while (att != null) {
125: len++;
126: att = att.next;
127: }
128: return len;
129: }
130:
131: /**
132: * @todo DOM level 2 setNamedItem() Not implemented. Throws NOT_SUPPORTED_ERR.
133: * @see org.w3c.dom.NamedNodeMap#setNamedItem
134: */
135: public org.w3c.dom.Node setNamedItem(org.w3c.dom.Node arg)
136: throws DOMException {
137: throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
138: "DOM method not supported");
139: }
140:
141: /**
142: * @see org.w3c.dom.NamedNodeMap#removeNamedItem
143: */
144: public org.w3c.dom.Node removeNamedItem(String name)
145: throws DOMException {
146: AttVal att = this .first;
147: AttVal previous = null;
148:
149: while (att != null) {
150: if (att.attribute.equals(name)) {
151: if (previous == null) {
152: this .first = att.getNext();
153: } else {
154: previous.setNext(att.getNext());
155: }
156:
157: break;
158: }
159: previous = att;
160: att = att.next;
161: }
162:
163: if (att != null) {
164: return att.getAdapter();
165: }
166:
167: throw new DOMException(DOMException.NOT_FOUND_ERR,
168: "Named item " + name + "Not found");
169: }
170:
171: /**
172: * Not supported, returns <code>DOMException.NOT_SUPPORTED_ERR</code>.
173: * @see org.w3c.dom.NamedNodeMap#getNamedItemNS(java.lang.String, java.lang.String)
174: */
175: public org.w3c.dom.Node getNamedItemNS(String namespaceURI,
176: String localName) {
177: // NOT_SUPPORTED_ERR: May be raised if the implementation does not support the feature "XML" and the language
178: // exposed through the Document does not support XML Namespaces (such as HTML 4.01).
179: throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
180: "DOM method not supported");
181: }
182:
183: /**
184: * Not supported, returns <code>DOMException.NOT_SUPPORTED_ERR</code>.
185: * @see org.w3c.dom.NamedNodeMap#setNamedItemNS(org.w3c.dom.Node)
186: */
187: public org.w3c.dom.Node setNamedItemNS(org.w3c.dom.Node arg)
188: throws org.w3c.dom.DOMException {
189: // NOT_SUPPORTED_ERR: May be raised if the implementation does not support the feature "XML" and the language
190: // exposed through the Document does not support XML Namespaces (such as HTML 4.01).
191: throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
192: "DOM method not supported");
193: }
194:
195: /**
196: * Not supported, returns <code>DOMException.NOT_SUPPORTED_ERR</code>.
197: * @see org.w3c.dom.NamedNodeMap#removeNamedItemNS(java.lang.String, java.lang.String)
198: */
199: public org.w3c.dom.Node removeNamedItemNS(String namespaceURI,
200: String localName) throws org.w3c.dom.DOMException {
201: // NOT_SUPPORTED_ERR: May be raised if the implementation does not support the feature "XML" and the language
202: // exposed through the Document does not support XML Namespaces (such as HTML 4.01).
203: throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
204: "DOM method not supported");
205: }
206:
207: }
|