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>
22 #include <oox/helper/attributelist.hxx>
23 #include <oox/token/namespaces.hxx>
24 #include <oox/token/tokens.hxx>
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()
51 void SAL_CALL
FragmentHandler2::endDocument()
56 bool FragmentHandler2::prepareMceContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
60 case MCE_TOKEN( AlternateContent
):
61 aMceState
.push_back( MCE_STATE::Started
);
64 case MCE_TOKEN( Choice
):
66 if (aMceState
.empty() || aMceState
.back() != MCE_STATE::Started
)
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
=
83 if (std::find(aSupportedNS
.begin(), aSupportedNS
.end(), aRequires
) != aSupportedNS
.end())
84 aMceState
.back() = MCE_STATE::FoundChoice
;
90 case MCE_TOKEN( Fallback
):
91 if( !aMceState
.empty() && aMceState
.back() == MCE_STATE::Started
)
96 OUString str
= rAttribs
.getString( MCE_TOKEN( Ignorable
), OUString() );
99 // Sequence< css::xml::FastAttribute > attrs = rAttribs.getFastAttributeList()->getFastAttributes();
100 // printf("MCE: %s\n", OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr() );
101 // TODO: Check & Get the namespaces in "Ignorable"
102 // printf("NS: %d : %s\n", attrs.getLength(), OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr() );
110 // com.sun.star.xml.sax.XFastContextHandler interface -------------------------
112 Reference
< XFastContextHandler
> SAL_CALL
FragmentHandler2::createFastChildContext(
113 sal_Int32 nElement
, const Reference
< XFastAttributeList
>& rxAttribs
)
115 if( getNamespace( nElement
) == NMSP_mce
) // TODO for checking 'Ignorable'
117 if( prepareMceContext( nElement
, AttributeList( rxAttribs
) ) )
118 return getFastContextHandler();
121 return implCreateChildContext( nElement
, rxAttribs
);
124 void SAL_CALL
FragmentHandler2::startFastElement(
125 sal_Int32 nElement
, const Reference
< XFastAttributeList
>& rxAttribs
)
127 implStartElement( nElement
, rxAttribs
);
130 void SAL_CALL
FragmentHandler2::characters( const OUString
& rChars
)
132 implCharacters( rChars
);
135 void SAL_CALL
FragmentHandler2::endFastElement( sal_Int32 nElement
)
140 case MCE_TOKEN( AlternateContent
):
141 aMceState
.pop_back();
145 implEndElement( nElement
);
148 // oox.core.ContextHandler interface ------------------------------------------
150 ContextHandlerRef
FragmentHandler2::createRecordContext( sal_Int32 nRecId
, SequenceInputStream
& rStrm
)
152 return implCreateRecordContext( nRecId
, rStrm
);
155 void FragmentHandler2::startRecord( sal_Int32 nRecId
, SequenceInputStream
& rStrm
)
157 implStartRecord( nRecId
, rStrm
);
160 void FragmentHandler2::endRecord( sal_Int32 nRecId
)
162 implEndRecord( nRecId
);
165 // oox.core.ContextHandler2Helper interface -----------------------------------
167 ContextHandlerRef
FragmentHandler2::onCreateContext( sal_Int32
, const AttributeList
& )
172 void FragmentHandler2::onStartElement( const AttributeList
& )
176 void FragmentHandler2::onCharacters( const OUString
& )
180 void FragmentHandler2::onEndElement()
184 ContextHandlerRef
FragmentHandler2::onCreateRecordContext( sal_Int32
, SequenceInputStream
& )
189 void FragmentHandler2::onStartRecord( SequenceInputStream
& )
193 void FragmentHandler2::onEndRecord()
197 // oox.core.FragmentHandler2 interface ----------------------------------------
199 void FragmentHandler2::initializeImport()
203 void FragmentHandler2::finalizeImport()
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */