xref: /AOO41X/main/xmloff/source/transform/FrameOOoTContext.cxx (revision 63bba73cc51e0afb45f8a8d578158724bb5afee8)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include "FrameOOoTContext.hxx"
27 #include "IgnoreTContext.hxx"
28 #include "MutableAttrList.hxx"
29 #include "xmloff/xmlnmspe.hxx"
30 #include <xmloff/nmspmap.hxx>
31 #include "ActionMapTypesOOo.hxx"
32 #include "AttrTransformerAction.hxx"
33 #include "ElemTransformerAction.hxx"
34 #include "TransformerActions.hxx"
35 #ifndef _XMLOFF_TRANSFORMERBASE_HXX
36 #include "TransformerBase.hxx"
37 #endif
38 
39 using ::rtl::OUString;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::xml::sax;
42 using namespace ::xmloff::token;
43 
44 TYPEINIT1( XMLFrameOOoTransformerContext, XMLPersElemContentTContext );
45 
XMLFrameOOoTransformerContext(XMLTransformerBase & rImp,const OUString & rQName)46 XMLFrameOOoTransformerContext::XMLFrameOOoTransformerContext(
47         XMLTransformerBase& rImp,
48         const OUString& rQName ) :
49     XMLPersElemContentTContext( rImp, rQName ),
50     m_aElemQName( rImp.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_DRAW,
51                             ::xmloff::token::GetXMLToken( XML_FRAME ) ) )
52 {
53 }
54 
~XMLFrameOOoTransformerContext()55 XMLFrameOOoTransformerContext::~XMLFrameOOoTransformerContext()
56 {
57 }
58 
StartElement(const Reference<XAttributeList> & rAttrList)59 void XMLFrameOOoTransformerContext::StartElement(
60     const Reference< XAttributeList >& rAttrList )
61 {
62 
63     XMLTransformerActions *pActions =
64         GetTransformer().GetUserDefinedActions( OOO_FRAME_ATTR_ACTIONS );
65     OSL_ENSURE( pActions, "go no actions" );
66 
67     Reference< XAttributeList > xAttrList( rAttrList );
68     XMLMutableAttributeList *pMutableAttrList =
69         GetTransformer().ProcessAttrList( xAttrList, OOO_SHAPE_ACTIONS,
70                                           sal_True );
71     if( !pMutableAttrList )
72         pMutableAttrList = new XMLMutableAttributeList( rAttrList );
73     xAttrList = pMutableAttrList;
74 
75     XMLMutableAttributeList *pFrameMutableAttrList =
76         new XMLMutableAttributeList;
77     Reference< XAttributeList > xFrameAttrList( pFrameMutableAttrList );
78 
79     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
80     for( sal_Int16 i=0; i < nAttrCount; i++ )
81     {
82         const OUString& rAttrName = xAttrList->getNameByIndex( i );
83         OUString aLocalName;
84         sal_uInt16 nPrefix =
85             GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
86                                                                  &aLocalName );
87         XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
88         XMLTransformerActions::const_iterator aIter =
89             pActions->find( aKey );
90         if( !(aIter == pActions->end() ) )
91         {
92             const OUString& rAttrValue = xAttrList->getValueByIndex( i );
93             switch( (*aIter).second.m_nActionType )
94             {
95             case XML_ATACTION_MOVE_TO_ELEM:
96                 pFrameMutableAttrList->AddAttribute( rAttrName, rAttrValue );
97                 pMutableAttrList->RemoveAttributeByIndex( i );
98                 --i;
99                 --nAttrCount;
100                 break;
101             default:
102                 OSL_ENSURE( !this, "unknown action" );
103                 break;
104             }
105         }
106     }
107 
108     GetTransformer().GetDocHandler()->startElement( m_aElemQName,
109                                                     xFrameAttrList );
110     XMLTransformerContext::StartElement( xAttrList );
111 }
112 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const OUString & rQName,const Reference<XAttributeList> & rAttrList)113 XMLTransformerContext *XMLFrameOOoTransformerContext::CreateChildContext(
114         sal_uInt16 nPrefix,
115         const OUString& rLocalName,
116         const OUString& rQName,
117         const Reference< XAttributeList >& rAttrList )
118 {
119     XMLTransformerContext *pContext = 0;
120 
121     XMLTransformerActions *pActions =
122         GetTransformer().GetUserDefinedActions( OOO_FRAME_ELEM_ACTIONS );
123     OSL_ENSURE( pActions, "go no actions" );
124     XMLTransformerActions::key_type aKey( nPrefix, rLocalName );
125     XMLTransformerActions::const_iterator aIter = pActions->find( aKey );
126 
127     if( !(aIter == pActions->end()) )
128     {
129         switch( (*aIter).second.m_nActionType )
130         {
131         case XML_ETACTION_COPY:
132         case XML_ETACTION_COPY_TEXT:
133         case XML_ETACTION_RENAME_ELEM:
134             // the ones in the list have to be persistent
135 
136             pContext = XMLPersElemContentTContext::CreateChildContext(
137                         nPrefix, rLocalName, rQName, rAttrList );
138             break;
139         default:
140             OSL_ENSURE( !this, "unknown action" );
141             break;
142         }
143     }
144 
145     // default is copying
146     if( !pContext )
147         pContext = XMLTransformerContext::CreateChildContext(
148                     nPrefix, rLocalName, rQName, rAttrList );
149 
150     return pContext;
151 }
152 
EndElement()153 void XMLFrameOOoTransformerContext::EndElement()
154 {
155     XMLTransformerContext::EndElement();
156     ExportContent();
157     GetTransformer().GetDocHandler()->endElement( m_aElemQName );
158 }
159 
Characters(const OUString & rChars)160 void XMLFrameOOoTransformerContext::Characters( const OUString& rChars )
161 {
162     XMLTransformerContext::Characters( rChars );
163 }
164 
IsPersistent() const165 sal_Bool XMLFrameOOoTransformerContext::IsPersistent() const
166 {
167     // this context stores some of its child elements, but is not persistent
168     // itself.
169     return sal_False;
170 }
171