FDO API Reference | Feature Data Objects |
00001 #ifndef FDO_XML_COPYHANDLER_H 00002 #define FDO_XML_COPYHANDLER_H 00003 // 00004 00005 // 00006 // Copyright (C) 2004-2006 Autodesk, Inc. 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of version 2.1 of the GNU Lesser 00010 // General Public License as published by the Free Software Foundation. 00011 // 00012 // This library is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 // Lesser General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU Lesser General Public 00018 // License along with this library; if not, write to the Free Software 00019 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00020 // 00021 00022 #ifdef _WIN32 00023 #pragma once 00024 #endif 00025 00026 /// \brief 00027 /// FdoXmlCopyHandler can be used to copy a set of elements from one XML 00028 /// document to another. It can be created and set as the SAX Handler for an XML Reader 00029 /// on the document to copy from. An XML Writer to the document to copy to is 00030 /// passed to one of the Create methods below. The elements to copy will be inserted 00031 /// at the XML writer's current position. 00032 class FdoXmlCopyHandler : 00033 public FdoDisposable, 00034 public FdoXmlSaxHandler 00035 { 00036 public: 00037 /// \brief 00038 /// Constructs a Copy Handler. When attached (as the SAX Handler) to 00039 /// a FdoXmlReader, this object copies all sub-elements of the current element 00040 /// being parsed. 00041 /// 00042 /// \param writer 00043 /// Input the sub-elements are written to this XML writer. 00044 /// 00045 /// \return 00046 /// Returns FdoXmlCopyHandler 00047 /// 00048 FDO_API_COMMON static FdoXmlCopyHandler* Create( FdoXmlWriter* writer ) 00049 { 00050 return new FdoXmlCopyHandler( writer ); 00051 } 00052 00053 /// \brief 00054 /// Constructs a Copy Handler. When attached (as the SAX Handler) to 00055 /// a FdoXmlReader, this object copies the current element 00056 /// being parsed, plus all of its sub-elements. 00057 /// 00058 /// \param writer 00059 /// Input the sub-elements are written to this XML writer. 00060 /// \param uri 00061 /// Input current element's Universal Resource Indicator 00062 /// \param name 00063 /// Input the unqualified name of the current element (doesn't include namespace) 00064 /// \param qname 00065 /// Input the qualified name of the current element(includes namespace) 00066 /// \param atts 00067 /// Input the attributes for the current element. 00068 /// \warning 00069 /// If the current element will become the root element in the destination 00070 /// document, the caller is responsible for including all required xmlns: namespace 00071 /// declarations in the atts list. 00072 /// \param namespaces 00073 /// Input list of XML namespace declarations to write to the 00074 /// destination document. 00075 /// 00076 /// \return 00077 /// Returns FdoXmlCopyHandler 00078 /// 00079 FDO_API_COMMON static FdoXmlCopyHandler* Create( 00080 FdoXmlWriter* writer, 00081 FdoString* uri, 00082 FdoString* name, 00083 FdoString* qName, 00084 FdoXmlAttributeCollection* atts, 00085 FdoDictionary* namespaces = NULL 00086 ) 00087 { 00088 return new FdoXmlCopyHandler( writer, uri, name, qName, atts, namespaces ); 00089 } 00090 00091 protected: 00092 /// \cond DOXYGEN-IGNORE 00093 FdoXmlCopyHandler() {} 00094 /// \endcond 00095 00096 FDO_API_COMMON FdoXmlCopyHandler( FdoXmlWriter* writer ); 00097 00098 FDO_API_COMMON FdoXmlCopyHandler( 00099 FdoXmlWriter* writer, 00100 FdoString* uri, 00101 FdoString* name, 00102 FdoString* qName, 00103 FdoXmlAttributeCollection* atts, 00104 FdoDictionary* namespaces = NULL 00105 ); 00106 00107 FDO_API_COMMON virtual ~FdoXmlCopyHandler(); 00108 00109 /// \cond DOXYGEN-IGNORE 00110 void SetWriter( FdoXmlWriter* writer ); 00111 00112 /// General function for writing start of an element. 00113 /// Handles namespace translation, of the element name, 00114 /// between the source and destination documents. 00115 00116 void WriteStartElement( 00117 FdoString* uri , 00118 FdoString* name, 00119 FdoString* qName, 00120 FdoXmlAttributeCollection* atts 00121 ); 00122 00123 /// writes the given set of XML namespaces to the output document 00124 void WriteNamespaces( FdoDictionary* namespaces ); 00125 00126 /// handles an attribute qualified by namespace. Adds namespace declaration 00127 /// to output document if not already there. 00128 FdoStringP HandleQAtt(FdoStringP uri, FdoStringP localName, FdoStringP prefix, FdoStringP QName ); 00129 00130 00131 /// SAX handlers to catch and copy various XML fragments. 00132 00133 FDO_API_COMMON virtual FdoXmlSaxHandler* XmlStartElement(FdoXmlSaxContext*, FdoString*, FdoString* name, FdoString*, FdoXmlAttributeCollection*); 00134 FDO_API_COMMON virtual FdoBoolean XmlEndElement(FdoXmlSaxContext*, FdoString*, FdoString*, FdoString* qName); 00135 FDO_API_COMMON virtual void XmlCharacters(FdoXmlSaxContext*, FdoString*); 00136 00137 /// \endcond 00138 00139 /// \brief 00140 /// This function is called before each attribute is copied to the 00141 /// destination document. It determines whether the attribute value 00142 /// references a qualified XML element name. If it does, then the 00143 /// namespace prefix for the value is converted to the equivalent prefix 00144 /// in the destination document. 00145 /// 00146 /// \param uri 00147 /// Input the namespace URI for attribute's containing element. 00148 /// \param name 00149 /// Input the local name for attribute's containing element. 00150 /// \param qname 00151 /// Input the fully qualified name from attribute's containing element. 00152 /// \param att 00153 /// Input the attribute to check. 00154 /// 00155 /// \return 00156 /// returns true if the attribute value is a qualified XML element name. 00157 /// This default implementation returns true only if the containing element 00158 /// is in the XML Schema namespace and the attribute name is one of 00159 /// ("base","type","ref"). Classes derived from FdoXmlCopyHandler 00160 /// can override this virtual function to change this behaviour. 00161 /// 00162 FDO_API_COMMON virtual FdoBoolean AttHasNs( 00163 FdoString* uri, 00164 FdoString* name, 00165 FdoString* qName, 00166 FdoXmlAttribute* att 00167 ); 00168 00169 private: 00170 FdoXmlWriterP mWriter; 00171 FdoBoolean mWroteCurrElement; 00172 }; 00173 00174 00175 /// \brief 00176 /// FdoXmlCopyHandlerP is a FdoPtr on FdoXmlCopyHandler, provided for convenience. 00177 typedef FdoPtr<FdoXmlCopyHandler> FdoXmlCopyHandlerP; 00178 00179 #endif 00180 00181
Comments or suggestions? Send us feedback. |