1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: FrameOASISTContext.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "FrameOASISTContext.hxx"
34 #include "IgnoreTContext.hxx"
35 #include "MutableAttrList.hxx"
36 #include "xmlnmspe.hxx"
37 #include "ActionMapTypesOASIS.hxx"
38 #include "ElemTransformerAction.hxx"
39 #include "TransformerActions.hxx"
40 #ifndef _XMLOFF_TRANSFORMERBASE_HXX
41 #include "TransformerBase.hxx"
44 using ::rtl::OUString
;
46 using namespace ::com::sun::star::uno
;
47 using namespace ::com::sun::star::xml::sax
;
48 using namespace ::xmloff::token
;
50 TYPEINIT1( XMLFrameOASISTransformerContext
, XMLTransformerContext
);
52 sal_Bool
XMLFrameOASISTransformerContext::IsLinkedEmbeddedObject(
53 const OUString
& rLocalName
,
54 const Reference
< XAttributeList
>& rAttrList
)
56 if( !(IsXMLToken( rLocalName
, XML_OBJECT
) ||
57 IsXMLToken( rLocalName
, XML_OBJECT_OLE
) ) )
60 sal_Int16 nAttrCount
= rAttrList
.is() ? rAttrList
->getLength() : 0;
61 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
63 OUString
aAttrName( rAttrList
->getNameByIndex( i
) );
66 GetTransformer().GetNamespaceMap().GetKeyByAttrName( aAttrName
,
68 if( XML_NAMESPACE_XLINK
== nPrefix
&&
69 IsXMLToken( aLocalName
, XML_HREF
) )
71 OUString
sHRef( rAttrList
->getValueByIndex( i
) );
72 if (sHRef
.getLength() == 0)
74 // When the href is empty then the object is not linked but
78 GetTransformer().ConvertURIToOOo( sHRef
, sal_True
);
79 return !(sHRef
.getLength() && '#'==sHRef
[0]);
87 XMLFrameOASISTransformerContext::XMLFrameOASISTransformerContext(
88 XMLTransformerBase
& rImp
,
89 const OUString
& rQName
) :
90 XMLTransformerContext( rImp
, rQName
),
91 m_bIgnoreElement( false )
95 XMLFrameOASISTransformerContext::~XMLFrameOASISTransformerContext()
99 void XMLFrameOASISTransformerContext::StartElement(
100 const Reference
< XAttributeList
>& rAttrList
)
102 m_xAttrList
= new XMLMutableAttributeList( rAttrList
, sal_True
);
104 sal_Int16 nAttrCount
= rAttrList
.is() ? rAttrList
->getLength() : 0;
105 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
107 const OUString
& rAttrName
= rAttrList
->getNameByIndex( i
);
110 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
, &aLocalName
);
112 if( (nPrefix
== XML_NAMESPACE_PRESENTATION
) && IsXMLToken( aLocalName
, XML_CLASS
) )
114 const OUString
& rAttrValue
= rAttrList
->getValueByIndex( i
);
115 if( IsXMLToken( rAttrValue
, XML_HEADER
) || IsXMLToken( rAttrValue
, XML_FOOTER
) ||
116 IsXMLToken( rAttrValue
, XML_PAGE_NUMBER
) || IsXMLToken( rAttrValue
, XML_DATE_TIME
) )
118 m_bIgnoreElement
= true;
125 XMLTransformerContext
*XMLFrameOASISTransformerContext::CreateChildContext(
127 const OUString
& rLocalName
,
128 const OUString
& rQName
,
129 const Reference
< XAttributeList
>& rAttrList
)
131 XMLTransformerContext
*pContext
= 0;
133 if( m_bIgnoreElement
)
135 // do not export the frame element and all of its children
136 pContext
= new XMLIgnoreTransformerContext( GetTransformer(),
138 sal_True
, sal_True
);
142 XMLTransformerActions
*pActions
=
143 GetTransformer().GetUserDefinedActions( OASIS_FRAME_ELEM_ACTIONS
);
144 OSL_ENSURE( pActions
, "go no actions" );
145 XMLTransformerActions::key_type
aKey( nPrefix
, rLocalName
);
146 XMLTransformerActions::const_iterator aIter
= pActions
->find( aKey
);
148 if( !(aIter
== pActions
->end()) )
150 switch( (*aIter
).second
.m_nActionType
)
152 case XML_ETACTION_COPY
:
153 if( !m_aElemQName
.getLength() &&
154 !IsLinkedEmbeddedObject( rLocalName
, rAttrList
) )
156 pContext
= new XMLIgnoreTransformerContext( GetTransformer(),
158 sal_False
, sal_False
);
159 m_aElemQName
= rQName
;
160 static_cast< XMLMutableAttributeList
* >( m_xAttrList
.get() )
161 ->AppendAttributeList( rAttrList
);
162 GetTransformer().ProcessAttrList( m_xAttrList
,
165 GetTransformer().GetDocHandler()->startElement( m_aElemQName
,
170 pContext
= new XMLIgnoreTransformerContext( GetTransformer(),
172 sal_True
, sal_True
);
176 OSL_ENSURE( !this, "unknown action" );
182 // default is copying
184 pContext
= XMLTransformerContext::CreateChildContext( nPrefix
,
192 void XMLFrameOASISTransformerContext::EndElement()
194 if( !m_bIgnoreElement
)
195 GetTransformer().GetDocHandler()->endElement( m_aElemQName
);
198 void XMLFrameOASISTransformerContext::Characters( const OUString
& rChars
)
201 if( m_aElemQName
.getLength() && !m_bIgnoreElement
)
202 XMLTransformerContext::Characters( rChars
);