bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / transform / FrameOASISTContext.cxx
blobecb4f33d209d1d92aede07e2b6f444d293aab80b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "FrameOASISTContext.hxx"
21 #include "IgnoreTContext.hxx"
22 #include "MutableAttrList.hxx"
23 #include <xmloff/xmlnmspe.hxx>
24 #include "ActionMapTypesOASIS.hxx"
25 #include "ElemTransformerAction.hxx"
26 #include "TransformerActions.hxx"
27 #include "TransformerBase.hxx"
28 #include <osl/diagnose.h>
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::xml::sax;
33 using namespace ::xmloff::token;
35 TYPEINIT1( XMLFrameOASISTransformerContext, XMLTransformerContext );
37 bool XMLFrameOASISTransformerContext::IsLinkedEmbeddedObject(
38 const OUString& rLocalName,
39 const Reference< XAttributeList >& rAttrList )
41 if( !(IsXMLToken( rLocalName, XML_OBJECT ) ||
42 IsXMLToken( rLocalName, XML_OBJECT_OLE) ) )
43 return false;
45 sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
46 for( sal_Int16 i=0; i < nAttrCount; i++ )
48 OUString aAttrName( rAttrList->getNameByIndex( i ) );
49 OUString aLocalName;
50 sal_uInt16 nPrefix =
51 GetTransformer().GetNamespaceMap().GetKeyByAttrName( aAttrName,
52 &aLocalName );
53 if( XML_NAMESPACE_XLINK == nPrefix &&
54 IsXMLToken( aLocalName, XML_HREF ) )
56 OUString sHRef( rAttrList->getValueByIndex( i ) );
57 if (sHRef.isEmpty())
59 // When the href is empty then the object is not linked but
60 // a placeholder.
61 return false;
63 GetTransformer().ConvertURIToOOo( sHRef, true );
64 return !(!sHRef.isEmpty() && '#'==sHRef[0]);
68 return false;
72 XMLFrameOASISTransformerContext::XMLFrameOASISTransformerContext(
73 XMLTransformerBase& rImp,
74 const OUString& rQName ) :
75 XMLTransformerContext( rImp, rQName ),
76 m_bIgnoreElement( false )
80 XMLFrameOASISTransformerContext::~XMLFrameOASISTransformerContext()
84 void XMLFrameOASISTransformerContext::StartElement(
85 const Reference< XAttributeList >& rAttrList )
87 m_xAttrList = new XMLMutableAttributeList( rAttrList, true );
89 sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
90 for( sal_Int16 i=0; i < nAttrCount; i++ )
92 const OUString& rAttrName = rAttrList->getNameByIndex( i );
93 OUString aLocalName;
94 sal_uInt16 nPrefix =
95 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
97 if( (nPrefix == XML_NAMESPACE_PRESENTATION) && IsXMLToken( aLocalName, XML_CLASS ) )
99 const OUString& rAttrValue = rAttrList->getValueByIndex( i );
100 if( IsXMLToken( rAttrValue, XML_HEADER ) || IsXMLToken( rAttrValue, XML_FOOTER ) ||
101 IsXMLToken( rAttrValue, XML_PAGE_NUMBER ) || IsXMLToken( rAttrValue, XML_DATE_TIME ) )
103 m_bIgnoreElement = true;
104 break;
110 XMLTransformerContext *XMLFrameOASISTransformerContext::CreateChildContext(
111 sal_uInt16 nPrefix,
112 const OUString& rLocalName,
113 const OUString& rQName,
114 const Reference< XAttributeList >& rAttrList )
116 XMLTransformerContext *pContext = 0;
118 if( m_bIgnoreElement )
120 // do not export the frame element and all of its children
121 pContext = new XMLIgnoreTransformerContext( GetTransformer(),
122 rQName,
123 true, true );
125 else
127 XMLTransformerActions *pActions =
128 GetTransformer().GetUserDefinedActions( OASIS_FRAME_ELEM_ACTIONS );
129 OSL_ENSURE( pActions, "go no actions" );
130 XMLTransformerActions::key_type aKey( nPrefix, rLocalName );
131 XMLTransformerActions::const_iterator aIter = pActions->find( aKey );
133 if( !(aIter == pActions->end()) )
135 switch( (*aIter).second.m_nActionType )
137 case XML_ETACTION_COPY:
138 if( m_aElemQName.isEmpty() &&
139 !IsLinkedEmbeddedObject( rLocalName, rAttrList ) )
141 pContext = new XMLIgnoreTransformerContext( GetTransformer(),
142 rQName,
143 false, false );
144 m_aElemQName = rQName;
145 static_cast< XMLMutableAttributeList * >( m_xAttrList.get() )
146 ->AppendAttributeList( rAttrList );
147 GetTransformer().ProcessAttrList( m_xAttrList,
148 OASIS_SHAPE_ACTIONS,
149 false );
150 GetTransformer().GetDocHandler()->startElement( m_aElemQName,
151 m_xAttrList );
153 else
155 pContext = new XMLIgnoreTransformerContext( GetTransformer(),
156 rQName,
157 true, true );
159 break;
160 default:
161 OSL_ENSURE( false, "unknown action" );
162 break;
167 // default is copying
168 if( !pContext )
169 pContext = XMLTransformerContext::CreateChildContext( nPrefix,
170 rLocalName,
171 rQName,
172 rAttrList );
174 return pContext;
177 void XMLFrameOASISTransformerContext::EndElement()
179 if( !m_bIgnoreElement )
180 GetTransformer().GetDocHandler()->endElement( m_aElemQName );
183 void XMLFrameOASISTransformerContext::Characters( const OUString& rChars )
185 // ignore
186 if( !m_aElemQName.isEmpty() && !m_bIgnoreElement )
187 XMLTransformerContext::Characters( rChars );
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */