1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include <ooxml/resourceids.hxx>
25 #include <resourcemodel/QNameToString.hxx>
26 #include "Handler.hxx"
27 
28 namespace writerfilter {
29 namespace ooxml
30 {
31 
32 /*
33   class OOXMLFootnoteHandler
34  */
OOXMLFootnoteHandler(OOXMLFastContextHandler * pContext)35 OOXMLFootnoteHandler::OOXMLFootnoteHandler(OOXMLFastContextHandler * pContext)
36 : mpFastContext(pContext)
37 {
38 }
39 
~OOXMLFootnoteHandler()40 OOXMLFootnoteHandler::~OOXMLFootnoteHandler()
41 {
42 }
43 
attribute(Id name,Value & val)44 void OOXMLFootnoteHandler::attribute(Id name, Value & val)
45 {
46     switch (name)
47     {
48     case NS_ooxml::LN_CT_FtnEdnRef_id:
49         mpFastContext->resolveFootnote(val.getInt());
50         break;
51     default:
52         break;
53     }
54 }
55 
sprm(Sprm &)56 void OOXMLFootnoteHandler::sprm(Sprm & /*sprm*/)
57 {
58 }
59 
60 /*
61   class OOXMLEndnoteHandler
62  */
OOXMLEndnoteHandler(OOXMLFastContextHandler * pContext)63 OOXMLEndnoteHandler::OOXMLEndnoteHandler(OOXMLFastContextHandler * pContext)
64 : mpFastContext(pContext)
65 {
66 }
67 
~OOXMLEndnoteHandler()68 OOXMLEndnoteHandler::~OOXMLEndnoteHandler()
69 {
70 }
71 
attribute(Id name,Value & val)72 void OOXMLEndnoteHandler::attribute(Id name, Value & val)
73 {
74     switch (name)
75     {
76     case NS_ooxml::LN_CT_FtnEdnRef_id:
77         mpFastContext->resolveEndnote(val.getInt());
78         break;
79     default:
80         break;
81     }
82 }
83 
sprm(Sprm &)84 void OOXMLEndnoteHandler::sprm(Sprm & /*sprm*/)
85 {
86 }
87 
88 /*
89   class OOXMLCommentHandler
90 */
OOXMLCommentHandler(OOXMLFastContextHandler * pContext)91 OOXMLCommentHandler::OOXMLCommentHandler(OOXMLFastContextHandler * pContext)
92 : mpFastContext(pContext)
93 {
94 }
95 
~OOXMLCommentHandler()96 OOXMLCommentHandler::~OOXMLCommentHandler()
97 {
98 }
99 
attribute(Id name,Value & val)100 void OOXMLCommentHandler::attribute(Id name, Value & val)
101 {
102     switch (name)
103     {
104     case NS_ooxml::LN_CT_Markup_id:
105         mpFastContext->resolveComment(val.getInt());
106         break;
107     default:
108         ;
109     }
110 }
111 
sprm(Sprm &)112 void OOXMLCommentHandler::sprm(Sprm & /*sprm*/)
113 {
114 }
115 
116 /*
117    class OOXMLOLEHandler
118 */
OOXMLOLEHandler(OOXMLFastContextHandler * pContext)119 OOXMLOLEHandler::OOXMLOLEHandler(OOXMLFastContextHandler * pContext)
120 : mpFastContext(pContext)
121 {
122 }
123 
~OOXMLOLEHandler()124 OOXMLOLEHandler::~OOXMLOLEHandler()
125 {
126 }
127 
attribute(Id name,Value & val)128 void OOXMLOLEHandler::attribute(Id name, Value & val)
129 {
130     switch (name)
131     {
132     case NS_ooxml::LN_CT_OLEObject_r_id:
133         mpFastContext->resolveOLE(val.getString());
134         break;
135     default:
136         ;
137     }
138 }
139 
sprm(Sprm &)140 void OOXMLOLEHandler::sprm(Sprm & /*sprm*/)
141 {
142 }
143 
144 /*
145   class OOXMLFooterHandler
146  */
OOXMLFooterHandler(OOXMLFastContextHandler * pContext)147 OOXMLFooterHandler::OOXMLFooterHandler(OOXMLFastContextHandler * pContext)
148 : mpFastContext(pContext), msStreamId(), mnType(0)
149 {
150 }
151 
~OOXMLFooterHandler()152 OOXMLFooterHandler::~OOXMLFooterHandler()
153 {
154     mpFastContext->resolveFooter(mnType, msStreamId);
155 }
156 
attribute(Id name,Value & val)157 void OOXMLFooterHandler::attribute(Id name, Value & val)
158 {
159     switch (name)
160     {
161     case NS_ooxml::LN_CT_HdrFtrRef_id:
162         msStreamId = val.getString();
163         break;
164     case NS_ooxml::LN_CT_HdrFtrRef_type:
165         mnType = val.getInt();
166         break;
167     default:
168         break;
169     }
170 }
171 
sprm(Sprm &)172 void OOXMLFooterHandler::sprm(Sprm & /*sprm*/)
173 {
174 }
175 
176 /*
177   class OOXMLHeaderHandler
178  */
OOXMLHeaderHandler(OOXMLFastContextHandler * pContext)179 OOXMLHeaderHandler::OOXMLHeaderHandler(OOXMLFastContextHandler * pContext)
180 : mpFastContext(pContext), msStreamId(), mnType(0)
181 {
182 }
183 
~OOXMLHeaderHandler()184 OOXMLHeaderHandler::~OOXMLHeaderHandler()
185 {
186     mpFastContext->resolveHeader(mnType, msStreamId);
187 }
188 
attribute(Id name,Value & val)189 void OOXMLHeaderHandler::attribute(Id name, Value & val)
190 {
191     switch (name)
192     {
193     case NS_ooxml::LN_CT_HdrFtrRef_id:
194         msStreamId = val.getString();
195         break;
196     case NS_ooxml::LN_CT_HdrFtrRef_type:
197         mnType = val.getInt();
198         break;
199     default:
200         break;
201     }
202 }
203 
sprm(Sprm &)204 void OOXMLHeaderHandler::sprm(Sprm & /*sprm*/)
205 {
206 }
207 
208 /*
209   class OOXMLBreakHandler
210  */
OOXMLBreakHandler(Stream & rStream,OOXMLFastContextHandler * pContext)211 OOXMLBreakHandler::OOXMLBreakHandler(Stream &rStream,
212                                      OOXMLFastContextHandler * pContext)
213 : mpFastContext(pContext), mnType(0), mnClear(0),
214   mrStream(rStream)
215 {
216 }
217 
~OOXMLBreakHandler()218 OOXMLBreakHandler::~OOXMLBreakHandler()
219 {
220     sal_uInt8 tmpBreak[1];
221     switch (mnType)
222     {
223     case NS_ooxml::LN_Value_ST_BrType_column:
224         tmpBreak[0] = 0x0E;
225         break;
226     case NS_ooxml::LN_Value_ST_BrType_page:
227         tmpBreak[0] = 0x0C;
228         break;
229     case NS_ooxml::LN_Value_ST_BrType_textWrapping:
230     default: // when no attribute type is present, the spec assume textWrapping
231         tmpBreak[0] = 0x0A;
232         break;
233     }
234     mrStream.text(&tmpBreak[0], 1);
235 }
236 
attribute(Id name,Value & val)237 void OOXMLBreakHandler::attribute(Id name, Value & val)
238 {
239     switch (name)
240     {
241     case NS_ooxml::LN_CT_Br_type:
242         mnType = val.getInt();
243         break;
244     case NS_ooxml::LN_CT_Br_clear:
245     	mnClear = val.getInt();
246     	break;
247     default:
248         break;
249     }
250 }
251 
sprm(Sprm &)252 void OOXMLBreakHandler::sprm(Sprm & /*sprm*/)
253 {
254 }
255 
256 /*
257   class OOXMLPictureHandler
258  */
OOXMLPictureHandler(OOXMLFastContextHandler * pContext)259 OOXMLPictureHandler::OOXMLPictureHandler(OOXMLFastContextHandler * pContext)
260 : mpFastContext(pContext)
261 {
262 }
263 
~OOXMLPictureHandler()264 OOXMLPictureHandler::~OOXMLPictureHandler()
265 {
266 }
267 
attribute(Id name,Value & val)268 void OOXMLPictureHandler::attribute(Id name, Value & val)
269 {
270     if (name == NS_ooxml::LN_AG_Blob_r_embed)
271         mpFastContext->resolvePicture(val.getString());
272     else
273     {
274         writerfilter::Reference<Properties>::Pointer_t pProps
275             (val.getProperties());
276         if (pProps.get() != NULL)
277             pProps->resolve(*this);
278     }
279 }
280 
sprm(Sprm & rSprm)281 void OOXMLPictureHandler::sprm(Sprm & rSprm)
282 {
283     writerfilter::Reference<Properties>::Pointer_t pProps
284         (rSprm.getProps());
285 
286     if (pProps.get() != NULL)
287         pProps->resolve(*this);
288 }
289 
290 /**
291    class OOXMLHyperlinkHandler
292  */
293 
OOXMLHyperlinkHandler(OOXMLFastContextHandler * pContext)294 OOXMLHyperlinkHandler::OOXMLHyperlinkHandler(OOXMLFastContextHandler * pContext)
295 : mpFastContext(pContext)
296 {
297 }
298 
~OOXMLHyperlinkHandler()299 OOXMLHyperlinkHandler::~OOXMLHyperlinkHandler()
300 {
301     ::rtl::OUString sReturn(RTL_CONSTASCII_USTRINGPARAM(" HYPERLINK \""));
302 
303     sReturn += mURL;
304     sReturn += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\""));
305     sReturn += mFieldCode;
306 
307     mpFastContext->characters(sReturn);
308 }
309 
attribute(Id name,Value & val)310 void OOXMLHyperlinkHandler::attribute(Id name, Value & val)
311 {
312     switch (name)
313     {
314     case NS_ooxml::LN_CT_Hyperlink_tgtFrame:
315         mFieldCode += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" \\t \""));
316         mFieldCode += val.getString();
317         mFieldCode += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\""));
318         break;
319     case NS_ooxml::LN_CT_Hyperlink_tooltip:
320         mFieldCode += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" \\o \""));
321         mFieldCode += val.getString();
322         mFieldCode += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\""));
323         break;
324     case NS_ooxml::LN_CT_Hyperlink_docLocation:
325         break;
326     case NS_ooxml::LN_CT_Hyperlink_history:
327         break;
328     case NS_ooxml::LN_CT_Hyperlink_anchor:
329         mFieldCode += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" \\l \""));
330         mFieldCode += val.getString();
331         mFieldCode += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\""));
332         break;
333     case NS_ooxml::LN_CT_Hyperlink_r_id:
334         mURL = mpFastContext->getTargetForId(val.getString());
335         break;
336     default:
337         break;
338     }
339 }
340 
sprm(Sprm &)341 void OOXMLHyperlinkHandler::sprm(Sprm & /*rSprm*/)
342 {
343 }
344 }}
345