1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include "OOXMLParserState.hxx"
23 #include "Handler.hxx"
25 #include <sal/log.hxx>
27 namespace writerfilter
{
31 class OOXMLParserState
34 OOXMLParserState::OOXMLParserState() :
35 mbInSectionGroup(false),
36 mbInParagraphGroup(false),
37 mbInCharacterGroup(false),
38 mbLastParagraphInSection(false),
39 mbForwardEvents(true),
44 savedInParagraphGroup(false),
45 savedInCharacterGroup(false),
46 savedLastParagraphInSection(false)
50 OOXMLParserState::~OOXMLParserState()
54 void OOXMLParserState::setLastParagraphInSection(bool bLastParagraphInSection
)
56 mbLastParagraphInSection
= bLastParagraphInSection
;
60 void OOXMLParserState::setInSectionGroup(bool bInSectionGroup
)
62 mbInSectionGroup
= bInSectionGroup
;
66 void OOXMLParserState::setInParagraphGroup(bool bInParagraphGroup
)
68 mbInParagraphGroup
= bInParagraphGroup
;
72 void OOXMLParserState::setInCharacterGroup(bool bInCharacterGroup
)
74 mbInCharacterGroup
= bInCharacterGroup
;
77 void OOXMLParserState::setForwardEvents(bool bForwardEvents
)
79 mbForwardEvents
= bForwardEvents
;
83 const std::string
OOXMLParserState::getHandle() const
87 snprintf(sBuffer
, sizeof(sBuffer
), "%u", mnHandle
);
92 void OOXMLParserState::setHandle()
94 mnHandle
= mnContexts
;
97 void OOXMLParserState::setDocument(OOXMLDocumentImpl
* pDocument
)
99 mpDocument
= pDocument
;
103 void OOXMLParserState::setXNoteId(const sal_Int32 nId
)
105 mpDocument
->setXNoteId(nId
);
108 sal_Int32
OOXMLParserState::getXNoteId() const
110 return mpDocument
->getXNoteId();
113 const OUString
& OOXMLParserState::getTarget() const
115 return mpDocument
->getTarget();
118 void OOXMLParserState::resolveCharacterProperties(Stream
& rStream
)
120 if (mpCharacterProps
.get() != nullptr)
122 rStream
.props(mpCharacterProps
.get());
123 mpCharacterProps
= new OOXMLPropertySet
;
127 void OOXMLParserState::setCharacterProperties(const OOXMLPropertySet::Pointer_t
& pProps
)
129 if (mpCharacterProps
.get() == nullptr)
130 mpCharacterProps
= pProps
;
132 mpCharacterProps
->add(pProps
);
135 void OOXMLParserState::setCellProperties(const OOXMLPropertySet::Pointer_t
& pProps
)
137 if (!mCellProps
.empty())
139 OOXMLPropertySet::Pointer_t
& rCellProps
= mCellProps
.top();
141 if (rCellProps
.get() == nullptr)
144 rCellProps
->add(pProps
);
148 void OOXMLParserState::setRowProperties(const OOXMLPropertySet::Pointer_t
& pProps
)
150 if (!mRowProps
.empty())
152 OOXMLPropertySet::Pointer_t
& rRowProps
= mRowProps
.top();
154 if (rRowProps
.get() == nullptr)
157 rRowProps
->add(pProps
);
161 void OOXMLParserState::resolveCellProperties(Stream
& rStream
)
163 if (!mCellProps
.empty())
165 OOXMLPropertySet::Pointer_t
& rCellProps
= mCellProps
.top();
167 if (rCellProps
.get() != nullptr)
169 rStream
.props(rCellProps
.get());
170 rCellProps
= new OOXMLPropertySet
;
175 void OOXMLParserState::resolveRowProperties(Stream
& rStream
)
177 if (!mRowProps
.empty())
179 OOXMLPropertySet::Pointer_t
& rRowProps
= mRowProps
.top();
181 if (rRowProps
.get() != nullptr)
183 rStream
.props(rRowProps
.get());
184 rRowProps
= new OOXMLPropertySet
;
189 void OOXMLParserState::resolveTableProperties(Stream
& rStream
)
191 if (!mTableProps
.empty())
193 OOXMLPropertySet::Pointer_t
& rTableProps
= mTableProps
.top();
195 if (rTableProps
.get() != nullptr)
197 rStream
.props(rTableProps
.get());
198 // Don't clean the table props to send them again for each row
199 // This mimics the behaviour from RTF tokenizer.
204 void OOXMLParserState::setTableProperties(const OOXMLPropertySet::Pointer_t
& pProps
)
206 if (!mTableProps
.empty())
208 OOXMLPropertySet::Pointer_t
& rTableProps
= mTableProps
.top();
209 if (rTableProps
.get() == nullptr)
210 rTableProps
= pProps
;
212 rTableProps
->add(pProps
);
217 void OOXMLParserState::resolvePostponedBreak(Stream
& rStream
)
219 for (const auto & rBreak
: mvPostponedBreaks
)
221 OOXMLBreakHandler
aBreakHandler(rStream
);
222 rBreak
->resolve(aBreakHandler
);
224 mvPostponedBreaks
.clear();
227 void OOXMLParserState::setPostponedBreak(const OOXMLPropertySet::Pointer_t
& pProps
)
229 mvPostponedBreaks
.push_back(pProps
);
232 void OOXMLParserState::startTable()
234 OOXMLPropertySet::Pointer_t pCellProps
;
235 OOXMLPropertySet::Pointer_t pRowProps
;
236 OOXMLPropertySet::Pointer_t pTableProps
;
238 mCellProps
.push(pCellProps
);
239 mRowProps
.push(pRowProps
);
240 mTableProps
.push(pTableProps
);
243 void OOXMLParserState::endTable()
250 void OOXMLParserState::incContextCount()
255 void OOXMLParserState::startTxbxContent()
257 SAL_WARN_IF(inTxbxContent
, "writerfilter", "Nested w:txbxContent");
259 inTxbxContent
= true;
260 // Do not save and reset section group state, it'd cause a new page.
261 // savedInSectionGroup = mbInSectionGroup;
262 savedInParagraphGroup
= mbInParagraphGroup
;
263 savedInCharacterGroup
= mbInCharacterGroup
;
264 savedLastParagraphInSection
= mbLastParagraphInSection
;
265 // mbInSectionGroup = false;
266 mbInParagraphGroup
= false;
267 mbInCharacterGroup
= false;
268 mbLastParagraphInSection
= false;
271 void OOXMLParserState::endTxbxContent()
275 SAL_WARN( "writerfilter", "Non-matching closing w:txbxContent" );
278 // mbInSectionGroup = savedInSectionGroup;
279 mbInParagraphGroup
= savedInParagraphGroup
;
280 mbInCharacterGroup
= savedInCharacterGroup
;
281 mbLastParagraphInSection
= savedLastParagraphInSection
;
282 inTxbxContent
= false;
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */