LibreOffice Module xmloff (master) 1
ControlOASISTContext.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "MutableAttrList.hxx"
26#include "TransformerBase.hxx"
28#include <osl/diagnose.h>
29
30using namespace ::com::sun::star::uno;
31using namespace ::com::sun::star::xml::sax;
32using namespace ::xmloff::token;
33
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 )
42{
43}
44
46 const Reference< XAttributeList >& rAttrList )
47{
48
49 XMLTransformerActions *pActions =
51 OSL_ENSURE( pActions, "go no actions" );
52
53 Reference< XAttributeList > xAttrList( rAttrList );
55// GetTransformer().ProcessAttrList( xAttrList, OOO_SHAPE_ACTIONS,
56// sal_True );
57
58 XMLMutableAttributeList *pControlMutableAttrList =
60 Reference< XAttributeList > xControlAttrList( pControlMutableAttrList );
61
62 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
63 for( sal_Int16 i=0; i < nAttrCount; i++ )
64 {
65 const OUString& rAttrName = xAttrList->getNameByIndex( i );
66 OUString aLocalName;
67 sal_uInt16 nPrefix =
69 &aLocalName );
70 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
71 XMLTransformerActions::const_iterator aIter =
72 pActions->find( aKey );
73 if( aIter != pActions->end() )
74 {
75 if( !pMutableAttrList )
76 {
77 pMutableAttrList =
78 new XMLMutableAttributeList( rAttrList );
79 xAttrList = pMutableAttrList;
80 }
81 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
82 switch( (*aIter).second.m_nActionType )
83 {
86 {
87 pControlMutableAttrList->AddAttribute( rAttrName,
88 rAttrValue );
89 pMutableAttrList->RemoveAttributeByIndex( i );
90 --i;
91 --nAttrCount;
92 }
93 break;
95 {
96 OUString aAttrValue( rAttrValue );
97 sal_uInt16 nValPrefix =
98 static_cast<sal_uInt16>( (*aIter).second.m_nParam2 );
100 nValPrefix );
101 OUString aNewAttrQName(
102 GetTransformer().GetNamespaceMap().GetQNameByKey(
103 (*aIter).second.GetQNamePrefixFromParam1(),
105 (*aIter).second.GetQNameTokenFromParam1()) ) );
106 if( m_bCreateControl )
107 {
108 pControlMutableAttrList->AddAttribute( aNewAttrQName,
109 aAttrValue );
110 pMutableAttrList->RemoveAttributeByIndex( i );
111 --i;
112 --nAttrCount;
113 }
114 else
115 {
116 pMutableAttrList->RenameAttributeByIndex( i,
117 aNewAttrQName );
118 pMutableAttrList->SetValueByIndex( i, aAttrValue );
119 }
120 }
121 break;
123 {
124 OUString aAttrValue( rAttrValue );
125 if( GetTransformer().ConvertURIToOOo( aAttrValue,
126 static_cast< bool >((*aIter).second.m_nParam1)) )
127 pMutableAttrList->SetValueByIndex( i, aAttrValue );
128 }
129 break;
130 default:
131 OSL_ENSURE( false, "unknown action" );
132 break;
133 }
134 }
135 }
136
137 if( m_bCreateControl )
138 GetTransformer().GetDocHandler()->startElement( m_aElemQName,
139 xControlAttrList );
141}
142
144{
146 if( m_bCreateControl )
147 GetTransformer().GetDocHandler()->endElement( m_aElemQName );
148}
149
150/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@ OASIS_FORM_CONTROL_ACTIONS
@ XML_ATACTION_MOVE_TO_ELEM
@ XML_ATACTION_URI_OASIS
@ XML_ATACTION_RENAME_REMOVE_NAMESPACE_PREFIX
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
XMLControlOASISTransformerContext(XMLTransformerBase &rTransformer, const OUString &rQName, bool bCreateControl)
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
void AddAttribute(const OUString &sName, const OUString &sValue)
virtual XMLTransformerActions * GetUserDefinedActions(sal_uInt16 n)
SvXMLNamespaceMap & GetNamespaceMap()
bool RemoveNamespacePrefix(OUString &rName, sal_uInt16 nPrefixOnly=0xffffU) const
const css::uno::Reference< css::xml::sax::XDocumentHandler > & GetDocHandler() const
XMLTransformerBase & GetTransformer()
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList)
int i
Handling of tokens in XML:
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3541
constexpr sal_uInt16 XML_NAMESPACE_FORM