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
{
30 class OOXMLFootnoteHandler
32 OOXMLFootnoteHandler::OOXMLFootnoteHandler(OOXMLFastContextHandler
* pContext
)
33 : mpFastContext(pContext
)
37 OOXMLFootnoteHandler::~OOXMLFootnoteHandler()
41 void OOXMLFootnoteHandler::attribute(Id name
, Value
& val
)
45 case NS_ooxml::LN_CT_FtnEdnRef_id
:
46 mpFastContext
->resolveFootnote(sal_Int32(val
.getInt()));
53 void OOXMLFootnoteHandler::sprm(Sprm
& /*sprm*/)
58 class OOXMLEndnoteHandler
60 OOXMLEndnoteHandler::OOXMLEndnoteHandler(OOXMLFastContextHandler
* pContext
)
61 : mpFastContext(pContext
)
65 OOXMLEndnoteHandler::~OOXMLEndnoteHandler()
69 void OOXMLEndnoteHandler::attribute(Id name
, Value
& val
)
73 case NS_ooxml::LN_CT_FtnEdnRef_id
:
74 mpFastContext
->resolveEndnote(sal_Int32(val
.getInt()));
81 void OOXMLEndnoteHandler::sprm(Sprm
& /*sprm*/)
86 class OOXMLCommentHandler
88 OOXMLCommentHandler::OOXMLCommentHandler(OOXMLFastContextHandler
* pContext
)
89 : mpFastContext(pContext
)
93 OOXMLCommentHandler::~OOXMLCommentHandler()
97 void OOXMLCommentHandler::attribute(Id name
, Value
& val
)
101 case NS_ooxml::LN_CT_Markup_id
:
102 mpFastContext
->resolveComment(val
.getInt());
109 void OOXMLCommentHandler::sprm(Sprm
& /*sprm*/)
114 class OOXMLOLEHandler
116 OOXMLOLEHandler::OOXMLOLEHandler(OOXMLFastContextHandler
* pContext
)
117 : mpFastContext(pContext
)
121 OOXMLOLEHandler::~OOXMLOLEHandler()
125 void OOXMLOLEHandler::attribute(Id name
, Value
& val
)
129 case NS_ooxml::LN_CT_OLEObject_r_id
:
131 mpFastContext
->resolveData(val
.getString());
133 catch (const ::css::uno::Exception
&)
135 // Can't resolve OLE stream
136 SAL_WARN("writerfilter.ooxml", "Failed to open OLE stream!");
144 void OOXMLOLEHandler::sprm(Sprm
& /*sprm*/)
148 OOXMLEmbeddedFontHandler::OOXMLEmbeddedFontHandler(OOXMLFastContextHandler
* pContext
)
149 : mpFastContext(pContext
)
153 OOXMLEmbeddedFontHandler::~OOXMLEmbeddedFontHandler()
157 void OOXMLEmbeddedFontHandler::attribute(Id name
, Value
& val
)
161 case NS_ooxml::LN_CT_Rel_id
:
162 mpFastContext
->resolveData(val
.getString());
169 void OOXMLEmbeddedFontHandler::sprm(Sprm
& /*sprm*/)
174 class OOXMLFooterHandler
176 OOXMLFooterHandler::OOXMLFooterHandler(OOXMLFastContextHandler
* pContext
)
177 : mpFastContext(pContext
), msStreamId(), mnType(0)
181 void OOXMLFooterHandler::finalize()
183 mpFastContext
->resolveFooter(mnType
, msStreamId
);
186 void OOXMLFooterHandler::attribute(Id name
, Value
& val
)
190 case NS_ooxml::LN_CT_HdrFtrRef_id
:
191 msStreamId
= val
.getString();
193 case NS_ooxml::LN_CT_HdrFtrRef_type
:
194 mnType
= val
.getInt();
201 void OOXMLFooterHandler::sprm(Sprm
& /*sprm*/)
206 class OOXMLHeaderHandler
208 OOXMLHeaderHandler::OOXMLHeaderHandler(OOXMLFastContextHandler
* pContext
)
209 : mpFastContext(pContext
), msStreamId(), mnType(0)
213 void OOXMLHeaderHandler::finalize()
215 mpFastContext
->resolveHeader(mnType
, msStreamId
);
218 void OOXMLHeaderHandler::attribute(Id name
, Value
& val
)
222 case NS_ooxml::LN_CT_HdrFtrRef_id
:
223 msStreamId
= val
.getString();
225 case NS_ooxml::LN_CT_HdrFtrRef_type
:
226 mnType
= val
.getInt();
233 void OOXMLHeaderHandler::sprm(Sprm
& /*sprm*/)
238 class OOXMLBreakHandler
240 OOXMLBreakHandler::OOXMLBreakHandler(Stream
&rStream
)
241 : mnType(0), mnClear(0),
246 OOXMLBreakHandler::~OOXMLBreakHandler()
248 sal_uInt8 tmpBreak
[1];
251 case NS_ooxml::LN_Value_ST_BrType_column
:
254 case NS_ooxml::LN_Value_ST_BrType_page
:
257 case NS_ooxml::LN_Value_ST_BrType_textWrapping
:
258 default: // when no attribute type is present, the spec assume textWrapping
262 mrStream
.text(&tmpBreak
[0], 1);
265 void OOXMLBreakHandler::attribute(Id name
, Value
& val
)
269 case NS_ooxml::LN_CT_Br_type
:
270 mnType
= val
.getInt();
272 case NS_ooxml::LN_CT_Br_clear
:
273 mnClear
= val
.getInt();
280 void OOXMLBreakHandler::sprm(Sprm
& /*sprm*/)
285 class OOXMLPictureHandler
287 OOXMLPictureHandler::OOXMLPictureHandler(OOXMLFastContextHandler
* pContext
)
288 : mpFastContext(pContext
)
292 OOXMLPictureHandler::~OOXMLPictureHandler()
296 void OOXMLPictureHandler::attribute(Id name
, Value
& val
)
298 if (name
== NS_ooxml::LN_AG_Blob_r_embed
)
299 mpFastContext
->resolvePicture(val
.getString());
302 writerfilter::Reference
<Properties
>::Pointer_t pProps
303 (val
.getProperties());
304 if (pProps
.get() != nullptr)
305 pProps
->resolve(*this);
309 void OOXMLPictureHandler::sprm(Sprm
& rSprm
)
311 writerfilter::Reference
<Properties
>::Pointer_t pProps
314 if (pProps
.get() != nullptr)
315 pProps
->resolve(*this);
319 class OOXMLHyperlinkHandler
322 OOXMLHyperlinkHandler::OOXMLHyperlinkHandler(OOXMLFastContextHandler
* pContext
)
323 : mpFastContext(pContext
)
327 OOXMLHyperlinkHandler::~OOXMLHyperlinkHandler()
331 void OOXMLHyperlinkHandler::writetext()
333 OUString
sReturn(" HYPERLINK \"");
337 sReturn
+= 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*/)
410 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */