Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <com/sun/star/io/XActiveDataControl.hpp>
30 : : #include <com/sun/star/io/XActiveDataSource.hpp>
31 : : #include <com/sun/star/xml/sax/XParser.hpp>
32 : : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
33 : : #include <com/sun/star/io/XOutputStream.hpp>
34 : : #include <com/sun/star/text/XText.hpp>
35 : : #include <comphelper/processfactory.hxx>
36 : : #include <unotools/streamwrap.hxx>
37 : : #include <rtl/ustrbuf.hxx>
38 : : #include <sot/storage.hxx>
39 : : #include <svl/itemprop.hxx>
40 : : #include <xmloff/xmlimp.hxx>
41 : : #include <xmloff/xmlmetae.hxx>
42 : : #include <xmloff/xmlictxt.hxx>
43 : : #include <xmloff/xmltoken.hxx>
44 : : #include <xmloff/xmlnmspe.hxx>
45 : : #include <xmloff/xmlstyle.hxx>
46 : : #include "editsource.hxx"
47 : : #include <editeng/editeng.hxx>
48 : : #include <editeng/unotext.hxx>
49 : : #include <editeng/unoprnms.hxx>
50 : : #include <editeng/unoipset.hxx>
51 : :
52 : : using namespace com::sun::star;
53 : : using namespace com::sun::star::document;
54 : : using namespace com::sun::star::uno;
55 : : using namespace com::sun::star::lang;
56 : : using namespace com::sun::star::xml::sax;
57 : : using namespace com::sun::star::text;
58 : : using namespace ::rtl;
59 : : using namespace cppu;
60 : : using namespace xmloff::token;
61 : :
62 : :
63 : : ///////////////////////////////////////////////////////////////////////
64 : :
65 : : class SvxXMLTextImportContext : public SvXMLImportContext
66 : : {
67 : : public:
68 : : SvxXMLTextImportContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, const uno::Reference< XAttributeList >& xAttrList, const uno::Reference< XText >& xText );
69 : : virtual ~SvxXMLTextImportContext();
70 : :
71 : : virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList );
72 : :
73 : : // SvxXMLXTableImport& getImport() const { return *(SvxXMLXTableImport*)&GetImport(); }
74 : :
75 : : private:
76 : : const uno::Reference< XText > mxText;
77 : : };
78 : :
79 : : ///////////////////////////////////////////////////////////////////////
80 : :
81 : 0 : SvxXMLTextImportContext::SvxXMLTextImportContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, const uno::Reference< XAttributeList >&, const uno::Reference< XText >& xText )
82 : 0 : : SvXMLImportContext( rImport, nPrfx, rLName ), mxText( xText )
83 : : {
84 : 0 : }
85 : :
86 : 0 : SvxXMLTextImportContext::~SvxXMLTextImportContext()
87 : : {
88 [ # # ]: 0 : }
89 : :
90 : 0 : SvXMLImportContext *SvxXMLTextImportContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList )
91 : : {
92 : 0 : SvXMLImportContext* pContext = NULL;
93 [ # # ][ # # ]: 0 : if(XML_NAMESPACE_OFFICE == nPrefix && IsXMLToken( rLocalName, XML_BODY ) )
[ # # ]
94 : : {
95 [ # # ]: 0 : pContext = new SvxXMLTextImportContext( GetImport(), nPrefix, rLocalName, xAttrList, mxText );
96 : : }
97 [ # # ][ # # ]: 0 : else if( XML_NAMESPACE_OFFICE == nPrefix && IsXMLToken( rLocalName, XML_AUTOMATIC_STYLES ) )
[ # # ]
98 : : {
99 [ # # ]: 0 : pContext = new SvXMLStylesContext( GetImport(), nPrefix, rLocalName, xAttrList );
100 [ # # ][ # # ]: 0 : GetImport().GetTextImport()->SetAutoStyles( (SvXMLStylesContext*)pContext );
101 : :
102 : : }
103 : : else
104 : : {
105 [ # # ][ # # ]: 0 : pContext = GetImport().GetTextImport()->CreateTextChildContext( GetImport(), nPrefix, rLocalName, xAttrList );
106 : : }
107 : :
108 [ # # ]: 0 : if( NULL == pContext )
109 [ # # ]: 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
110 : :
111 : 0 : return pContext;
112 : : }
113 : :
114 : : ///////////////////////////////////////////////////////////////////////
115 : :
116 : : class SvxXMLXTextImportComponent : public SvXMLImport
117 : : {
118 : : public:
119 : : SvxXMLXTextImportComponent(
120 : : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
121 : : const uno::Reference< XText > & xText );
122 : :
123 : : virtual ~SvxXMLXTextImportComponent() throw ();
124 : :
125 : : static sal_Bool load( const rtl::OUString& rUrl, const com::sun::star::uno::Reference< com::sun::star::container::XNameContainer >& xTable ) throw();
126 : : protected:
127 : : virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList );
128 : :
129 : : private:
130 : : const uno::Reference< XText > mxText;
131 : : };
132 : :
133 : : // --------------------------------------------------------------------
134 : :
135 : 0 : SvxXMLXTextImportComponent::SvxXMLXTextImportComponent(
136 : : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
137 : : const uno::Reference< XText > & xText )
138 : : : SvXMLImport(xServiceFactory),
139 : 0 : mxText( xText )
140 : : {
141 [ # # ][ # # ]: 0 : GetTextImport()->SetCursor( mxText->createTextCursor() );
[ # # ][ # # ]
[ # # ][ # # ]
142 : 0 : }
143 : :
144 : 0 : SvxXMLXTextImportComponent::~SvxXMLXTextImportComponent() throw ()
145 : : {
146 [ # # ]: 0 : }
147 : :
148 : 0 : void SvxReadXML( EditEngine& rEditEngine, SvStream& rStream, const ESelection& rSel )
149 : : {
150 [ # # ]: 0 : SvxEditEngineSource aEditSource( &rEditEngine );
151 : :
152 : : static const SfxItemPropertyMapEntry SvxXMLTextImportComponentPropertyMap[] =
153 : : {
154 [ # # ][ # # ]: 0 : SVX_UNOEDIT_CHAR_PROPERTIES,
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
155 [ # # ]: 0 : SVX_UNOEDIT_FONT_PROPERTIES,
156 : : // SVX_UNOEDIT_OUTLINER_PROPERTIES,
157 [ # # ][ # # ]: 0 : SVX_UNOEDIT_PARA_PROPERTIES,
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
158 : : {0,0,0,0,0,0}
159 [ # # ][ # # ]: 0 : };
[ # # ]
160 [ # # ][ # # ]: 0 : static SvxItemPropertySet aSvxXMLTextImportComponentPropertySet( SvxXMLTextImportComponentPropertyMap, EditEngine::GetGlobalItemPool() );
[ # # ][ # # ]
[ # # ]
161 : :
162 : 0 : uno::Reference<text::XText > xParent;
163 : 0 : SvxUnoText* pUnoText = new SvxUnoText( &aEditSource, &aSvxXMLTextImportComponentPropertySet, xParent );
164 : 0 : pUnoText->SetSelection( rSel );
165 [ # # ][ # # ]: 0 : uno::Reference<text::XText > xText( pUnoText );
166 : :
167 : : try
168 : : {
169 : : do
170 : : {
171 [ # # ]: 0 : uno::Reference<lang::XMultiServiceFactory> xServiceFactory( ::comphelper::getProcessServiceFactory() );
172 [ # # ]: 0 : if( !xServiceFactory.is() )
173 : : {
174 : : OSL_FAIL( "SvxXMLXTableImport::load: got no service manager" );
175 : : break;
176 : : }
177 : :
178 [ # # ][ # # ]: 0 : uno::Reference< xml::sax::XParser > xParser( xServiceFactory->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.Parser" ) ) ), uno::UNO_QUERY );
[ # # ][ # # ]
179 [ # # ]: 0 : if( !xParser.is() )
180 : : {
181 : : OSL_FAIL( "com.sun.star.xml.sax.Parser service missing" );
182 : : break;
183 : : }
184 : :
185 [ # # ][ # # ]: 0 : uno::Reference<io::XInputStream> xInputStream = new utl::OInputStreamWrapper( rStream );
[ # # ]
186 : :
187 : : /* testcode
188 : : const OUString aURL( RTL_CONSTASCII_USTRINGPARAM( "file:///e:/test.xml" ) );
189 : : SfxMedium aMedium( aURL, STREAM_READ | STREAM_NOCREATE, sal_True );
190 : : aMedium.IsRemote();
191 : : uno::Reference<io::XOutputStream> xOut( new utl::OOutputStreamWrapper( *aMedium.GetOutStream() ) );
192 : :
193 : : aMedium.GetInStream()->Seek( 0 );
194 : : uno::Reference< io::XActiveDataSource > xSource( aMedium.GetDataSource() );
195 : :
196 : : if( !xSource.is() )
197 : : {
198 : : OSL_FAIL( "got no data source from medium" );
199 : : break;
200 : : }
201 : :
202 : : uno::Reference< XInterface > xPipe( xServiceFactory->createInstance(OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.Pipe") ) ) );
203 : : if( !xPipe.is() )
204 : : {
205 : : OSL_FAIL( "XMLReader::Read: com.sun.star.io.Pipe service missing" );
206 : : break;
207 : : }
208 : :
209 : : // connect pipe's output stream to the data source
210 : : xSource->setOutputStream( uno::Reference< io::XOutputStream >::query( xPipe ) );
211 : :
212 : : xml::sax::InputSource aParserInput;
213 : : aParserInput.aInputStream = uno::Reference< io::XInputStream >::query( xPipe );
214 : : aParserInput.sSystemId = aMedium.GetName();
215 : :
216 : :
217 : : if( xSource.is() )
218 : : {
219 : : uno::Reference< io::XActiveDataControl > xSourceControl( xSource, UNO_QUERY );
220 : : xSourceControl->start();
221 : : }
222 : :
223 : : */
224 : :
225 : : // uno::Reference< XDocumentHandler > xHandler( new SvxXMLXTextImportComponent( xText ) );
226 [ # # ][ # # ]: 0 : uno::Reference< XDocumentHandler > xHandler( new SvxXMLXTextImportComponent( xServiceFactory, xText ) );
[ # # ]
227 : :
228 [ # # ][ # # ]: 0 : xParser->setDocumentHandler( xHandler );
229 : :
230 [ # # ]: 0 : xml::sax::InputSource aParserInput;
231 [ # # ]: 0 : aParserInput.aInputStream = xInputStream;
232 : : // aParserInput.sSystemId = aMedium.GetName();
233 [ # # ][ # # ]: 0 : xParser->parseStream( aParserInput );
[ # # ][ # # ]
[ # # ][ # # ]
234 : : }
235 : : while(0);
236 : : }
237 [ # # ]: 0 : catch( const uno::Exception& )
238 : : {
239 [ # # ]: 0 : }
240 : 0 : }
241 : :
242 : 0 : SvXMLImportContext *SvxXMLXTextImportComponent::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList )
243 : : {
244 : : SvXMLImportContext* pContext;
245 [ # # ][ # # ]: 0 : if(XML_NAMESPACE_OFFICE == nPrefix && ( IsXMLToken( rLocalName, XML_DOCUMENT ) || IsXMLToken( rLocalName, XML_DOCUMENT_CONTENT ) ) )
[ # # ][ # # ]
246 : : {
247 [ # # ]: 0 : pContext = new SvxXMLTextImportContext(*this, nPrefix, rLocalName, xAttrList, mxText );
248 : : }
249 : : else
250 : : {
251 : 0 : pContext = SvXMLImport::CreateContext(nPrefix, rLocalName, xAttrList);
252 : : }
253 : 0 : return pContext;
254 : : }
255 : :
256 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|