Update git submodules
[LibreOffice.git] / xmloff / source / transform / FrameOASISTContext.cxx
blobbb81190161c15c918c3ce62848af9edd4e8b32dc
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/xmlnamespace.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 bool XMLFrameOASISTransformerContext::IsLinkedEmbeddedObject(
36 std::u16string_view rLocalName,
37 const Reference< XAttributeList >& rAttrList )
39 if( !(IsXMLToken( rLocalName, XML_OBJECT ) ||
40 IsXMLToken( rLocalName, XML_OBJECT_OLE) ) )
41 return false;
43 sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
44 for( sal_Int16 i=0; i < nAttrCount; i++ )
46 OUString aAttrName( rAttrList->getNameByIndex( i ) );
47 OUString aLocalName;
48 sal_uInt16 nPrefix =
49 GetTransformer().GetNamespaceMap().GetKeyByAttrName( aAttrName,
50 &aLocalName );
51 if( XML_NAMESPACE_XLINK == nPrefix &&
52 IsXMLToken( aLocalName, XML_HREF ) )
54 OUString sHRef( rAttrList->getValueByIndex( i ) );
55 if (sHRef.isEmpty())
57 // When the href is empty then the object is not linked but
58 // a placeholder.
59 return false;
61 GetTransformer().ConvertURIToOOo( sHRef, true );
62 return sHRef.isEmpty() || '#' != sHRef[0];
66 return false;
70 XMLFrameOASISTransformerContext::XMLFrameOASISTransformerContext(
71 XMLTransformerBase& rImp,
72 const OUString& rQName ) :
73 XMLTransformerContext( rImp, rQName ),
74 m_bIgnoreElement( false )
78 XMLFrameOASISTransformerContext::~XMLFrameOASISTransformerContext()
82 void XMLFrameOASISTransformerContext::StartElement(
83 const Reference< XAttributeList >& rAttrList )
85 m_xAttrList = new XMLMutableAttributeList( rAttrList, true );
87 sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
88 for( sal_Int16 i=0; i < nAttrCount; i++ )
90 const OUString aAttrName = rAttrList->getNameByIndex( i );
91 OUString aLocalName;
92 sal_uInt16 nPrefix =
93 GetTransformer().GetNamespaceMap().GetKeyByAttrName( aAttrName, &aLocalName );
95 if( (nPrefix == XML_NAMESPACE_PRESENTATION) && IsXMLToken( aLocalName, XML_CLASS ) )
97 const OUString aAttrValue = rAttrList->getValueByIndex( i );
98 if( IsXMLToken( aAttrValue, XML_HEADER ) || IsXMLToken( aAttrValue, XML_FOOTER ) ||
99 IsXMLToken( aAttrValue, XML_PAGE_NUMBER ) || IsXMLToken( aAttrValue, XML_DATE_TIME ) )
101 m_bIgnoreElement = true;
102 break;
108 rtl::Reference<XMLTransformerContext> XMLFrameOASISTransformerContext::CreateChildContext(
109 sal_uInt16 nPrefix,
110 const OUString& rLocalName,
111 const OUString& rQName,
112 const Reference< XAttributeList >& rAttrList )
114 rtl::Reference<XMLTransformerContext> pContext;
116 if( m_bIgnoreElement )
118 // do not export the frame element and all of its children
119 pContext.set(new XMLIgnoreTransformerContext( GetTransformer(),
120 rQName,
121 true, true ));
123 else
125 XMLTransformerActions *pActions =
126 GetTransformer().GetUserDefinedActions( OASIS_FRAME_ELEM_ACTIONS );
127 OSL_ENSURE( pActions, "go no actions" );
128 XMLTransformerActions::key_type aKey( nPrefix, rLocalName );
129 XMLTransformerActions::const_iterator aIter = pActions->find( aKey );
131 if( aIter != pActions->end() )
133 switch( (*aIter).second.m_nActionType )
135 case XML_ETACTION_COPY:
136 if( m_aElemQName.isEmpty() &&
137 !IsLinkedEmbeddedObject( rLocalName, rAttrList ) )
139 pContext.set(new XMLIgnoreTransformerContext( GetTransformer(),
140 rQName,
141 false, false ));
142 m_aElemQName = rQName;
143 static_cast< XMLMutableAttributeList * >( m_xAttrList.get() )
144 ->AppendAttributeList( rAttrList );
145 GetTransformer().ProcessAttrList( m_xAttrList,
146 OASIS_SHAPE_ACTIONS,
147 false );
148 GetTransformer().GetDocHandler()->startElement( m_aElemQName, m_xAttrList );
150 else
152 pContext.set(new XMLIgnoreTransformerContext( GetTransformer(),
153 rQName,
154 true, true ));
156 break;
157 default:
158 OSL_ENSURE( false, "unknown action" );
159 break;
164 // default is copying
165 if( !pContext.is() )
166 pContext = XMLTransformerContext::CreateChildContext( nPrefix,
167 rLocalName,
168 rQName,
169 rAttrList );
171 return pContext;
174 void XMLFrameOASISTransformerContext::EndElement()
176 if( !m_bIgnoreElement )
177 GetTransformer().GetDocHandler()->endElement( m_aElemQName );
180 void XMLFrameOASISTransformerContext::Characters( const OUString& rChars )
182 // ignore
183 if( !m_aElemQName.isEmpty() && !m_bIgnoreElement )
184 XMLTransformerContext::Characters( rChars );
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */