Branch libreoffice-5-0-4
[LibreOffice.git] / oox / source / core / fragmenthandler2.cxx
blobaae3206403751766b7f81448cbde4e1eec91d190
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"
23 namespace oox {
24 namespace core {
26 using namespace ::com::sun::star::uno;
27 using namespace ::com::sun::star::xml::sax;
29 using ::com::sun::star::uno::Sequence;
31 FragmentHandler2::FragmentHandler2( XmlFilterBase& rFilter, const OUString& rFragmentPath, bool bEnableTrimSpace ) :
32 FragmentHandler( rFilter, rFragmentPath ),
33 ContextHandler2Helper( bEnableTrimSpace )
37 FragmentHandler2::~FragmentHandler2()
41 // com.sun.star.xml.sax.XFastDocumentHandler interface --------------------
43 void SAL_CALL FragmentHandler2::startDocument() throw( SAXException, RuntimeException, std::exception )
45 initializeImport();
48 void SAL_CALL FragmentHandler2::endDocument() throw( SAXException, RuntimeException, std::exception )
50 finalizeImport();
53 bool FragmentHandler2::prepareMceContext( sal_Int32 nElement, const AttributeList& rAttribs )
55 switch( nElement )
57 case MCE_TOKEN( AlternateContent ):
58 aMceState.push_back( MCE_STARTED );
59 break;
61 case MCE_TOKEN( Choice ):
63 OUString aRequires = rAttribs.getString( ( XML_Requires ), OUString("none") );
64 if (!getFilter().hasNamespaceURL(aRequires))
65 // Check to see if we have this namespace defined first,
66 // because calling getNamespaceURL() would throw if the
67 // namespace doesn't exist.
68 return false;
70 aRequires = getFilter().getNamespaceURL( aRequires );
71 if( getFilter().getNamespaceId( aRequires ) > 0 && !aMceState.empty() && aMceState.back() == MCE_STARTED )
72 aMceState.back() = MCE_FOUND_CHOICE;
73 else
74 return false;
76 break;
78 case MCE_TOKEN( Fallback ):
79 if( !aMceState.empty() && aMceState.back() == MCE_STARTED )
80 break;
81 return false;
82 default:
84 OUString str = rAttribs.getString( MCE_TOKEN( Ignorable ), OUString() );
85 if( !str.isEmpty() )
87 // Sequence< ::com::sun::star::xml::FastAttribute > attrs = rAttribs.getFastAttributeList()->getFastAttributes();
88 // printf("MCE: %s\n", OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr() );
89 // TODO: Check & Get the namespaces in "Ignorable"
90 // printf("NS: %d : %s\n", attrs.getLength(), OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr() );
93 return false;
95 return true;
98 // com.sun.star.xml.sax.XFastContextHandler interface -------------------------
100 Reference< XFastContextHandler > SAL_CALL FragmentHandler2::createFastChildContext(
101 sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw( SAXException, RuntimeException, std::exception )
103 if( getNamespace( nElement ) == NMSP_mce ) // TODO for checking 'Ignorable'
105 if( prepareMceContext( nElement, AttributeList( rxAttribs ) ) )
106 return getFastContextHandler();
107 return NULL;
109 return implCreateChildContext( nElement, rxAttribs );
112 void SAL_CALL FragmentHandler2::startFastElement(
113 sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw( SAXException, RuntimeException, std::exception )
115 implStartElement( nElement, rxAttribs );
118 void SAL_CALL FragmentHandler2::characters( const OUString& rChars ) throw( SAXException, RuntimeException, std::exception )
120 implCharacters( rChars );
123 void SAL_CALL FragmentHandler2::endFastElement( sal_Int32 nElement ) throw( SAXException, RuntimeException, std::exception )
125 /* If MCE */
126 switch( nElement )
128 case MCE_TOKEN( AlternateContent ):
129 aMceState.pop_back();
130 break;
133 implEndElement( nElement );
136 // oox.core.ContextHandler interface ------------------------------------------
138 ContextHandlerRef FragmentHandler2::createRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
140 return implCreateRecordContext( nRecId, rStrm );
143 void FragmentHandler2::startRecord( sal_Int32 nRecId, SequenceInputStream& rStrm )
145 implStartRecord( nRecId, rStrm );
148 void FragmentHandler2::endRecord( sal_Int32 nRecId )
150 implEndRecord( nRecId );
153 // oox.core.ContextHandler2Helper interface -----------------------------------
155 ContextHandlerRef FragmentHandler2::onCreateContext( sal_Int32, const AttributeList& )
157 return 0;
160 void FragmentHandler2::onStartElement( const AttributeList& )
164 void FragmentHandler2::onCharacters( const OUString& )
168 void FragmentHandler2::onEndElement()
172 ContextHandlerRef FragmentHandler2::onCreateRecordContext( sal_Int32, SequenceInputStream& )
174 return 0;
177 void FragmentHandler2::onStartRecord( SequenceInputStream& )
181 void FragmentHandler2::onEndRecord()
185 // oox.core.FragmentHandler2 interface ----------------------------------------
187 void FragmentHandler2::initializeImport()
191 void FragmentHandler2::finalizeImport()
195 } // namespace core
196 } // namespace oox
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */