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 _DOMEXPATAGENT_ 17 #define _DOMEXPATAGENT_ 18 19 #include <Drm2CommonTypes.h> 20 #include <ofstream.h> 21 #include <sostream.h> 22 #include <ustring.h> 23 #include <sistream.h> 24 #include <util/domcore/NodeImpl.h> 25 #include <util/domcore/DOMString.h> 26 #include "ExpatWrapper.h" 27 #include "XMLElementImpl.h" 28 #include "XMLDocumentImpl.h" 29 using namespace ustl; 30 31 class DomExpatAgent : public ExpatWrapper { 32 public: 33 /** 34 * Constructor for DomExpatAgent. 35 * @param xmlDocPtr XMLDocument pointer. 36 */ 37 DomExpatAgent(XMLDocumentImpl* xmlDocPtr); 38 39 /** Destructor for DomExpatAgent. */ 40 ~DomExpatAgent(); 41 42 /** 43 * Generate XML DOM Document from XML source. 44 * @param <code>xmlStream</code> the XML source stream. 45 * @return ture or false to indicate whether generate successfully. 46 */ 47 bool generateDocumentFromXML(istringstream *xmlStream); 48 49 /** 50 * Generate XML stream from XML DOM document. 51 * @return xml stream. 52 */ 53 ostringstream* generateXMLFromDocument(); 54 55 /** 56 * deal with start element in Expat. 57 */ 58 virtual void startElement(const XML_Char *name, 59 const XML_Char **atts); 60 61 /** 62 * deal with end element for Expat. 63 */ 64 virtual void endElement(const XML_Char *name); 65 66 /** 67 * deal with data handler for Expat. 68 */ 69 virtual void dataHandler(const XML_Char *s, int len); 70 71 PRIVATE: 72 /** 73 * Push a xml element with the specific tag name into stack. 74 * @param name The name of tag. 75 * @param atts The attributes of related tag. 76 */ 77 void pushTag(const DOMString *name, const XML_Char **atts); 78 79 /** 80 * Append text into top element of stack. 81 * @param text The data related to the present tag. 82 */ 83 void appendText(const DOMString *text); 84 85 /** 86 * Pop the xml element with the specific tag name. 87 * @param name The name of tag. 88 */ 89 void popTag(const DOMString *name); 90 91 /** 92 * Traverse the XML DOM document starting from specific element. 93 * @param root The specific element start to traverse. 94 */ 95 void traverse(ElementImpl *root); 96 97 PRIVATE: 98 vector<NodeImpl*> mStack; /**< the stack to manage the tag. */ 99 XMLElementImpl* mTopElementPtr; /**< the top element of the stack. */ 100 XMLDocumentImpl* mXMLDocumentPtr; /**< XML DOM document pointer. */ 101 ostringstream mXMLostream; /**< xml output stream. */ 102 }; 103 104 #endif 105