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