Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "oox/core/fragmenthandler2.hxx"
21 : #include "oox/core/xmlfilterbase.hxx"
22 :
23 : namespace oox {
24 : namespace core {
25 :
26 : // ============================================================================
27 :
28 : using namespace ::com::sun::star::uno;
29 : using namespace ::com::sun::star::xml::sax;
30 :
31 : using ::rtl::OUString;
32 :
33 :
34 : using ::com::sun::star::uno::Sequence;
35 :
36 : // ============================================================================
37 :
38 109 : FragmentHandler2::FragmentHandler2( XmlFilterBase& rFilter, const OUString& rFragmentPath, bool bEnableTrimSpace ) :
39 : FragmentHandler( rFilter, rFragmentPath ),
40 109 : ContextHandler2Helper( bEnableTrimSpace )
41 : {
42 109 : }
43 :
44 131 : FragmentHandler2::~FragmentHandler2()
45 : {
46 131 : }
47 :
48 : // com.sun.star.xml.sax.XFastDocumentHandler interface --------------------
49 :
50 88 : void SAL_CALL FragmentHandler2::startDocument() throw( SAXException, RuntimeException )
51 : {
52 88 : initializeImport();
53 88 : }
54 :
55 88 : void SAL_CALL FragmentHandler2::endDocument() throw( SAXException, RuntimeException )
56 : {
57 88 : finalizeImport();
58 88 : }
59 :
60 14 : bool FragmentHandler2::prepareMceContext( sal_Int32 nElement, const AttributeList& rAttribs )
61 : {
62 14 : switch( nElement )
63 : {
64 : case MCE_TOKEN( AlternateContent ):
65 6 : aMceState.push_back( MCE_STARTED );
66 6 : break;
67 :
68 : case MCE_TOKEN( Choice ):
69 : {
70 6 : OUString aRequires = rAttribs.getString( ( XML_Requires ), OUString("none") );
71 6 : aRequires = getFilter().getNamespaceURL( aRequires );
72 6 : if( getFilter().getNamespaceId( aRequires ) > 0 && !aMceState.empty() && aMceState.back() == MCE_STARTED )
73 3 : aMceState.back() = MCE_FOUND_CHOICE;
74 : else
75 3 : return false;
76 : }
77 3 : break;
78 :
79 : case MCE_TOKEN( Fallback ):
80 2 : if( !aMceState.empty() && aMceState.back() == MCE_STARTED )
81 1 : break;
82 1 : return false;
83 : default:
84 : {
85 0 : OUString str = rAttribs.getString( MCE_TOKEN( Ignorable ), OUString() );
86 0 : if( !str.isEmpty() )
87 : {
88 0 : Sequence< ::com::sun::star::xml::FastAttribute > attrs = rAttribs.getFastAttributeList()->getFastAttributes();
89 : // printf("MCE: %s\n", ::rtl::OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr() );
90 : // TODO: Check & Get the namespaces in "Ignorable"
91 : // printf("NS: %d : %s\n", attrs.getLength(), ::rtl::OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr() );
92 0 : }
93 : }
94 0 : return false;
95 : }
96 10 : return true;
97 : }
98 :
99 :
100 :
101 : // com.sun.star.xml.sax.XFastContextHandler interface -------------------------
102 :
103 1700 : Reference< XFastContextHandler > SAL_CALL FragmentHandler2::createFastChildContext(
104 : sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw( SAXException, RuntimeException )
105 : {
106 1700 : if( getNamespace( nElement ) == NMSP_mce ) // TODO for checking 'Ignorable'
107 : {
108 14 : if( prepareMceContext( nElement, AttributeList( rxAttribs ) ) )
109 10 : return getFastContextHandler();
110 4 : return NULL;
111 : }
112 1686 : return implCreateChildContext( nElement, rxAttribs );
113 : }
114 :
115 601 : void SAL_CALL FragmentHandler2::startFastElement(
116 : sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw( SAXException, RuntimeException )
117 : {
118 601 : implStartElement( nElement, rxAttribs );
119 601 : }
120 :
121 315 : void SAL_CALL FragmentHandler2::characters( const OUString& rChars ) throw( SAXException, RuntimeException )
122 : {
123 315 : implCharacters( rChars );
124 315 : }
125 :
126 601 : void SAL_CALL FragmentHandler2::endFastElement( sal_Int32 nElement ) throw( SAXException, RuntimeException )
127 : {
128 : /* If MCE */
129 601 : switch( nElement )
130 : {
131 : case MCE_TOKEN( AlternateContent ):
132 6 : aMceState.pop_back();
133 6 : break;
134 : }
135 :
136 601 : implEndElement( nElement );
137 601 : }
138 :
139 : // oox.core.ContextHandler interface ------------------------------------------
140 :
141 0 : ContextHandlerRef FragmentHandler2::createRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
142 : {
143 0 : return implCreateRecordContext( nRecId, rStrm );
144 : }
145 :
146 0 : void FragmentHandler2::startRecord( sal_Int32 nRecId, SequenceInputStream& rStrm )
147 : {
148 0 : implStartRecord( nRecId, rStrm );
149 0 : }
150 :
151 0 : void FragmentHandler2::endRecord( sal_Int32 nRecId )
152 : {
153 0 : implEndRecord( nRecId );
154 0 : }
155 :
156 : // oox.core.ContextHandler2Helper interface -----------------------------------
157 :
158 0 : ContextHandlerRef FragmentHandler2::onCreateContext( sal_Int32, const AttributeList& )
159 : {
160 0 : return 0;
161 : }
162 :
163 601 : void FragmentHandler2::onStartElement( const AttributeList& )
164 : {
165 601 : }
166 :
167 36 : void FragmentHandler2::onCharacters( const OUString& )
168 : {
169 36 : }
170 :
171 574 : void FragmentHandler2::onEndElement()
172 : {
173 574 : }
174 :
175 0 : ContextHandlerRef FragmentHandler2::onCreateRecordContext( sal_Int32, SequenceInputStream& )
176 : {
177 0 : return 0;
178 : }
179 :
180 0 : void FragmentHandler2::onStartRecord( SequenceInputStream& )
181 : {
182 0 : }
183 :
184 0 : void FragmentHandler2::onEndRecord()
185 : {
186 0 : }
187 :
188 : // oox.core.FragmentHandler2 interface ----------------------------------------
189 :
190 63 : void FragmentHandler2::initializeImport()
191 : {
192 63 : }
193 :
194 12 : void FragmentHandler2::finalizeImport()
195 : {
196 12 : }
197 :
198 : // ============================================================================
199 :
200 : } // namespace core
201 51 : } // namespace oox
202 :
203 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|