update dev300-m58
[ooovba.git] / writerfilter / source / ooxml / OOXMLDocumentImpl.cxx
blobfef00e4cef43a1b51e4def887cd23a26574b12e1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OOXMLDocumentImpl.cxx,v $
10 * $Revision: 1.19 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <com/sun/star/xml/sax/XParser.hpp>
33 #include <doctok/resourceids.hxx>
34 #include <ooxml/resourceids.hxx>
35 #include "OOXMLDocumentImpl.hxx"
36 #include "OOXMLBinaryObjectReference.hxx"
37 #include "OOXMLFastDocumentHandler.hxx"
38 #include "OOXMLPropertySetImpl.hxx"
39 #include "ooxmlLoggers.hxx"
41 #include <iostream>
43 namespace writerfilter {
44 namespace ooxml
46 TagLogger::Pointer_t debug_logger(TagLogger::getInstance("DEBUG"));
47 using namespace ::std;
49 OOXMLDocumentImpl::OOXMLDocumentImpl
50 (OOXMLStream::Pointer_t pStream)
51 : mpStream(pStream), mXNoteType(0)
55 OOXMLDocumentImpl::~OOXMLDocumentImpl()
59 void OOXMLDocumentImpl::resolveFastSubStream(Stream & rStreamHandler,
60 OOXMLStream::StreamType_t nType)
62 OOXMLStream::Pointer_t pStream
63 (OOXMLDocumentFactory::createStream(mpStream, nType));
65 uno::Reference< xml::sax::XFastParser > xParser
66 (mpStream->getFastParser());
68 if (xParser.is())
70 uno::Reference<uno::XComponentContext> xContext(mpStream->getContext());
71 OOXMLFastDocumentHandler * pDocHandler =
72 new OOXMLFastDocumentHandler(xContext);
73 pDocHandler->setStream(&rStreamHandler);
74 pDocHandler->setDocument(this);
75 pDocHandler->setXNoteId(msXNoteId);
77 uno::Reference < xml::sax::XFastDocumentHandler > xDocumentHandler
78 (pDocHandler);
79 uno::Reference < xml::sax::XFastTokenHandler > xTokenHandler
80 (mpStream->getFastTokenHandler(xContext));
82 xParser->setFastDocumentHandler(xDocumentHandler);
83 xParser->setTokenHandler(xTokenHandler);
85 uno::Reference<io::XInputStream> xInputStream =
86 pStream->getDocumentStream();
88 if (xInputStream.is())
90 struct xml::sax::InputSource oInputSource;
91 oInputSource.aInputStream = xInputStream;
92 xParser->parseStream(oInputSource);
94 xInputStream->closeInput();
99 void OOXMLDocumentImpl::resolveFastSubStreamWithId(Stream & rStream,
100 writerfilter::Reference<Stream>::Pointer_t pStream,
101 sal_uInt32 nId)
103 rStream.substream(nId, pStream);
106 void OOXMLDocumentImpl::setXNoteId(const rtl::OUString & rId)
108 msXNoteId = rId;
111 const rtl::OUString & OOXMLDocumentImpl::getXNoteId() const
113 return msXNoteId;
116 void OOXMLDocumentImpl::setXNoteType(const Id & nId)
118 mXNoteType = nId;
121 const Id & OOXMLDocumentImpl::getXNoteType() const
123 return mXNoteType;
126 const ::rtl::OUString & OOXMLDocumentImpl::getTarget() const
128 return mpStream->getTarget();
131 writerfilter::Reference<Stream>::Pointer_t
132 OOXMLDocumentImpl::getSubStream(const rtl::OUString & rId)
134 OOXMLStream::Pointer_t pStream
135 (OOXMLDocumentFactory::createStream(mpStream, rId));
137 OOXMLDocumentImpl * pTemp;
138 writerfilter::Reference<Stream>::Pointer_t pRet( pTemp = new OOXMLDocumentImpl(pStream) );
139 pTemp->setModel(mxModel);
140 pTemp->setDrawPage(mxDrawPage);
141 return pRet;
144 writerfilter::Reference<Stream>::Pointer_t
145 OOXMLDocumentImpl::getXNoteStream(OOXMLStream::StreamType_t nType, const Id & rType,
146 const rtl::OUString & rId)
148 #ifdef DEBUG_ELEMENT
149 debug_logger->startElement("getXNoteStream");
150 debug_logger->attribute("id", rId);
151 debug_logger->endElement("getXNoteStream");
152 #endif
154 OOXMLStream::Pointer_t pStream =
155 (OOXMLDocumentFactory::createStream(mpStream, nType));
156 OOXMLDocumentImpl * pDocument = new OOXMLDocumentImpl(pStream);
157 pDocument->setXNoteId(rId);
158 pDocument->setXNoteType(rType);
160 return writerfilter::Reference<Stream>::Pointer_t(pDocument);
163 void OOXMLDocumentImpl::resolveFootnote(Stream & rStream,
164 const Id & rType,
165 const rtl::OUString & rNoteId)
167 writerfilter::Reference<Stream>::Pointer_t pStream =
168 getXNoteStream(OOXMLStream::FOOTNOTES, rType, rNoteId);
170 Id nId;
171 switch (rType)
173 case NS_ooxml::LN_Value_wordprocessingml_ST_FtnEdn_separator:
174 case NS_ooxml::LN_Value_wordprocessingml_ST_FtnEdn_continuationSeparator:
175 nId = rType;
176 break;
177 default:
178 nId = NS_rtf::LN_footnote;
179 break;
182 resolveFastSubStreamWithId(rStream, pStream, nId);
185 void OOXMLDocumentImpl::resolveEndnote(Stream & rStream,
186 const Id & rType,
187 const rtl::OUString & rNoteId)
189 writerfilter::Reference<Stream>::Pointer_t pStream =
190 getXNoteStream(OOXMLStream::ENDNOTES, rType, rNoteId);
192 Id nId;
193 switch (rType)
195 case NS_ooxml::LN_Value_wordprocessingml_ST_FtnEdn_separator:
196 case NS_ooxml::LN_Value_wordprocessingml_ST_FtnEdn_continuationSeparator:
197 nId = rType;
198 break;
199 default:
200 nId = NS_rtf::LN_endnote;
201 break;
204 resolveFastSubStreamWithId(rStream, pStream, nId);
207 void OOXMLDocumentImpl::resolveComment(Stream & rStream,
208 const rtl::OUString & rId)
210 writerfilter::Reference<Stream>::Pointer_t pStream =
211 getXNoteStream(OOXMLStream::COMMENTS, 0, rId);
213 resolveFastSubStreamWithId(rStream, pStream, NS_rtf::LN_annotation);
216 OOXMLPropertySet * OOXMLDocumentImpl::getPicturePropSet
217 (const ::rtl::OUString & rId)
219 OOXMLStream::Pointer_t pStream
220 (OOXMLDocumentFactory::createStream(mpStream, rId));
222 writerfilter::Reference<BinaryObj>::Pointer_t pPicture
223 (new OOXMLBinaryObjectReference(pStream));
225 OOXMLValue::Pointer_t pPayloadValue(new OOXMLBinaryValue(pPicture));
227 OOXMLProperty::Pointer_t pPayloadProperty
228 (new OOXMLPropertyImpl(NS_rtf::LN_payload, pPayloadValue,
229 OOXMLPropertyImpl::ATTRIBUTE));
231 OOXMLPropertySet::Pointer_t pBlipSet(new OOXMLPropertySetImpl());
233 pBlipSet->add(pPayloadProperty);
235 OOXMLValue::Pointer_t pBlipValue(new OOXMLPropertySetValue(pBlipSet));
237 OOXMLProperty::Pointer_t pBlipProperty
238 (new OOXMLPropertyImpl(NS_rtf::LN_blip, pBlipValue,
239 OOXMLPropertyImpl::ATTRIBUTE));
241 OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
243 pProps->add(pBlipProperty);
245 return pProps;
248 void OOXMLDocumentImpl::resolvePicture(Stream & rStream,
249 const rtl::OUString & rId)
251 OOXMLPropertySet * pProps = getPicturePropSet(rId);
253 rStream.props(writerfilter::Reference<Properties>::Pointer_t(pProps));
256 ::rtl::OUString OOXMLDocumentImpl::getTargetForId(const ::rtl::OUString & rId)
258 return mpStream->getTargetForId(rId);
261 void OOXMLDocumentImpl::resolveHeader(Stream & rStream,
262 const sal_Int32 type,
263 const rtl::OUString & rId)
265 writerfilter::Reference<Stream>::Pointer_t pStream =
266 getSubStream(rId);
267 switch (type)
269 case NS_ooxml::LN_Value_ST_HrdFtr_even:
270 resolveFastSubStreamWithId(rStream, pStream, NS_rtf::LN_headerl);
271 break;
272 case NS_ooxml::LN_Value_ST_HrdFtr_default: // here we assume that default is right, but not necessarily true :-(
273 resolveFastSubStreamWithId(rStream, pStream, NS_rtf::LN_headerr);
274 break;
275 case NS_ooxml::LN_Value_ST_HrdFtr_first:
276 resolveFastSubStreamWithId(rStream, pStream, NS_rtf::LN_headerf);
277 break;
278 default:
279 break;
283 void OOXMLDocumentImpl::resolveFooter(Stream & rStream,
284 const sal_Int32 type,
285 const rtl::OUString & rId)
287 writerfilter::Reference<Stream>::Pointer_t pStream =
288 getSubStream(rId);
290 switch (type)
292 case NS_ooxml::LN_Value_ST_HrdFtr_even:
293 resolveFastSubStreamWithId(rStream, pStream, NS_rtf::LN_footerl);
294 break;
295 case NS_ooxml::LN_Value_ST_HrdFtr_default: // here we assume that default is right, but not necessarily true :-(
296 resolveFastSubStreamWithId(rStream, pStream, NS_rtf::LN_footerr);
297 break;
298 case NS_ooxml::LN_Value_ST_HrdFtr_first:
299 resolveFastSubStreamWithId(rStream, pStream, NS_rtf::LN_footerf);
300 break;
301 default:
302 break;
306 void OOXMLDocumentImpl::resolve(Stream & rStream)
308 uno::Reference< xml::sax::XFastParser > xParser
309 (mpStream->getFastParser());
311 if (xParser.is())
313 uno::Reference<uno::XComponentContext> xContext(mpStream->getContext());
315 OOXMLFastDocumentHandler * pDocHandler =
316 new OOXMLFastDocumentHandler(xContext);
317 pDocHandler->setStream(&rStream);
318 pDocHandler->setDocument(this);
319 pDocHandler->setXNoteId(msXNoteId);
320 uno::Reference < xml::sax::XFastDocumentHandler > xDocumentHandler
321 (pDocHandler);
322 uno::Reference < xml::sax::XFastTokenHandler > xTokenHandler
323 (mpStream->getFastTokenHandler(xContext));
325 resolveFastSubStream(rStream, OOXMLStream::SETTINGS);
326 resolveFastSubStream(rStream, OOXMLStream::THEME);
327 resolveFastSubStream(rStream, OOXMLStream::NUMBERING);
328 resolveFastSubStream(rStream, OOXMLStream::FONTTABLE);
329 resolveFastSubStream(rStream, OOXMLStream::STYLES);
331 xParser->setFastDocumentHandler( xDocumentHandler );
332 xParser->setTokenHandler( xTokenHandler );
334 xml::sax::InputSource aParserInput;
335 aParserInput.aInputStream = mpStream->getDocumentStream();
336 xParser->parseStream(aParserInput);
340 uno::Reference<io::XInputStream> OOXMLDocumentImpl::getInputStreamForId(const ::rtl::OUString & rId)
342 OOXMLStream::Pointer_t pStream(OOXMLDocumentFactory::createStream(mpStream, rId));
344 return pStream->getDocumentStream();
347 string OOXMLDocumentImpl::getType() const
349 return "OOXMLDocumentImpl";
352 void OOXMLDocumentImpl::setModel(uno::Reference<frame::XModel> xModel)
354 mxModel.set(xModel);
357 uno::Reference<frame::XModel> OOXMLDocumentImpl::getModel()
359 return mxModel;
362 void OOXMLDocumentImpl::setDrawPage(uno::Reference<drawing::XDrawPage> xDrawPage)
364 mxDrawPage.set(xDrawPage);
367 uno::Reference<drawing::XDrawPage> OOXMLDocumentImpl::getDrawPage()
369 return mxDrawPage;
372 uno::Reference<io::XInputStream> OOXMLDocumentImpl::getInputStream()
374 return mpStream->getDocumentStream();
377 uno::Reference<io::XInputStream> OOXMLDocumentImpl::getStorageStream()
379 return mpStream->getStorageStream();
382 OOXMLDocument *
383 OOXMLDocumentFactory::createDocument
384 (OOXMLStream::Pointer_t pStream)
386 return new OOXMLDocumentImpl(pStream);