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