xref: /AOO41X/main/xmloff/source/transform/DeepTContext.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 "DeepTContext.hxx"
27 #ifndef _XMLOFF_FLATTTCONTEXT_HXX
28 #include "FlatTContext.hxx"
29 #endif
30 #include "EventOOoTContext.hxx"
31 #include "TransformerActions.hxx"
32 #include "ElemTransformerAction.hxx"
33 #include "PersMixedContentTContext.hxx"
34 #ifndef _XMLOFF_TRANSFORMERBASE_HXX
35 #include "TransformerBase.hxx"
36 #endif
37 
38 using ::rtl::OUString;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::xml::sax;
41 
42 TYPEINIT1( XMLPersElemContentTContext, XMLPersAttrListTContext );
43 
AddContent(XMLTransformerContext * pContext)44 void XMLPersElemContentTContext::AddContent( XMLTransformerContext *pContext )
45 {
46     OSL_ENSURE( pContext && pContext->IsPersistent(),
47                 "non-persistent context" );
48     XMLTransformerContextVector::value_type aVal( pContext );
49     m_aChildContexts.push_back( aVal );
50 }
51 
XMLPersElemContentTContext(XMLTransformerBase & rImp,const OUString & rQName)52 XMLPersElemContentTContext::XMLPersElemContentTContext(
53         XMLTransformerBase& rImp,
54         const OUString& rQName ) :
55     XMLPersAttrListTContext( rImp, rQName )
56 {
57 }
58 
XMLPersElemContentTContext(XMLTransformerBase & rImp,const OUString & rQName,sal_uInt16 nActionMap)59 XMLPersElemContentTContext::XMLPersElemContentTContext(
60         XMLTransformerBase& rImp,
61         const OUString& rQName,
62        sal_uInt16 nActionMap ) :
63     XMLPersAttrListTContext( rImp, rQName, nActionMap )
64 {
65 }
66 
XMLPersElemContentTContext(XMLTransformerBase & rImp,const OUString & rQName,sal_uInt16 nPrefix,::xmloff::token::XMLTokenEnum eToken)67 XMLPersElemContentTContext::XMLPersElemContentTContext(
68         XMLTransformerBase& rImp,
69         const OUString& rQName,
70         sal_uInt16 nPrefix,
71         ::xmloff::token::XMLTokenEnum eToken ) :
72     XMLPersAttrListTContext( rImp, rQName, nPrefix, eToken )
73 {
74 }
75 
XMLPersElemContentTContext(XMLTransformerBase & rImp,const OUString & rQName,sal_uInt16 nPrefix,::xmloff::token::XMLTokenEnum eToken,sal_uInt16 nActionMap)76 XMLPersElemContentTContext::XMLPersElemContentTContext(
77         XMLTransformerBase& rImp,
78         const OUString& rQName,
79         sal_uInt16 nPrefix,
80         ::xmloff::token::XMLTokenEnum eToken,
81        sal_uInt16 nActionMap ) :
82     XMLPersAttrListTContext( rImp, rQName, nPrefix, eToken, nActionMap )
83 {
84 }
85 
~XMLPersElemContentTContext()86 XMLPersElemContentTContext::~XMLPersElemContentTContext()
87 {
88 }
89 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const OUString & rQName,const Reference<XAttributeList> &)90 XMLTransformerContext *XMLPersElemContentTContext::CreateChildContext(
91         sal_uInt16 nPrefix,
92         const OUString& rLocalName,
93         const OUString& rQName,
94         const Reference< XAttributeList >& )
95 {
96     XMLTransformerContext *pContext = 0;
97 
98     XMLTransformerActions::key_type aKey( nPrefix, rLocalName );
99     XMLTransformerActions::const_iterator aIter =
100         GetTransformer().GetElemActions().find( aKey );
101 
102     if( !(aIter == GetTransformer().GetElemActions().end()) )
103     {
104         switch( (*aIter).second.m_nActionType )
105         {
106         case XML_ETACTION_COPY:
107             pContext = new XMLPersMixedContentTContext( GetTransformer(),
108                                                        rQName );
109             break;
110         case XML_ETACTION_COPY_TEXT:
111             pContext = new XMLPersMixedContentTContext( GetTransformer(),
112                                                        rQName );
113             break;
114         case XML_ETACTION_RENAME_ELEM:
115             pContext = new XMLPersMixedContentTContext( GetTransformer(), rQName,
116                     (*aIter).second.GetQNamePrefixFromParam1(),
117                     (*aIter).second.GetQNameTokenFromParam1() );
118             break;
119         case XML_ETACTION_RENAME_ELEM_PROC_ATTRS:
120             pContext = new XMLPersMixedContentTContext( GetTransformer(), rQName,
121                     (*aIter).second.GetQNamePrefixFromParam1(),
122                     (*aIter).second.GetQNameTokenFromParam1(),
123                     static_cast< sal_uInt16 >( (*aIter).second.m_nParam2 ) );
124             break;
125         case XML_ETACTION_RENAME_ELEM_ADD_PROC_ATTR:
126             {
127                 XMLPersMixedContentTContext *pMC =
128                     new XMLPersMixedContentTContext( GetTransformer(), rQName,
129                         (*aIter).second.GetQNamePrefixFromParam1(),
130                         (*aIter).second.GetQNameTokenFromParam1(),
131                         static_cast< sal_uInt16 >(
132                             (*aIter).second.m_nParam3  >> 16 ) );
133                 pMC->AddAttribute(
134                     (*aIter).second.GetQNamePrefixFromParam2(),
135                     (*aIter).second.GetQNameTokenFromParam2(),
136                     static_cast< ::xmloff::token::XMLTokenEnum >(
137                         (*aIter).second.m_nParam3 & 0xffff ) );
138                 pContext = pMC;
139             }
140             break;
141         case XML_ETACTION_PROC_ATTRS:
142             pContext = new XMLPersMixedContentTContext( GetTransformer(), rQName,
143                     static_cast< sal_uInt16 >( (*aIter).second.m_nParam1 ) );
144             break;
145         default:
146             pContext = GetTransformer().CreateUserDefinedContext(
147                             (*aIter).second, rQName, sal_True );
148             OSL_ENSURE( pContext && pContext->IsPersistent(),
149                         "unknown or not persistent action" );
150             if( pContext && !pContext->IsPersistent() )
151             {
152                 delete pContext;
153                 pContext = 0;
154             }
155             break;
156         }
157     }
158 
159     // default is copying
160     if( !pContext )
161         pContext = new XMLPersMixedContentTContext( GetTransformer(), rQName );
162     XMLTransformerContextVector::value_type aVal( pContext );
163     m_aChildContexts.push_back( aVal );
164 
165     return pContext;
166 }
167 
ExportContent()168 void XMLPersElemContentTContext::ExportContent()
169 {
170     XMLTransformerContextVector::iterator aIter = m_aChildContexts.begin();
171 
172     for( ; aIter != m_aChildContexts.end(); ++aIter )
173     {
174         (*aIter)->Export();
175     }
176 }
177 
178