SmartArt: text alignment
[LibreOffice.git] / oox / source / core / fragmenthandler2.cxx
blob1e4c06ab1cf2a9c1c7f6385a4cf48a7f3edc9e9a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include "oox/core/fragmenthandler2.hxx"
21 #include "oox/core/xmlfilterbase.hxx"
22 #include <oox/helper/attributelist.hxx>
23 #include <oox/token/namespaces.hxx>
24 #include <oox/token/tokens.hxx>
26 namespace oox {
27 namespace core {
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::xml::sax;
32 using ::com::sun::star::uno::Sequence;
34 FragmentHandler2::FragmentHandler2( XmlFilterBase& rFilter, const OUString& rFragmentPath, bool bEnableTrimSpace ) :
35 FragmentHandler( rFilter, rFragmentPath ),
36 ContextHandler2Helper( bEnableTrimSpace )
40 FragmentHandler2::~FragmentHandler2()
44 // com.sun.star.xml.sax.XFastDocumentHandler interface --------------------
46 void SAL_CALL FragmentHandler2::startDocument()
48 initializeImport();
51 void SAL_CALL FragmentHandler2::endDocument()
53 finalizeImport();
56 bool FragmentHandler2::prepareMceContext( sal_Int32 nElement, const AttributeList& rAttribs )
58 switch( nElement )
60 case MCE_TOKEN( AlternateContent ):
61 aMceState.push_back( MCE_STATE::Started );
62 break;
64 case MCE_TOKEN( Choice ):
66 if (aMceState.empty() || aMceState.back() != MCE_STATE::Started)
67 return false;
69 OUString aRequires = rAttribs.getString( XML_Requires, "none" );
71 // At this point we can't access namespaces as the correct xml filter
72 // is long gone. For now let's decide depending on a list of supported
73 // namespaces like we do in writerfilter
75 static std::vector<OUString> aSupportedNS =
77 "p14",
78 "p15",
79 "x12ac",
82 if (std::find(aSupportedNS.begin(), aSupportedNS.end(), aRequires) != aSupportedNS.end())
83 aMceState.back() = MCE_STATE::FoundChoice;
84 else
85 return false;
87 break;
89 case MCE_TOKEN( Fallback ):
90 if( !aMceState.empty() && aMceState.back() == MCE_STATE::Started )
91 break;
92 return false;
93 default:
95 OUString str = rAttribs.getString( MCE_TOKEN( Ignorable ), OUString() );
96 if( !str.isEmpty() )
98 // Sequence< css::xml::FastAttribute > attrs = rAttribs.getFastAttributeList()->getFastAttributes();
99 // printf("MCE: %s\n", OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr() );
100 // TODO: Check & Get the namespaces in "Ignorable"
101 // printf("NS: %d : %s\n", attrs.getLength(), OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr() );
104 return false;
106 return true;
109 // com.sun.star.xml.sax.XFastContextHandler interface -------------------------
111 Reference< XFastContextHandler > SAL_CALL FragmentHandler2::createFastChildContext(
112 sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs )
114 if( getNamespace( nElement ) == NMSP_mce ) // TODO for checking 'Ignorable'
116 if( prepareMceContext( nElement, AttributeList( rxAttribs ) ) )
117 return getFastContextHandler();
118 return nullptr;
120 return implCreateChildContext( nElement, rxAttribs );
123 void SAL_CALL FragmentHandler2::startFastElement(
124 sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs )
126 implStartElement( nElement, rxAttribs );
129 void SAL_CALL FragmentHandler2::characters( const OUString& rChars )
131 implCharacters( rChars );
134 void SAL_CALL FragmentHandler2::endFastElement( sal_Int32 nElement )
136 /* If MCE */
137 switch( nElement )
139 case MCE_TOKEN( AlternateContent ):
140 aMceState.pop_back();
141 break;
144 implEndElement( nElement );
147 // oox.core.ContextHandler interface ------------------------------------------
149 ContextHandlerRef FragmentHandler2::createRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
151 return implCreateRecordContext( nRecId, rStrm );
154 void FragmentHandler2::startRecord( sal_Int32 nRecId, SequenceInputStream& rStrm )
156 implStartRecord( nRecId, rStrm );
159 void FragmentHandler2::endRecord( sal_Int32 nRecId )
161 implEndRecord( nRecId );
164 // oox.core.ContextHandler2Helper interface -----------------------------------
166 ContextHandlerRef FragmentHandler2::onCreateContext( sal_Int32, const AttributeList& )
168 return nullptr;
171 void FragmentHandler2::onStartElement( const AttributeList& )
175 void FragmentHandler2::onCharacters( const OUString& )
179 void FragmentHandler2::onEndElement()
183 ContextHandlerRef FragmentHandler2::onCreateRecordContext( sal_Int32, SequenceInputStream& )
185 return nullptr;
188 void FragmentHandler2::onStartRecord( SequenceInputStream& )
192 void FragmentHandler2::onEndRecord()
196 // oox.core.FragmentHandler2 interface ----------------------------------------
198 void FragmentHandler2::initializeImport()
202 void FragmentHandler2::finalizeImport()
206 } // namespace core
207 } // namespace oox
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */