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