merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / transform / FrameOOoTContext.cxx
blob6c5a2b0b2146d26d3a310ee0b60f42dbd2c8bc4b
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: FrameOOoTContext.cxx,v $
10 * $Revision: 1.6 $
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 "FrameOOoTContext.hxx"
34 #include "IgnoreTContext.hxx"
35 #include "MutableAttrList.hxx"
36 #include "xmlnmspe.hxx"
37 #include <xmloff/nmspmap.hxx>
38 #include "ActionMapTypesOOo.hxx"
39 #include "AttrTransformerAction.hxx"
40 #include "ElemTransformerAction.hxx"
41 #include "TransformerActions.hxx"
42 #ifndef _XMLOFF_TRANSFORMERBASE_HXX
43 #include "TransformerBase.hxx"
44 #endif
46 using ::rtl::OUString;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::xml::sax;
49 using namespace ::xmloff::token;
51 TYPEINIT1( XMLFrameOOoTransformerContext, XMLPersElemContentTContext );
53 XMLFrameOOoTransformerContext::XMLFrameOOoTransformerContext(
54 XMLTransformerBase& rImp,
55 const OUString& rQName ) :
56 XMLPersElemContentTContext( rImp, rQName ),
57 m_aElemQName( rImp.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_DRAW,
58 ::xmloff::token::GetXMLToken( XML_FRAME ) ) )
62 XMLFrameOOoTransformerContext::~XMLFrameOOoTransformerContext()
66 void XMLFrameOOoTransformerContext::StartElement(
67 const Reference< XAttributeList >& rAttrList )
70 XMLTransformerActions *pActions =
71 GetTransformer().GetUserDefinedActions( OOO_FRAME_ATTR_ACTIONS );
72 OSL_ENSURE( pActions, "go no actions" );
74 Reference< XAttributeList > xAttrList( rAttrList );
75 XMLMutableAttributeList *pMutableAttrList =
76 GetTransformer().ProcessAttrList( xAttrList, OOO_SHAPE_ACTIONS,
77 sal_True );
78 if( !pMutableAttrList )
79 pMutableAttrList = new XMLMutableAttributeList( rAttrList );
80 xAttrList = pMutableAttrList;
82 XMLMutableAttributeList *pFrameMutableAttrList =
83 new XMLMutableAttributeList;
84 Reference< XAttributeList > xFrameAttrList( pFrameMutableAttrList );
86 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
87 for( sal_Int16 i=0; i < nAttrCount; i++ )
89 const OUString& rAttrName = xAttrList->getNameByIndex( i );
90 OUString aLocalName;
91 sal_uInt16 nPrefix =
92 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
93 &aLocalName );
94 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
95 XMLTransformerActions::const_iterator aIter =
96 pActions->find( aKey );
97 if( !(aIter == pActions->end() ) )
99 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
100 switch( (*aIter).second.m_nActionType )
102 case XML_ATACTION_MOVE_TO_ELEM:
103 pFrameMutableAttrList->AddAttribute( rAttrName, rAttrValue );
104 pMutableAttrList->RemoveAttributeByIndex( i );
105 --i;
106 --nAttrCount;
107 break;
108 default:
109 OSL_ENSURE( !this, "unknown action" );
110 break;
115 GetTransformer().GetDocHandler()->startElement( m_aElemQName,
116 xFrameAttrList );
117 XMLTransformerContext::StartElement( xAttrList );
120 XMLTransformerContext *XMLFrameOOoTransformerContext::CreateChildContext(
121 sal_uInt16 nPrefix,
122 const OUString& rLocalName,
123 const OUString& rQName,
124 const Reference< XAttributeList >& rAttrList )
126 XMLTransformerContext *pContext = 0;
128 XMLTransformerActions *pActions =
129 GetTransformer().GetUserDefinedActions( OOO_FRAME_ELEM_ACTIONS );
130 OSL_ENSURE( pActions, "go no actions" );
131 XMLTransformerActions::key_type aKey( nPrefix, rLocalName );
132 XMLTransformerActions::const_iterator aIter = pActions->find( aKey );
134 if( !(aIter == pActions->end()) )
136 switch( (*aIter).second.m_nActionType )
138 case XML_ETACTION_COPY:
139 case XML_ETACTION_COPY_TEXT:
140 case XML_ETACTION_RENAME_ELEM:
141 // the ones in the list have to be persistent
143 pContext = XMLPersElemContentTContext::CreateChildContext(
144 nPrefix, rLocalName, rQName, rAttrList );
145 break;
146 default:
147 OSL_ENSURE( !this, "unknown action" );
148 break;
152 // default is copying
153 if( !pContext )
154 pContext = XMLTransformerContext::CreateChildContext(
155 nPrefix, rLocalName, rQName, rAttrList );
157 return pContext;
160 void XMLFrameOOoTransformerContext::EndElement()
162 XMLTransformerContext::EndElement();
163 ExportContent();
164 GetTransformer().GetDocHandler()->endElement( m_aElemQName );
167 void XMLFrameOOoTransformerContext::Characters( const OUString& rChars )
169 XMLTransformerContext::Characters( rChars );
172 sal_Bool XMLFrameOOoTransformerContext::IsPersistent() const
174 // this context stores some of its child elements, but is not persistent
175 // itself.
176 return sal_False;