bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / transform / ControlOASISTContext.cxx
blobbc50e22f8d82a7f7afb86db4c812d235c4118ffc
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 TYPEINIT1( XMLControlOASISTransformerContext, XMLTransformerContext );
36 XMLControlOASISTransformerContext::XMLControlOASISTransformerContext(
37 XMLTransformerBase& rImp,
38 const OUString& rQName,
39 bool bCreateControl ) :
40 XMLTransformerContext( rImp, rQName ),
41 m_aElemQName( rImp.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_FORM,
42 ::xmloff::token::GetXMLToken( XML_CONTROL ) ) ),
43 m_bCreateControl( bCreateControl )
47 XMLControlOASISTransformerContext::~XMLControlOASISTransformerContext()
51 void XMLControlOASISTransformerContext::StartElement(
52 const Reference< XAttributeList >& rAttrList )
55 XMLTransformerActions *pActions =
56 GetTransformer().GetUserDefinedActions( OASIS_FORM_CONTROL_ACTIONS );
57 OSL_ENSURE( pActions, "go no actions" );
59 Reference< XAttributeList > xAttrList( rAttrList );
60 XMLMutableAttributeList *pMutableAttrList = 0;
61 // GetTransformer().ProcessAttrList( xAttrList, OOO_SHAPE_ACTIONS,
62 // sal_True );
64 XMLMutableAttributeList *pControlMutableAttrList =
65 m_bCreateControl ? new XMLMutableAttributeList : 0;
66 Reference< XAttributeList > xControlAttrList( pControlMutableAttrList );
68 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
69 for( sal_Int16 i=0; i < nAttrCount; i++ )
71 const OUString& rAttrName = xAttrList->getNameByIndex( i );
72 OUString aLocalName;
73 sal_uInt16 nPrefix =
74 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
75 &aLocalName );
76 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
77 XMLTransformerActions::const_iterator aIter =
78 pActions->find( aKey );
79 if( !(aIter == pActions->end() ) )
81 if( !pMutableAttrList )
83 pMutableAttrList =
84 new XMLMutableAttributeList( rAttrList );
85 xAttrList = pMutableAttrList;
87 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
88 switch( (*aIter).second.m_nActionType )
90 case XML_ATACTION_MOVE_TO_ELEM:
91 if( m_bCreateControl )
93 pControlMutableAttrList->AddAttribute( rAttrName,
94 rAttrValue );
95 pMutableAttrList->RemoveAttributeByIndex( i );
96 --i;
97 --nAttrCount;
99 break;
100 case XML_ATACTION_RENAME_REMOVE_NAMESPACE_PREFIX:
102 OUString aAttrValue( rAttrValue );
103 sal_uInt16 nValPrefix =
104 static_cast<sal_uInt16>( (*aIter).second.m_nParam2 );
105 GetTransformer().RemoveNamespacePrefix( aAttrValue,
106 nValPrefix );
107 OUString aNewAttrQName(
108 GetTransformer().GetNamespaceMap().GetQNameByKey(
109 (*aIter).second.GetQNamePrefixFromParam1(),
110 ::xmloff::token::GetXMLToken(
111 (*aIter).second.GetQNameTokenFromParam1()) ) );
112 if( m_bCreateControl )
114 pControlMutableAttrList->AddAttribute( aNewAttrQName,
115 aAttrValue );
116 pMutableAttrList->RemoveAttributeByIndex( i );
117 --i;
118 --nAttrCount;
120 else
122 pMutableAttrList->RenameAttributeByIndex( i,
123 aNewAttrQName );
124 pMutableAttrList->SetValueByIndex( i, aAttrValue );
127 break;
128 case XML_ATACTION_URI_OASIS:
130 OUString aAttrValue( rAttrValue );
131 if( GetTransformer().ConvertURIToOOo( aAttrValue,
132 static_cast< bool >((*aIter).second.m_nParam1)) )
133 pMutableAttrList->SetValueByIndex( i, aAttrValue );
135 break;
136 default:
137 OSL_ENSURE( false, "unknown action" );
138 break;
143 if( m_bCreateControl )
144 GetTransformer().GetDocHandler()->startElement( m_aElemQName,
145 xControlAttrList );
146 XMLTransformerContext::StartElement( xAttrList );
149 void XMLControlOASISTransformerContext::EndElement()
151 XMLTransformerContext::EndElement();
152 if( m_bCreateControl )
153 GetTransformer().GetDocHandler()->endElement( m_aElemQName );
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */