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 INCLUDED_PDFIADAPTOR_HXX 25 #define INCLUDED_PDFIADAPTOR_HXX 26 27 #include "xmlemitter.hxx" 28 #include "treevisitorfactory.hxx" 29 30 #include <com/sun/star/xml/XImportFilter.hpp> 31 #include <com/sun/star/xml/sax/XDocumentHandler.hpp> 32 #include <com/sun/star/uno/XComponentContext.hpp> 33 #include <com/sun/star/task/XStatusIndicator.hpp> 34 #include <com/sun/star/document/XFilter.hpp> 35 #include <com/sun/star/io/XInputStream.hpp> 36 #include <com/sun/star/io/XOutputStream.hpp> 37 #include <com/sun/star/document/XImporter.hpp> 38 #include <com/sun/star/frame/XModel.hpp> 39 40 #include <cppuhelper/compbase2.hxx> 41 #include <cppuhelper/basemutex.hxx> 42 43 44 namespace pdfi 45 { 46 typedef ::cppu::WeakComponentImplHelper2< 47 com::sun::star::document::XFilter, 48 com::sun::star::document::XImporter > PDFIHybridAdaptorBase; 49 50 class PDFIHybridAdaptor : private cppu::BaseMutex, 51 public PDFIHybridAdaptorBase 52 { 53 private: 54 com::sun::star::uno::Reference< 55 com::sun::star::uno::XComponentContext > m_xContext; 56 com::sun::star::uno::Reference< 57 com::sun::star::frame::XModel > m_xModel; 58 59 public: 60 explicit PDFIHybridAdaptor( const ::com::sun::star::uno::Reference< 61 ::com::sun::star::uno::XComponentContext >& xContext ); 62 63 // XFilter 64 virtual sal_Bool SAL_CALL filter( const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& rFilterData ); 65 virtual void SAL_CALL cancel() throw(); 66 67 // XImporter 68 virtual void SAL_CALL setTargetDocument( const com::sun::star::uno::Reference< com::sun::star::lang::XComponent >& xDocument ); 69 70 }; 71 72 typedef ::cppu::WeakComponentImplHelper2< 73 com::sun::star::xml::XImportFilter, 74 com::sun::star::document::XImporter > PDFIAdaptorBase; 75 76 /** Adapts raw pdf import to XImportFilter interface 77 */ 78 class PDFIRawAdaptor : private cppu::BaseMutex, 79 public PDFIAdaptorBase 80 { 81 private: 82 com::sun::star::uno::Reference< 83 com::sun::star::uno::XComponentContext > m_xContext; 84 com::sun::star::uno::Reference< 85 com::sun::star::frame::XModel > m_xModel; 86 TreeVisitorFactorySharedPtr m_pVisitorFactory; 87 bool m_bEnableToplevelText; 88 89 bool parse( const com::sun::star::uno::Reference<com::sun::star::io::XInputStream>& xInput, 90 const com::sun::star::uno::Reference<com::sun::star::task::XInteractionHandler>& xIHdl, 91 const rtl::OUString& rPwd, 92 const com::sun::star::uno::Reference<com::sun::star::task::XStatusIndicator>& xStatus, 93 const XmlEmitterSharedPtr& rEmitter, 94 const rtl::OUString& rURL ); 95 96 public: 97 explicit PDFIRawAdaptor( const ::com::sun::star::uno::Reference< 98 ::com::sun::star::uno::XComponentContext >& xContext ); 99 100 /** Set factory object used to create the tree visitors 101 102 Used for customizing the tree to the specific output 103 format (writer, draw, etc) 104 */ 105 void setTreeVisitorFactory(const TreeVisitorFactorySharedPtr& rVisitorFactory); 106 107 /// TEMP - enable writer-like text:p on doc level enableToplevelText()108 void enableToplevelText() { m_bEnableToplevelText=true; } 109 110 /** Export pdf document to ODG 111 112 @param xOutput 113 Stream to write the flat xml file to 114 115 @param xStatus 116 Optional status indicator 117 */ 118 bool odfConvert( const rtl::OUString& rURL, 119 const com::sun::star::uno::Reference<com::sun::star::io::XOutputStream>& xOutput, 120 const com::sun::star::uno::Reference<com::sun::star::task::XStatusIndicator>& xStatus ); 121 122 // XImportFilter 123 virtual sal_Bool SAL_CALL importer( const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& rSourceData, 124 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& rHdl, 125 const com::sun::star::uno::Sequence< rtl::OUString >& rUserData ); 126 127 // XImporter 128 virtual void SAL_CALL setTargetDocument( const com::sun::star::uno::Reference< com::sun::star::lang::XComponent >& xDocument ); 129 }; 130 } 131 132 #endif 133