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 18 package com.android.mms.dom; 19 20 import org.w3c.dom.Attr; 21 import org.w3c.dom.DOMException; 22 import org.w3c.dom.Element; 23 import org.w3c.dom.NamedNodeMap; 24 import org.w3c.dom.NodeList; 25 26 public class ElementImpl extends NodeImpl implements Element { 27 private String mTagName; 28 private NamedNodeMap mAttributes = new NamedNodeMapImpl(); 29 30 /* 31 * Internal methods 32 */ 33 ElementImpl(DocumentImpl owner, String tagName)34 protected ElementImpl(DocumentImpl owner, String tagName) { 35 super(owner); 36 mTagName = tagName; 37 } 38 39 /* 40 * Element Interface methods 41 */ 42 getAttribute(String name)43 public String getAttribute(String name) { 44 Attr attrNode = getAttributeNode(name); 45 String attrValue = ""; 46 if (attrNode != null) { 47 attrValue = attrNode.getValue(); 48 } 49 return attrValue; 50 } 51 getAttributeNS(String namespaceURI, String localName)52 public String getAttributeNS(String namespaceURI, String localName) { 53 // TODO Auto-generated method stub 54 return null; 55 } 56 getAttributeNode(String name)57 public Attr getAttributeNode(String name) { 58 return (Attr)mAttributes.getNamedItem(name); 59 } 60 getAttributeNodeNS(String namespaceURI, String localName)61 public Attr getAttributeNodeNS(String namespaceURI, String localName) { 62 // TODO Auto-generated method stub 63 return null; 64 } 65 getElementsByTagName(String name)66 public NodeList getElementsByTagName(String name) { 67 return new NodeListImpl(this, name, true); 68 } 69 getElementsByTagNameNS(String namespaceURI, String localName)70 public NodeList getElementsByTagNameNS(String namespaceURI, String localName) { 71 // TODO Auto-generated method stub 72 return null; 73 } 74 getTagName()75 public String getTagName() { 76 return mTagName; 77 } 78 hasAttribute(String name)79 public boolean hasAttribute(String name) { 80 return (getAttributeNode(name) != null); 81 } 82 hasAttributeNS(String namespaceURI, String localName)83 public boolean hasAttributeNS(String namespaceURI, String localName) { 84 // TODO Auto-generated method stub 85 return false; 86 } 87 removeAttribute(String name)88 public void removeAttribute(String name) throws DOMException { 89 // TODO Auto-generated method stub 90 91 } 92 removeAttributeNS(String namespaceURI, String localName)93 public void removeAttributeNS(String namespaceURI, String localName) 94 throws DOMException { 95 // TODO Auto-generated method stub 96 97 } 98 removeAttributeNode(Attr oldAttr)99 public Attr removeAttributeNode(Attr oldAttr) throws DOMException { 100 // TODO Auto-generated method stub 101 return null; 102 } 103 setAttribute(String name, String value)104 public void setAttribute(String name, String value) throws DOMException { 105 Attr attribute = getAttributeNode(name); 106 if (attribute == null) { 107 attribute = mOwnerDocument.createAttribute(name); 108 } 109 attribute.setNodeValue(value); 110 mAttributes.setNamedItem(attribute); 111 } 112 setAttributeNS(String namespaceURI, String qualifiedName, String value)113 public void setAttributeNS(String namespaceURI, String qualifiedName, 114 String value) throws DOMException { 115 // TODO Auto-generated method stub 116 117 } 118 setAttributeNode(Attr newAttr)119 public Attr setAttributeNode(Attr newAttr) throws DOMException { 120 // TODO Auto-generated method stub 121 return null; 122 } 123 setAttributeNodeNS(Attr newAttr)124 public Attr setAttributeNodeNS(Attr newAttr) throws DOMException { 125 // TODO Auto-generated method stub 126 return null; 127 } 128 129 /* 130 * Node Interface methods 131 */ 132 133 @Override getNodeType()134 public short getNodeType() { 135 return ELEMENT_NODE; 136 } 137 138 @Override getNodeName()139 public String getNodeName() { 140 // The value of nodeName is tagName when Node is an Element 141 return mTagName; 142 } 143 144 @Override getAttributes()145 public NamedNodeMap getAttributes() { 146 return mAttributes; 147 } 148 149 @Override hasAttributes()150 public boolean hasAttributes() { 151 return (mAttributes.getLength() > 0); 152 } 153 } 154