xref: /trunk/main/oox/source/ppt/commonbehaviorcontext.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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     {
69         switch( aElement )
70         {
71         case PPT_TOKEN( cBhvr ):
72         {
73             if( !maAttributes.empty() )
74             {
75                 OUStringBuffer sAttributes;
76                 std::list< Attribute >::const_iterator iter;
77                 for(iter = maAttributes.begin(); iter != maAttributes.end(); iter++)
78                 {
79                     if( sAttributes.getLength() )
80                     {
81                         sAttributes.appendAscii( ";" );
82                     }
83                     sAttributes.append( iter->name );
84                 }
85                 OUString sTmp( sAttributes.makeStringAndClear() );
86                 mpNode->getNodeProperties()[ NP_ATTRIBUTENAME ] = makeAny( sTmp );
87             }
88             break;
89         }
90         case PPT_TOKEN( attrNameLst ):
91             mbInAttrList = false;
92             break;
93         case PPT_TOKEN( attrName ):
94             if( mbIsInAttrName )
95             {
96                 const ImplAttributeNameConversion *attrConv = gImplConversionList;
97                 while( attrConv->mpMSName != NULL )
98                 {
99                     if(msCurrentAttribute.compareToAscii( attrConv->mpMSName ) == 0 )
100                     {
101                         Attribute attr;
102                         attr.name = ::rtl::OUString::intern( attrConv->mpAPIName,
103                                                              strlen(attrConv->mpAPIName),
104                                                              RTL_TEXTENCODING_ASCII_US );
105                         attr.type = attrConv->meAttribute;
106                         maAttributes.push_back( attr );
107                         OSL_TRACE( "OOX: attrName is %s -> %s",
108                                    OUSTRING_TO_CSTR( msCurrentAttribute ),
109                                    attrConv->mpAPIName );
110                         break;
111                     }
112                     attrConv++;
113                 }
114                 mbIsInAttrName = false;
115             }
116             break;
117         default:
118             break;
119         }
120     }
121 
122 
characters(const OUString & aChars)123     void CommonBehaviorContext::characters( const OUString& aChars )
124     {
125         if( mbIsInAttrName )
126         {
127             msCurrentAttribute += aChars;
128         }
129     }
130 
131 
createFastChildContext(::sal_Int32 aElementToken,const Reference<XFastAttributeList> & xAttribs)132     Reference< XFastContextHandler > SAL_CALL CommonBehaviorContext::createFastChildContext( ::sal_Int32 aElementToken,
133                                                                                                                                                                                      const Reference< XFastAttributeList >& xAttribs )
134     {
135         Reference< XFastContextHandler > xRet;
136 
137         switch ( aElementToken )
138         {
139         case PPT_TOKEN( cTn ):
140             xRet.set( new CommonTimeNodeContext( *this, aElementToken, xAttribs, mpNode ) );
141             break;
142         case PPT_TOKEN( tgtEl ):
143             xRet.set( new TimeTargetElementContext( *this, mpNode->getTarget() ) );
144             break;
145         case PPT_TOKEN( attrNameLst ):
146             mbInAttrList = true;
147             break;
148         case PPT_TOKEN( attrName ):
149         {
150             if( mbInAttrList )
151             {
152                 mbIsInAttrName = true;
153                 msCurrentAttribute = OUString();
154             }
155             else
156             {
157                 OSL_TRACE( "OOX: Attribute Name outside an Attribute List" );
158             }
159             break;
160         }
161         default:
162             break;
163         }
164 
165         if( !xRet.is() )
166             xRet.set( this );
167 
168         return xRet;
169     }
170 
171 } }
172