Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / xmloff / source / transform / ControlOASISTContext.cxx
blobb2f570217a342feee85dcd4f2c184c02561e8ba7
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 "MutableAttrList.hxx"
21 #include <xmloff/xmlnmspe.hxx>
22 #include <xmloff/nmspmap.hxx>
23 #include "ActionMapTypesOASIS.hxx"
24 #include "AttrTransformerAction.hxx"
25 #include "TransformerActions.hxx"
26 #include "TransformerBase.hxx"
27 #include "ControlOASISTContext.hxx"
28 #include <osl/diagnose.h>
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::xml::sax;
32 using namespace ::xmloff::token;
34 XMLControlOASISTransformerContext::XMLControlOASISTransformerContext(
35 XMLTransformerBase& rImp,
36 const OUString& rQName,
37 bool bCreateControl ) :
38 XMLTransformerContext( rImp, rQName ),
39 m_aElemQName( rImp.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_FORM,
40 ::xmloff::token::GetXMLToken( XML_CONTROL ) ) ),
41 m_bCreateControl( bCreateControl )
45 XMLControlOASISTransformerContext::~XMLControlOASISTransformerContext()
49 void XMLControlOASISTransformerContext::StartElement(
50 const Reference< XAttributeList >& rAttrList )
53 XMLTransformerActions *pActions =
54 GetTransformer().GetUserDefinedActions( OASIS_FORM_CONTROL_ACTIONS );
55 OSL_ENSURE( pActions, "go no actions" );
57 Reference< XAttributeList > xAttrList( rAttrList );
58 XMLMutableAttributeList *pMutableAttrList = nullptr;
59 // GetTransformer().ProcessAttrList( xAttrList, OOO_SHAPE_ACTIONS,
60 // sal_True );
62 XMLMutableAttributeList *pControlMutableAttrList =
63 m_bCreateControl ? new XMLMutableAttributeList : nullptr;
64 Reference< XAttributeList > xControlAttrList( pControlMutableAttrList );
66 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
67 for( sal_Int16 i=0; i < nAttrCount; i++ )
69 const OUString& rAttrName = xAttrList->getNameByIndex( i );
70 OUString aLocalName;
71 sal_uInt16 nPrefix =
72 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
73 &aLocalName );
74 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
75 XMLTransformerActions::const_iterator aIter =
76 pActions->find( aKey );
77 if( !(aIter == pActions->end() ) )
79 if( !pMutableAttrList )
81 pMutableAttrList =
82 new XMLMutableAttributeList( rAttrList );
83 xAttrList = pMutableAttrList;
85 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
86 switch( (*aIter).second.m_nActionType )
88 case XML_ATACTION_MOVE_TO_ELEM:
89 if( m_bCreateControl )
91 pControlMutableAttrList->AddAttribute( rAttrName,
92 rAttrValue );
93 pMutableAttrList->RemoveAttributeByIndex( i );
94 --i;
95 --nAttrCount;
97 break;
98 case XML_ATACTION_RENAME_REMOVE_NAMESPACE_PREFIX:
100 OUString aAttrValue( rAttrValue );
101 sal_uInt16 nValPrefix =
102 static_cast<sal_uInt16>( (*aIter).second.m_nParam2 );
103 GetTransformer().RemoveNamespacePrefix( aAttrValue,
104 nValPrefix );
105 OUString aNewAttrQName(
106 GetTransformer().GetNamespaceMap().GetQNameByKey(
107 (*aIter).second.GetQNamePrefixFromParam1(),
108 ::xmloff::token::GetXMLToken(
109 (*aIter).second.GetQNameTokenFromParam1()) ) );
110 if( m_bCreateControl )
112 pControlMutableAttrList->AddAttribute( aNewAttrQName,
113 aAttrValue );
114 pMutableAttrList->RemoveAttributeByIndex( i );
115 --i;
116 --nAttrCount;
118 else
120 pMutableAttrList->RenameAttributeByIndex( i,
121 aNewAttrQName );
122 pMutableAttrList->SetValueByIndex( i, aAttrValue );
125 break;
126 case XML_ATACTION_URI_OASIS:
128 OUString aAttrValue( rAttrValue );
129 if( GetTransformer().ConvertURIToOOo( aAttrValue,
130 static_cast< bool >((*aIter).second.m_nParam1)) )
131 pMutableAttrList->SetValueByIndex( i, aAttrValue );
133 break;
134 default:
135 OSL_ENSURE( false, "unknown action" );
136 break;
141 if( m_bCreateControl )
142 GetTransformer().GetDocHandler()->startElement( m_aElemQName,
143 xControlAttrList );
144 XMLTransformerContext::StartElement( xAttrList );
147 void XMLControlOASISTransformerContext::EndElement()
149 XMLTransformerContext::EndElement();
150 if( m_bCreateControl )
151 GetTransformer().GetDocHandler()->endElement( m_aElemQName );
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */