update dev300-m58
[ooovba.git] / writerfilter / source / ooxml / OOXMLParserState.cxx
blobf7264494f638bfeb1a7010be4029b3d89534f7b3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OOXMLParserState.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <stdio.h>
32 #include <iostream>
33 #include "OOXMLParserState.hxx"
34 #include "ooxmlLoggers.hxx"
36 namespace writerfilter {
37 namespace ooxml
40 class OOXMLParserState
43 OOXMLParserState::OOXMLParserState() :
44 mbInSectionGroup(false),
45 mbInParagraphGroup(false),
46 mbInCharacterGroup(false),
47 mbLastParagraphInSection(false),
48 mbForwardEvents(true),
49 mnContexts(0),
50 mnHandle(0),
51 mpDocument(NULL)
55 OOXMLParserState::~OOXMLParserState()
59 void OOXMLParserState::setLastParagraphInSection(bool bLastParagraphInSection)
61 mbLastParagraphInSection = bLastParagraphInSection;
64 bool OOXMLParserState::isLastParagraphInSection() const
66 return mbLastParagraphInSection;
69 bool OOXMLParserState::isInSectionGroup() const
71 return mbInSectionGroup;
74 void OOXMLParserState::setInSectionGroup(bool bInSectionGroup)
76 mbInSectionGroup = bInSectionGroup;
79 bool OOXMLParserState::isInParagraphGroup() const
81 return mbInParagraphGroup;
84 void OOXMLParserState::setInParagraphGroup(bool bInParagraphGroup)
86 mbInParagraphGroup = bInParagraphGroup;
89 bool OOXMLParserState::isInCharacterGroup() const
91 return mbInCharacterGroup;
94 void OOXMLParserState::setInCharacterGroup(bool bInCharacterGroup)
96 mbInCharacterGroup = bInCharacterGroup;
99 void OOXMLParserState::setForwardEvents(bool bForwardEvents)
101 mbForwardEvents = bForwardEvents;
104 bool OOXMLParserState::isForwardEvents() const
106 return mbForwardEvents;
109 void OOXMLParserState::incContextCount()
111 mnContexts++;
114 const string OOXMLParserState::getHandle() const
116 char sBuffer[256];
118 snprintf(sBuffer, sizeof(sBuffer), "%d", mnHandle);
120 return sBuffer;
123 void OOXMLParserState::setHandle()
125 mnHandle = mnContexts;
128 unsigned int OOXMLParserState::getContextCount() const
130 return mnContexts;
133 void OOXMLParserState::setDocument(OOXMLDocument * pDocument)
135 mpDocument = pDocument;
138 OOXMLDocument * OOXMLParserState::getDocument() const
140 return mpDocument;
143 void OOXMLParserState::setXNoteId(const rtl::OUString & rId)
145 mpDocument->setXNoteId(rId);
148 const rtl::OUString & OOXMLParserState::getXNoteId() const
150 return mpDocument->getXNoteId();
153 void OOXMLParserState::setXNoteType(const Id & rId)
155 mpDocument->setXNoteType(rId);
158 const Id & OOXMLParserState::getXNoteType() const
160 return mpDocument->getXNoteType();
163 const ::rtl::OUString & OOXMLParserState::getTarget() const
165 return mpDocument->getTarget();
168 void OOXMLParserState::newCharacterProperty(const Id & rId,
169 OOXMLValue::Pointer_t pVal)
171 if (rId != 0x0)
173 if (mpCharacterProps.get() == NULL)
174 mpCharacterProps =
175 OOXMLPropertySet::Pointer_t(new OOXMLPropertySetImpl());
177 OOXMLPropertyImpl::Pointer_t pProperty
178 (new OOXMLPropertyImpl(rId, pVal, OOXMLPropertyImpl::ATTRIBUTE));
180 #ifdef DEBUG_PROPERTIES
181 debug_logger->startElement("<newCharacterProperty");
182 debug_logger->chars(pProperty->toString());
183 debug_logger->endElement("newCharacterProperty");
184 #endif
186 mpCharacterProps->add(pProperty);
191 void OOXMLParserState::resolveCharacterProperties(Stream & rStream)
193 if (mpCharacterProps.get() != NULL)
195 #ifdef DEBUG_PROPERTIES
196 debug_logger->startElement("resolveCharacterProperties");
197 debug_logger->chars(mpCharacterProps->toString());
198 debug_logger->endElement("resolveCharacterProperties");
199 #endif
200 rStream.props(mpCharacterProps);
201 mpCharacterProps.reset(new OOXMLPropertySetImpl());
205 OOXMLPropertySet::Pointer_t OOXMLParserState::getCharacterProperties() const
207 return mpCharacterProps;
210 void OOXMLParserState::setCharacterProperties
211 (OOXMLPropertySet::Pointer_t pProps)
213 if (mpCharacterProps.get() == NULL)
214 mpCharacterProps = pProps;
215 else
216 mpCharacterProps->add(pProps);
219 void OOXMLParserState::resolveTableProperties(Stream & rStream)
221 if (mpTableProps.get() != NULL)
223 rStream.props(mpTableProps);
224 mpTableProps.reset(new OOXMLPropertySetImpl());
228 void OOXMLParserState::setTableProperties
229 (OOXMLPropertySet::Pointer_t pProps)
231 if (mpTableProps.get() == NULL)
232 mpTableProps = pProps;
233 else
234 mpTableProps->add(pProps);
237 XMLTag::Pointer_t OOXMLParserState::toTag() const
239 XMLTag::Pointer_t pTag(new XMLTag("parserstate"));
241 string sTmp;
243 if (isInSectionGroup())
244 sTmp += "s";
245 else
246 sTmp += "-";
248 if (isInParagraphGroup())
249 sTmp += "p";
250 else
251 sTmp += "-";
253 if (isInCharacterGroup())
254 sTmp += "c";
255 else
256 sTmp += "-";
258 if (isForwardEvents())
259 sTmp += "f";
260 else
261 sTmp += "-";
263 pTag->addAttr("state", sTmp);
264 pTag->addAttr("XNoteId",
265 OUStringToOString(getXNoteId(),
266 RTL_TEXTENCODING_ASCII_US).getStr());
267 if (mpCharacterProps != OOXMLPropertySet::Pointer_t())
268 pTag->chars(mpCharacterProps->toString());
270 return pTag;
273 string OOXMLParserState::toString() const
275 return toTag()->toString();