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 ) throw(com::sun::star::uno::RuntimeException);
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             throw( com::sun::star::lang::IllegalArgumentException );
70 
71     };
72 
73     typedef ::cppu::WeakComponentImplHelper2<
74         com::sun::star::xml::XImportFilter,
75         com::sun::star::document::XImporter > PDFIAdaptorBase;
76 
77     /** Adapts raw pdf import to XImportFilter interface
78      */
79 	class PDFIRawAdaptor : private cppu::BaseMutex,
80                            public PDFIAdaptorBase
81     {
82     private:
83         com::sun::star::uno::Reference<
84             com::sun::star::uno::XComponentContext >  m_xContext;
85         com::sun::star::uno::Reference<
86             com::sun::star::frame::XModel >           m_xModel;
87         TreeVisitorFactorySharedPtr                   m_pVisitorFactory;
88         bool                                          m_bEnableToplevelText;
89 
90         bool parse( const com::sun::star::uno::Reference<com::sun::star::io::XInputStream>&       xInput,
91                     const com::sun::star::uno::Reference<com::sun::star::task::XInteractionHandler>& xIHdl,
92                     const rtl::OUString&                                                          rPwd,
93                     const com::sun::star::uno::Reference<com::sun::star::task::XStatusIndicator>& xStatus,
94                     const XmlEmitterSharedPtr&                                                    rEmitter,
95                     const rtl::OUString&                                                          rURL );
96 
97     public:
98         explicit PDFIRawAdaptor( const ::com::sun::star::uno::Reference<
99                                        ::com::sun::star::uno::XComponentContext >& xContext );
100 
101         /** Set factory object used to create the tree visitors
102 
103             Used for customizing the tree to the specific output
104             format (writer, draw, etc)
105          */
106         void setTreeVisitorFactory(const TreeVisitorFactorySharedPtr& rVisitorFactory);
107 
108         /// TEMP - enable writer-like text:p on doc level
enableToplevelText()109         void enableToplevelText() { m_bEnableToplevelText=true; }
110 
111         /** Export pdf document to ODG
112 
113             @param xOutput
114             Stream to write the flat xml file to
115 
116             @param xStatus
117             Optional status indicator
118          */
119         bool odfConvert( const rtl::OUString&                                                          rURL,
120                          const com::sun::star::uno::Reference<com::sun::star::io::XOutputStream>&      xOutput,
121                          const com::sun::star::uno::Reference<com::sun::star::task::XStatusIndicator>& xStatus );
122 
123         // XImportFilter
124         virtual sal_Bool SAL_CALL importer( const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& rSourceData,
125                                             const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& rHdl,
126                                             const com::sun::star::uno::Sequence< rtl::OUString >& rUserData ) throw( com::sun::star::uno::RuntimeException );
127 
128         // XImporter
129         virtual void SAL_CALL setTargetDocument( const com::sun::star::uno::Reference< com::sun::star::lang::XComponent >& xDocument )
130             throw( com::sun::star::lang::IllegalArgumentException );
131     };
132 }
133 
134 #endif
135