/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- *//* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */#include <stdio.h>#include <iostream>#include "OOXMLParserState.hxx"#include "Handler.hxx"#include <sal/log.hxx>namespacewriterfilter{namespaceooxml{/* class OOXMLParserState*/OOXMLParserState::OOXMLParserState():mbInSectionGroup(false),mbInParagraphGroup(false),mbInCharacterGroup(false),mbLastParagraphInSection(false),mbForwardEvents(true),mnContexts(0),mnHandle(0),mpDocument(nullptr),inTxbxContent(false),savedInParagraphGroup(false),savedInCharacterGroup(false),savedLastParagraphInSection(false){}OOXMLParserState::~OOXMLParserState(){}voidOOXMLParserState::setLastParagraphInSection(boolbLastParagraphInSection){mbLastParagraphInSection=bLastParagraphInSection;}voidOOXMLParserState::setInSectionGroup(boolbInSectionGroup){mbInSectionGroup=bInSectionGroup;}voidOOXMLParserState::setInParagraphGroup(boolbInParagraphGroup){mbInParagraphGroup=bInParagraphGroup;}voidOOXMLParserState::setInCharacterGroup(boolbInCharacterGroup){mbInCharacterGroup=bInCharacterGroup;}voidOOXMLParserState::setForwardEvents(boolbForwardEvents){mbForwardEvents=bForwardEvents;}conststd::stringOOXMLParserState::getHandle()const{charsBuffer[256];snprintf(sBuffer,sizeof(sBuffer),"%u",mnHandle);returnsBuffer;<--- Returning pointer to local variable 'sBuffer' that will be invalid when returning.}voidOOXMLParserState::setHandle(){mnHandle=mnContexts;}voidOOXMLParserState::setDocument(OOXMLDocumentImpl*pDocument){mpDocument=pDocument;}voidOOXMLParserState::setXNoteId(constsal_Int32nId){mpDocument->setXNoteId(nId);}sal_Int32OOXMLParserState::getXNoteId()const{returnmpDocument->getXNoteId();}constOUString&OOXMLParserState::getTarget()const{returnmpDocument->getTarget();}voidOOXMLParserState::resolveCharacterProperties(Stream&rStream){if(mpCharacterProps.get()!=nullptr){rStream.props(mpCharacterProps.get());mpCharacterProps=newOOXMLPropertySet;}}voidOOXMLParserState::setCharacterProperties(constOOXMLPropertySet::Pointer_t&pProps){if(mpCharacterProps.get()==nullptr)mpCharacterProps=pProps;elsempCharacterProps->add(pProps);}voidOOXMLParserState::setCellProperties(constOOXMLPropertySet::Pointer_t&pProps){if(!mCellProps.empty()){OOXMLPropertySet::Pointer_t&rCellProps=mCellProps.top();if(rCellProps.get()==nullptr)rCellProps=pProps;elserCellProps->add(pProps);}}voidOOXMLParserState::setRowProperties(constOOXMLPropertySet::Pointer_t&pProps){if(!mRowProps.empty()){OOXMLPropertySet::Pointer_t&rRowProps=mRowProps.top();if(rRowProps.get()==nullptr)rRowProps=pProps;elserRowProps->add(pProps);}}voidOOXMLParserState::resolveCellProperties(Stream&rStream){if(!mCellProps.empty()){OOXMLPropertySet::Pointer_t&rCellProps=mCellProps.top();if(rCellProps.get()!=nullptr){rStream.props(rCellProps.get());rCellProps=newOOXMLPropertySet;}}}voidOOXMLParserState::resolveRowProperties(Stream&rStream){if(!mRowProps.empty()){OOXMLPropertySet::Pointer_t&rRowProps=mRowProps.top();if(rRowProps.get()!=nullptr){rStream.props(rRowProps.get());rRowProps=newOOXMLPropertySet;}}}voidOOXMLParserState::resolveTableProperties(Stream&rStream){if(!mTableProps.empty()){OOXMLPropertySet::Pointer_t&rTableProps=mTableProps.top();if(rTableProps.get()!=nullptr){rStream.props(rTableProps.get());// Don't clean the table props to send them again for each row// This mimics the behaviour from RTF tokenizer.}}}voidOOXMLParserState::setTableProperties(constOOXMLPropertySet::Pointer_t&pProps){if(!mTableProps.empty()){OOXMLPropertySet::Pointer_t&rTableProps=mTableProps.top();if(rTableProps.get()==nullptr)rTableProps=pProps;elserTableProps->add(pProps);}}// tdf#108714voidOOXMLParserState::resolvePostponedBreak(Stream&rStream){for(constauto&rBreak:mvPostponedBreaks){OOXMLBreakHandleraBreakHandler(rStream);rBreak->resolve(aBreakHandler);}mvPostponedBreaks.clear();}voidOOXMLParserState::setPostponedBreak(constOOXMLPropertySet::Pointer_t&pProps){mvPostponedBreaks.push_back(pProps);}voidOOXMLParserState::startTable(){OOXMLPropertySet::Pointer_tpCellProps;OOXMLPropertySet::Pointer_tpRowProps;OOXMLPropertySet::Pointer_tpTableProps;mCellProps.push(pCellProps);mRowProps.push(pRowProps);mTableProps.push(pTableProps);}voidOOXMLParserState::endTable(){mCellProps.pop();mRowProps.pop();mTableProps.pop();}voidOOXMLParserState::incContextCount(){mnContexts++;}voidOOXMLParserState::startTxbxContent(){SAL_WARN_IF(inTxbxContent,"writerfilter","Nested w:txbxContent");inTxbxContent=true;// Do not save and reset section group state, it'd cause a new page.// savedInSectionGroup = mbInSectionGroup;savedInParagraphGroup=mbInParagraphGroup;savedInCharacterGroup=mbInCharacterGroup;savedLastParagraphInSection=mbLastParagraphInSection;// mbInSectionGroup = false;mbInParagraphGroup=false;mbInCharacterGroup=false;mbLastParagraphInSection=false;}voidOOXMLParserState::endTxbxContent(){if(!inTxbxContent){SAL_WARN("writerfilter","Non-matching closing w:txbxContent");return;}// mbInSectionGroup = savedInSectionGroup;mbInParagraphGroup=savedInParagraphGroup;mbInCharacterGroup=savedInCharacterGroup;mbLastParagraphInSection=savedLastParagraphInSection;inTxbxContent=false;}}}/* vim:set shiftwidth=4 softtabstop=4 expandtab: */