1 /* 2 * Copyright (C) 2007 The Android Open Source Project 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 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #ifndef _XMLELEMENTIMPL_H_ 17 #define _XMLELEMENTIMPL_H_ 18 19 #include <Drm2CommonTypes.h> 20 #include <util/domcore/ElementImpl.h> 21 #include <util/domcore/DOMString.h> 22 #include <umap.h> 23 #include <ustring.h> 24 using namespace ustl; 25 26 typedef map<DOMString, DOMString> DOMStringMap; 27 28 class XMLElementImpl : public ElementImpl { 29 public: 30 /** 31 * Constructor for XMLElementImpl. 32 * @param tag The name of the tag. 33 */ 34 XMLElementImpl(const DOMString *tag); 35 36 /** Destructor for XMLElementImpl. */ 37 ~XMLElementImpl(); 38 39 /** 40 * Get the attribute map of the XML element. 41 * @return <code>DOMStringMap</code> 42 */ 43 const DOMStringMap* getAttributeMap() const; 44 45 /** 46 * Get the tag name of the element. 47 * return tag name. 48 */ 49 virtual const DOMString* getTagName() const; 50 51 /** 52 * Set the attribute of the element. 53 * @param name The key of the attribute. 54 * @param value The value of the attribute. 55 */ 56 virtual void setAttribute(const DOMString* name, const DOMString* value) throw (DOMException); 57 58 /** 59 * Remove the specific attribute. 60 * @param name The key of the attribute. 61 * @exception DOMException. 62 */ 63 virtual void removeAttribute(const DOMString* name) throw (DOMException); 64 65 /** 66 * Get the specific attribute. 67 * @param name The key of the attribute. 68 * @return the value of the attribute. 69 */ 70 virtual const DOMString* getAttribute(const DOMString* name) const; 71 72 /** 73 * Detect whether element has attributes or not. 74 * @return true or false to indicate the result. 75 */ 76 virtual bool hasAttributes() const; 77 78 /** 79 * Find the first child node in element by its tag name. 80 * @param element the specific element to be found. 81 * @param tag the specific tag name to be searched. 82 * @return NULL if not found otherwise the child node. 83 */ 84 const NodeImpl* findSoloChildNode(const char* tag) const; 85 86 /** 87 * Get the first text containted in first child of the element. 88 * @param tag the specific tag name to be searched. 89 * @return NULL if not found otherwise the text. 90 */ 91 const string* getSoloText(const char* tag) const; 92 93 /** 94 * Get the first child xml element containted in the element. 95 * @param tag the specific tag name to be searched. 96 * @return NULL if not found otherwise the element. 97 */ 98 const XMLElementImpl* getSoloElement(const char* tag) const; 99 100 PRIVATE: 101 DOMString mTagName; /**< The tag name. */ 102 DOMStringMap mAttributeMap; /** The map of attributes. */ 103 }; 104 105 #endif 106