fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / xmloff / source / transform / FrameOASISTContext.cxx
blob20a825b82982579867a1c7e2d4a999161ade890e
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"
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::xml::sax;
32 using namespace ::xmloff::token;
34 TYPEINIT1( XMLFrameOASISTransformerContext, XMLTransformerContext );
36 sal_Bool XMLFrameOASISTransformerContext::IsLinkedEmbeddedObject(
37 const OUString& rLocalName,
38 const Reference< XAttributeList >& rAttrList )
40 if( !(IsXMLToken( rLocalName, XML_OBJECT ) ||
41 IsXMLToken( rLocalName, XML_OBJECT_OLE) ) )
42 return sal_False;
44 sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
45 for( sal_Int16 i=0; i < nAttrCount; i++ )
47 OUString aAttrName( rAttrList->getNameByIndex( i ) );
48 OUString aLocalName;
49 sal_uInt16 nPrefix =
50 GetTransformer().GetNamespaceMap().GetKeyByAttrName( aAttrName,
51 &aLocalName );
52 if( XML_NAMESPACE_XLINK == nPrefix &&
53 IsXMLToken( aLocalName, XML_HREF ) )
55 OUString sHRef( rAttrList->getValueByIndex( i ) );
56 if (sHRef.isEmpty())
58 // When the href is empty then the object is not linked but
59 // a placeholder.
60 return sal_False;
62 GetTransformer().ConvertURIToOOo( sHRef, sal_True );
63 return !(!sHRef.isEmpty() && '#'==sHRef[0]);
67 return sal_False;
71 XMLFrameOASISTransformerContext::XMLFrameOASISTransformerContext(
72 XMLTransformerBase& rImp,
73 const OUString& rQName ) :
74 XMLTransformerContext( rImp, rQName ),
75 m_bIgnoreElement( false )
79 XMLFrameOASISTransformerContext::~XMLFrameOASISTransformerContext()
83 void XMLFrameOASISTransformerContext::StartElement(
84 const Reference< XAttributeList >& rAttrList )
86 m_xAttrList = new XMLMutableAttributeList( rAttrList, sal_True );
88 sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
89 for( sal_Int16 i=0; i < nAttrCount; i++ )
91 const OUString& rAttrName = rAttrList->getNameByIndex( i );
92 OUString aLocalName;
93 sal_uInt16 nPrefix =
94 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
96 if( (nPrefix == XML_NAMESPACE_PRESENTATION) && IsXMLToken( aLocalName, XML_CLASS ) )
98 const OUString& rAttrValue = rAttrList->getValueByIndex( i );
99 if( IsXMLToken( rAttrValue, XML_HEADER ) || IsXMLToken( rAttrValue, XML_FOOTER ) ||
100 IsXMLToken( rAttrValue, XML_PAGE_NUMBER ) || IsXMLToken( rAttrValue, XML_DATE_TIME ) )
102 m_bIgnoreElement = true;
103 break;
109 XMLTransformerContext *XMLFrameOASISTransformerContext::CreateChildContext(
110 sal_uInt16 nPrefix,
111 const OUString& rLocalName,
112 const OUString& rQName,
113 const Reference< XAttributeList >& rAttrList )
115 XMLTransformerContext *pContext = 0;
117 if( m_bIgnoreElement )
119 // do not export the frame element and all of its children
120 pContext = new XMLIgnoreTransformerContext( GetTransformer(),
121 rQName,
122 sal_True, sal_True );
124 else
126 XMLTransformerActions *pActions =
127 GetTransformer().GetUserDefinedActions( OASIS_FRAME_ELEM_ACTIONS );
128 OSL_ENSURE( pActions, "go no actions" );
129 XMLTransformerActions::key_type aKey( nPrefix, rLocalName );
130 XMLTransformerActions::const_iterator aIter = pActions->find( aKey );
132 if( !(aIter == pActions->end()) )
134 switch( (*aIter).second.m_nActionType )
136 case XML_ETACTION_COPY:
137 if( m_aElemQName.isEmpty() &&
138 !IsLinkedEmbeddedObject( rLocalName, rAttrList ) )
140 pContext = new XMLIgnoreTransformerContext( GetTransformer(),
141 rQName,
142 sal_False, sal_False );
143 m_aElemQName = rQName;
144 static_cast< XMLMutableAttributeList * >( m_xAttrList.get() )
145 ->AppendAttributeList( rAttrList );
146 GetTransformer().ProcessAttrList( m_xAttrList,
147 OASIS_SHAPE_ACTIONS,
148 sal_False );
149 GetTransformer().GetDocHandler()->startElement( m_aElemQName,
150 m_xAttrList );
152 else
154 pContext = new XMLIgnoreTransformerContext( GetTransformer(),
155 rQName,
156 sal_True, sal_True );
158 break;
159 default:
160 OSL_ENSURE( !this, "unknown action" );
161 break;
166 // default is copying
167 if( !pContext )
168 pContext = XMLTransformerContext::CreateChildContext( nPrefix,
169 rLocalName,
170 rQName,
171 rAttrList );
173 return pContext;
176 void XMLFrameOASISTransformerContext::EndElement()
178 if( !m_bIgnoreElement )
179 GetTransformer().GetDocHandler()->endElement( m_aElemQName );
182 void XMLFrameOASISTransformerContext::Characters( const OUString& rChars )
184 // ignore
185 if( !m_aElemQName.isEmpty() && !m_bIgnoreElement )
186 XMLTransformerContext::Characters( rChars );
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */