1*ca5ec200SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ca5ec200SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ca5ec200SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ca5ec200SAndrew Rist  * distributed with this work for additional information
6*ca5ec200SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ca5ec200SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ca5ec200SAndrew Rist  * "License"); you may not use this file except in compliance
9*ca5ec200SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ca5ec200SAndrew Rist  *
11*ca5ec200SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ca5ec200SAndrew Rist  *
13*ca5ec200SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ca5ec200SAndrew Rist  * software distributed under the License is distributed on an
15*ca5ec200SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ca5ec200SAndrew Rist  * KIND, either express or implied.  See the License for the
17*ca5ec200SAndrew Rist  * specific language governing permissions and limitations
18*ca5ec200SAndrew Rist  * under the License.
19*ca5ec200SAndrew Rist  *
20*ca5ec200SAndrew Rist  *************************************************************/
21*ca5ec200SAndrew Rist 
22*ca5ec200SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "comphelper/anytostring.hxx"
25cdf0e10cSrcweir #include "cppuhelper/exc_hlp.hxx"
26cdf0e10cSrcweir #include <osl/diagnose.h>
27cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <com/sun/star/animations/XTimeContainer.hpp>
30cdf0e10cSrcweir #include <com/sun/star/animations/XAnimationNode.hpp>
31cdf0e10cSrcweir #include <com/sun/star/animations/XAnimate.hpp>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include "oox/core/fragmenthandler.hxx"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include "commonbehaviorcontext.hxx"
36cdf0e10cSrcweir #include "commontimenodecontext.hxx"
37cdf0e10cSrcweir #include "timetargetelementcontext.hxx"
38cdf0e10cSrcweir #include "pptfilterhelpers.hxx"
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include <string.h>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir using ::rtl::OUString;
43cdf0e10cSrcweir using ::rtl::OUStringBuffer;
44cdf0e10cSrcweir using namespace ::oox::core;
45cdf0e10cSrcweir using namespace ::com::sun::star::uno;
46cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
47cdf0e10cSrcweir using namespace ::com::sun::star::animations;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir namespace oox { namespace ppt {
50cdf0e10cSrcweir 
CommonBehaviorContext(ContextHandler & rParent,const Reference<XFastAttributeList> & xAttribs,const TimeNodePtr & pNode)51cdf0e10cSrcweir     CommonBehaviorContext::CommonBehaviorContext( ContextHandler& rParent,
52cdf0e10cSrcweir             const Reference< XFastAttributeList >& xAttribs,
53cdf0e10cSrcweir             const TimeNodePtr & pNode )
54cdf0e10cSrcweir         : TimeNodeContext( rParent, PPT_TOKEN( cBhvr ), xAttribs, pNode )
55cdf0e10cSrcweir 			, mbInAttrList( false )
56cdf0e10cSrcweir 			, mbIsInAttrName( false )
57cdf0e10cSrcweir 	{
58cdf0e10cSrcweir 	}
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 
~CommonBehaviorContext()61cdf0e10cSrcweir 	CommonBehaviorContext::~CommonBehaviorContext( ) throw( )
62cdf0e10cSrcweir 	{
63cdf0e10cSrcweir 	}
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 
endFastElement(sal_Int32 aElement)67cdf0e10cSrcweir 	void SAL_CALL CommonBehaviorContext::endFastElement( sal_Int32 aElement )
68cdf0e10cSrcweir 		throw ( SAXException, RuntimeException)
69cdf0e10cSrcweir 	{
70cdf0e10cSrcweir 		switch( aElement )
71cdf0e10cSrcweir 		{
72cdf0e10cSrcweir 		case PPT_TOKEN( cBhvr ):
73cdf0e10cSrcweir 		{
74cdf0e10cSrcweir 			if( !maAttributes.empty() )
75cdf0e10cSrcweir 			{
76cdf0e10cSrcweir 				OUStringBuffer sAttributes;
77cdf0e10cSrcweir 				std::list< Attribute >::const_iterator iter;
78cdf0e10cSrcweir 				for(iter = maAttributes.begin(); iter != maAttributes.end(); iter++)
79cdf0e10cSrcweir 				{
80cdf0e10cSrcweir 					if( sAttributes.getLength() )
81cdf0e10cSrcweir 					{
82cdf0e10cSrcweir 						sAttributes.appendAscii( ";" );
83cdf0e10cSrcweir 					}
84cdf0e10cSrcweir 					sAttributes.append( iter->name );
85cdf0e10cSrcweir 				}
86cdf0e10cSrcweir 				OUString sTmp( sAttributes.makeStringAndClear() );
87cdf0e10cSrcweir 				mpNode->getNodeProperties()[ NP_ATTRIBUTENAME ] = makeAny( sTmp );
88cdf0e10cSrcweir 			}
89cdf0e10cSrcweir 			break;
90cdf0e10cSrcweir 		}
91cdf0e10cSrcweir 		case PPT_TOKEN( attrNameLst ):
92cdf0e10cSrcweir 			mbInAttrList = false;
93cdf0e10cSrcweir 			break;
94cdf0e10cSrcweir 		case PPT_TOKEN( attrName ):
95cdf0e10cSrcweir 			if( mbIsInAttrName )
96cdf0e10cSrcweir 			{
97cdf0e10cSrcweir 				const ImplAttributeNameConversion *attrConv = gImplConversionList;
98cdf0e10cSrcweir 				while( attrConv->mpMSName != NULL )
99cdf0e10cSrcweir 				{
100cdf0e10cSrcweir 					if(msCurrentAttribute.compareToAscii( attrConv->mpMSName ) == 0 )
101cdf0e10cSrcweir 					{
102cdf0e10cSrcweir 						Attribute attr;
103cdf0e10cSrcweir 						attr.name = ::rtl::OUString::intern( attrConv->mpAPIName,
104cdf0e10cSrcweir 															 strlen(attrConv->mpAPIName),
105cdf0e10cSrcweir 															 RTL_TEXTENCODING_ASCII_US );
106cdf0e10cSrcweir 						attr.type = attrConv->meAttribute;
107cdf0e10cSrcweir 						maAttributes.push_back( attr );
108cdf0e10cSrcweir 						OSL_TRACE( "OOX: attrName is %s -> %s",
109cdf0e10cSrcweir 								   OUSTRING_TO_CSTR( msCurrentAttribute ),
110cdf0e10cSrcweir 								   attrConv->mpAPIName );
111cdf0e10cSrcweir 						break;
112cdf0e10cSrcweir 					}
113cdf0e10cSrcweir 					attrConv++;
114cdf0e10cSrcweir 				}
115cdf0e10cSrcweir 				mbIsInAttrName = false;
116cdf0e10cSrcweir 			}
117cdf0e10cSrcweir 			break;
118cdf0e10cSrcweir 		default:
119cdf0e10cSrcweir 			break;
120cdf0e10cSrcweir 		}
121cdf0e10cSrcweir 	}
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 
characters(const OUString & aChars)124cdf0e10cSrcweir 	void CommonBehaviorContext::characters( const OUString& aChars )
125cdf0e10cSrcweir 		throw( SAXException, RuntimeException )
126cdf0e10cSrcweir 	{
127cdf0e10cSrcweir 		if( mbIsInAttrName )
128cdf0e10cSrcweir 		{
129cdf0e10cSrcweir 			msCurrentAttribute += aChars;
130cdf0e10cSrcweir 		}
131cdf0e10cSrcweir 	}
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 
createFastChildContext(::sal_Int32 aElementToken,const Reference<XFastAttributeList> & xAttribs)134cdf0e10cSrcweir 	Reference< XFastContextHandler > SAL_CALL CommonBehaviorContext::createFastChildContext( ::sal_Int32 aElementToken,
135cdf0e10cSrcweir 																																													 const Reference< XFastAttributeList >& xAttribs )
136cdf0e10cSrcweir 		throw ( SAXException, RuntimeException )
137cdf0e10cSrcweir 	{
138cdf0e10cSrcweir 		Reference< XFastContextHandler > xRet;
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 		switch ( aElementToken )
141cdf0e10cSrcweir 		{
142cdf0e10cSrcweir 		case PPT_TOKEN( cTn ):
143cdf0e10cSrcweir             xRet.set( new CommonTimeNodeContext( *this, aElementToken, xAttribs, mpNode ) );
144cdf0e10cSrcweir 			break;
145cdf0e10cSrcweir 		case PPT_TOKEN( tgtEl ):
146cdf0e10cSrcweir             xRet.set( new TimeTargetElementContext( *this, mpNode->getTarget() ) );
147cdf0e10cSrcweir 			break;
148cdf0e10cSrcweir 		case PPT_TOKEN( attrNameLst ):
149cdf0e10cSrcweir 			mbInAttrList = true;
150cdf0e10cSrcweir 			break;
151cdf0e10cSrcweir 		case PPT_TOKEN( attrName ):
152cdf0e10cSrcweir 		{
153cdf0e10cSrcweir 			if( mbInAttrList )
154cdf0e10cSrcweir 			{
155cdf0e10cSrcweir 				mbIsInAttrName = true;
156cdf0e10cSrcweir 				msCurrentAttribute = OUString();
157cdf0e10cSrcweir 			}
158cdf0e10cSrcweir 			else
159cdf0e10cSrcweir 			{
160cdf0e10cSrcweir 				OSL_TRACE( "OOX: Attribute Name outside an Attribute List" );
161cdf0e10cSrcweir 			}
162cdf0e10cSrcweir 			break;
163cdf0e10cSrcweir 		}
164cdf0e10cSrcweir 		default:
165cdf0e10cSrcweir 			break;
166cdf0e10cSrcweir 		}
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 		if( !xRet.is() )
169cdf0e10cSrcweir 			xRet.set( this );
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 		return xRet;
172cdf0e10cSrcweir 	}
173cdf0e10cSrcweir 
174cdf0e10cSrcweir } }
175