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: import org.w3c.dom.TypeInfo;
058:
059: /**
060: * Tidy implementation of org.w3c.dom.DOMAttrImpl.
061: * @author Dave Raggett <a href="mailto:dsr@w3.org">dsr@w3.org </a>
062: * @author Andy Quick <a href="mailto:ac.quick@sympatico.ca">ac.quick@sympatico.ca </a> (translation to Java)
063: * @author Fabrizio Giustina
064: * @version $Revision: 1.9 $ ($Author: fgiust $)
065: */
066: public class DOMAttrImpl extends DOMNodeImpl implements
067: org.w3c.dom.Attr, Cloneable {
068:
069: /**
070: * wrapped org.w3c.tidy.AttVal.
071: */
072: protected AttVal avAdaptee;
073:
074: /**
075: * instantiates a new DOMAttrImpl which wraps the given AttVal.
076: * @param adaptee wrapped AttVal
077: */
078: protected DOMAttrImpl(AttVal adaptee) {
079: super (null); // must override all methods of DOMNodeImpl
080: this .avAdaptee = adaptee;
081: }
082:
083: /**
084: * @see org.w3c.dom.Node#getNodeValue()
085: */
086: public String getNodeValue() throws DOMException {
087: return getValue();
088: }
089:
090: /**
091: * @see org.w3c.dom.Node#setNodeValue(java.lang.String)
092: */
093: public void setNodeValue(String nodeValue) throws DOMException {
094: setValue(nodeValue);
095: }
096:
097: /**
098: * @see org.w3c.dom.Node#getNodeName()
099: */
100: public String getNodeName() {
101: return getName();
102: }
103:
104: /**
105: * @see org.w3c.dom.Node#getNodeType()
106: */
107: public short getNodeType() {
108: return org.w3c.dom.Node.ATTRIBUTE_NODE;
109: }
110:
111: /**
112: * @see org.w3c.dom.Attr#getName
113: */
114: public String getName() {
115: return avAdaptee.attribute;
116: }
117:
118: /**
119: * @see org.w3c.dom.Attr#getSpecified
120: */
121: public boolean getSpecified() {
122: return avAdaptee.value != null;
123: }
124:
125: /**
126: * @see org.w3c.dom.Attr#getValue
127: */
128: public String getValue() {
129: // Thanks to Brett Knights brett@knightsofthenet.com for this fix.
130: return (avAdaptee.value == null) ? avAdaptee.attribute
131: : avAdaptee.value;
132: }
133:
134: /**
135: * @see org.w3c.dom.Attr#setValue(java.lang.String)
136: */
137: public void setValue(String value) {
138: avAdaptee.value = value;
139: }
140:
141: /**
142: * @see org.w3c.dom.Node#getParentNode()
143: */
144: public org.w3c.dom.Node getParentNode() {
145: // Attr.getParentNode() should always return null
146: // http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-637646024
147: return null;
148: }
149:
150: /**
151: * @todo DOM level 2 getChildNodes() Not implemented. Returns an empty NodeList.
152: * @see org.w3c.dom.Node#getChildNodes()
153: */
154: public org.w3c.dom.NodeList getChildNodes() {
155: // Calling getChildNodes on a DOM Attr node does return the children of the Attr, which are the text and
156: // EntityReference nodes that make up the Attr's content.
157: return new DOMNodeListImpl(null);
158: }
159:
160: /**
161: * @todo DOM level 2 getFirstChild() Not implemented. Returns null.
162: * @see org.w3c.dom.Node#getFirstChild()
163: */
164: public org.w3c.dom.Node getFirstChild() {
165: return null;
166: }
167:
168: /**
169: * @todo DOM level 2 getLastChild() Not implemented. Returns null.
170: * @see org.w3c.dom.Node#getLastChild()
171: */
172: public org.w3c.dom.Node getLastChild() {
173: return null;
174: }
175:
176: /**
177: * @see org.w3c.dom.Node#getPreviousSibling()
178: */
179: public org.w3c.dom.Node getPreviousSibling() {
180: // Attr.getPreviousSibling() should always return null
181: return null;
182: }
183:
184: /**
185: * @see org.w3c.dom.Node#getNextSibling()
186: */
187: public org.w3c.dom.Node getNextSibling() {
188: // Attr.getNextSibling() should always return null
189: return null;
190: }
191:
192: /**
193: * @see org.w3c.dom.Node#getAttributes()
194: */
195: public org.w3c.dom.NamedNodeMap getAttributes() {
196: return null;
197: }
198:
199: /**
200: * @todo DOM level 2 getOwnerDocument() Not implemented. Returns null.
201: * @see org.w3c.dom.Node#getOwnerDocument()
202: */
203: public org.w3c.dom.Document getOwnerDocument() {
204: return null;
205: }
206:
207: /**
208: * Not supported.
209: * @see org.w3c.dom.Node#insertBefore(org.w3c.dom.Node, org.w3c.dom.Node)
210: */
211: public org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild,
212: org.w3c.dom.Node refChild) throws DOMException {
213: throw new DOMException(
214: DOMException.NO_MODIFICATION_ALLOWED_ERR,
215: "Not supported");
216: }
217:
218: /**
219: * Not supported.
220: * @see org.w3c.dom.Node#replaceChild(org.w3c.dom.Node, org.w3c.dom.Node)
221: */
222: public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild,
223: org.w3c.dom.Node oldChild) throws DOMException {
224: throw new DOMException(
225: DOMException.NO_MODIFICATION_ALLOWED_ERR,
226: "Not supported");
227: }
228:
229: /**
230: * Not supported.
231: * @see org.w3c.dom.Node#removeChild(org.w3c.dom.Node)
232: */
233: public org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild)
234: throws DOMException {
235: throw new DOMException(
236: DOMException.NO_MODIFICATION_ALLOWED_ERR,
237: "Not supported");
238: }
239:
240: /**
241: * Not supported.
242: * @see org.w3c.dom.Node#appendChild(org.w3c.dom.Node)
243: */
244: public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild)
245: throws DOMException {
246: throw new DOMException(
247: DOMException.NO_MODIFICATION_ALLOWED_ERR,
248: "Not supported");
249: }
250:
251: /**
252: * @see org.w3c.dom.Node#hasChildNodes()
253: */
254: public boolean hasChildNodes() {
255: return false;
256: }
257:
258: /**
259: * @see org.w3c.dom.Node#cloneNode(boolean)
260: */
261: public org.w3c.dom.Node cloneNode(boolean deep) {
262: // http://java.sun.com/j2se/1.5.0/docs/api/index.html?org/w3c/dom/Attr.html
263: // Cloning an Attr always clones its children, since they represent its value, no matter whether this is a deep
264: // clone or not.
265: return (org.w3c.dom.Node) clone();
266: }
267:
268: /**
269: * @todo DOM level 2 getOwnerElement() Not implemented. Returns null.
270: * @see org.w3c.dom.Attr#getOwnerElement()
271: */
272: public org.w3c.dom.Element getOwnerElement() {
273: return null;
274: }
275:
276: /**
277: * @todo DOM level 3 getSchemaTypeInfo() Not implemented. Returns null.
278: * @see org.w3c.dom.Attr#getSchemaTypeInfo()
279: */
280: public TypeInfo getSchemaTypeInfo() {
281: return null;
282: }
283:
284: /**
285: * @see org.w3c.dom.Attr#isId()
286: */
287: public boolean isId() {
288: return "id".equals(this .avAdaptee.getAttribute());
289: }
290:
291: /**
292: * @see java.lang.Object#clone()
293: */
294: protected Object clone() {
295: DOMAttrImpl clone;
296: try {
297: clone = (DOMAttrImpl) super .clone();
298: } catch (CloneNotSupportedException e) {
299: // should never happen
300: throw new RuntimeException("Clone not supported");
301: }
302: clone.avAdaptee = (AttVal) this.avAdaptee.clone();
303: return clone;
304: }
305: }
|