xref: /trunk/main/xmloff/source/transform/FrameOOoTContext.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 #include "FrameOOoTContext.hxx"
31 #include "IgnoreTContext.hxx"
32 #include "MutableAttrList.hxx"
33 #include "xmloff/xmlnmspe.hxx"
34 #include <xmloff/nmspmap.hxx>
35 #include "ActionMapTypesOOo.hxx"
36 #include "AttrTransformerAction.hxx"
37 #include "ElemTransformerAction.hxx"
38 #include "TransformerActions.hxx"
39 #ifndef _XMLOFF_TRANSFORMERBASE_HXX
40 #include "TransformerBase.hxx"
41 #endif
42 
43 using ::rtl::OUString;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::xml::sax;
46 using namespace ::xmloff::token;
47 
48 TYPEINIT1( XMLFrameOOoTransformerContext, XMLPersElemContentTContext );
49 
50 XMLFrameOOoTransformerContext::XMLFrameOOoTransformerContext(
51         XMLTransformerBase& rImp,
52         const OUString& rQName ) :
53     XMLPersElemContentTContext( rImp, rQName ),
54     m_aElemQName( rImp.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_DRAW,
55                             ::xmloff::token::GetXMLToken( XML_FRAME ) ) )
56 {
57 }
58 
59 XMLFrameOOoTransformerContext::~XMLFrameOOoTransformerContext()
60 {
61 }
62 
63 void XMLFrameOOoTransformerContext::StartElement(
64     const Reference< XAttributeList >& rAttrList )
65 {
66 
67     XMLTransformerActions *pActions =
68         GetTransformer().GetUserDefinedActions( OOO_FRAME_ATTR_ACTIONS );
69     OSL_ENSURE( pActions, "go no actions" );
70 
71     Reference< XAttributeList > xAttrList( rAttrList );
72     XMLMutableAttributeList *pMutableAttrList =
73         GetTransformer().ProcessAttrList( xAttrList, OOO_SHAPE_ACTIONS,
74                                           sal_True );
75     if( !pMutableAttrList )
76         pMutableAttrList = new XMLMutableAttributeList( rAttrList );
77     xAttrList = pMutableAttrList;
78 
79     XMLMutableAttributeList *pFrameMutableAttrList =
80         new XMLMutableAttributeList;
81     Reference< XAttributeList > xFrameAttrList( pFrameMutableAttrList );
82 
83     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
84     for( sal_Int16 i=0; i < nAttrCount; i++ )
85     {
86         const OUString& rAttrName = xAttrList->getNameByIndex( i );
87         OUString aLocalName;
88         sal_uInt16 nPrefix =
89             GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
90                                                                  &aLocalName );
91         XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
92         XMLTransformerActions::const_iterator aIter =
93             pActions->find( aKey );
94         if( !(aIter == pActions->end() ) )
95         {
96             const OUString& rAttrValue = xAttrList->getValueByIndex( i );
97             switch( (*aIter).second.m_nActionType )
98             {
99             case XML_ATACTION_MOVE_TO_ELEM:
100                 pFrameMutableAttrList->AddAttribute( rAttrName, rAttrValue );
101                 pMutableAttrList->RemoveAttributeByIndex( i );
102                 --i;
103                 --nAttrCount;
104                 break;
105             default:
106                 OSL_ENSURE( !this, "unknown action" );
107                 break;
108             }
109         }
110     }
111 
112     GetTransformer().GetDocHandler()->startElement( m_aElemQName,
113                                                     xFrameAttrList );
114     XMLTransformerContext::StartElement( xAttrList );
115 }
116 
117 XMLTransformerContext *XMLFrameOOoTransformerContext::CreateChildContext(
118         sal_uInt16 nPrefix,
119         const OUString& rLocalName,
120         const OUString& rQName,
121         const Reference< XAttributeList >& rAttrList )
122 {
123     XMLTransformerContext *pContext = 0;
124 
125     XMLTransformerActions *pActions =
126         GetTransformer().GetUserDefinedActions( OOO_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 );
130 
131     if( !(aIter == pActions->end()) )
132     {
133         switch( (*aIter).second.m_nActionType )
134         {
135         case XML_ETACTION_COPY:
136         case XML_ETACTION_COPY_TEXT:
137         case XML_ETACTION_RENAME_ELEM:
138             // the ones in the list have to be persistent
139 
140             pContext = XMLPersElemContentTContext::CreateChildContext(
141                         nPrefix, rLocalName, rQName, rAttrList );
142             break;
143         default:
144             OSL_ENSURE( !this, "unknown action" );
145             break;
146         }
147     }
148 
149     // default is copying
150     if( !pContext )
151         pContext = XMLTransformerContext::CreateChildContext(
152                     nPrefix, rLocalName, rQName, rAttrList );
153 
154     return pContext;
155 }
156 
157 void XMLFrameOOoTransformerContext::EndElement()
158 {
159     XMLTransformerContext::EndElement();
160     ExportContent();
161     GetTransformer().GetDocHandler()->endElement( m_aElemQName );
162 }
163 
164 void XMLFrameOOoTransformerContext::Characters( const OUString& rChars )
165 {
166     XMLTransformerContext::Characters( rChars );
167 }
168 
169 sal_Bool XMLFrameOOoTransformerContext::IsPersistent() const
170 {
171     // this context stores some of its child elements, but is not persistent
172     // itself.
173     return sal_False;
174 }
175