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