merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / transform / FrameOASISTContext.cxx
blobf1ed44dd05d01553e3b37c09044a47ff9fdc29e4
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: FrameOASISTContext.cxx,v $
10 * $Revision: 1.10 $
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 "FrameOASISTContext.hxx"
34 #include "IgnoreTContext.hxx"
35 #include "MutableAttrList.hxx"
36 #include "xmlnmspe.hxx"
37 #include "ActionMapTypesOASIS.hxx"
38 #include "ElemTransformerAction.hxx"
39 #include "TransformerActions.hxx"
40 #ifndef _XMLOFF_TRANSFORMERBASE_HXX
41 #include "TransformerBase.hxx"
42 #endif
44 using ::rtl::OUString;
46 using namespace ::com::sun::star::uno;
47 using namespace ::com::sun::star::xml::sax;
48 using namespace ::xmloff::token;
50 TYPEINIT1( XMLFrameOASISTransformerContext, XMLTransformerContext );
52 sal_Bool XMLFrameOASISTransformerContext::IsLinkedEmbeddedObject(
53 const OUString& rLocalName,
54 const Reference< XAttributeList >& rAttrList )
56 if( !(IsXMLToken( rLocalName, XML_OBJECT ) ||
57 IsXMLToken( rLocalName, XML_OBJECT_OLE) ) )
58 return sal_False;
60 sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
61 for( sal_Int16 i=0; i < nAttrCount; i++ )
63 OUString aAttrName( rAttrList->getNameByIndex( i ) );
64 OUString aLocalName;
65 sal_uInt16 nPrefix =
66 GetTransformer().GetNamespaceMap().GetKeyByAttrName( aAttrName,
67 &aLocalName );
68 if( XML_NAMESPACE_XLINK == nPrefix &&
69 IsXMLToken( aLocalName, XML_HREF ) )
71 OUString sHRef( rAttrList->getValueByIndex( i ) );
72 if (sHRef.getLength() == 0)
74 // When the href is empty then the object is not linked but
75 // a placeholder.
76 return sal_False;
78 GetTransformer().ConvertURIToOOo( sHRef, sal_True );
79 return !(sHRef.getLength() && '#'==sHRef[0]);
83 return sal_False;
87 XMLFrameOASISTransformerContext::XMLFrameOASISTransformerContext(
88 XMLTransformerBase& rImp,
89 const OUString& rQName ) :
90 XMLTransformerContext( rImp, rQName ),
91 m_bIgnoreElement( false )
95 XMLFrameOASISTransformerContext::~XMLFrameOASISTransformerContext()
99 void XMLFrameOASISTransformerContext::StartElement(
100 const Reference< XAttributeList >& rAttrList )
102 m_xAttrList = new XMLMutableAttributeList( rAttrList, sal_True );
104 sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
105 for( sal_Int16 i=0; i < nAttrCount; i++ )
107 const OUString& rAttrName = rAttrList->getNameByIndex( i );
108 OUString aLocalName;
109 sal_uInt16 nPrefix =
110 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
112 if( (nPrefix == XML_NAMESPACE_PRESENTATION) && IsXMLToken( aLocalName, XML_CLASS ) )
114 const OUString& rAttrValue = rAttrList->getValueByIndex( i );
115 if( IsXMLToken( rAttrValue, XML_HEADER ) || IsXMLToken( rAttrValue, XML_FOOTER ) ||
116 IsXMLToken( rAttrValue, XML_PAGE_NUMBER ) || IsXMLToken( rAttrValue, XML_DATE_TIME ) )
118 m_bIgnoreElement = true;
119 break;
125 XMLTransformerContext *XMLFrameOASISTransformerContext::CreateChildContext(
126 sal_uInt16 nPrefix,
127 const OUString& rLocalName,
128 const OUString& rQName,
129 const Reference< XAttributeList >& rAttrList )
131 XMLTransformerContext *pContext = 0;
133 if( m_bIgnoreElement )
135 // do not export the frame element and all of its children
136 pContext = new XMLIgnoreTransformerContext( GetTransformer(),
137 rQName,
138 sal_True, sal_True );
140 else
142 XMLTransformerActions *pActions =
143 GetTransformer().GetUserDefinedActions( OASIS_FRAME_ELEM_ACTIONS );
144 OSL_ENSURE( pActions, "go no actions" );
145 XMLTransformerActions::key_type aKey( nPrefix, rLocalName );
146 XMLTransformerActions::const_iterator aIter = pActions->find( aKey );
148 if( !(aIter == pActions->end()) )
150 switch( (*aIter).second.m_nActionType )
152 case XML_ETACTION_COPY:
153 if( !m_aElemQName.getLength() &&
154 !IsLinkedEmbeddedObject( rLocalName, rAttrList ) )
156 pContext = new XMLIgnoreTransformerContext( GetTransformer(),
157 rQName,
158 sal_False, sal_False );
159 m_aElemQName = rQName;
160 static_cast< XMLMutableAttributeList * >( m_xAttrList.get() )
161 ->AppendAttributeList( rAttrList );
162 GetTransformer().ProcessAttrList( m_xAttrList,
163 OASIS_SHAPE_ACTIONS,
164 sal_False );
165 GetTransformer().GetDocHandler()->startElement( m_aElemQName,
166 m_xAttrList );
168 else
170 pContext = new XMLIgnoreTransformerContext( GetTransformer(),
171 rQName,
172 sal_True, sal_True );
174 break;
175 default:
176 OSL_ENSURE( !this, "unknown action" );
177 break;
182 // default is copying
183 if( !pContext )
184 pContext = XMLTransformerContext::CreateChildContext( nPrefix,
185 rLocalName,
186 rQName,
187 rAttrList );
189 return pContext;
192 void XMLFrameOASISTransformerContext::EndElement()
194 if( !m_bIgnoreElement )
195 GetTransformer().GetDocHandler()->endElement( m_aElemQName );
198 void XMLFrameOASISTransformerContext::Characters( const OUString& rChars )
200 // ignore
201 if( m_aElemQName.getLength() && !m_bIgnoreElement )
202 XMLTransformerContext::Characters( rChars );