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 448 : 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 448 : savedLastParagraphInSection(false)
45 : {
46 448 : }
47 :
48 896 : OOXMLParserState::~OOXMLParserState()
49 : {
50 896 : }
51 :
52 114 : void OOXMLParserState::setLastParagraphInSection(bool bLastParagraphInSection)
53 : {
54 114 : mbLastParagraphInSection = bLastParagraphInSection;
55 114 : }
56 :
57 425 : bool OOXMLParserState::isLastParagraphInSection() const
58 : {
59 425 : return mbLastParagraphInSection;
60 : }
61 :
62 806 : bool OOXMLParserState::isInSectionGroup() const
63 : {
64 806 : return mbInSectionGroup;
65 : }
66 :
67 334 : void OOXMLParserState::setInSectionGroup(bool bInSectionGroup)
68 : {
69 334 : mbInSectionGroup = bInSectionGroup;
70 334 : }
71 :
72 2202 : bool OOXMLParserState::isInParagraphGroup() const
73 : {
74 2202 : return mbInParagraphGroup;
75 : }
76 :
77 946 : void OOXMLParserState::setInParagraphGroup(bool bInParagraphGroup)
78 : {
79 946 : mbInParagraphGroup = bInParagraphGroup;
80 946 : }
81 :
82 2850 : bool OOXMLParserState::isInCharacterGroup() const
83 : {
84 2850 : return mbInCharacterGroup;
85 : }
86 :
87 1302 : void OOXMLParserState::setInCharacterGroup(bool bInCharacterGroup)
88 : {
89 1302 : mbInCharacterGroup = bInCharacterGroup;
90 1302 : }
91 :
92 452 : void OOXMLParserState::setForwardEvents(bool bForwardEvents)
93 : {
94 452 : mbForwardEvents = bForwardEvents;
95 452 : }
96 :
97 4769 : bool OOXMLParserState::isForwardEvents() const
98 : {
99 4769 : return mbForwardEvents;
100 : }
101 :
102 532 : const string OOXMLParserState::getHandle() const
103 : {
104 : char sBuffer[256];
105 :
106 532 : snprintf(sBuffer, sizeof(sBuffer), "%d", mnHandle);
107 :
108 532 : return sBuffer;
109 : }
110 :
111 425 : void OOXMLParserState::setHandle()
112 : {
113 425 : mnHandle = mnContexts;
114 425 : }
115 :
116 448 : void OOXMLParserState::setDocument(OOXMLDocument * pDocument)
117 : {
118 448 : mpDocument = pDocument;
119 448 : }
120 :
121 194 : OOXMLDocument * OOXMLParserState::getDocument() const
122 : {
123 194 : return mpDocument;
124 : }
125 :
126 448 : void OOXMLParserState::setXNoteId(const sal_Int32 nId)
127 : {
128 448 : mpDocument->setXNoteId(nId);
129 448 : }
130 :
131 2 : sal_Int32 OOXMLParserState::getXNoteId() const
132 : {
133 2 : return mpDocument->getXNoteId();
134 : }
135 :
136 36 : const OUString & OOXMLParserState::getTarget() const
137 : {
138 36 : return mpDocument->getTarget();
139 : }
140 :
141 664 : void OOXMLParserState::resolveCharacterProperties(Stream & rStream)
142 : {
143 664 : if (mpCharacterProps.get() != NULL)
144 : {
145 : #ifdef DEBUG_PROPERTIES
146 : debug_logger->startElement("resolveCharacterProperties");
147 : #endif
148 :
149 296 : rStream.props(mpCharacterProps);
150 296 : mpCharacterProps.reset(new OOXMLPropertySetImpl());
151 :
152 : #ifdef DEBUG_PROPERTIES
153 : debug_logger->endElement();
154 : #endif
155 : }
156 664 : }
157 :
158 35 : void OOXMLParserState::setCharacterProperties
159 : (OOXMLPropertySet::Pointer_t pProps)
160 : {
161 35 : if (mpCharacterProps.get() == NULL)
162 17 : mpCharacterProps = pProps;
163 : else
164 18 : mpCharacterProps->add(pProps);
165 35 : }
166 :
167 182 : void OOXMLParserState::setCellProperties
168 : (OOXMLPropertySet::Pointer_t pProps)
169 : {
170 182 : if (!mCellProps.empty())
171 : {
172 182 : OOXMLPropertySet::Pointer_t & rCellProps = mCellProps.top();
173 :
174 182 : if (rCellProps.get() == NULL)
175 32 : rCellProps = pProps;
176 : else
177 150 : rCellProps->add(pProps);
178 : }
179 182 : }
180 :
181 27 : void OOXMLParserState::setRowProperties
182 : (OOXMLPropertySet::Pointer_t pProps)
183 : {
184 27 : if (!mRowProps.empty())
185 : {
186 27 : OOXMLPropertySet::Pointer_t & rRowProps = mRowProps.top();
187 :
188 27 : if (rRowProps.get() == NULL)
189 14 : rRowProps = pProps;
190 : else
191 13 : rRowProps->add(pProps);
192 : }
193 27 : }
194 :
195 191 : void OOXMLParserState::resolveCellProperties(Stream & rStream)
196 : {
197 191 : if (!mCellProps.empty())
198 : {
199 191 : OOXMLPropertySet::Pointer_t & rCellProps = mCellProps.top();
200 :
201 191 : if (rCellProps.get() != NULL)
202 : {
203 187 : rStream.props(rCellProps);
204 187 : rCellProps.reset(new OOXMLPropertySetImpl());
205 : }
206 : }
207 191 : }
208 :
209 53 : void OOXMLParserState::resolveRowProperties(Stream & rStream)
210 : {
211 53 : if (!mRowProps.empty())
212 : {
213 53 : OOXMLPropertySet::Pointer_t & rRowProps = mRowProps.top();
214 :
215 53 : if (rRowProps.get() != NULL)
216 : {
217 27 : rStream.props(rRowProps);
218 27 : rRowProps.reset(new OOXMLPropertySetImpl());
219 : }
220 : }
221 53 : }
222 :
223 53 : void OOXMLParserState::resolveTableProperties(Stream & rStream)
224 : {
225 53 : if (!mTableProps.empty())
226 : {
227 53 : OOXMLPropertySet::Pointer_t & rTableProps = mTableProps.top();
228 :
229 53 : if (rTableProps.get() != NULL)
230 : {
231 53 : rStream.props(rTableProps);
232 53 : rTableProps.reset(new OOXMLPropertySetImpl());
233 : }
234 : }
235 53 : }
236 :
237 96 : void OOXMLParserState::setTableProperties
238 : (OOXMLPropertySet::Pointer_t pProps)
239 : {
240 96 : if (!mTableProps.empty())
241 : {
242 69 : OOXMLPropertySet::Pointer_t & rTableProps = mTableProps.top();
243 69 : if (rTableProps.get() == NULL)
244 32 : rTableProps = pProps;
245 : else
246 37 : rTableProps->add(pProps);
247 : }
248 96 : }
249 :
250 32 : void OOXMLParserState::startTable()
251 : {
252 32 : OOXMLPropertySet::Pointer_t pCellProps;
253 32 : OOXMLPropertySet::Pointer_t pRowProps;
254 32 : OOXMLPropertySet::Pointer_t pTableProps;
255 :
256 32 : mCellProps.push(pCellProps);
257 32 : mRowProps.push(pRowProps);
258 32 : mTableProps.push(pTableProps);
259 32 : }
260 :
261 32 : void OOXMLParserState::endTable()
262 : {
263 32 : mCellProps.pop();
264 32 : mRowProps.pop();
265 32 : mTableProps.pop();
266 32 : }
267 :
268 26963 : void OOXMLParserState::incContextCount()
269 : {
270 26963 : mnContexts++;
271 26963 : }
272 :
273 8 : void OOXMLParserState::startTxbxContent()
274 : {
275 8 : if( inTxbxContent )
276 : SAL_WARN( "writerfilter", "Nested w:txbxContent" );
277 8 : inTxbxContent = true;
278 : // Do not save and reset section group state, it'd cause a new page.
279 : // savedInSectionGroup = mbInSectionGroup;
280 8 : savedInParagraphGroup = mbInParagraphGroup;
281 8 : savedInCharacterGroup = mbInCharacterGroup;
282 8 : savedLastParagraphInSection = mbLastParagraphInSection;
283 : // mbInSectionGroup = false;
284 8 : mbInParagraphGroup = false;
285 8 : mbInCharacterGroup = false;
286 8 : mbLastParagraphInSection = false;
287 8 : }
288 :
289 8 : void OOXMLParserState::endTxbxContent()
290 : {
291 8 : if( !inTxbxContent )
292 : {
293 : SAL_WARN( "writerfilter", "Non-matching closing w:txbxContent" );
294 8 : return;
295 : }
296 : // mbInSectionGroup = savedInSectionGroup;
297 8 : mbInParagraphGroup = savedInParagraphGroup;
298 8 : mbInCharacterGroup = savedInCharacterGroup;
299 8 : mbLastParagraphInSection = savedLastParagraphInSection;
300 8 : inTxbxContent = false;
301 : }
302 :
303 : #if OSL_DEBUG_LEVEL > 1
304 : void OOXMLParserState::dumpXml( const TagLogger::Pointer_t& pLogger )
305 : {
306 : pLogger->startElement("parserstate");
307 :
308 : string sTmp;
309 :
310 : if (isInSectionGroup())
311 : sTmp += "s";
312 : else
313 : sTmp += "-";
314 :
315 : if (isInParagraphGroup())
316 : sTmp += "p";
317 : else
318 : sTmp += "-";
319 :
320 : if (isInCharacterGroup())
321 : sTmp += "c";
322 : else
323 : sTmp += "-";
324 :
325 : if (isForwardEvents())
326 : sTmp += "f";
327 : else
328 : sTmp += "-";
329 :
330 : pLogger->attribute("state", sTmp);
331 : pLogger->attribute("XNoteId", getXNoteId() );
332 : if (mpCharacterProps != OOXMLPropertySet::Pointer_t())
333 : pLogger->chars(mpCharacterProps->toString());
334 :
335 : pLogger->endElement();
336 : }
337 :
338 : XPathLogger & OOXMLParserState::getXPathLogger()
339 : {
340 : return m_xPathLogger;
341 : }
342 : #endif
343 :
344 15 : }}
345 :
346 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|