bump product version to 4.2.0.1
[LibreOffice.git] / oox / source / core / fragmenthandler2.cxx
blob8133b7382133762b02bad0e973334d0405a2683e
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 // ============================================================================
28 using namespace ::com::sun::star::uno;
29 using namespace ::com::sun::star::xml::sax;
33 using ::com::sun::star::uno::Sequence;
35 // ============================================================================
37 FragmentHandler2::FragmentHandler2( XmlFilterBase& rFilter, const OUString& rFragmentPath, bool bEnableTrimSpace ) :
38 FragmentHandler( rFilter, rFragmentPath ),
39 ContextHandler2Helper( bEnableTrimSpace )
43 FragmentHandler2::~FragmentHandler2()
47 // com.sun.star.xml.sax.XFastDocumentHandler interface --------------------
49 void SAL_CALL FragmentHandler2::startDocument() throw( SAXException, RuntimeException )
51 initializeImport();
54 void SAL_CALL FragmentHandler2::endDocument() throw( SAXException, RuntimeException )
56 finalizeImport();
59 bool FragmentHandler2::prepareMceContext( sal_Int32 nElement, const AttributeList& rAttribs )
61 switch( nElement )
63 case MCE_TOKEN( AlternateContent ):
64 aMceState.push_back( MCE_STARTED );
65 break;
67 case MCE_TOKEN( Choice ):
69 OUString aRequires = rAttribs.getString( ( XML_Requires ), OUString("none") );
70 if (!getFilter().hasNamespaceURL(aRequires))
71 // Check to see if we have this namespace defined first,
72 // because calling getNamespaceURL() would throw if the
73 // namespace doesn't exist.
74 return false;
76 aRequires = getFilter().getNamespaceURL( aRequires );
77 if( getFilter().getNamespaceId( aRequires ) > 0 && !aMceState.empty() && aMceState.back() == MCE_STARTED )
78 aMceState.back() = MCE_FOUND_CHOICE;
79 else
80 return false;
82 break;
84 case MCE_TOKEN( Fallback ):
85 if( !aMceState.empty() && aMceState.back() == MCE_STARTED )
86 break;
87 return false;
88 default:
90 OUString str = rAttribs.getString( MCE_TOKEN( Ignorable ), OUString() );
91 if( !str.isEmpty() )
93 // Sequence< ::com::sun::star::xml::FastAttribute > attrs = rAttribs.getFastAttributeList()->getFastAttributes();
94 // printf("MCE: %s\n", OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr() );
95 // TODO: Check & Get the namespaces in "Ignorable"
96 // printf("NS: %d : %s\n", attrs.getLength(), OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr() );
99 return false;
101 return true;
106 // com.sun.star.xml.sax.XFastContextHandler interface -------------------------
108 Reference< XFastContextHandler > SAL_CALL FragmentHandler2::createFastChildContext(
109 sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw( SAXException, RuntimeException )
111 if( getNamespace( nElement ) == NMSP_mce ) // TODO for checking 'Ignorable'
113 if( prepareMceContext( nElement, AttributeList( rxAttribs ) ) )
114 return getFastContextHandler();
115 return NULL;
117 return implCreateChildContext( nElement, rxAttribs );
120 void SAL_CALL FragmentHandler2::startFastElement(
121 sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw( SAXException, RuntimeException )
123 implStartElement( nElement, rxAttribs );
126 void SAL_CALL FragmentHandler2::characters( const OUString& rChars ) throw( SAXException, RuntimeException )
128 implCharacters( rChars );
131 void SAL_CALL FragmentHandler2::endFastElement( sal_Int32 nElement ) throw( SAXException, RuntimeException )
133 /* If MCE */
134 switch( nElement )
136 case MCE_TOKEN( AlternateContent ):
137 aMceState.pop_back();
138 break;
141 implEndElement( nElement );
144 // oox.core.ContextHandler interface ------------------------------------------
146 ContextHandlerRef FragmentHandler2::createRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
148 return implCreateRecordContext( nRecId, rStrm );
151 void FragmentHandler2::startRecord( sal_Int32 nRecId, SequenceInputStream& rStrm )
153 implStartRecord( nRecId, rStrm );
156 void FragmentHandler2::endRecord( sal_Int32 nRecId )
158 implEndRecord( nRecId );
161 // oox.core.ContextHandler2Helper interface -----------------------------------
163 ContextHandlerRef FragmentHandler2::onCreateContext( sal_Int32, const AttributeList& )
165 return 0;
168 void FragmentHandler2::onStartElement( const AttributeList& )
172 void FragmentHandler2::onCharacters( const OUString& )
176 void FragmentHandler2::onEndElement()
180 ContextHandlerRef FragmentHandler2::onCreateRecordContext( sal_Int32, SequenceInputStream& )
182 return 0;
185 void FragmentHandler2::onStartRecord( SequenceInputStream& )
189 void FragmentHandler2::onEndRecord()
193 // oox.core.FragmentHandler2 interface ----------------------------------------
195 void FragmentHandler2::initializeImport()
199 void FragmentHandler2::finalizeImport()
203 // ============================================================================
205 } // namespace core
206 } // namespace oox
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */