Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / oox / source / ppt / commonbehaviorcontext.cxx
blob3112e084f8a6a091c3c0e98361d84dac9b7253fb
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>
22 #include <sal/log.hxx>
24 #include <oox/core/fragmenthandler.hxx>
25 #include <oox/helper/attributelist.hxx>
26 #include <oox/token/namespaces.hxx>
27 #include <oox/token/tokens.hxx>
28 #include <oox/ppt/pptfilterhelpers.hxx>
30 #include "commonbehaviorcontext.hxx"
31 #include "commontimenodecontext.hxx"
32 #include "timetargetelementcontext.hxx"
34 #include <string.h>
36 using namespace ::oox::core;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::xml::sax;
40 namespace oox { namespace ppt {
42 CommonBehaviorContext::CommonBehaviorContext( FragmentHandler2 const & rParent,
43 const TimeNodePtr & pNode)
44 : FragmentHandler2(rParent)
45 , mbInAttrList( false )
46 , mbIsInAttrName( false )
47 , mpNode(pNode)
51 CommonBehaviorContext::~CommonBehaviorContext( ) throw( )
55 void CommonBehaviorContext::onEndElement()
57 switch( getCurrentElement() )
59 case PPT_TOKEN( cBhvr ):
61 if( !maAttributes.empty() )
63 OUStringBuffer sAttributes;
64 for (auto const& attribute : maAttributes)
66 if( !sAttributes.isEmpty() )
68 sAttributes.append( ";" );
70 sAttributes.append( attribute.name );
72 OUString sTmp( sAttributes.makeStringAndClear() );
73 mpNode->getNodeProperties()[ NP_ATTRIBUTENAME ] <<= sTmp;
75 break;
77 case PPT_TOKEN( attrNameLst ):
78 mbInAttrList = false;
79 break;
80 case PPT_TOKEN( attrName ):
81 if( mbIsInAttrName )
83 const ImplAttributeNameConversion *attrConv = getAttributeConversionList();
84 while( attrConv->mpMSName != nullptr )
86 if(msCurrentAttribute.equalsAscii( attrConv->mpMSName ) )
88 Attribute attr;
89 attr.name = OUString::intern( attrConv->mpAPIName,
90 strlen(attrConv->mpAPIName),
91 RTL_TEXTENCODING_ASCII_US );
92 attr.type = attrConv->meAttribute;
93 maAttributes.push_back( attr );
94 SAL_INFO("oox.ppt", "OOX: attrName is " << msCurrentAttribute << " -> " << attrConv->mpAPIName );
95 break;
97 attrConv++;
99 mbIsInAttrName = false;
101 break;
102 default:
103 break;
107 void CommonBehaviorContext::onCharacters( const OUString& aChars )
109 if( mbIsInAttrName )
111 msCurrentAttribute += aChars;
115 ::oox::core::ContextHandlerRef CommonBehaviorContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
117 switch ( aElementToken )
119 case PPT_TOKEN( cTn ):
120 return new CommonTimeNodeContext( *this, aElementToken, rAttribs.getFastAttributeList(), mpNode );
121 case PPT_TOKEN( tgtEl ):
122 return new TimeTargetElementContext( *this, mpNode->getTarget() );
123 case PPT_TOKEN( attrNameLst ):
124 mbInAttrList = true;
125 return this;
126 case PPT_TOKEN( attrName ):
128 if( mbInAttrList )
130 mbIsInAttrName = true;
131 msCurrentAttribute.clear();
133 else
135 SAL_INFO("oox.ppt", "OOX: Attribute Name outside an Attribute List" );
137 return this;
139 default:
140 break;
143 return this;
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */