xref: /trunk/main/oox/source/ppt/commonbehaviorcontext.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 "comphelper/anytostring.hxx"
29 #include "cppuhelper/exc_hlp.hxx"
30 #include <osl/diagnose.h>
31 #include <rtl/ustrbuf.hxx>
32 
33 #include <com/sun/star/animations/XTimeContainer.hpp>
34 #include <com/sun/star/animations/XAnimationNode.hpp>
35 #include <com/sun/star/animations/XAnimate.hpp>
36 
37 #include "oox/core/fragmenthandler.hxx"
38 
39 #include "commonbehaviorcontext.hxx"
40 #include "commontimenodecontext.hxx"
41 #include "timetargetelementcontext.hxx"
42 #include "pptfilterhelpers.hxx"
43 
44 #include <string.h>
45 
46 using ::rtl::OUString;
47 using ::rtl::OUStringBuffer;
48 using namespace ::oox::core;
49 using namespace ::com::sun::star::uno;
50 using namespace ::com::sun::star::xml::sax;
51 using namespace ::com::sun::star::animations;
52 
53 namespace oox { namespace ppt {
54 
55     CommonBehaviorContext::CommonBehaviorContext( ContextHandler& rParent,
56             const Reference< XFastAttributeList >& xAttribs,
57             const TimeNodePtr & pNode )
58         : TimeNodeContext( rParent, PPT_TOKEN( cBhvr ), xAttribs, pNode )
59             , mbInAttrList( false )
60             , mbIsInAttrName( false )
61     {
62     }
63 
64 
65     CommonBehaviorContext::~CommonBehaviorContext( ) throw( )
66     {
67     }
68 
69 
70 
71     void SAL_CALL CommonBehaviorContext::endFastElement( sal_Int32 aElement )
72         throw ( SAXException, RuntimeException)
73     {
74         switch( aElement )
75         {
76         case PPT_TOKEN( cBhvr ):
77         {
78             if( !maAttributes.empty() )
79             {
80                 OUStringBuffer sAttributes;
81                 std::list< Attribute >::const_iterator iter;
82                 for(iter = maAttributes.begin(); iter != maAttributes.end(); iter++)
83                 {
84                     if( sAttributes.getLength() )
85                     {
86                         sAttributes.appendAscii( ";" );
87                     }
88                     sAttributes.append( iter->name );
89                 }
90                 OUString sTmp( sAttributes.makeStringAndClear() );
91                 mpNode->getNodeProperties()[ NP_ATTRIBUTENAME ] = makeAny( sTmp );
92             }
93             break;
94         }
95         case PPT_TOKEN( attrNameLst ):
96             mbInAttrList = false;
97             break;
98         case PPT_TOKEN( attrName ):
99             if( mbIsInAttrName )
100             {
101                 const ImplAttributeNameConversion *attrConv = gImplConversionList;
102                 while( attrConv->mpMSName != NULL )
103                 {
104                     if(msCurrentAttribute.compareToAscii( attrConv->mpMSName ) == 0 )
105                     {
106                         Attribute attr;
107                         attr.name = ::rtl::OUString::intern( attrConv->mpAPIName,
108                                                              strlen(attrConv->mpAPIName),
109                                                              RTL_TEXTENCODING_ASCII_US );
110                         attr.type = attrConv->meAttribute;
111                         maAttributes.push_back( attr );
112                         OSL_TRACE( "OOX: attrName is %s -> %s",
113                                    OUSTRING_TO_CSTR( msCurrentAttribute ),
114                                    attrConv->mpAPIName );
115                         break;
116                     }
117                     attrConv++;
118                 }
119                 mbIsInAttrName = false;
120             }
121             break;
122         default:
123             break;
124         }
125     }
126 
127 
128     void CommonBehaviorContext::characters( const OUString& aChars )
129         throw( SAXException, RuntimeException )
130     {
131         if( mbIsInAttrName )
132         {
133             msCurrentAttribute += aChars;
134         }
135     }
136 
137 
138     Reference< XFastContextHandler > SAL_CALL CommonBehaviorContext::createFastChildContext( ::sal_Int32 aElementToken,
139                                                                                                                                                                                      const Reference< XFastAttributeList >& xAttribs )
140         throw ( SAXException, RuntimeException )
141     {
142         Reference< XFastContextHandler > xRet;
143 
144         switch ( aElementToken )
145         {
146         case PPT_TOKEN( cTn ):
147             xRet.set( new CommonTimeNodeContext( *this, aElementToken, xAttribs, mpNode ) );
148             break;
149         case PPT_TOKEN( tgtEl ):
150             xRet.set( new TimeTargetElementContext( *this, mpNode->getTarget() ) );
151             break;
152         case PPT_TOKEN( attrNameLst ):
153             mbInAttrList = true;
154             break;
155         case PPT_TOKEN( attrName ):
156         {
157             if( mbInAttrList )
158             {
159                 mbIsInAttrName = true;
160                 msCurrentAttribute = OUString();
161             }
162             else
163             {
164                 OSL_TRACE( "OOX: Attribute Name outside an Attribute List" );
165             }
166             break;
167         }
168         default:
169             break;
170         }
171 
172         if( !xRet.is() )
173             xRet.set( this );
174 
175         return xRet;
176     }
177 
178 } }
179