Update ooo320-m1
[ooovba.git] / xmloff / source / transform / EventOOoTContext.cxx
blobcc5e796f063b5030113e9cb9efcb379d186d7e64
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: EventOOoTContext.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "EventOOoTContext.hxx"
34 #include "EventMap.hxx"
35 #include "MutableAttrList.hxx"
36 #include "xmlnmspe.hxx"
37 #ifndef _XMLOFF_ACTIONMAPTYPESOOo_HXX
38 #include "ActionMapTypesOOo.hxx"
39 #endif
40 #include "AttrTransformerAction.hxx"
41 #include "TransformerActions.hxx"
42 #ifndef _XMLOFF_TRANSFORMERBASE_HXX
43 #include "TransformerBase.hxx"
44 #endif
45 #include <comphelper/stl_types.hxx>
46 #include <rtl/ustrbuf.hxx>
48 #include <hash_map>
50 using ::rtl::OUString;
51 using ::rtl::OUStringBuffer;
52 using namespace ::com::sun::star::uno;
53 using namespace ::com::sun::star::xml::sax;
54 using namespace ::xmloff::token;
56 class XMLTransformerOOoEventMap_Impl:
57 public ::std::hash_map< ::rtl::OUString, NameKey_Impl,
58 ::rtl::OUStringHash, ::comphelper::UStringEqual >
60 public:
62 void AddMap( XMLTransformerEventMapEntry *pInit );
64 XMLTransformerOOoEventMap_Impl( XMLTransformerEventMapEntry *pInit,
65 XMLTransformerEventMapEntry *pInit2 );
66 ~XMLTransformerOOoEventMap_Impl();
69 void XMLTransformerOOoEventMap_Impl::AddMap( XMLTransformerEventMapEntry *pInit )
71 XMLTransformerOOoEventMap_Impl::key_type aKey;
72 XMLTransformerOOoEventMap_Impl::data_type aData;
73 while( pInit->m_pOOoName )
75 aKey = OUString::createFromAscii(pInit->m_pOOoName);
77 OSL_ENSURE( find( aKey ) == end(), "duplicate event map entry" );
79 aData.m_nPrefix = pInit->m_nOASISPrefix;
80 aData.m_aLocalName = OUString::createFromAscii(pInit->m_pOASISName);
82 XMLTransformerOOoEventMap_Impl::value_type aVal( aKey, aData );
84 if( !insert( aVal ).second )
86 OSL_ENSURE( false, "duplicate OOo event name extry" );
89 ++pInit;
93 XMLTransformerOOoEventMap_Impl::XMLTransformerOOoEventMap_Impl(
94 XMLTransformerEventMapEntry *pInit,
95 XMLTransformerEventMapEntry *pInit2 )
97 if( pInit )
98 AddMap( pInit );
99 if( pInit )
100 AddMap( pInit2 );
103 XMLTransformerOOoEventMap_Impl::~XMLTransformerOOoEventMap_Impl()
107 // -----------------------------------------------------------------------------
109 TYPEINIT1( XMLEventOOoTransformerContext, XMLPersElemContentTContext );
111 XMLEventOOoTransformerContext::XMLEventOOoTransformerContext(
112 XMLTransformerBase& rImp,
113 const OUString& rQName,
114 sal_Bool bPersistent ) :
115 XMLPersElemContentTContext( rImp, rQName,
116 rImp.GetNamespaceMap().GetKeyByAttrName( rQName ), XML_EVENT_LISTENER ),
117 m_bPersistent( bPersistent )
121 XMLEventOOoTransformerContext::~XMLEventOOoTransformerContext()
125 XMLTransformerOOoEventMap_Impl
126 *XMLEventOOoTransformerContext::CreateEventMap()
128 return new XMLTransformerOOoEventMap_Impl( aTransformerEventMap,
129 aFormTransformerEventMap );
132 void XMLEventOOoTransformerContext::FlushEventMap(
133 XMLTransformerOOoEventMap_Impl *p )
135 delete p;
138 sal_uInt16 XMLEventOOoTransformerContext::GetEventName(
139 const OUString& rName,
140 OUString& rNewName,
141 XMLTransformerOOoEventMap_Impl& rMap )
143 XMLTransformerOOoEventMap_Impl::key_type aKey( rName );
144 XMLTransformerOOoEventMap_Impl::const_iterator aIter = rMap.find( aKey );
145 if( aIter == rMap.end() )
147 rNewName = rName;
148 return XML_NAMESPACE_UNKNOWN;
150 else
152 rNewName = (*aIter).second.m_aLocalName;
153 return (*aIter).second.m_nPrefix;
158 void XMLEventOOoTransformerContext::StartElement(
159 const Reference< XAttributeList >& rAttrList )
161 XMLTransformerActions *pActions =
162 GetTransformer().GetUserDefinedActions( OOO_EVENT_ACTIONS );
163 OSL_ENSURE( pActions, "go no actions" );
165 OUString aLocation, aMacroName;
166 sal_Int16 nMacroName = -1;
167 Reference< XAttributeList > xAttrList( rAttrList );
168 XMLMutableAttributeList *pMutableAttrList = 0;
169 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
170 for( sal_Int16 i=0; i < nAttrCount; i++ )
172 const OUString& rAttrName = xAttrList->getNameByIndex( i );
173 OUString aLocalName;
174 sal_uInt16 nPrefix =
175 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
176 &aLocalName );
177 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
178 XMLTransformerActions::const_iterator aIter =
179 pActions->find( aKey );
180 if( !(aIter == pActions->end() ) )
182 if( !pMutableAttrList )
184 pMutableAttrList =
185 new XMLMutableAttributeList( xAttrList );
186 xAttrList = pMutableAttrList;
188 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
189 switch( (*aIter).second.m_nActionType )
191 case XML_ATACTION_HREF:
192 // TODO
193 break;
194 case XML_ATACTION_EVENT_NAME:
195 pMutableAttrList->SetValueByIndex( i,
196 GetTransformer().GetEventName( rAttrValue ) );
197 break;
198 case XML_ATACTION_ADD_NAMESPACE_PREFIX:
200 OUString aAttrValue( rAttrValue );
201 sal_uInt16 nValPrefix =
202 static_cast<sal_uInt16>((*aIter).second.m_nParam1);
203 if( GetTransformer().AddNamespacePrefix( aAttrValue,
204 nValPrefix ) )
205 pMutableAttrList->SetValueByIndex( i, aAttrValue );
207 break;
208 case XML_ATACTION_MACRO_LOCATION:
209 aLocation = rAttrValue;
210 pMutableAttrList->RemoveAttributeByIndex( i );
211 --i;
212 --nAttrCount;
213 break;
214 case XML_ATACTION_MACRO_NAME:
215 aMacroName = rAttrValue;
216 nMacroName = i;
217 break;
218 case XML_ATACTION_COPY:
219 break;
220 default:
221 OSL_ENSURE( !this, "unknown action" );
222 break;
227 if( nMacroName != -1 && aLocation.getLength() > 0 )
229 if( !IsXMLToken( aLocation, XML_APPLICATION ) )
230 aLocation = GetXMLToken( XML_DOCUMENT );
231 OUStringBuffer sTmp( aLocation.getLength() + aMacroName.getLength() + 1 );
232 sTmp = aLocation;
233 sTmp.append( sal_Unicode( ':' ) );
234 sTmp.append( aMacroName );
235 pMutableAttrList->SetValueByIndex( nMacroName,
236 sTmp.makeStringAndClear() );
239 if( m_bPersistent )
240 XMLPersElemContentTContext::StartElement( xAttrList );
241 else
242 GetTransformer().GetDocHandler()->startElement( GetExportQName(),
243 xAttrList );
246 void XMLEventOOoTransformerContext::EndElement()
248 if( m_bPersistent )
249 XMLPersElemContentTContext::EndElement();
250 else
251 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
254 XMLTransformerContext * XMLEventOOoTransformerContext::CreateChildContext(
255 sal_uInt16 nPrefix,
256 const OUString& rLocalName,
257 const OUString& rQName,
258 const Reference< XAttributeList >& xAttrList )
260 if( m_bPersistent )
261 return XMLPersElemContentTContext::CreateChildContext(nPrefix, rLocalName, rQName, xAttrList);
262 else
263 return XMLTransformerContext::CreateChildContext(nPrefix, rLocalName, rQName, xAttrList);
266 sal_Bool XMLEventOOoTransformerContext::IsPersistent() const
268 return m_bPersistent;