1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _XMLDOCUMENTWRAPPER_XMLSECIMPL_HXX 25 #define _XMLDOCUMENTWRAPPER_XMLSECIMPL_HXX 26 27 #include <com/sun/star/xml/wrapper/XXMLDocumentWrapper.hpp> 28 #include <com/sun/star/xml/csax/XCompressedDocumentHandler.hpp> 29 #include <com/sun/star/xml/crypto/sax/XSAXEventKeeper.hpp> 30 #include <com/sun/star/lang/XServiceInfo.hpp> 31 #include <cppuhelper/implbase4.hxx> 32 33 #include "saxhelper.hxx" 34 //#include "libxml/parserInternals.h" 35 //#include "libxslt/xslt.h" 36 37 #define NODEPOSITION_NORMAL 1 38 #define NODEPOSITION_STARTELEMENT 2 39 #define NODEPOSITION_ENDELEMENT 3 40 41 #include <libxml/tree.h> 42 43 class XMLDocumentWrapper_XmlSecImpl : public cppu::WeakImplHelper4 44 < 45 com::sun::star::xml::wrapper::XXMLDocumentWrapper, 46 com::sun::star::xml::sax::XDocumentHandler, 47 com::sun::star::xml::csax::XCompressedDocumentHandler, 48 com::sun::star::lang::XServiceInfo 49 > 50 /****** XMLDocumentWrapper_XmlSecImpl.hxx/CLASS XMLDocumentWrapper_XmlSecImpl * 51 * 52 * NAME 53 * XMLDocumentWrapper_XmlSecImpl -- Class to manipulate a libxml2 54 * document 55 * 56 * FUNCTION 57 * Converts SAX events into a libxml2 document, converts the document back 58 * into SAX event stream, and manipulate nodes in the document. 59 * 60 * HISTORY 61 * 05.01.2004 - Interface supported: XXMLDocumentWrapper, 62 * XDocumentHandler, XCompressedDocumentHandler, 63 * XServiceInfo 64 * 65 * AUTHOR 66 * Michael Mi 67 * Email: michael.mi@sun.com 68 ******************************************************************************/ 69 { 70 private: 71 /* the sax helper */ 72 SAXHelper saxHelper; 73 74 /* the document used to convert SAX events to */ 75 xmlDocPtr m_pDocument; 76 77 /* the root element */ 78 xmlNodePtr m_pRootElement; 79 80 /* 81 * the current active element. The next incoming SAX event will be 82 * appended to this element 83 */ 84 xmlNodePtr m_pCurrentElement; 85 86 /* 87 * This variable is used when converting the document or part of it into 88 * SAX events. See getNextSAXEvent method. 89 */ 90 sal_Int32 m_nCurrentPosition; 91 92 /* 93 * used for recursive deletion. See recursiveDelete method 94 */ 95 xmlNodePtr m_pStopAtNode; 96 xmlNodePtr m_pCurrentReservedNode; 97 com::sun::star::uno::Sequence< com::sun::star::uno::Reference< 98 com::sun::star::xml::wrapper::XXMLElementWrapper > > m_aReservedNodes; 99 sal_Int32 m_nReservedNodeIndex; 100 101 private: 102 void getNextSAXEvent(); 103 104 void sendStartElement( 105 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xHandler, 106 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xHandler2, 107 const xmlNodePtr pNode) const; 108 109 void sendEndElement( 110 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xHandler, 111 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xHandler2, 112 const xmlNodePtr pNode) const; 113 114 void sendNode( 115 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xHandler, 116 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xHandler2, 117 const xmlNodePtr pNode) const; 118 119 rtl::OString getNodeQName(const xmlNodePtr pNode) const; 120 121 sal_Int32 recursiveDelete( const xmlNodePtr pNode); 122 123 void getNextReservedNode(); 124 125 void removeNode( const xmlNodePtr pNode) const; 126 127 xmlNodePtr checkElement( 128 const com::sun::star::uno::Reference< 129 com::sun::star::xml::wrapper::XXMLElementWrapper >& xXMLElement) const; 130 131 void buildIDAttr( xmlNodePtr pNode ) const; 132 void rebuildIDLink( xmlNodePtr pNode ) const; 133 134 public: 135 XMLDocumentWrapper_XmlSecImpl(); 136 virtual ~XMLDocumentWrapper_XmlSecImpl(); 137 138 /* com::sun::star::xml::wrapper::XXMLDocumentWrapper */ 139 virtual com::sun::star::uno::Reference< 140 com::sun::star::xml::wrapper::XXMLElementWrapper > SAL_CALL getCurrentElement( ); 141 142 virtual void SAL_CALL setCurrentElement( const com::sun::star::uno::Reference< 143 com::sun::star::xml::wrapper::XXMLElementWrapper >& element ); 144 145 virtual void SAL_CALL removeCurrentElement( ); 146 147 virtual sal_Bool SAL_CALL isCurrent( const com::sun::star::uno::Reference< 148 com::sun::star::xml::wrapper::XXMLElementWrapper >& node ); 149 150 virtual sal_Bool SAL_CALL isCurrentElementEmpty( ); 151 152 virtual rtl::OUString SAL_CALL getNodeName( const com::sun::star::uno::Reference< 153 com::sun::star::xml::wrapper::XXMLElementWrapper >& node ); 154 155 virtual void SAL_CALL clearUselessData( 156 const com::sun::star::uno::Reference< 157 com::sun::star::xml::wrapper::XXMLElementWrapper >& node, 158 const com::sun::star::uno::Sequence< com::sun::star::uno::Reference< 159 com::sun::star::xml::wrapper::XXMLElementWrapper > >& reservedDescendants, 160 const com::sun::star::uno::Reference< 161 com::sun::star::xml::wrapper::XXMLElementWrapper >& stopAtNode ); 162 163 virtual void SAL_CALL collapse( const com::sun::star::uno::Reference< 164 com::sun::star::xml::wrapper::XXMLElementWrapper >& node ); 165 166 virtual void SAL_CALL generateSAXEvents( 167 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& handler, 168 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xEventKeeperHandler, 169 const com::sun::star::uno::Reference< 170 com::sun::star::xml::wrapper::XXMLElementWrapper >& startNode, 171 const com::sun::star::uno::Reference< 172 com::sun::star::xml::wrapper::XXMLElementWrapper >& endNode ); 173 174 virtual void SAL_CALL getTree( 175 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& handler ); 176 177 virtual void SAL_CALL rebuildIDLink( 178 const com::sun::star::uno::Reference< com::sun::star::xml::wrapper::XXMLElementWrapper >& node ); 179 180 /* com::sun::star::xml::sax::XDocumentHandler */ 181 virtual void SAL_CALL startDocument( ); 182 183 virtual void SAL_CALL endDocument( ); 184 185 virtual void SAL_CALL startElement( 186 const rtl::OUString& aName, 187 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttribs ); 188 189 virtual void SAL_CALL endElement( const rtl::OUString& aName ); 190 191 virtual void SAL_CALL characters( const rtl::OUString& aChars ); 192 193 virtual void SAL_CALL ignorableWhitespace( const rtl::OUString& aWhitespaces ); 194 195 virtual void SAL_CALL processingInstruction( const rtl::OUString& aTarget, const rtl::OUString& aData ); 196 197 virtual void SAL_CALL setDocumentLocator( const com::sun::star::uno::Reference< com::sun::star::xml::sax::XLocator >& xLocator ); 198 199 /* com::sun::star::xml::csax::XCompressedDocumentHandler */ 200 virtual void SAL_CALL _startDocument( ); 201 202 virtual void SAL_CALL _endDocument( ); 203 204 virtual void SAL_CALL _startElement( 205 const rtl::OUString& aName, 206 const com::sun::star::uno::Sequence< 207 com::sun::star::xml::csax::XMLAttribute >& aAttributes ); 208 209 virtual void SAL_CALL _endElement( const rtl::OUString& aName ); 210 211 virtual void SAL_CALL _characters( const rtl::OUString& aChars ); 212 213 virtual void SAL_CALL _ignorableWhitespace( const rtl::OUString& aWhitespaces ); 214 215 virtual void SAL_CALL _processingInstruction( const rtl::OUString& aTarget, const rtl::OUString& aData ); 216 217 virtual void SAL_CALL _setDocumentLocator( 218 sal_Int32 columnNumber, 219 sal_Int32 lineNumber, 220 const rtl::OUString& publicId, 221 const rtl::OUString& systemId ); 222 223 /* com::sun::star::lang::XServiceInfo */ 224 virtual rtl::OUString SAL_CALL getImplementationName( ); 225 226 virtual sal_Bool SAL_CALL supportsService( const rtl::OUString& ServiceName ); 227 228 virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames( ); 229 }; 230 231 rtl::OUString XMLDocumentWrapper_XmlSecImpl_getImplementationName(); 232 233 sal_Bool SAL_CALL XMLDocumentWrapper_XmlSecImpl_supportsService( const rtl::OUString& ServiceName ); 234 235 com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL 236 XMLDocumentWrapper_XmlSecImpl_getSupportedServiceNames( ); 237 238 com::sun::star::uno::Reference< com::sun::star::uno::XInterface > 239 SAL_CALL XMLDocumentWrapper_XmlSecImpl_createInstance( 240 const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > & rSMgr); 241 242 #endif 243