1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _XMLDOCUMENTWRAPPER_XMLSECIMPL_HXX 29 #define _XMLDOCUMENTWRAPPER_XMLSECIMPL_HXX 30 31 #include <com/sun/star/xml/wrapper/XXMLDocumentWrapper.hpp> 32 #include <com/sun/star/xml/csax/XCompressedDocumentHandler.hpp> 33 #include <com/sun/star/xml/crypto/sax/XSAXEventKeeper.hpp> 34 #include <com/sun/star/lang/XServiceInfo.hpp> 35 #include <cppuhelper/implbase4.hxx> 36 37 #include "saxhelper.hxx" 38 //#include "libxml/parserInternals.h" 39 //#include "libxslt/xslt.h" 40 41 #define NODEPOSITION_NORMAL 1 42 #define NODEPOSITION_STARTELEMENT 2 43 #define NODEPOSITION_ENDELEMENT 3 44 45 #include <libxml/tree.h> 46 47 class XMLDocumentWrapper_XmlSecImpl : public cppu::WeakImplHelper4 48 < 49 com::sun::star::xml::wrapper::XXMLDocumentWrapper, 50 com::sun::star::xml::sax::XDocumentHandler, 51 com::sun::star::xml::csax::XCompressedDocumentHandler, 52 com::sun::star::lang::XServiceInfo 53 > 54 /****** XMLDocumentWrapper_XmlSecImpl.hxx/CLASS XMLDocumentWrapper_XmlSecImpl * 55 * 56 * NAME 57 * XMLDocumentWrapper_XmlSecImpl -- Class to manipulate a libxml2 58 * document 59 * 60 * FUNCTION 61 * Converts SAX events into a libxml2 document, converts the document back 62 * into SAX event stream, and manipulate nodes in the document. 63 * 64 * HISTORY 65 * 05.01.2004 - Interface supported: XXMLDocumentWrapper, 66 * XDocumentHandler, XCompressedDocumentHandler, 67 * XServiceInfo 68 * 69 * AUTHOR 70 * Michael Mi 71 * Email: michael.mi@sun.com 72 ******************************************************************************/ 73 { 74 private: 75 /* the sax helper */ 76 SAXHelper saxHelper; 77 78 /* the document used to convert SAX events to */ 79 xmlDocPtr m_pDocument; 80 81 /* the root element */ 82 xmlNodePtr m_pRootElement; 83 84 /* 85 * the current active element. The next incoming SAX event will be 86 * appended to this element 87 */ 88 xmlNodePtr m_pCurrentElement; 89 90 /* 91 * This variable is used when converting the document or part of it into 92 * SAX events. See getNextSAXEvent method. 93 */ 94 sal_Int32 m_nCurrentPosition; 95 96 /* 97 * used for recursive deletion. See recursiveDelete method 98 */ 99 xmlNodePtr m_pStopAtNode; 100 xmlNodePtr m_pCurrentReservedNode; 101 com::sun::star::uno::Sequence< com::sun::star::uno::Reference< 102 com::sun::star::xml::wrapper::XXMLElementWrapper > > m_aReservedNodes; 103 sal_Int32 m_nReservedNodeIndex; 104 105 private: 106 void getNextSAXEvent(); 107 108 void sendStartElement( 109 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xHandler, 110 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xHandler2, 111 const xmlNodePtr pNode) const 112 throw (com::sun::star::xml::sax::SAXException); 113 114 void sendEndElement( 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 throw (com::sun::star::xml::sax::SAXException); 119 120 void sendNode( 121 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xHandler, 122 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xHandler2, 123 const xmlNodePtr pNode) const 124 throw (com::sun::star::xml::sax::SAXException); 125 126 rtl::OString getNodeQName(const xmlNodePtr pNode) const; 127 128 sal_Int32 recursiveDelete( const xmlNodePtr pNode); 129 130 void getNextReservedNode(); 131 132 void removeNode( const xmlNodePtr pNode) const; 133 134 xmlNodePtr checkElement( 135 const com::sun::star::uno::Reference< 136 com::sun::star::xml::wrapper::XXMLElementWrapper >& xXMLElement) const; 137 138 void buildIDAttr( xmlNodePtr pNode ) const; 139 void rebuildIDLink( xmlNodePtr pNode ) const; 140 141 public: 142 XMLDocumentWrapper_XmlSecImpl(); 143 virtual ~XMLDocumentWrapper_XmlSecImpl(); 144 145 /* com::sun::star::xml::wrapper::XXMLDocumentWrapper */ 146 virtual com::sun::star::uno::Reference< 147 com::sun::star::xml::wrapper::XXMLElementWrapper > SAL_CALL getCurrentElement( ) 148 throw (com::sun::star::uno::RuntimeException); 149 150 virtual void SAL_CALL setCurrentElement( const com::sun::star::uno::Reference< 151 com::sun::star::xml::wrapper::XXMLElementWrapper >& element ) 152 throw (com::sun::star::uno::RuntimeException); 153 154 virtual void SAL_CALL removeCurrentElement( ) 155 throw (com::sun::star::uno::RuntimeException); 156 157 virtual sal_Bool SAL_CALL isCurrent( const com::sun::star::uno::Reference< 158 com::sun::star::xml::wrapper::XXMLElementWrapper >& node ) 159 throw (com::sun::star::uno::RuntimeException); 160 161 virtual sal_Bool SAL_CALL isCurrentElementEmpty( ) 162 throw (com::sun::star::uno::RuntimeException); 163 164 virtual rtl::OUString SAL_CALL getNodeName( const com::sun::star::uno::Reference< 165 com::sun::star::xml::wrapper::XXMLElementWrapper >& node ) 166 throw (com::sun::star::uno::RuntimeException); 167 168 virtual void SAL_CALL clearUselessData( 169 const com::sun::star::uno::Reference< 170 com::sun::star::xml::wrapper::XXMLElementWrapper >& node, 171 const com::sun::star::uno::Sequence< com::sun::star::uno::Reference< 172 com::sun::star::xml::wrapper::XXMLElementWrapper > >& reservedDescendants, 173 const com::sun::star::uno::Reference< 174 com::sun::star::xml::wrapper::XXMLElementWrapper >& stopAtNode ) 175 throw (com::sun::star::uno::RuntimeException); 176 177 virtual void SAL_CALL collapse( const com::sun::star::uno::Reference< 178 com::sun::star::xml::wrapper::XXMLElementWrapper >& node ) 179 throw (com::sun::star::uno::RuntimeException); 180 181 virtual void SAL_CALL generateSAXEvents( 182 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& handler, 183 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xEventKeeperHandler, 184 const com::sun::star::uno::Reference< 185 com::sun::star::xml::wrapper::XXMLElementWrapper >& startNode, 186 const com::sun::star::uno::Reference< 187 com::sun::star::xml::wrapper::XXMLElementWrapper >& endNode ) 188 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException); 189 190 virtual void SAL_CALL getTree( 191 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& handler ) 192 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException); 193 194 virtual void SAL_CALL rebuildIDLink( 195 const com::sun::star::uno::Reference< com::sun::star::xml::wrapper::XXMLElementWrapper >& node ) 196 throw (com::sun::star::uno::RuntimeException); 197 198 /* com::sun::star::xml::sax::XDocumentHandler */ 199 virtual void SAL_CALL startDocument( ) 200 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException); 201 202 virtual void SAL_CALL endDocument( ) 203 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException); 204 205 virtual void SAL_CALL startElement( 206 const rtl::OUString& aName, 207 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttribs ) 208 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException); 209 210 virtual void SAL_CALL endElement( const rtl::OUString& aName ) 211 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException); 212 213 virtual void SAL_CALL characters( const rtl::OUString& aChars ) 214 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException); 215 216 virtual void SAL_CALL ignorableWhitespace( const rtl::OUString& aWhitespaces ) 217 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException); 218 219 virtual void SAL_CALL processingInstruction( const rtl::OUString& aTarget, const rtl::OUString& aData ) 220 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException); 221 222 virtual void SAL_CALL setDocumentLocator( const com::sun::star::uno::Reference< com::sun::star::xml::sax::XLocator >& xLocator ) 223 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException); 224 225 /* com::sun::star::xml::csax::XCompressedDocumentHandler */ 226 virtual void SAL_CALL _startDocument( ) 227 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException); 228 229 virtual void SAL_CALL _endDocument( ) 230 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException); 231 232 virtual void SAL_CALL _startElement( 233 const rtl::OUString& aName, 234 const com::sun::star::uno::Sequence< 235 com::sun::star::xml::csax::XMLAttribute >& aAttributes ) 236 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException); 237 238 virtual void SAL_CALL _endElement( const rtl::OUString& aName ) 239 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException); 240 241 virtual void SAL_CALL _characters( const rtl::OUString& aChars ) 242 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException); 243 244 virtual void SAL_CALL _ignorableWhitespace( const rtl::OUString& aWhitespaces ) 245 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException); 246 247 virtual void SAL_CALL _processingInstruction( const rtl::OUString& aTarget, const rtl::OUString& aData ) 248 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException); 249 250 virtual void SAL_CALL _setDocumentLocator( 251 sal_Int32 columnNumber, 252 sal_Int32 lineNumber, 253 const rtl::OUString& publicId, 254 const rtl::OUString& systemId ) 255 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException); 256 257 /* com::sun::star::lang::XServiceInfo */ 258 virtual rtl::OUString SAL_CALL getImplementationName( ) 259 throw (com::sun::star::uno::RuntimeException); 260 261 virtual sal_Bool SAL_CALL supportsService( const rtl::OUString& ServiceName ) 262 throw (com::sun::star::uno::RuntimeException); 263 264 virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames( ) 265 throw (com::sun::star::uno::RuntimeException); 266 }; 267 268 rtl::OUString XMLDocumentWrapper_XmlSecImpl_getImplementationName() 269 throw ( com::sun::star::uno::RuntimeException ); 270 271 sal_Bool SAL_CALL XMLDocumentWrapper_XmlSecImpl_supportsService( const rtl::OUString& ServiceName ) 272 throw ( com::sun::star::uno::RuntimeException ); 273 274 com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL 275 XMLDocumentWrapper_XmlSecImpl_getSupportedServiceNames( ) 276 throw ( com::sun::star::uno::RuntimeException ); 277 278 com::sun::star::uno::Reference< com::sun::star::uno::XInterface > 279 SAL_CALL XMLDocumentWrapper_XmlSecImpl_createInstance( 280 const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > & rSMgr) 281 throw ( com::sun::star::uno::Exception ); 282 283 #endif 284 285