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 std::string
OOXMLParserState::getHandle() const
85 return std::to_string(mnHandle
);
88 void OOXMLParserState::setHandle()
90 mnHandle
= mnContexts
;
93 void OOXMLParserState::setDocument(OOXMLDocumentImpl
* pDocument
)
95 mpDocument
= pDocument
;
99 void OOXMLParserState::setXNoteId(const sal_Int32 nId
)
101 mpDocument
->setXNoteId(nId
);
104 sal_Int32
OOXMLParserState::getXNoteId() const
106 return mpDocument
->getXNoteId();
109 const OUString
& OOXMLParserState::getTarget() const
111 return mpDocument
->getTarget();
114 void OOXMLParserState::resolveCharacterProperties(Stream
& rStream
)
116 if (mpCharacterProps
.get() != nullptr)
118 rStream
.props(mpCharacterProps
.get());
119 mpCharacterProps
= new OOXMLPropertySet
;
123 void OOXMLParserState::setCharacterProperties(const OOXMLPropertySet::Pointer_t
& pProps
)
125 if (mpCharacterProps
.get() == nullptr)
126 mpCharacterProps
= pProps
;
128 mpCharacterProps
->add(pProps
);
131 void OOXMLParserState::setCellProperties(const OOXMLPropertySet::Pointer_t
& pProps
)
133 if (!mCellProps
.empty())
135 OOXMLPropertySet::Pointer_t
& rCellProps
= mCellProps
.top();
137 if (rCellProps
.get() == nullptr)
140 rCellProps
->add(pProps
);
144 void OOXMLParserState::setRowProperties(const OOXMLPropertySet::Pointer_t
& pProps
)
146 if (!mRowProps
.empty())
148 OOXMLPropertySet::Pointer_t
& rRowProps
= mRowProps
.top();
150 if (rRowProps
.get() == nullptr)
153 rRowProps
->add(pProps
);
157 void OOXMLParserState::resolveCellProperties(Stream
& rStream
)
159 if (!mCellProps
.empty())
161 OOXMLPropertySet::Pointer_t
& rCellProps
= mCellProps
.top();
163 if (rCellProps
.get() != nullptr)
165 rStream
.props(rCellProps
.get());
166 rCellProps
= new OOXMLPropertySet
;
171 void OOXMLParserState::resolveRowProperties(Stream
& rStream
)
173 if (!mRowProps
.empty())
175 OOXMLPropertySet::Pointer_t
& rRowProps
= mRowProps
.top();
177 if (rRowProps
.get() != nullptr)
179 rStream
.props(rRowProps
.get());
180 rRowProps
= new OOXMLPropertySet
;
185 void OOXMLParserState::resolveTableProperties(Stream
& rStream
)
187 if (!mTableProps
.empty())
189 OOXMLPropertySet::Pointer_t
& rTableProps
= mTableProps
.top();
191 if (rTableProps
.get() != nullptr)
193 rStream
.props(rTableProps
.get());
194 // Don't clean the table props to send them again for each row
195 // This mimics the behaviour from RTF tokenizer.
200 void OOXMLParserState::setTableProperties(const OOXMLPropertySet::Pointer_t
& pProps
)
202 if (!mTableProps
.empty())
204 OOXMLPropertySet::Pointer_t
& rTableProps
= mTableProps
.top();
205 if (rTableProps
.get() == nullptr)
206 rTableProps
= pProps
;
208 rTableProps
->add(pProps
);
213 void OOXMLParserState::resolvePostponedBreak(Stream
& rStream
)
215 for (const auto & rBreak
: mvPostponedBreaks
)
217 OOXMLBreakHandler
aBreakHandler(rStream
);
218 rBreak
->resolve(aBreakHandler
);
220 mvPostponedBreaks
.clear();
223 void OOXMLParserState::setPostponedBreak(const OOXMLPropertySet::Pointer_t
& pProps
)
225 mvPostponedBreaks
.push_back(pProps
);
228 void OOXMLParserState::startTable()
230 OOXMLPropertySet::Pointer_t pCellProps
;
231 OOXMLPropertySet::Pointer_t pRowProps
;
232 OOXMLPropertySet::Pointer_t pTableProps
;
234 mCellProps
.push(pCellProps
);
235 mRowProps
.push(pRowProps
);
236 mTableProps
.push(pTableProps
);
239 void OOXMLParserState::endTable()
246 void OOXMLParserState::incContextCount()
251 void OOXMLParserState::startTxbxContent()
253 SAL_WARN_IF(inTxbxContent
, "writerfilter", "Nested w:txbxContent");
255 inTxbxContent
= true;
256 // Do not save and reset section group state, it'd cause a new page.
257 // savedInSectionGroup = mbInSectionGroup;
258 savedInParagraphGroup
= mbInParagraphGroup
;
259 savedInCharacterGroup
= mbInCharacterGroup
;
260 savedLastParagraphInSection
= mbLastParagraphInSection
;
261 // mbInSectionGroup = false;
262 mbInParagraphGroup
= false;
263 mbInCharacterGroup
= false;
264 mbLastParagraphInSection
= false;
267 void OOXMLParserState::endTxbxContent()
271 SAL_WARN( "writerfilter", "Non-matching closing w:txbxContent" );
274 // mbInSectionGroup = savedInSectionGroup;
275 mbInParagraphGroup
= savedInParagraphGroup
;
276 mbInCharacterGroup
= savedInCharacterGroup
;
277 mbLastParagraphInSection
= savedLastParagraphInSection
;
278 inTxbxContent
= false;
283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */