1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
) ) )
44 sal_Int16 nAttrCount
= rAttrList
.is() ? rAttrList
->getLength() : 0;
45 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
47 OUString
aAttrName( rAttrList
->getNameByIndex( i
) );
50 GetTransformer().GetNamespaceMap().GetKeyByAttrName( aAttrName
,
52 if( XML_NAMESPACE_XLINK
== nPrefix
&&
53 IsXMLToken( aLocalName
, XML_HREF
) )
55 OUString
sHRef( rAttrList
->getValueByIndex( i
) );
58 // When the href is empty then the object is not linked but
62 GetTransformer().ConvertURIToOOo( sHRef
, sal_True
);
63 return !(!sHRef
.isEmpty() && '#'==sHRef
[0]);
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
);
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;
109 XMLTransformerContext
*XMLFrameOASISTransformerContext::CreateChildContext(
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(),
122 sal_True
, sal_True
);
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(),
142 sal_False
, sal_False
);
143 m_aElemQName
= rQName
;
144 static_cast< XMLMutableAttributeList
* >( m_xAttrList
.get() )
145 ->AppendAttributeList( rAttrList
);
146 GetTransformer().ProcessAttrList( m_xAttrList
,
149 GetTransformer().GetDocHandler()->startElement( m_aElemQName
,
154 pContext
= new XMLIgnoreTransformerContext( GetTransformer(),
156 sal_True
, sal_True
);
160 OSL_ENSURE( !this, "unknown action" );
166 // default is copying
168 pContext
= XMLTransformerContext::CreateChildContext( nPrefix
,
176 void XMLFrameOASISTransformerContext::EndElement()
178 if( !m_bIgnoreElement
)
179 GetTransformer().GetDocHandler()->endElement( m_aElemQName
);
182 void XMLFrameOASISTransformerContext::Characters( const OUString
& rChars
)
185 if( !m_aElemQName
.isEmpty() && !m_bIgnoreElement
)
186 XMLTransformerContext::Characters( rChars
);
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */