Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / oox / source / ppt / commonbehaviorcontext.cxx
blob844c81803e039262fb9a6e79d874471f52a4be6a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <cppuhelper/exc_hlp.hxx>
21 #include <rtl/ustrbuf.hxx>
23 #include <oox/core/fragmenthandler.hxx>
24 #include <oox/helper/attributelist.hxx>
25 #include <oox/token/namespaces.hxx>
26 #include <oox/token/tokens.hxx>
27 #include <oox/ppt/pptfilterhelpers.hxx>
29 #include "commonbehaviorcontext.hxx"
30 #include "commontimenodecontext.hxx"
31 #include "timetargetelementcontext.hxx"
33 #include <string.h>
35 using namespace ::oox::core;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::xml::sax;
39 namespace oox { namespace ppt {
41 CommonBehaviorContext::CommonBehaviorContext( FragmentHandler2 const & rParent,
42 const TimeNodePtr & pNode )
43 : TimeNodeContext( rParent, PPT_TOKEN( cBhvr ), pNode )
44 , mbInAttrList( false )
45 , mbIsInAttrName( false )
49 CommonBehaviorContext::~CommonBehaviorContext( ) throw( )
53 void CommonBehaviorContext::onEndElement()
55 switch( getCurrentElement() )
57 case PPT_TOKEN( cBhvr ):
59 if( !maAttributes.empty() )
61 OUStringBuffer sAttributes;
62 for (auto const& attribute : maAttributes)
64 if( !sAttributes.isEmpty() )
66 sAttributes.append( ";" );
68 sAttributes.append( attribute.name );
70 OUString sTmp( sAttributes.makeStringAndClear() );
71 mpNode->getNodeProperties()[ NP_ATTRIBUTENAME ] <<= sTmp;
73 break;
75 case PPT_TOKEN( attrNameLst ):
76 mbInAttrList = false;
77 break;
78 case PPT_TOKEN( attrName ):
79 if( mbIsInAttrName )
81 const ImplAttributeNameConversion *attrConv = getAttributeConversionList();
82 while( attrConv->mpMSName != nullptr )
84 if(msCurrentAttribute.equalsAscii( attrConv->mpMSName ) )
86 Attribute attr;
87 attr.name = OUString::intern( attrConv->mpAPIName,
88 strlen(attrConv->mpAPIName),
89 RTL_TEXTENCODING_ASCII_US );
90 attr.type = attrConv->meAttribute;
91 maAttributes.push_back( attr );
92 SAL_INFO("oox.ppt", "OOX: attrName is " << OUSTRING_TO_CSTR( msCurrentAttribute ) << " -> " << attrConv->mpAPIName );
93 break;
95 attrConv++;
97 mbIsInAttrName = false;
99 break;
100 default:
101 break;
105 void CommonBehaviorContext::onCharacters( const OUString& aChars )
107 if( mbIsInAttrName )
109 msCurrentAttribute += aChars;
113 ::oox::core::ContextHandlerRef CommonBehaviorContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
115 switch ( aElementToken )
117 case PPT_TOKEN( cTn ):
118 return new CommonTimeNodeContext( *this, aElementToken, rAttribs.getFastAttributeList(), mpNode );
119 case PPT_TOKEN( tgtEl ):
120 return new TimeTargetElementContext( *this, mpNode->getTarget() );
121 case PPT_TOKEN( attrNameLst ):
122 mbInAttrList = true;
123 return this;
124 case PPT_TOKEN( attrName ):
126 if( mbInAttrList )
128 mbIsInAttrName = true;
129 msCurrentAttribute.clear();
131 else
133 SAL_INFO("oox.ppt", "OOX: Attribute Name outside an Attribute List" );
135 return this;
137 default:
138 break;
141 return this;
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */