001: // Copyright (c) 2004 Per M.A. Bothner.
002: // This is free software; for terms and warranty disclaimer see ./COPYING.
003:
004: package gnu.kawa.xml;
005:
006: import gnu.xml.*;
007:
008: /* #ifdef use:org.w3c.dom.Node */
009: // import org.w3c.dom.*;
010: /* #endif */
011:
012: public class KElement extends KNode
013: /* #ifdef use:org.w3c.dom.Node */
014: // implements org.w3c.dom.Element
015: /* #endif */
016: {
017: public KElement(NodeTree seq, int ipos) {
018: super (seq, ipos);
019: }
020:
021: /* #ifdef use:org.w3c.dom.Node */
022: // public short getNodeType () { return Node.ELEMENT_NODE; }
023: /* #endif */
024:
025: public String getTagName() {
026: return sequence.getNextTypeName(ipos);
027: }
028:
029: public String getNodeValue() {
030: return null;
031: }
032:
033: public boolean hasAttributes() {
034: return ((NodeTree) sequence).posHasAttributes(ipos);
035: }
036:
037: public String getAttribute(String name) {
038: if (name == null)
039: name = "";
040: NodeTree nodes = (NodeTree) sequence;
041: int attr = nodes.getAttribute(ipos, null, name);
042: if (attr == 0)
043: return "";
044: else
045: return KNode.getNodeValue(nodes, attr);
046: }
047:
048: /* #ifdef use:org.w3c.dom.Node */
049: // /** Not implemented. */
050: // public void setAttribute (String name, String value)
051: // throws DOMException
052: // {
053: // throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
054: // "setAttribute not supported");
055: // }
056: // /** Not implemented. */
057: // public void setIdAttribute (String name, boolean isId)
058: // throws DOMException
059: // {
060: // throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
061: // "setIdAttribute not supported");
062: // }
063: // /** Not implemented. */
064: // public void setIdAttributeNS (String namespaceURI, String localName,
065: // boolean isId)
066: // throws DOMException
067: // {
068: // throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
069: // "setIdAttributeNS not supported");
070: // }
071: // /** Not implemented. */
072: // public void setIdAttributeNode (Attr idAttr, boolean isId)
073: // throws DOMException
074: // {
075: // throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
076: // "setIdAttributeNode not supported");
077: // }
078: // /** Not implemented. */
079: // public void removeAttribute (String name)
080: // throws DOMException
081: // {
082: // throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
083: // "removeAttribute not supported");
084: // }
085: /* #endif */
086:
087: /* #ifdef JAVA5 */
088: // public KAttr
089: /* #else */
090: /* #ifdef use:org.w3c.dom.Node */
091: // public Attr
092: /* #else */
093: public KAttr
094: /* #endif */
095: /* #endif */
096: getAttributeNode(String name) {
097: if (name == null)
098: name = "";
099: NodeTree nodes = (NodeTree) sequence;
100: int attr = nodes.getAttribute(ipos, null, name);
101: if (attr == 0)
102: return null;
103: else
104: return new KAttr(nodes, attr);
105: }
106:
107: /* #ifdef use:org.w3c.dom.Node */
108: // /** Not implemented. */
109: // public Attr setAttributeNode (Attr newAttr)
110: // throws DOMException
111: // {
112: // throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
113: // "setAttributeNode not supported");
114: // }
115: // /** Not implemented. */
116: // public Attr removeAttributeNode (Attr oldAttr)
117: // throws DOMException
118: // {
119: // throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
120: // "removeAttributeNode not supported");
121: // }
122: /* #endif */
123:
124: public String getAttributeNS(String namespaceURI, String localName) {
125: if (namespaceURI == null)
126: namespaceURI = "";
127: if (localName == null)
128: localName = "";
129: NodeTree nodes = (NodeTree) sequence;
130: int attr = nodes.getAttribute(ipos, namespaceURI, localName);
131: if (attr == 0)
132: return "";
133: else
134: return getNodeValue(nodes, attr);
135: }
136:
137: /* #ifdef use:org.w3c.dom.Node */
138: // /** Not implemented. */
139: // public void setAttributeNS (String namespaceURI, String qualifiedName,
140: // String value) throws DOMException
141: // {
142: // throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
143: // "setAttributeNS not supported");
144: // }
145: /* #endif */
146:
147: /* #ifdef use:org.w3c.dom.Node */
148: // /** Not implemented. */
149: // public void removeAttributeNS (String namespaceURI, String localName)
150: // throws DOMException
151: // {
152: // throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
153: // "removeAttributeNS not supported");
154: // }
155: /* #endif */
156:
157: /* #ifdef JAVA5 */
158: // public KAttr
159: /* #else */
160: /* #ifdef use:org.w3c.dom.Node */
161: // public Attr
162: /* #else */
163: public KAttr
164: /* #endif */
165: /* #endif */
166: getAttributeNodeNS(String namespaceURI, String localName) {
167: if (namespaceURI == null)
168: namespaceURI = "";
169: if (localName == null)
170: localName = "";
171: NodeTree nodes = (NodeTree) sequence;
172: int attr = nodes.getAttribute(ipos, namespaceURI, localName);
173: if (attr == 0)
174: return null;
175: else
176: return new KAttr(nodes, attr);
177: }
178:
179: /** Not implemented. */
180: /* #ifdef use:org.w3c.dom.Node */
181: // public Attr setAttributeNodeNS (Attr newAttr)
182: // throws DOMException
183: // {
184: // throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
185: // "setAttributeNodeNS not supported");
186: // }
187: /* #endif */
188:
189: // Not implemented yet.
190: /* #ifdef use:org.w3c.dom.Node */
191: // public NodeList getElementsByTagNameNS(String namespaceURI, String localName)
192: // {
193: // throw new UnsupportedOperationException("getElementsByTagNameNS not implemented yet");
194: // }
195: /* #endif */
196:
197: /** Not implemented yet. */
198: public boolean hasAttribute(String name) {
199: int attr = ((NodeTree) sequence).getAttribute(ipos, null,
200: name == null ? "" : name);
201: return attr != 0;
202: }
203:
204: public boolean hasAttributeNS(String namespaceURI, String localName) {
205: if (namespaceURI == null)
206: namespaceURI = "";
207: if (localName == null)
208: localName = "";
209: int attr = ((NodeTree) sequence).getAttribute(ipos,
210: namespaceURI, localName);
211: return attr != 0;
212: }
213:
214: /* #ifdef JAXP-1.3 */
215: // public TypeInfo getSchemaTypeInfo ()
216: // {
217: // return null;
218: // }
219: /* #endif JAXP-1.3 */
220: }
|