1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <ooxml/resourceids.hxx>
21 #include "Handler.hxx"
23 #include <sal/log.hxx>
25 namespace writerfilter::ooxml
29 class OOXMLFootnoteHandler
31 OOXMLFootnoteHandler::OOXMLFootnoteHandler(OOXMLFastContextHandler
* pContext
)
32 : mpFastContext(pContext
)
36 OOXMLFootnoteHandler::~OOXMLFootnoteHandler()
40 void OOXMLFootnoteHandler::attribute(Id name
, Value
& val
)
44 case NS_ooxml::LN_CT_FtnEdnRef_id
:
45 mpFastContext
->resolveFootnote(sal_Int32(val
.getInt()));
52 void OOXMLFootnoteHandler::sprm(Sprm
& /*sprm*/)
57 class OOXMLEndnoteHandler
59 OOXMLEndnoteHandler::OOXMLEndnoteHandler(OOXMLFastContextHandler
* pContext
)
60 : mpFastContext(pContext
)
64 OOXMLEndnoteHandler::~OOXMLEndnoteHandler()
68 void OOXMLEndnoteHandler::attribute(Id name
, Value
& val
)
72 case NS_ooxml::LN_CT_FtnEdnRef_id
:
73 mpFastContext
->resolveEndnote(sal_Int32(val
.getInt()));
80 void OOXMLEndnoteHandler::sprm(Sprm
& /*sprm*/)
85 class OOXMLCommentHandler
87 OOXMLCommentHandler::OOXMLCommentHandler(OOXMLFastContextHandler
* pContext
)
88 : mpFastContext(pContext
)
92 OOXMLCommentHandler::~OOXMLCommentHandler()
96 void OOXMLCommentHandler::attribute(Id name
, Value
& val
)
100 case NS_ooxml::LN_CT_Markup_id
:
101 mpFastContext
->resolveComment(val
.getInt());
108 void OOXMLCommentHandler::sprm(Sprm
& /*sprm*/)
113 class OOXMLOLEHandler
115 OOXMLOLEHandler::OOXMLOLEHandler(OOXMLFastContextHandler
* pContext
)
116 : mpFastContext(pContext
)
120 OOXMLOLEHandler::~OOXMLOLEHandler()
124 void OOXMLOLEHandler::attribute(Id name
, Value
& val
)
128 case NS_ooxml::LN_CT_OLEObject_r_id
:
130 mpFastContext
->resolveData(val
.getString());
132 catch (const ::css::uno::Exception
&)
134 // Can't resolve OLE stream
135 SAL_WARN("writerfilter.ooxml", "Failed to open OLE stream!");
143 void OOXMLOLEHandler::sprm(Sprm
& /*sprm*/)
147 OOXMLEmbeddedFontHandler::OOXMLEmbeddedFontHandler(OOXMLFastContextHandler
* pContext
)
148 : mpFastContext(pContext
)
152 OOXMLEmbeddedFontHandler::~OOXMLEmbeddedFontHandler()
156 void OOXMLEmbeddedFontHandler::attribute(Id name
, Value
& val
)
160 case NS_ooxml::LN_CT_Rel_id
:
161 mpFastContext
->resolveData(val
.getString());
168 void OOXMLEmbeddedFontHandler::sprm(Sprm
& /*sprm*/)
173 class OOXMLFooterHandler
175 OOXMLFooterHandler::OOXMLFooterHandler(OOXMLFastContextHandler
* pContext
)
176 : mpFastContext(pContext
), mnType(0)
180 void OOXMLFooterHandler::finalize()
182 mpFastContext
->resolveFooter(mnType
, msStreamId
);
185 void OOXMLFooterHandler::attribute(Id name
, Value
& val
)
189 case NS_ooxml::LN_CT_HdrFtrRef_id
:
190 msStreamId
= val
.getString();
192 case NS_ooxml::LN_CT_HdrFtrRef_type
:
193 mnType
= val
.getInt();
200 void OOXMLFooterHandler::sprm(Sprm
& /*sprm*/)
205 class OOXMLHeaderHandler
207 OOXMLHeaderHandler::OOXMLHeaderHandler(OOXMLFastContextHandler
* pContext
)
208 : mpFastContext(pContext
), mnType(0)
212 void OOXMLHeaderHandler::finalize()
214 mpFastContext
->resolveHeader(mnType
, msStreamId
);
217 void OOXMLHeaderHandler::attribute(Id name
, Value
& val
)
221 case NS_ooxml::LN_CT_HdrFtrRef_id
:
222 msStreamId
= val
.getString();
224 case NS_ooxml::LN_CT_HdrFtrRef_type
:
225 mnType
= val
.getInt();
232 void OOXMLHeaderHandler::sprm(Sprm
& /*sprm*/)
237 class OOXMLBreakHandler
239 OOXMLBreakHandler::OOXMLBreakHandler(OOXMLFastContextHandler
* pContext
, Stream
&rStream
)
241 mpFastContext(pContext
),
246 OOXMLBreakHandler::~OOXMLBreakHandler()
250 mrStream
.props(mpFastContext
->getPropertySet().get());
251 mpFastContext
->clearProps();
254 sal_uInt8 tmpBreak
[1];
257 case NS_ooxml::LN_Value_ST_BrType_column
:
260 case NS_ooxml::LN_Value_ST_BrType_page
:
263 case NS_ooxml::LN_Value_ST_BrType_textWrapping
:
264 default: // when no attribute type is present, the spec assume textWrapping
268 mrStream
.text(&tmpBreak
[0], 1);
271 void OOXMLBreakHandler::attribute(Id name
, Value
& val
)
275 case NS_ooxml::LN_CT_Br_type
:
276 mnType
= val
.getInt();
278 case NS_ooxml::LN_CT_Br_clear
:
285 void OOXMLBreakHandler::sprm(Sprm
& /*sprm*/)
290 class OOXMLPictureHandler
292 OOXMLPictureHandler::OOXMLPictureHandler(OOXMLFastContextHandler
* pContext
)
293 : mpFastContext(pContext
)
297 OOXMLPictureHandler::~OOXMLPictureHandler()
301 void OOXMLPictureHandler::attribute(Id name
, Value
& val
)
303 if (name
== NS_ooxml::LN_AG_Blob_r_embed
)
304 mpFastContext
->resolvePicture(val
.getString());
307 writerfilter::Reference
<Properties
>::Pointer_t pProps
308 (val
.getProperties());
310 pProps
->resolve(*this);
314 void OOXMLPictureHandler::sprm(Sprm
& rSprm
)
316 writerfilter::Reference
<Properties
>::Pointer_t pProps
320 pProps
->resolve(*this);
324 class OOXMLHyperlinkHandler
327 OOXMLHyperlinkHandler::OOXMLHyperlinkHandler(OOXMLFastContextHandler
* pContext
)
328 : mpFastContext(pContext
)
332 OOXMLHyperlinkHandler::~OOXMLHyperlinkHandler()
336 void OOXMLHyperlinkHandler::writetext()
338 OUString sReturn
= " HYPERLINK \"" + mURL
+ "\"" + mFieldCode
;
339 mpFastContext
->text(sReturn
);
342 void OOXMLHyperlinkHandler::attribute(Id name
, Value
& val
)
346 case NS_ooxml::LN_CT_Hyperlink_tgtFrame
:
347 mFieldCode
+= " \\t \"";
348 mFieldCode
+= val
.getString();
351 case NS_ooxml::LN_CT_Hyperlink_tooltip
:
352 mFieldCode
+= " \\o \"";
353 mFieldCode
+= val
.getString();
356 case NS_ooxml::LN_CT_Hyperlink_docLocation
:
358 case NS_ooxml::LN_CT_Hyperlink_history
:
360 case NS_ooxml::LN_CT_Hyperlink_anchor
:
361 mFieldCode
+= " \\l \"";
362 mFieldCode
+= val
.getString();
365 case NS_ooxml::LN_CT_Hyperlink_r_id
:
366 mURL
= mpFastContext
->getTargetForId(val
.getString());
373 void OOXMLHyperlinkHandler::sprm(Sprm
& /*rSprm*/)
378 class OOXMLHyperlinkURLHandler
381 OOXMLHyperlinkURLHandler::OOXMLHyperlinkURLHandler(OOXMLFastContextHandler
* pContext
)
382 : mpFastContext(pContext
)
386 OOXMLHyperlinkURLHandler::~OOXMLHyperlinkURLHandler()
388 mpFastContext
->clearProps();
389 mpFastContext
->newProperty(NS_ooxml::LN_CT_Hyperlink_URL
, OOXMLValue::Pointer_t(new OOXMLStringValue(mURL
)));
392 void OOXMLHyperlinkURLHandler::attribute(Id name
, Value
& val
)
396 case NS_ooxml::LN_CT_Hyperlink_URL
:
397 mURL
= mpFastContext
->getTargetForId(val
.getString());
404 void OOXMLHyperlinkURLHandler::sprm(Sprm
& /*rSprm*/)
408 OOXMLAltChunkHandler::OOXMLAltChunkHandler(OOXMLFastContextHandler
* pContext
)
409 : mpFastContext(pContext
)
413 OOXMLAltChunkHandler::~OOXMLAltChunkHandler()
415 mpFastContext
->clearProps();
416 mpFastContext
->newProperty(NS_ooxml::LN_CT_AltChunk
,
417 OOXMLValue::Pointer_t(new OOXMLStringValue(m_aStreamName
)));
420 void OOXMLAltChunkHandler::attribute(Id nName
, Value
& rValue
)
424 case NS_ooxml::LN_CT_AltChunk
:
425 m_aStreamName
= mpFastContext
->getTargetForId(rValue
.getString());
432 void OOXMLAltChunkHandler::sprm(Sprm
& /*rSprm*/) {}
435 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */