1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "oox/vml/vmldrawingfragment.hxx"
25 
26 #include "oox/core/xmlfilterbase.hxx"
27 #include "oox/vml/vmldrawing.hxx"
28 #include "oox/vml/vmlinputstream.hxx"
29 #include "oox/vml/vmlshapecontext.hxx"
30 
31 namespace oox {
32 namespace vml {
33 
34 // ============================================================================
35 
36 using namespace ::com::sun::star::io;
37 using namespace ::com::sun::star::uno;
38 using namespace ::oox::core;
39 
40 using ::rtl::OUString;
41 
42 // ============================================================================
43 
DrawingFragment(XmlFilterBase & rFilter,const OUString & rFragmentPath,Drawing & rDrawing)44 DrawingFragment::DrawingFragment( XmlFilterBase& rFilter, const OUString& rFragmentPath, Drawing& rDrawing ) :
45     FragmentHandler2( rFilter, rFragmentPath, false ),  // do not trim whitespace, has been preprocessed by the input stream
46     mrDrawing( rDrawing )
47 {
48 }
49 
openFragmentStream() const50 Reference< XInputStream > DrawingFragment::openFragmentStream() const
51 {
52     // #i104719# create an input stream that preprocesses the VML data
53     return new InputStream( getFilter().getComponentContext(), FragmentHandler2::openFragmentStream() );
54 }
55 
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)56 ContextHandlerRef DrawingFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
57 {
58     switch( mrDrawing.getType() )
59     {
60         // DOCX filter handles plain shape elements with this fragment handler
61         case VMLDRAWING_WORD:
62             if( isRootElement() )
63                 return ShapeContextBase::createShapeContext( *this, mrDrawing.getShapes(), nElement, rAttribs );
64         break;
65 
66         // XLSX and PPTX filters load the entire VML fragment
67         case VMLDRAWING_EXCEL:
68         case VMLDRAWING_POWERPOINT:
69             switch( getCurrentElement() )
70             {
71                 case XML_ROOT_CONTEXT:
72                     if( nElement == XML_xml ) return this;
73                 break;
74                 case XML_xml:
75                     return ShapeContextBase::createShapeContext( *this, mrDrawing.getShapes(), nElement, rAttribs );
76             }
77         break;
78     }
79     return 0;
80 }
81 
finalizeImport()82 void DrawingFragment::finalizeImport()
83 {
84     // resolve shape template references for all shapes
85     mrDrawing.finalizeFragmentImport();
86 }
87 
88 // ============================================================================
89 
90 } // namespace vml
91 } // namespace oox
92