1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "FrameOOoTContext.hxx"
30 #include "IgnoreTContext.hxx"
31 #include "MutableAttrList.hxx"
32 #include "xmloff/xmlnmspe.hxx"
33 #include <xmloff/nmspmap.hxx>
34 #include "ActionMapTypesOOo.hxx"
35 #include "AttrTransformerAction.hxx"
36 #include "ElemTransformerAction.hxx"
37 #include "TransformerActions.hxx"
38 #include "TransformerBase.hxx"
40 using ::rtl::OUString
;
41 using namespace ::com::sun::star::uno
;
42 using namespace ::com::sun::star::xml::sax
;
43 using namespace ::xmloff::token
;
45 TYPEINIT1( XMLFrameOOoTransformerContext
, XMLPersElemContentTContext
);
47 XMLFrameOOoTransformerContext::XMLFrameOOoTransformerContext(
48 XMLTransformerBase
& rImp
,
49 const OUString
& rQName
) :
50 XMLPersElemContentTContext( rImp
, rQName
),
51 m_aElemQName( rImp
.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_DRAW
,
52 ::xmloff::token::GetXMLToken( XML_FRAME
) ) )
56 XMLFrameOOoTransformerContext::~XMLFrameOOoTransformerContext()
60 void XMLFrameOOoTransformerContext::StartElement(
61 const Reference
< XAttributeList
>& rAttrList
)
64 XMLTransformerActions
*pActions
=
65 GetTransformer().GetUserDefinedActions( OOO_FRAME_ATTR_ACTIONS
);
66 OSL_ENSURE( pActions
, "go no actions" );
68 Reference
< XAttributeList
> xAttrList( rAttrList
);
69 XMLMutableAttributeList
*pMutableAttrList
=
70 GetTransformer().ProcessAttrList( xAttrList
, OOO_SHAPE_ACTIONS
,
72 if( !pMutableAttrList
)
73 pMutableAttrList
= new XMLMutableAttributeList( rAttrList
);
74 xAttrList
= pMutableAttrList
;
76 XMLMutableAttributeList
*pFrameMutableAttrList
=
77 new XMLMutableAttributeList
;
78 Reference
< XAttributeList
> xFrameAttrList( pFrameMutableAttrList
);
80 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
81 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
83 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
86 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
88 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
89 XMLTransformerActions::const_iterator aIter
=
90 pActions
->find( aKey
);
91 if( !(aIter
== pActions
->end() ) )
93 const OUString
& rAttrValue
= xAttrList
->getValueByIndex( i
);
94 switch( (*aIter
).second
.m_nActionType
)
96 case XML_ATACTION_MOVE_TO_ELEM
:
97 pFrameMutableAttrList
->AddAttribute( rAttrName
, rAttrValue
);
98 pMutableAttrList
->RemoveAttributeByIndex( i
);
103 OSL_ENSURE( !this, "unknown action" );
109 GetTransformer().GetDocHandler()->startElement( m_aElemQName
,
111 XMLTransformerContext::StartElement( xAttrList
);
114 XMLTransformerContext
*XMLFrameOOoTransformerContext::CreateChildContext(
116 const OUString
& rLocalName
,
117 const OUString
& rQName
,
118 const Reference
< XAttributeList
>& rAttrList
)
120 XMLTransformerContext
*pContext
= 0;
122 XMLTransformerActions
*pActions
=
123 GetTransformer().GetUserDefinedActions( OOO_FRAME_ELEM_ACTIONS
);
124 OSL_ENSURE( pActions
, "go no actions" );
125 XMLTransformerActions::key_type
aKey( nPrefix
, rLocalName
);
126 XMLTransformerActions::const_iterator aIter
= pActions
->find( aKey
);
128 if( !(aIter
== pActions
->end()) )
130 switch( (*aIter
).second
.m_nActionType
)
132 case XML_ETACTION_COPY
:
133 case XML_ETACTION_COPY_TEXT
:
134 case XML_ETACTION_RENAME_ELEM
:
135 // the ones in the list have to be persistent
137 pContext
= XMLPersElemContentTContext::CreateChildContext(
138 nPrefix
, rLocalName
, rQName
, rAttrList
);
141 OSL_ENSURE( !this, "unknown action" );
146 // default is copying
148 pContext
= XMLTransformerContext::CreateChildContext(
149 nPrefix
, rLocalName
, rQName
, rAttrList
);
154 void XMLFrameOOoTransformerContext::EndElement()
156 XMLTransformerContext::EndElement();
158 GetTransformer().GetDocHandler()->endElement( m_aElemQName
);
161 void XMLFrameOOoTransformerContext::Characters( const OUString
& rChars
)
163 XMLTransformerContext::Characters( rChars
);
166 sal_Bool
XMLFrameOOoTransformerContext::IsPersistent() const
168 // this context stores some of its child elements, but is not persistent
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */