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 .
20 #include "oox/core/fragmenthandler2.hxx"
21 #include "oox/core/xmlfilterbase.hxx"
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
)
54 void SAL_CALL
FragmentHandler2::endDocument() throw( SAXException
, RuntimeException
)
59 bool FragmentHandler2::prepareMceContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
63 case MCE_TOKEN( AlternateContent
):
64 aMceState
.push_back( MCE_STARTED
);
67 case MCE_TOKEN( Choice
):
69 OUString aRequires
= rAttribs
.getString( ( XML_Requires
), OUString("none") );
70 aRequires
= getFilter().getNamespaceURL( aRequires
);
71 if( getFilter().getNamespaceId( aRequires
) > 0 && !aMceState
.empty() && aMceState
.back() == MCE_STARTED
)
72 aMceState
.back() = MCE_FOUND_CHOICE
;
78 case MCE_TOKEN( Fallback
):
79 if( !aMceState
.empty() && aMceState
.back() == MCE_STARTED
)
84 OUString str
= rAttribs
.getString( MCE_TOKEN( Ignorable
), OUString() );
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() );
100 // com.sun.star.xml.sax.XFastContextHandler interface -------------------------
102 Reference
< XFastContextHandler
> SAL_CALL
FragmentHandler2::createFastChildContext(
103 sal_Int32 nElement
, const Reference
< XFastAttributeList
>& rxAttribs
) throw( SAXException
, RuntimeException
)
105 if( getNamespace( nElement
) == NMSP_mce
) // TODO for checking 'Ignorable'
107 if( prepareMceContext( nElement
, AttributeList( rxAttribs
) ) )
108 return getFastContextHandler();
111 return implCreateChildContext( nElement
, rxAttribs
);
114 void SAL_CALL
FragmentHandler2::startFastElement(
115 sal_Int32 nElement
, const Reference
< XFastAttributeList
>& rxAttribs
) throw( SAXException
, RuntimeException
)
117 implStartElement( nElement
, rxAttribs
);
120 void SAL_CALL
FragmentHandler2::characters( const OUString
& rChars
) throw( SAXException
, RuntimeException
)
122 implCharacters( rChars
);
125 void SAL_CALL
FragmentHandler2::endFastElement( sal_Int32 nElement
) throw( SAXException
, RuntimeException
)
130 case MCE_TOKEN( AlternateContent
):
131 aMceState
.pop_back();
135 implEndElement( nElement
);
138 // oox.core.ContextHandler interface ------------------------------------------
140 ContextHandlerRef
FragmentHandler2::createRecordContext( sal_Int32 nRecId
, SequenceInputStream
& rStrm
)
142 return implCreateRecordContext( nRecId
, rStrm
);
145 void FragmentHandler2::startRecord( sal_Int32 nRecId
, SequenceInputStream
& rStrm
)
147 implStartRecord( nRecId
, rStrm
);
150 void FragmentHandler2::endRecord( sal_Int32 nRecId
)
152 implEndRecord( nRecId
);
155 // oox.core.ContextHandler2Helper interface -----------------------------------
157 ContextHandlerRef
FragmentHandler2::onCreateContext( sal_Int32
, const AttributeList
& )
162 void FragmentHandler2::onStartElement( const AttributeList
& )
166 void FragmentHandler2::onCharacters( const OUString
& )
170 void FragmentHandler2::onEndElement()
174 ContextHandlerRef
FragmentHandler2::onCreateRecordContext( sal_Int32
, SequenceInputStream
& )
179 void FragmentHandler2::onStartRecord( SequenceInputStream
& )
183 void FragmentHandler2::onEndRecord()
187 // oox.core.FragmentHandler2 interface ----------------------------------------
189 void FragmentHandler2::initializeImport()
193 void FragmentHandler2::finalizeImport()
197 // ============================================================================
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */