1 /*
2 * Copyright (c) 2002-2008 Gargoyle Software Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 package com.gargoylesoftware.htmlunit.xml;
16
17 import java.util.Map;
18
19 import org.w3c.dom.Attr;
20 import org.w3c.dom.DOMException;
21 import org.w3c.dom.Element;
22 import org.w3c.dom.TypeInfo;
23
24 import com.gargoylesoftware.htmlunit.Page;
25 import com.gargoylesoftware.htmlunit.html.DomNamespaceNode;
26 import com.gargoylesoftware.htmlunit.html.DomNode;
27
28 /**
29 * An attribute of an element. Attributes are stored in {@link XmlElement},
30 * but the XPath engine expects attributes to be in a {@link DomNode}.
31 *
32 * @version $Revision: 3163 $
33 * @author Ahmed Ashour
34 * @author Sudhan Moghe
35 * @deprecated As of 2.2, no more used, please use {@link XmlDomAttr} instead.
36 */
37 @Deprecated
38 public class XmlAttr extends DomNamespaceNode implements Attr {
39
40 private static final long serialVersionUID = 4832218455328064213L;
41
42 private String value_;
43
44 /**
45 * Instantiates a new attribute.
46 *
47 * @param xmlElement the parent element
48 * @param mapEntry the wrapped map entry
49 * @deprecated Use constructor with explicit names.
50 */
51 @Deprecated
52 public XmlAttr(final XmlElement xmlElement, final Map.Entry<String, String> mapEntry) {
53 super(null, mapEntry.getKey(), xmlElement.getPage());
54 value_ = mapEntry.getValue();
55 setParentNode(xmlElement);
56 }
57
58 /**
59 * Instantiates a new attribute.
60 *
61 * @param page the page that the attribute belongs to
62 * @param namespaceURI the namespace that defines the attribute name (may be <tt>null</tt>)
63 * @param qualifiedName the name of the attribute
64 * @param value the value of the attribute
65 */
66 public XmlAttr(final Page page, final String namespaceURI, final String qualifiedName, final String value) {
67 super(namespaceURI, qualifiedName, page);
68 value_ = value;
69 }
70
71 /**
72 * {@inheritDoc}
73 */
74 @Override
75 public short getNodeType() {
76 return org.w3c.dom.Node.ATTRIBUTE_NODE;
77 }
78
79 /**
80 * {@inheritDoc}
81 */
82 @Override
83 public String getNodeName() {
84 return getName();
85 }
86
87 /**
88 * {@inheritDoc}
89 */
90 @Override
91 public String getNodeValue() {
92 return getValue();
93 }
94
95 /**
96 * @return the qualified name of the attribute
97 */
98 public String getName() {
99 return getQualifiedName();
100 }
101
102 /**
103 * @return the value of the attribute
104 */
105 public String getValue() {
106 return value_;
107 }
108
109 /**
110 * {@inheritDoc}
111 */
112 public void setValue(final String value) throws DOMException {
113 value_ = value;
114 }
115
116 /**
117 * Sets the parent node.
118 * @param parent the parent node
119 */
120 @Override
121 public void setParentNode(final DomNode parent) {
122 super.setParentNode(parent);
123 }
124
125 /**
126 * {@inheritDoc}
127 * Not yet implemented.
128 */
129 public Element getOwnerElement() {
130 return (Element) getParentNode();
131 }
132
133 /**
134 * {@inheritDoc}
135 * Not yet implemented.
136 */
137 public TypeInfo getSchemaTypeInfo() {
138 throw new UnsupportedOperationException("XmlAttr.getSchemaTypeInfo is not yet implemented.");
139 }
140
141 /**
142 * {@inheritDoc}
143 */
144 public boolean getSpecified() {
145 return true;
146 }
147
148 /**
149 * {@inheritDoc}
150 */
151 public boolean isId() {
152 return "id".equals(getNodeName());
153 }
154 }