1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "oox/vml/vmldrawingfragment.hxx"
29 
30 #include "oox/core/xmlfilterbase.hxx"
31 #include "oox/vml/vmldrawing.hxx"
32 #include "oox/vml/vmlinputstream.hxx"
33 #include "oox/vml/vmlshapecontext.hxx"
34 
35 namespace oox {
36 namespace vml {
37 
38 // ============================================================================
39 
40 using namespace ::com::sun::star::io;
41 using namespace ::com::sun::star::uno;
42 using namespace ::oox::core;
43 
44 using ::rtl::OUString;
45 
46 // ============================================================================
47 
48 DrawingFragment::DrawingFragment( XmlFilterBase& rFilter, const OUString& rFragmentPath, Drawing& rDrawing ) :
49     FragmentHandler2( rFilter, rFragmentPath, false ),  // do not trim whitespace, has been preprocessed by the input stream
50     mrDrawing( rDrawing )
51 {
52 }
53 
54 Reference< XInputStream > DrawingFragment::openFragmentStream() const
55 {
56     // #i104719# create an input stream that preprocesses the VML data
57     return new InputStream( getFilter().getComponentContext(), FragmentHandler2::openFragmentStream() );
58 }
59 
60 ContextHandlerRef DrawingFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
61 {
62     switch( mrDrawing.getType() )
63     {
64         // DOCX filter handles plain shape elements with this fragment handler
65         case VMLDRAWING_WORD:
66             if( isRootElement() )
67                 return ShapeContextBase::createShapeContext( *this, mrDrawing.getShapes(), nElement, rAttribs );
68         break;
69 
70         // XLSX and PPTX filters load the entire VML fragment
71         case VMLDRAWING_EXCEL:
72         case VMLDRAWING_POWERPOINT:
73             switch( getCurrentElement() )
74             {
75                 case XML_ROOT_CONTEXT:
76                     if( nElement == XML_xml ) return this;
77                 break;
78                 case XML_xml:
79                     return ShapeContextBase::createShapeContext( *this, mrDrawing.getShapes(), nElement, rAttribs );
80             }
81         break;
82     }
83     return 0;
84 }
85 
86 void DrawingFragment::finalizeImport()
87 {
88     // resolve shape template references for all shapes
89     mrDrawing.finalizeFragmentImport();
90 }
91 
92 // ============================================================================
93 
94 } // namespace vml
95 } // namespace oox
96