1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OOXMLParserState.cxx,v $
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 ************************************************************************/
33 #include "OOXMLParserState.hxx"
34 #include "ooxmlLoggers.hxx"
36 namespace writerfilter
{
40 class OOXMLParserState
43 OOXMLParserState::OOXMLParserState() :
44 mbInSectionGroup(false),
45 mbInParagraphGroup(false),
46 mbInCharacterGroup(false),
47 mbLastParagraphInSection(false),
48 mbForwardEvents(true),
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()
114 const string
OOXMLParserState::getHandle() const
118 snprintf(sBuffer
, sizeof(sBuffer
), "%d", mnHandle
);
123 void OOXMLParserState::setHandle()
125 mnHandle
= mnContexts
;
128 unsigned int OOXMLParserState::getContextCount() const
133 void OOXMLParserState::setDocument(OOXMLDocument
* pDocument
)
135 mpDocument
= pDocument
;
138 OOXMLDocument
* OOXMLParserState::getDocument() const
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
)
173 if (mpCharacterProps
.get() == NULL
)
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");
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");
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
;
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
;
234 mpTableProps
->add(pProps
);
237 XMLTag::Pointer_t
OOXMLParserState::toTag() const
239 XMLTag::Pointer_t
pTag(new XMLTag("parserstate"));
243 if (isInSectionGroup())
248 if (isInParagraphGroup())
253 if (isInCharacterGroup())
258 if (isForwardEvents())
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());
273 string
OOXMLParserState::toString() const
275 return toTag()->toString();