Line data Source code
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"
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>
29 :
30 : using namespace ::com::sun::star::uno;
31 : using namespace ::com::sun::star::xml::sax;
32 : using namespace ::xmloff::token;
33 :
34 0 : TYPEINIT1( XMLControlOASISTransformerContext, XMLTransformerContext );
35 :
36 0 : XMLControlOASISTransformerContext::XMLControlOASISTransformerContext(
37 : XMLTransformerBase& rImp,
38 : const OUString& rQName,
39 : bool bCreateControl ) :
40 : XMLTransformerContext( rImp, rQName ),
41 0 : m_aElemQName( rImp.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_FORM,
42 0 : ::xmloff::token::GetXMLToken( XML_CONTROL ) ) ),
43 0 : m_bCreateControl( bCreateControl )
44 : {
45 0 : }
46 :
47 0 : XMLControlOASISTransformerContext::~XMLControlOASISTransformerContext()
48 : {
49 0 : }
50 :
51 0 : void XMLControlOASISTransformerContext::StartElement(
52 : const Reference< XAttributeList >& rAttrList )
53 : {
54 :
55 : XMLTransformerActions *pActions =
56 0 : GetTransformer().GetUserDefinedActions( OASIS_FORM_CONTROL_ACTIONS );
57 : OSL_ENSURE( pActions, "go no actions" );
58 :
59 0 : Reference< XAttributeList > xAttrList( rAttrList );
60 0 : XMLMutableAttributeList *pMutableAttrList = 0;
61 : // GetTransformer().ProcessAttrList( xAttrList, OOO_SHAPE_ACTIONS,
62 : // sal_True );
63 :
64 : XMLMutableAttributeList *pControlMutableAttrList =
65 0 : m_bCreateControl ? new XMLMutableAttributeList : 0;
66 0 : Reference< XAttributeList > xControlAttrList( pControlMutableAttrList );
67 :
68 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
69 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
70 : {
71 0 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
72 0 : OUString aLocalName;
73 : sal_uInt16 nPrefix =
74 0 : GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
75 0 : &aLocalName );
76 0 : XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
77 : XMLTransformerActions::const_iterator aIter =
78 0 : pActions->find( aKey );
79 0 : if( !(aIter == pActions->end() ) )
80 : {
81 0 : if( !pMutableAttrList )
82 : {
83 : pMutableAttrList =
84 0 : new XMLMutableAttributeList( rAttrList );
85 0 : xAttrList = pMutableAttrList;
86 : }
87 0 : const OUString& rAttrValue = xAttrList->getValueByIndex( i );
88 0 : switch( (*aIter).second.m_nActionType )
89 : {
90 : case XML_ATACTION_MOVE_TO_ELEM:
91 0 : if( m_bCreateControl )
92 : {
93 : pControlMutableAttrList->AddAttribute( rAttrName,
94 0 : rAttrValue );
95 0 : pMutableAttrList->RemoveAttributeByIndex( i );
96 0 : --i;
97 0 : --nAttrCount;
98 : }
99 0 : break;
100 : case XML_ATACTION_RENAME_REMOVE_NAMESPACE_PREFIX:
101 : {
102 0 : OUString aAttrValue( rAttrValue );
103 : sal_uInt16 nValPrefix =
104 0 : static_cast<sal_uInt16>( (*aIter).second.m_nParam2 );
105 0 : GetTransformer().RemoveNamespacePrefix( aAttrValue,
106 0 : nValPrefix );
107 : OUString aNewAttrQName(
108 0 : GetTransformer().GetNamespaceMap().GetQNameByKey(
109 0 : (*aIter).second.GetQNamePrefixFromParam1(),
110 : ::xmloff::token::GetXMLToken(
111 0 : (*aIter).second.GetQNameTokenFromParam1()) ) );
112 0 : if( m_bCreateControl )
113 : {
114 : pControlMutableAttrList->AddAttribute( aNewAttrQName,
115 0 : aAttrValue );
116 0 : pMutableAttrList->RemoveAttributeByIndex( i );
117 0 : --i;
118 0 : --nAttrCount;
119 : }
120 : else
121 : {
122 : pMutableAttrList->RenameAttributeByIndex( i,
123 0 : aNewAttrQName );
124 0 : pMutableAttrList->SetValueByIndex( i, aAttrValue );
125 0 : }
126 : }
127 0 : break;
128 : case XML_ATACTION_URI_OASIS:
129 : {
130 0 : OUString aAttrValue( rAttrValue );
131 0 : if( GetTransformer().ConvertURIToOOo( aAttrValue,
132 0 : static_cast< bool >((*aIter).second.m_nParam1)) )
133 0 : pMutableAttrList->SetValueByIndex( i, aAttrValue );
134 : }
135 0 : break;
136 : default:
137 : OSL_ENSURE( false, "unknown action" );
138 0 : break;
139 0 : }
140 : }
141 0 : }
142 :
143 0 : if( m_bCreateControl )
144 0 : GetTransformer().GetDocHandler()->startElement( m_aElemQName,
145 0 : xControlAttrList );
146 0 : XMLTransformerContext::StartElement( xAttrList );
147 0 : }
148 :
149 0 : void XMLControlOASISTransformerContext::EndElement()
150 : {
151 0 : XMLTransformerContext::EndElement();
152 0 : if( m_bCreateControl )
153 0 : GetTransformer().GetDocHandler()->endElement( m_aElemQName );
154 0 : }
155 :
156 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|