android: Update app-specific/MIME type icons
[LibreOffice.git] / writerfilter / source / ooxml / Handler.cxx
blob7cbd9b6bfdc3e615745615da323625804601080c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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)
42 switch (name)
44 case NS_ooxml::LN_CT_FtnEdnRef_id:
45 mpFastContext->resolveFootnote(sal_Int32(val.getInt()));
46 break;
47 default:
48 break;
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)
70 switch (name)
72 case NS_ooxml::LN_CT_FtnEdnRef_id:
73 mpFastContext->resolveEndnote(sal_Int32(val.getInt()));
74 break;
75 default:
76 break;
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)
98 switch (name)
100 case NS_ooxml::LN_CT_Markup_id:
101 mpFastContext->resolveComment(val.getInt());
102 break;
103 default:
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)
126 switch (name)
128 case NS_ooxml::LN_CT_OLEObject_r_id:
129 try {
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!");
137 break;
138 default:
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)
158 switch (name)
160 case NS_ooxml::LN_CT_Rel_id:
161 mpFastContext->resolveData(val.getString());
162 break;
163 default:
164 break;
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)
187 switch (name)
189 case NS_ooxml::LN_CT_HdrFtrRef_id:
190 msStreamId = val.getString();
191 break;
192 case NS_ooxml::LN_CT_HdrFtrRef_type:
193 mnType = val.getInt();
194 break;
195 default:
196 break;
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)
219 switch (name)
221 case NS_ooxml::LN_CT_HdrFtrRef_id:
222 msStreamId = val.getString();
223 break;
224 case NS_ooxml::LN_CT_HdrFtrRef_type:
225 mnType = val.getInt();
226 break;
227 default:
228 break;
232 void OOXMLHeaderHandler::sprm(Sprm & /*sprm*/)
237 class OOXMLBreakHandler
239 OOXMLBreakHandler::OOXMLBreakHandler(OOXMLFastContextHandler* pContext, Stream &rStream)
240 : mnType(0),
241 mpFastContext(pContext),
242 mrStream(rStream)
246 OOXMLBreakHandler::~OOXMLBreakHandler()
248 if (mpFastContext)
250 mrStream.props(mpFastContext->getPropertySet().get());
251 mpFastContext->clearProps();
254 sal_uInt8 tmpBreak[1];
255 switch (mnType)
257 case NS_ooxml::LN_Value_ST_BrType_column:
258 tmpBreak[0] = 0x0E;
259 break;
260 case NS_ooxml::LN_Value_ST_BrType_page:
261 tmpBreak[0] = 0x0C;
262 break;
263 case NS_ooxml::LN_Value_ST_BrType_textWrapping:
264 default: // when no attribute type is present, the spec assume textWrapping
265 tmpBreak[0] = 0x0A;
266 break;
268 mrStream.text(&tmpBreak[0], 1);
271 void OOXMLBreakHandler::attribute(Id name, Value & val)
273 switch (name)
275 case NS_ooxml::LN_CT_Br_type:
276 mnType = val.getInt();
277 break;
278 case NS_ooxml::LN_CT_Br_clear:
279 break;
280 default:
281 break;
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());
305 else
307 writerfilter::Reference<Properties>::Pointer_t pProps
308 (val.getProperties());
309 if (pProps)
310 pProps->resolve(*this);
314 void OOXMLPictureHandler::sprm(Sprm & rSprm)
316 writerfilter::Reference<Properties>::Pointer_t pProps
317 (rSprm.getProps());
319 if (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)
344 switch (name)
346 case NS_ooxml::LN_CT_Hyperlink_tgtFrame:
347 mFieldCode += " \\t \"";
348 mFieldCode += val.getString();
349 mFieldCode += "\"";
350 break;
351 case NS_ooxml::LN_CT_Hyperlink_tooltip:
352 mFieldCode += " \\o \"";
353 mFieldCode += val.getString();
354 mFieldCode += "\"";
355 break;
356 case NS_ooxml::LN_CT_Hyperlink_docLocation:
357 break;
358 case NS_ooxml::LN_CT_Hyperlink_history:
359 break;
360 case NS_ooxml::LN_CT_Hyperlink_anchor:
361 mFieldCode += " \\l \"";
362 mFieldCode += val.getString();
363 mFieldCode += "\"";
364 break;
365 case NS_ooxml::LN_CT_Hyperlink_r_id:
366 mURL = mpFastContext->getTargetForId(val.getString());
367 break;
368 default:
369 break;
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)
394 switch (name)
396 case NS_ooxml::LN_CT_Hyperlink_URL:
397 mURL = mpFastContext->getTargetForId(val.getString());
398 break;
399 default:
400 break;
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)
422 switch (nName)
424 case NS_ooxml::LN_CT_AltChunk:
425 m_aStreamName = mpFastContext->getTargetForId(rValue.getString());
426 break;
427 default:
428 break;
432 void OOXMLAltChunkHandler::sprm(Sprm& /*rSprm*/) {}
435 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */