Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <stdio.h>
21 : #include <iostream>
22 : #include "OOXMLParserState.hxx"
23 : #include "ooxmlLoggers.hxx"
24 :
25 : namespace writerfilter {
26 : namespace ooxml
27 : {
28 : /*
29 : class OOXMLParserState
30 : */
31 :
32 5380 : OOXMLParserState::OOXMLParserState() :
33 : mbInSectionGroup(false),
34 : mbInParagraphGroup(false),
35 : mbInCharacterGroup(false),
36 : mbLastParagraphInSection(false),
37 : mbForwardEvents(true),
38 : mnContexts(0),
39 : mnHandle(0),
40 : mpDocument(NULL),
41 : inTxbxContent(false),
42 : savedInParagraphGroup(false),
43 : savedInCharacterGroup(false),
44 5380 : savedLastParagraphInSection(false)
45 : {
46 5380 : }
47 :
48 10760 : OOXMLParserState::~OOXMLParserState()
49 : {
50 10760 : }
51 :
52 1088 : void OOXMLParserState::setLastParagraphInSection(bool bLastParagraphInSection)
53 : {
54 1088 : mbLastParagraphInSection = bLastParagraphInSection;
55 1088 : }
56 :
57 18234 : bool OOXMLParserState::isLastParagraphInSection() const
58 : {
59 18234 : return mbLastParagraphInSection;
60 : }
61 :
62 23672 : bool OOXMLParserState::isInSectionGroup() const
63 : {
64 23672 : return mbInSectionGroup;
65 : }
66 :
67 3871 : void OOXMLParserState::setInSectionGroup(bool bInSectionGroup)
68 : {
69 3871 : mbInSectionGroup = bInSectionGroup;
70 3871 : }
71 :
72 110976 : bool OOXMLParserState::isInParagraphGroup() const
73 : {
74 110976 : return mbInParagraphGroup;
75 : }
76 :
77 40841 : void OOXMLParserState::setInParagraphGroup(bool bInParagraphGroup)
78 : {
79 40841 : mbInParagraphGroup = bInParagraphGroup;
80 40841 : }
81 :
82 185458 : bool OOXMLParserState::isInCharacterGroup() const
83 : {
84 185458 : return mbInCharacterGroup;
85 : }
86 :
87 97155 : void OOXMLParserState::setInCharacterGroup(bool bInCharacterGroup)
88 : {
89 97155 : mbInCharacterGroup = bInCharacterGroup;
90 97155 : }
91 :
92 5986 : void OOXMLParserState::setForwardEvents(bool bForwardEvents)
93 : {
94 5986 : mbForwardEvents = bForwardEvents;
95 5986 : }
96 :
97 275712 : bool OOXMLParserState::isForwardEvents() const
98 : {
99 275712 : return mbForwardEvents;
100 : }
101 :
102 19298 : const string OOXMLParserState::getHandle() const
103 : {
104 : char sBuffer[256];
105 :
106 19298 : snprintf(sBuffer, sizeof(sBuffer), "%u", mnHandle);
107 :
108 19298 : return sBuffer;
109 : }
110 :
111 18234 : void OOXMLParserState::setHandle()
112 : {
113 18234 : mnHandle = mnContexts;
114 18234 : }
115 :
116 5380 : void OOXMLParserState::setDocument(OOXMLDocumentImpl* pDocument)
117 : {
118 5380 : mpDocument = pDocument;
119 5380 : }
120 :
121 25529 : OOXMLDocumentImpl* OOXMLParserState::getDocument() const
122 : {
123 25529 : return mpDocument;
124 : }
125 :
126 5410 : void OOXMLParserState::setXNoteId(const sal_Int32 nId)
127 : {
128 5410 : mpDocument->setXNoteId(nId);
129 5410 : }
130 :
131 303 : sal_Int32 OOXMLParserState::getXNoteId() const
132 : {
133 303 : return mpDocument->getXNoteId();
134 : }
135 :
136 1088 : const OUString & OOXMLParserState::getTarget() const
137 : {
138 1088 : return mpDocument->getTarget();
139 : }
140 :
141 48579 : void OOXMLParserState::resolveCharacterProperties(Stream & rStream)
142 : {
143 48579 : if (mpCharacterProps.get() != NULL)
144 : {
145 : #ifdef DEBUG_PROPERTIES
146 : debug_logger->startElement("resolveCharacterProperties");
147 : #endif
148 :
149 23295 : rStream.props(mpCharacterProps);
150 23295 : mpCharacterProps.reset(new OOXMLPropertySetImpl());
151 :
152 : #ifdef DEBUG_PROPERTIES
153 : debug_logger->endElement();
154 : #endif
155 : }
156 48579 : }
157 :
158 1896 : void OOXMLParserState::setCharacterProperties
159 : (OOXMLPropertySet::Pointer_t pProps)
160 : {
161 1896 : if (mpCharacterProps.get() == NULL)
162 258 : mpCharacterProps = pProps;
163 : else
164 1638 : mpCharacterProps->add(pProps);
165 1896 : }
166 :
167 6449 : void OOXMLParserState::setCellProperties
168 : (OOXMLPropertySet::Pointer_t pProps)
169 : {
170 6449 : if (!mCellProps.empty())
171 : {
172 6449 : OOXMLPropertySet::Pointer_t & rCellProps = mCellProps.top();
173 :
174 6449 : if (rCellProps.get() == NULL)
175 329 : rCellProps = pProps;
176 : else
177 6120 : rCellProps->add(pProps);
178 : }
179 6449 : }
180 :
181 1638 : void OOXMLParserState::setRowProperties
182 : (OOXMLPropertySet::Pointer_t pProps)
183 : {
184 1638 : if (!mRowProps.empty())
185 : {
186 1638 : OOXMLPropertySet::Pointer_t & rRowProps = mRowProps.top();
187 :
188 1638 : if (rRowProps.get() == NULL)
189 217 : rRowProps = pProps;
190 : else
191 1421 : rRowProps->add(pProps);
192 : }
193 1638 : }
194 :
195 6472 : void OOXMLParserState::resolveCellProperties(Stream & rStream)
196 : {
197 6472 : if (!mCellProps.empty())
198 : {
199 6472 : OOXMLPropertySet::Pointer_t & rCellProps = mCellProps.top();
200 :
201 6472 : if (rCellProps.get() != NULL)
202 : {
203 6454 : rStream.props(rCellProps);
204 6454 : rCellProps.reset(new OOXMLPropertySetImpl());
205 : }
206 : }
207 6472 : }
208 :
209 2102 : void OOXMLParserState::resolveRowProperties(Stream & rStream)
210 : {
211 2102 : if (!mRowProps.empty())
212 : {
213 2102 : OOXMLPropertySet::Pointer_t & rRowProps = mRowProps.top();
214 :
215 2102 : if (rRowProps.get() != NULL)
216 : {
217 1668 : rStream.props(rRowProps);
218 1668 : rRowProps.reset(new OOXMLPropertySetImpl());
219 : }
220 : }
221 2102 : }
222 :
223 2102 : void OOXMLParserState::resolveTableProperties(Stream & rStream)
224 : {
225 2102 : if (!mTableProps.empty())
226 : {
227 2102 : OOXMLPropertySet::Pointer_t & rTableProps = mTableProps.top();
228 :
229 2102 : if (rTableProps.get() != NULL)
230 : {
231 2102 : rStream.props(rTableProps);
232 : // Don't clean the table props to send them again for each row
233 : // This mimics the behaviour from RTF tokenizer.
234 : }
235 : }
236 2102 : }
237 :
238 991 : void OOXMLParserState::setTableProperties
239 : (OOXMLPropertySet::Pointer_t pProps)
240 : {
241 991 : if (!mTableProps.empty())
242 : {
243 689 : OOXMLPropertySet::Pointer_t & rTableProps = mTableProps.top();
244 689 : if (rTableProps.get() == NULL)
245 331 : rTableProps = pProps;
246 : else
247 358 : rTableProps->add(pProps);
248 : }
249 991 : }
250 :
251 331 : void OOXMLParserState::startTable()
252 : {
253 331 : OOXMLPropertySet::Pointer_t pCellProps;
254 662 : OOXMLPropertySet::Pointer_t pRowProps;
255 662 : OOXMLPropertySet::Pointer_t pTableProps;
256 :
257 331 : mCellProps.push(pCellProps);
258 331 : mRowProps.push(pRowProps);
259 662 : mTableProps.push(pTableProps);
260 331 : }
261 :
262 331 : void OOXMLParserState::endTable()
263 : {
264 331 : mCellProps.pop();
265 331 : mRowProps.pop();
266 331 : mTableProps.pop();
267 331 : }
268 :
269 1162809 : void OOXMLParserState::incContextCount()
270 : {
271 1162809 : mnContexts++;
272 1162809 : }
273 :
274 319 : void OOXMLParserState::startTxbxContent()
275 : {
276 319 : if( inTxbxContent )
277 : SAL_WARN( "writerfilter", "Nested w:txbxContent" );
278 319 : inTxbxContent = true;
279 : // Do not save and reset section group state, it'd cause a new page.
280 : // savedInSectionGroup = mbInSectionGroup;
281 319 : savedInParagraphGroup = mbInParagraphGroup;
282 319 : savedInCharacterGroup = mbInCharacterGroup;
283 319 : savedLastParagraphInSection = mbLastParagraphInSection;
284 : // mbInSectionGroup = false;
285 319 : mbInParagraphGroup = false;
286 319 : mbInCharacterGroup = false;
287 319 : mbLastParagraphInSection = false;
288 319 : }
289 :
290 319 : void OOXMLParserState::endTxbxContent()
291 : {
292 319 : if( !inTxbxContent )
293 : {
294 : SAL_WARN( "writerfilter", "Non-matching closing w:txbxContent" );
295 320 : return;
296 : }
297 : // mbInSectionGroup = savedInSectionGroup;
298 318 : mbInParagraphGroup = savedInParagraphGroup;
299 318 : mbInCharacterGroup = savedInCharacterGroup;
300 318 : mbLastParagraphInSection = savedLastParagraphInSection;
301 318 : inTxbxContent = false;
302 : }
303 :
304 : #if OSL_DEBUG_LEVEL > 1
305 : void OOXMLParserState::dumpXml( const TagLogger::Pointer_t& pLogger )
306 : {
307 : pLogger->startElement("parserstate");
308 :
309 : string sTmp;
310 :
311 : if (isInSectionGroup())
312 : sTmp += "s";
313 : else
314 : sTmp += "-";
315 :
316 : if (isInParagraphGroup())
317 : sTmp += "p";
318 : else
319 : sTmp += "-";
320 :
321 : if (isInCharacterGroup())
322 : sTmp += "c";
323 : else
324 : sTmp += "-";
325 :
326 : if (isForwardEvents())
327 : sTmp += "f";
328 : else
329 : sTmp += "-";
330 :
331 : pLogger->attribute("state", sTmp);
332 : pLogger->attribute("XNoteId", getXNoteId() );
333 : if (mpCharacterProps != OOXMLPropertySet::Pointer_t())
334 : pLogger->chars(mpCharacterProps->toString());
335 :
336 : pLogger->endElement();
337 : }
338 :
339 : XPathLogger & OOXMLParserState::getXPathLogger()
340 : {
341 : return m_xPathLogger;
342 : }
343 : #endif
344 :
345 42 : }}
346 :
347 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|