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