1/*
2 * Copyright (C) 2007 Esmertec AG.
3 * Copyright (C) 2007 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package com.android.mms.dom;
19
20import org.w3c.dom.Attr;
21import org.w3c.dom.DOMException;
22import org.w3c.dom.Element;
23import org.w3c.dom.NamedNodeMap;
24import org.w3c.dom.NodeList;
25import org.w3c.dom.TypeInfo;
26
27public class ElementImpl extends NodeImpl implements Element {
28    private String mTagName;
29    private NamedNodeMap mAttributes = new NamedNodeMapImpl();
30
31    /*
32     * Internal methods
33     */
34
35    protected ElementImpl(DocumentImpl owner, String tagName) {
36        super(owner);
37        mTagName = tagName;
38    }
39
40    /*
41     *  Element Interface methods
42     */
43
44    public String getAttribute(String name) {
45        Attr attrNode = getAttributeNode(name);
46        String attrValue = "";
47        if (attrNode != null) {
48            attrValue = attrNode.getValue();
49        }
50        return attrValue;
51    }
52
53    public String getAttributeNS(String namespaceURI, String localName) {
54        // TODO Auto-generated method stub
55        return null;
56    }
57
58    public Attr getAttributeNode(String name) {
59        return (Attr)mAttributes.getNamedItem(name);
60    }
61
62    public Attr getAttributeNodeNS(String namespaceURI, String localName) {
63        // TODO Auto-generated method stub
64        return null;
65    }
66
67    public NodeList getElementsByTagName(String name) {
68        return new NodeListImpl(this, name, true);
69    }
70
71    public NodeList getElementsByTagNameNS(String namespaceURI, String localName) {
72        // TODO Auto-generated method stub
73        return null;
74    }
75
76    public String getTagName() {
77        return mTagName;
78    }
79
80    public boolean hasAttribute(String name) {
81        return (getAttributeNode(name) != null);
82    }
83
84    public boolean hasAttributeNS(String namespaceURI, String localName) {
85        // TODO Auto-generated method stub
86        return false;
87    }
88
89    public void removeAttribute(String name) throws DOMException {
90        // TODO Auto-generated method stub
91
92    }
93
94    public void removeAttributeNS(String namespaceURI, String localName)
95            throws DOMException {
96        // TODO Auto-generated method stub
97
98    }
99
100    public Attr removeAttributeNode(Attr oldAttr) throws DOMException {
101        // TODO Auto-generated method stub
102        return null;
103    }
104
105    public void setAttribute(String name, String value) throws DOMException {
106        Attr attribute = getAttributeNode(name);
107        if (attribute == null) {
108            attribute = mOwnerDocument.createAttribute(name);
109        }
110        attribute.setNodeValue(value);
111        mAttributes.setNamedItem(attribute);
112    }
113
114    public void setAttributeNS(String namespaceURI, String qualifiedName,
115            String value) throws DOMException {
116        // TODO Auto-generated method stub
117
118    }
119
120    public Attr setAttributeNode(Attr newAttr) throws DOMException {
121        // TODO Auto-generated method stub
122        return null;
123    }
124
125    public Attr setAttributeNodeNS(Attr newAttr) throws DOMException {
126        // TODO Auto-generated method stub
127        return null;
128    }
129
130    /*
131     * Node Interface methods
132     */
133
134    @Override
135    public short getNodeType() {
136        return ELEMENT_NODE;
137    }
138
139    @Override
140    public String getNodeName() {
141        // The value of nodeName is tagName when Node is an Element
142        return mTagName;
143    }
144
145    @Override
146    public NamedNodeMap getAttributes() {
147        return mAttributes;
148    }
149
150    @Override
151    public boolean hasAttributes() {
152        return (mAttributes.getLength() > 0);
153    }
154
155    public TypeInfo getSchemaTypeInfo() {
156        return null;
157    }
158
159    public void setIdAttribute(String name, boolean isId) throws DOMException {
160        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, null);
161    }
162
163    public void setIdAttributeNS(String namespaceURI, String localName,
164            boolean isId) throws DOMException {
165        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, null);
166    }
167
168    public void setIdAttributeNode(Attr idAttr, boolean isId)
169            throws DOMException {
170        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, null);
171    }
172}
173