1*63bba73cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*63bba73cSAndrew Rist * distributed with this work for additional information 6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance 9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*63bba73cSAndrew Rist * software distributed under the License is distributed on an 15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the 17*63bba73cSAndrew Rist * specific language governing permissions and limitations 18*63bba73cSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*63bba73cSAndrew Rist *************************************************************/ 21*63bba73cSAndrew Rist 22*63bba73cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_xmloff.hxx" 26cdf0e10cSrcweir #include "FrameOASISTContext.hxx" 27cdf0e10cSrcweir #include "IgnoreTContext.hxx" 28cdf0e10cSrcweir #include "MutableAttrList.hxx" 29cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx" 30cdf0e10cSrcweir #include "ActionMapTypesOASIS.hxx" 31cdf0e10cSrcweir #include "ElemTransformerAction.hxx" 32cdf0e10cSrcweir #include "TransformerActions.hxx" 33cdf0e10cSrcweir #ifndef _XMLOFF_TRANSFORMERBASE_HXX 34cdf0e10cSrcweir #include "TransformerBase.hxx" 35cdf0e10cSrcweir #endif 36cdf0e10cSrcweir 37cdf0e10cSrcweir using ::rtl::OUString; 38cdf0e10cSrcweir 39cdf0e10cSrcweir using namespace ::com::sun::star::uno; 40cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax; 41cdf0e10cSrcweir using namespace ::xmloff::token; 42cdf0e10cSrcweir 43cdf0e10cSrcweir TYPEINIT1( XMLFrameOASISTransformerContext, XMLTransformerContext ); 44cdf0e10cSrcweir 45cdf0e10cSrcweir sal_Bool XMLFrameOASISTransformerContext::IsLinkedEmbeddedObject( 46cdf0e10cSrcweir const OUString& rLocalName, 47cdf0e10cSrcweir const Reference< XAttributeList >& rAttrList ) 48cdf0e10cSrcweir { 49cdf0e10cSrcweir if( !(IsXMLToken( rLocalName, XML_OBJECT ) || 50cdf0e10cSrcweir IsXMLToken( rLocalName, XML_OBJECT_OLE) ) ) 51cdf0e10cSrcweir return sal_False; 52cdf0e10cSrcweir 53cdf0e10cSrcweir sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0; 54cdf0e10cSrcweir for( sal_Int16 i=0; i < nAttrCount; i++ ) 55cdf0e10cSrcweir { 56cdf0e10cSrcweir OUString aAttrName( rAttrList->getNameByIndex( i ) ); 57cdf0e10cSrcweir OUString aLocalName; 58cdf0e10cSrcweir sal_uInt16 nPrefix = 59cdf0e10cSrcweir GetTransformer().GetNamespaceMap().GetKeyByAttrName( aAttrName, 60cdf0e10cSrcweir &aLocalName ); 61cdf0e10cSrcweir if( XML_NAMESPACE_XLINK == nPrefix && 62cdf0e10cSrcweir IsXMLToken( aLocalName, XML_HREF ) ) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir OUString sHRef( rAttrList->getValueByIndex( i ) ); 65cdf0e10cSrcweir if (sHRef.getLength() == 0) 66cdf0e10cSrcweir { 67cdf0e10cSrcweir // When the href is empty then the object is not linked but 68cdf0e10cSrcweir // a placeholder. 69cdf0e10cSrcweir return sal_False; 70cdf0e10cSrcweir } 71cdf0e10cSrcweir GetTransformer().ConvertURIToOOo( sHRef, sal_True ); 72cdf0e10cSrcweir return !(sHRef.getLength() && '#'==sHRef[0]); 73cdf0e10cSrcweir } 74cdf0e10cSrcweir } 75cdf0e10cSrcweir 76cdf0e10cSrcweir return sal_False; 77cdf0e10cSrcweir } 78cdf0e10cSrcweir 79cdf0e10cSrcweir 80cdf0e10cSrcweir XMLFrameOASISTransformerContext::XMLFrameOASISTransformerContext( 81cdf0e10cSrcweir XMLTransformerBase& rImp, 82cdf0e10cSrcweir const OUString& rQName ) : 83cdf0e10cSrcweir XMLTransformerContext( rImp, rQName ), 84cdf0e10cSrcweir m_bIgnoreElement( false ) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir XMLFrameOASISTransformerContext::~XMLFrameOASISTransformerContext() 89cdf0e10cSrcweir { 90cdf0e10cSrcweir } 91cdf0e10cSrcweir 92cdf0e10cSrcweir void XMLFrameOASISTransformerContext::StartElement( 93cdf0e10cSrcweir const Reference< XAttributeList >& rAttrList ) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir m_xAttrList = new XMLMutableAttributeList( rAttrList, sal_True ); 96cdf0e10cSrcweir 97cdf0e10cSrcweir sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0; 98cdf0e10cSrcweir for( sal_Int16 i=0; i < nAttrCount; i++ ) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir const OUString& rAttrName = rAttrList->getNameByIndex( i ); 101cdf0e10cSrcweir OUString aLocalName; 102cdf0e10cSrcweir sal_uInt16 nPrefix = 103cdf0e10cSrcweir GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName ); 104cdf0e10cSrcweir 105cdf0e10cSrcweir if( (nPrefix == XML_NAMESPACE_PRESENTATION) && IsXMLToken( aLocalName, XML_CLASS ) ) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir const OUString& rAttrValue = rAttrList->getValueByIndex( i ); 108cdf0e10cSrcweir if( IsXMLToken( rAttrValue, XML_HEADER ) || IsXMLToken( rAttrValue, XML_FOOTER ) || 109cdf0e10cSrcweir IsXMLToken( rAttrValue, XML_PAGE_NUMBER ) || IsXMLToken( rAttrValue, XML_DATE_TIME ) ) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir m_bIgnoreElement = true; 112cdf0e10cSrcweir break; 113cdf0e10cSrcweir } 114cdf0e10cSrcweir } 115cdf0e10cSrcweir } 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir XMLTransformerContext *XMLFrameOASISTransformerContext::CreateChildContext( 119cdf0e10cSrcweir sal_uInt16 nPrefix, 120cdf0e10cSrcweir const OUString& rLocalName, 121cdf0e10cSrcweir const OUString& rQName, 122cdf0e10cSrcweir const Reference< XAttributeList >& rAttrList ) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir XMLTransformerContext *pContext = 0; 125cdf0e10cSrcweir 126cdf0e10cSrcweir if( m_bIgnoreElement ) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir // do not export the frame element and all of its children 129cdf0e10cSrcweir pContext = new XMLIgnoreTransformerContext( GetTransformer(), 130cdf0e10cSrcweir rQName, 131cdf0e10cSrcweir sal_True, sal_True ); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir else 134cdf0e10cSrcweir { 135cdf0e10cSrcweir XMLTransformerActions *pActions = 136cdf0e10cSrcweir GetTransformer().GetUserDefinedActions( OASIS_FRAME_ELEM_ACTIONS ); 137cdf0e10cSrcweir OSL_ENSURE( pActions, "go no actions" ); 138cdf0e10cSrcweir XMLTransformerActions::key_type aKey( nPrefix, rLocalName ); 139cdf0e10cSrcweir XMLTransformerActions::const_iterator aIter = pActions->find( aKey ); 140cdf0e10cSrcweir 141cdf0e10cSrcweir if( !(aIter == pActions->end()) ) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir switch( (*aIter).second.m_nActionType ) 144cdf0e10cSrcweir { 145cdf0e10cSrcweir case XML_ETACTION_COPY: 146cdf0e10cSrcweir if( !m_aElemQName.getLength() && 147cdf0e10cSrcweir !IsLinkedEmbeddedObject( rLocalName, rAttrList ) ) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir pContext = new XMLIgnoreTransformerContext( GetTransformer(), 150cdf0e10cSrcweir rQName, 151cdf0e10cSrcweir sal_False, sal_False ); 152cdf0e10cSrcweir m_aElemQName = rQName; 153cdf0e10cSrcweir static_cast< XMLMutableAttributeList * >( m_xAttrList.get() ) 154cdf0e10cSrcweir ->AppendAttributeList( rAttrList ); 155cdf0e10cSrcweir GetTransformer().ProcessAttrList( m_xAttrList, 156cdf0e10cSrcweir OASIS_SHAPE_ACTIONS, 157cdf0e10cSrcweir sal_False ); 158cdf0e10cSrcweir GetTransformer().GetDocHandler()->startElement( m_aElemQName, 159cdf0e10cSrcweir m_xAttrList ); 160cdf0e10cSrcweir } 161cdf0e10cSrcweir else 162cdf0e10cSrcweir { 163cdf0e10cSrcweir pContext = new XMLIgnoreTransformerContext( GetTransformer(), 164cdf0e10cSrcweir rQName, 165cdf0e10cSrcweir sal_True, sal_True ); 166cdf0e10cSrcweir } 167cdf0e10cSrcweir break; 168cdf0e10cSrcweir default: 169cdf0e10cSrcweir OSL_ENSURE( !this, "unknown action" ); 170cdf0e10cSrcweir break; 171cdf0e10cSrcweir } 172cdf0e10cSrcweir } 173cdf0e10cSrcweir } 174cdf0e10cSrcweir 175cdf0e10cSrcweir // default is copying 176cdf0e10cSrcweir if( !pContext ) 177cdf0e10cSrcweir pContext = XMLTransformerContext::CreateChildContext( nPrefix, 178cdf0e10cSrcweir rLocalName, 179cdf0e10cSrcweir rQName, 180cdf0e10cSrcweir rAttrList ); 181cdf0e10cSrcweir 182cdf0e10cSrcweir return pContext; 183cdf0e10cSrcweir } 184cdf0e10cSrcweir 185cdf0e10cSrcweir void XMLFrameOASISTransformerContext::EndElement() 186cdf0e10cSrcweir { 187cdf0e10cSrcweir if( !m_bIgnoreElement ) 188cdf0e10cSrcweir GetTransformer().GetDocHandler()->endElement( m_aElemQName ); 189cdf0e10cSrcweir } 190cdf0e10cSrcweir 191cdf0e10cSrcweir void XMLFrameOASISTransformerContext::Characters( const OUString& rChars ) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir // ignore 194cdf0e10cSrcweir if( m_aElemQName.getLength() && !m_bIgnoreElement ) 195cdf0e10cSrcweir XMLTransformerContext::Characters( rChars ); 196cdf0e10cSrcweir } 197