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 <stdio.h>
25 #include <iostream>
26 #include "OOXMLParserState.hxx"
27 #include "ooxmlLoggers.hxx"
28
29 namespace writerfilter {
30 namespace ooxml
31 {
32 /*
33 class OOXMLParserState
34 */
35
OOXMLParserState()36 OOXMLParserState::OOXMLParserState() :
37 mbInSectionGroup(false),
38 mbInParagraphGroup(false),
39 mbInCharacterGroup(false),
40 mbLastParagraphInSection(false),
41 mbForwardEvents(true),
42 mnContexts(0),
43 mnHandle(0),
44 mpDocument(NULL)
45 {
46 }
47
~OOXMLParserState()48 OOXMLParserState::~OOXMLParserState()
49 {
50 }
51
setLastParagraphInSection(bool bLastParagraphInSection)52 void OOXMLParserState::setLastParagraphInSection(bool bLastParagraphInSection)
53 {
54 mbLastParagraphInSection = bLastParagraphInSection;
55 }
56
isLastParagraphInSection() const57 bool OOXMLParserState::isLastParagraphInSection() const
58 {
59 return mbLastParagraphInSection;
60 }
61
isInSectionGroup() const62 bool OOXMLParserState::isInSectionGroup() const
63 {
64 return mbInSectionGroup;
65 }
66
setInSectionGroup(bool bInSectionGroup)67 void OOXMLParserState::setInSectionGroup(bool bInSectionGroup)
68 {
69 mbInSectionGroup = bInSectionGroup;
70 }
71
isInParagraphGroup() const72 bool OOXMLParserState::isInParagraphGroup() const
73 {
74 return mbInParagraphGroup;
75 }
76
setInParagraphGroup(bool bInParagraphGroup)77 void OOXMLParserState::setInParagraphGroup(bool bInParagraphGroup)
78 {
79 mbInParagraphGroup = bInParagraphGroup;
80 }
81
isInCharacterGroup() const82 bool OOXMLParserState::isInCharacterGroup() const
83 {
84 return mbInCharacterGroup;
85 }
86
setInCharacterGroup(bool bInCharacterGroup)87 void OOXMLParserState::setInCharacterGroup(bool bInCharacterGroup)
88 {
89 mbInCharacterGroup = bInCharacterGroup;
90 }
91
setForwardEvents(bool bForwardEvents)92 void OOXMLParserState::setForwardEvents(bool bForwardEvents)
93 {
94 mbForwardEvents = bForwardEvents;
95 }
96
isForwardEvents() const97 bool OOXMLParserState::isForwardEvents() const
98 {
99 return mbForwardEvents;
100 }
101
getHandle() const102 const string OOXMLParserState::getHandle() const
103 {
104 char sBuffer[256];
105
106 snprintf(sBuffer, sizeof(sBuffer), "%d", mnHandle);
107
108 return sBuffer;
109 }
110
setHandle()111 void OOXMLParserState::setHandle()
112 {
113 mnHandle = mnContexts;
114 }
115
setDocument(OOXMLDocument * pDocument)116 void OOXMLParserState::setDocument(OOXMLDocument * pDocument)
117 {
118 mpDocument = pDocument;
119 }
120
getDocument() const121 OOXMLDocument * OOXMLParserState::getDocument() const
122 {
123 return mpDocument;
124 }
125
126
getTarget() const127 const ::rtl::OUString & OOXMLParserState::getTarget() const
128 {
129 return mpDocument->getTarget();
130 }
131
resolveCharacterProperties(Stream & rStream)132 void OOXMLParserState::resolveCharacterProperties(Stream & rStream)
133 {
134 if (mpCharacterProps.get() != NULL)
135 {
136 #ifdef DEBUG_PROPERTIES
137 debug_logger->startElement("resolveCharacterProperties");
138 #endif
139
140 rStream.props(mpCharacterProps);
141 mpCharacterProps.reset(new OOXMLPropertySetImpl());
142
143 #ifdef DEBUG_PROPERTIES
144 debug_logger->endElement("resolveCharacterProperties");
145 #endif
146 }
147 }
148
setCharacterProperties(OOXMLPropertySet::Pointer_t pProps)149 void OOXMLParserState::setCharacterProperties
150 (OOXMLPropertySet::Pointer_t pProps)
151 {
152 if (mpCharacterProps.get() == NULL)
153 mpCharacterProps = pProps;
154 else
155 mpCharacterProps->add(pProps);
156 }
157
setCellProperties(OOXMLPropertySet::Pointer_t pProps)158 void OOXMLParserState::setCellProperties
159 (OOXMLPropertySet::Pointer_t pProps)
160 {
161 if (mCellProps.size() > 0)
162 {
163 OOXMLPropertySet::Pointer_t & rCellProps = mCellProps.top();
164
165 if (rCellProps.get() == NULL)
166 rCellProps = pProps;
167 else
168 rCellProps->add(pProps);
169 }
170 }
171
setRowProperties(OOXMLPropertySet::Pointer_t pProps)172 void OOXMLParserState::setRowProperties
173 (OOXMLPropertySet::Pointer_t pProps)
174 {
175 if (mRowProps.size() > 0)
176 {
177 OOXMLPropertySet::Pointer_t & rRowProps = mRowProps.top();
178
179 if (rRowProps.get() == NULL)
180 rRowProps = pProps;
181 else
182 rRowProps->add(pProps);
183 }
184 }
185
resolveCellProperties(Stream & rStream)186 void OOXMLParserState::resolveCellProperties(Stream & rStream)
187 {
188 if (mCellProps.size() > 0)
189 {
190 OOXMLPropertySet::Pointer_t & rCellProps = mCellProps.top();
191
192 if (rCellProps.get() != NULL)
193 {
194 rStream.props(rCellProps);
195 rCellProps.reset(new OOXMLPropertySetImpl());
196 }
197 }
198 }
199
resolveRowProperties(Stream & rStream)200 void OOXMLParserState::resolveRowProperties(Stream & rStream)
201 {
202 if (mRowProps.size() > 0)
203 {
204 OOXMLPropertySet::Pointer_t & rRowProps = mRowProps.top();
205
206 if (rRowProps.get() != NULL)
207 {
208 rStream.props(rRowProps);
209 rRowProps.reset(new OOXMLPropertySetImpl());
210 }
211 }
212 }
213
resolveTableProperties(Stream & rStream)214 void OOXMLParserState::resolveTableProperties(Stream & rStream)
215 {
216 if (mTableProps.size() > 0)
217 {
218 OOXMLPropertySet::Pointer_t & rTableProps = mTableProps.top();
219
220 if (rTableProps.get() != NULL)
221 {
222 rStream.props(rTableProps);
223 rTableProps.reset(new OOXMLPropertySetImpl());
224 }
225 }
226 }
227
setTableProperties(OOXMLPropertySet::Pointer_t pProps)228 void OOXMLParserState::setTableProperties
229 (OOXMLPropertySet::Pointer_t pProps)
230 {
231 if (mTableProps.size() > 0)
232 {
233 OOXMLPropertySet::Pointer_t & rTableProps = mTableProps.top();
234 if (rTableProps.get() == NULL)
235 rTableProps = pProps;
236 else
237 rTableProps->add(pProps);
238 }
239 }
240
startTable()241 void OOXMLParserState::startTable()
242 {
243 OOXMLPropertySet::Pointer_t pCellProps;
244 OOXMLPropertySet::Pointer_t pRowProps;
245 OOXMLPropertySet::Pointer_t pTableProps;
246
247 mCellProps.push(pCellProps);
248 mRowProps.push(pRowProps);
249 mTableProps.push(pTableProps);
250 }
251
endTable()252 void OOXMLParserState::endTable()
253 {
254 mCellProps.pop();
255 mRowProps.pop();
256 mTableProps.pop();
257 }
258
incContextCount()259 void OOXMLParserState::incContextCount()
260 {
261 mnContexts++;
262 }
263
264 #ifdef DEBUG
getContextCount() const265 unsigned int OOXMLParserState::getContextCount() const
266 {
267 return mnContexts;
268 }
269
toString() const270 string OOXMLParserState::toString() const
271 {
272 return toTag()->toString();
273 }
274
toTag() const275 XMLTag::Pointer_t OOXMLParserState::toTag() const
276 {
277 XMLTag::Pointer_t pTag(new XMLTag("parserstate"));
278
279 string sTmp;
280
281 if (isInSectionGroup())
282 sTmp += "s";
283 else
284 sTmp += "-";
285
286 if (isInParagraphGroup())
287 sTmp += "p";
288 else
289 sTmp += "-";
290
291 if (isInCharacterGroup())
292 sTmp += "c";
293 else
294 sTmp += "-";
295
296 if (isForwardEvents())
297 sTmp += "f";
298 else
299 sTmp += "-";
300
301 pTag->addAttr("state", sTmp);
302 pTag->addAttr("XNoteId", getDocument()->getIDForXNoteStream() );
303 if (mpCharacterProps != OOXMLPropertySet::Pointer_t())
304 pTag->chars(mpCharacterProps->toString());
305
306 return pTag;
307 }
308
getXPathLogger()309 XPathLogger & OOXMLParserState::getXPathLogger()
310 {
311 return m_xPathLogger;
312 }
313 #endif
314
315 }}
316