|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| DOMAttrImpl.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 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 | import org.w3c.dom.TypeInfo; | |
| 58 | ||
| 59 | ||
| 60 | /** | |
| 61 | * Tidy implementation of org.w3c.dom.DOMAttrImpl. | |
| 62 | * @author Dave Raggett <a href="mailto:dsr@w3.org">dsr@w3.org </a> | |
| 63 | * @author Andy Quick <a href="mailto:ac.quick@sympatico.ca">ac.quick@sympatico.ca </a> (translation to Java) | |
| 64 | * @author Fabrizio Giustina | |
| 65 | * @version $Revision: 779 $ ($Author: fgiust $) | |
| 66 | */ | |
| 67 | public class DOMAttrImpl extends DOMNodeImpl implements org.w3c.dom.Attr, Cloneable | |
| 68 | { | |
| 69 | ||
| 70 | /** | |
| 71 | * wrapped org.w3c.tidy.AttVal. | |
| 72 | */ | |
| 73 | protected AttVal avAdaptee; | |
| 74 | ||
| 75 | /** | |
| 76 | * instantiates a new DOMAttrImpl which wraps the given AttVal. | |
| 77 | * @param adaptee wrapped AttVal | |
| 78 | */ | |
| 79 | 0 | protected DOMAttrImpl(AttVal adaptee) |
| 80 | { | |
| 81 | 0 | super(null); // must override all methods of DOMNodeImpl |
| 82 | 0 | this.avAdaptee = adaptee; |
| 83 | } | |
| 84 | ||
| 85 | /** | |
| 86 | * @see org.w3c.dom.Node#getNodeValue() | |
| 87 | */ | |
| 88 | 0 | public String getNodeValue() throws DOMException |
| 89 | { | |
| 90 | 0 | return getValue(); |
| 91 | } | |
| 92 | ||
| 93 | /** | |
| 94 | * @see org.w3c.dom.Node#setNodeValue(java.lang.String) | |
| 95 | */ | |
| 96 | 0 | public void setNodeValue(String nodeValue) throws DOMException |
| 97 | { | |
| 98 | 0 | setValue(nodeValue); |
| 99 | } | |
| 100 | ||
| 101 | /** | |
| 102 | * @see org.w3c.dom.Node#getNodeName() | |
| 103 | */ | |
| 104 | 0 | public String getNodeName() |
| 105 | { | |
| 106 | 0 | return getName(); |
| 107 | } | |
| 108 | ||
| 109 | /** | |
| 110 | * @see org.w3c.dom.Node#getNodeType() | |
| 111 | */ | |
| 112 | 0 | public short getNodeType() |
| 113 | { | |
| 114 | 0 | return org.w3c.dom.Node.ATTRIBUTE_NODE; |
| 115 | } | |
| 116 | ||
| 117 | /** | |
| 118 | * @see org.w3c.dom.Attr#getName | |
| 119 | */ | |
| 120 | 0 | public String getName() |
| 121 | { | |
| 122 | 0 | return avAdaptee.attribute; |
| 123 | } | |
| 124 | ||
| 125 | /** | |
| 126 | * @see org.w3c.dom.Attr#getSpecified | |
| 127 | */ | |
| 128 | 0 | public boolean getSpecified() |
| 129 | { | |
| 130 | 0 | return avAdaptee.value != null; |
| 131 | } | |
| 132 | ||
| 133 | /** | |
| 134 | * @see org.w3c.dom.Attr#getValue | |
| 135 | */ | |
| 136 | 0 | public String getValue() |
| 137 | { | |
| 138 | // Thanks to Brett Knights brett@knightsofthenet.com for this fix. | |
| 139 | 0 | return (avAdaptee.value == null) ? avAdaptee.attribute : avAdaptee.value; |
| 140 | } | |
| 141 | ||
| 142 | /** | |
| 143 | * @see org.w3c.dom.Attr#setValue(java.lang.String) | |
| 144 | */ | |
| 145 | 0 | public void setValue(String value) |
| 146 | { | |
| 147 | 0 | avAdaptee.value = value; |
| 148 | } | |
| 149 | ||
| 150 | /** | |
| 151 | * @see org.w3c.dom.Node#getParentNode() | |
| 152 | */ | |
| 153 | 0 | public org.w3c.dom.Node getParentNode() |
| 154 | { | |
| 155 | // Attr.getParentNode() should always return null | |
| 156 | // http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-637646024 | |
| 157 | 0 | return null; |
| 158 | } | |
| 159 | ||
| 160 | /** | |
| 161 | * @todo DOM level 2 getChildNodes() Not implemented. Returns an empty NodeList. | |
| 162 | * @see org.w3c.dom.Node#getChildNodes() | |
| 163 | */ | |
| 164 | 0 | public org.w3c.dom.NodeList getChildNodes() |
| 165 | { | |
| 166 | // Calling getChildNodes on a DOM Attr node does return the children of the Attr, which are the text and | |
| 167 | // EntityReference nodes that make up the Attr's content. | |
| 168 | 0 | return new DOMNodeListImpl(null); |
| 169 | } | |
| 170 | ||
| 171 | /** | |
| 172 | * @todo DOM level 2 getFirstChild() Not implemented. Returns null. | |
| 173 | * @see org.w3c.dom.Node#getFirstChild() | |
| 174 | */ | |
| 175 | 0 | public org.w3c.dom.Node getFirstChild() |
| 176 | { | |
| 177 | 0 | return null; |
| 178 | } | |
| 179 | ||
| 180 | /** | |
| 181 | * @todo DOM level 2 getLastChild() Not implemented. Returns null. | |
| 182 | * @see org.w3c.dom.Node#getLastChild() | |
| 183 | */ | |
| 184 | 0 | public org.w3c.dom.Node getLastChild() |
| 185 | { | |
| 186 | 0 | return null; |
| 187 | } | |
| 188 | ||
| 189 | /** | |
| 190 | * @see org.w3c.dom.Node#getPreviousSibling() | |
| 191 | */ | |
| 192 | 0 | public org.w3c.dom.Node getPreviousSibling() |
| 193 | { | |
| 194 | // Attr.getPreviousSibling() should always return null | |
| 195 | 0 | return null; |
| 196 | } | |
| 197 | ||
| 198 | /** | |
| 199 | * @see org.w3c.dom.Node#getNextSibling() | |
| 200 | */ | |
| 201 | 0 | public org.w3c.dom.Node getNextSibling() |
| 202 | { | |
| 203 | // Attr.getNextSibling() should always return null | |
| 204 | 0 | return null; |
| 205 | } | |
| 206 | ||
| 207 | /** | |
| 208 | * @see org.w3c.dom.Node#getAttributes() | |
| 209 | */ | |
| 210 | 0 | public org.w3c.dom.NamedNodeMap getAttributes() |
| 211 | { | |
| 212 | 0 | return null; |
| 213 | } | |
| 214 | ||
| 215 | /** | |
| 216 | * @todo DOM level 2 getOwnerDocument() Not implemented. Returns null. | |
| 217 | * @see org.w3c.dom.Node#getOwnerDocument() | |
| 218 | */ | |
| 219 | 0 | public org.w3c.dom.Document getOwnerDocument() |
| 220 | { | |
| 221 | 0 | return null; |
| 222 | } | |
| 223 | ||
| 224 | /** | |
| 225 | * Not supported. | |
| 226 | * @see org.w3c.dom.Node#insertBefore(org.w3c.dom.Node, org.w3c.dom.Node) | |
| 227 | */ | |
| 228 | 0 | public org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild) throws DOMException |
| 229 | { | |
| 230 | 0 | throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "Not supported"); |
| 231 | } | |
| 232 | ||
| 233 | /** | |
| 234 | * Not supported. | |
| 235 | * @see org.w3c.dom.Node#replaceChild(org.w3c.dom.Node, org.w3c.dom.Node) | |
| 236 | */ | |
| 237 | 0 | public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild, org.w3c.dom.Node oldChild) throws DOMException |
| 238 | { | |
| 239 | 0 | throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "Not supported"); |
| 240 | } | |
| 241 | ||
| 242 | /** | |
| 243 | * Not supported. | |
| 244 | * @see org.w3c.dom.Node#removeChild(org.w3c.dom.Node) | |
| 245 | */ | |
| 246 | 0 | public org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild) throws DOMException |
| 247 | { | |
| 248 | 0 | throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "Not supported"); |
| 249 | } | |
| 250 | ||
| 251 | /** | |
| 252 | * Not supported. | |
| 253 | * @see org.w3c.dom.Node#appendChild(org.w3c.dom.Node) | |
| 254 | */ | |
| 255 | 0 | public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild) throws DOMException |
| 256 | { | |
| 257 | 0 | throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "Not supported"); |
| 258 | } | |
| 259 | ||
| 260 | /** | |
| 261 | * @see org.w3c.dom.Node#hasChildNodes() | |
| 262 | */ | |
| 263 | 0 | public boolean hasChildNodes() |
| 264 | { | |
| 265 | 0 | return false; |
| 266 | } | |
| 267 | ||
| 268 | /** | |
| 269 | * @see org.w3c.dom.Node#cloneNode(boolean) | |
| 270 | */ | |
| 271 | 0 | public org.w3c.dom.Node cloneNode(boolean deep) |
| 272 | { | |
| 273 | // http://java.sun.com/j2se/1.5.0/docs/api/index.html?org/w3c/dom/Attr.html | |
| 274 | // Cloning an Attr always clones its children, since they represent its value, no matter whether this is a deep | |
| 275 | // clone or not. | |
| 276 | 0 | return (org.w3c.dom.Node) clone(); |
| 277 | } | |
| 278 | ||
| 279 | /** | |
| 280 | * @todo DOM level 2 getOwnerElement() Not implemented. Returns null. | |
| 281 | * @see org.w3c.dom.Attr#getOwnerElement() | |
| 282 | */ | |
| 283 | 0 | public org.w3c.dom.Element getOwnerElement() |
| 284 | { | |
| 285 | 0 | return null; |
| 286 | } | |
| 287 | ||
| 288 | /** | |
| 289 | * @todo DOM level 3 getSchemaTypeInfo() Not implemented. Returns null. | |
| 290 | * @see org.w3c.dom.Attr#getSchemaTypeInfo() | |
| 291 | */ | |
| 292 | 0 | public TypeInfo getSchemaTypeInfo() |
| 293 | { | |
| 294 | 0 | return null; |
| 295 | } | |
| 296 | ||
| 297 | /** | |
| 298 | * @see org.w3c.dom.Attr#isId() | |
| 299 | */ | |
| 300 | 0 | public boolean isId() |
| 301 | { | |
| 302 | 0 | return "id".equals(this.avAdaptee.getAttribute()); |
| 303 | } | |
| 304 | ||
| 305 | /** | |
| 306 | * @see java.lang.Object#clone() | |
| 307 | */ | |
| 308 | 0 | protected Object clone() |
| 309 | { | |
| 310 | 0 | DOMAttrImpl clone; |
| 311 | 0 | try |
| 312 | { | |
| 313 | 0 | clone = (DOMAttrImpl) super.clone(); |
| 314 | } | |
| 315 | catch (CloneNotSupportedException e) | |
| 316 | { | |
| 317 | // should never happen | |
| 318 | 0 | throw new RuntimeException("Clone not supported"); |
| 319 | } | |
| 320 | 0 | clone.avAdaptee = (AttVal) this.avAdaptee.clone(); |
| 321 | 0 | return clone; |
| 322 | } | |
| 323 | } |
|
||||||||||