merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / xforms / XFormsSubmissionContext.cxx
blob1c4be38f8c7a65174f876f858b739137aff29da2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XFormsSubmissionContext.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
34 #include "XFormsSubmissionContext.hxx"
36 #include "xformsapi.hxx"
38 #include <xmloff/xmlimp.hxx>
39 #include "xmlerror.hxx"
40 #include <xmloff/xmltoken.hxx>
41 #include <xmloff/xmltkmap.hxx>
42 #include "xmlnmspe.hxx"
43 #include <xmloff/nmspmap.hxx>
44 #include <xmloff/xmluconv.hxx>
46 #include <com/sun/star/container/XNameContainer.hpp>
47 #include <com/sun/star/xforms/XModel.hpp>
49 #include <tools/debug.hxx>
51 using rtl::OUString;
52 using com::sun::star::beans::XPropertySet;
53 using com::sun::star::container::XNameContainer;
54 using com::sun::star::xml::sax::XAttributeList;
55 using com::sun::star::xforms::XModel;
57 using namespace com::sun::star::uno;
58 using namespace xmloff::token;
63 static struct SvXMLTokenMapEntry aAttributeMap[] =
65 TOKEN_MAP_ENTRY( NONE, ID ),
66 TOKEN_MAP_ENTRY( NONE, BIND ),
67 TOKEN_MAP_ENTRY( NONE, REF ),
68 TOKEN_MAP_ENTRY( NONE, ACTION ),
69 TOKEN_MAP_ENTRY( NONE, METHOD ),
70 TOKEN_MAP_ENTRY( NONE, VERSION ),
71 TOKEN_MAP_ENTRY( NONE, INDENT ),
72 TOKEN_MAP_ENTRY( NONE, MEDIATYPE ),
73 TOKEN_MAP_ENTRY( NONE, ENCODING ),
74 TOKEN_MAP_ENTRY( NONE, OMIT_XML_DECLARATION ),
75 TOKEN_MAP_ENTRY( NONE, STANDALONE ),
76 TOKEN_MAP_ENTRY( NONE, CDATA_SECTION_ELEMENTS ),
77 TOKEN_MAP_ENTRY( NONE, REPLACE ),
78 TOKEN_MAP_ENTRY( NONE, SEPARATOR ),
79 TOKEN_MAP_ENTRY( NONE, INCLUDENAMESPACEPREFIXES ),
80 XML_TOKEN_MAP_END
83 // helper function; see below
84 void lcl_fillNamespaceContainer( const SvXMLNamespaceMap&,
85 Reference<XNameContainer>& );
87 XFormsSubmissionContext::XFormsSubmissionContext(
88 SvXMLImport& rImport,
89 USHORT nPrefix,
90 const OUString& rLocalName,
91 const Reference<XPropertySet>& xModel ) :
92 TokenContext( rImport, nPrefix, rLocalName, aAttributeMap, aEmptyMap ),
93 mxSubmission()
95 // register submission with model
96 DBG_ASSERT( xModel.is(), "need model" );
97 Reference<XModel> xXModel( xModel, UNO_QUERY );
98 DBG_ASSERT( xXModel.is(), "need XModel" );
99 mxSubmission = xXModel->createSubmission().get();
100 DBG_ASSERT( mxSubmission.is(), "can't create submission" );
101 xXModel->getSubmissions()->insert( makeAny( mxSubmission ) );
104 XFormsSubmissionContext::~XFormsSubmissionContext()
108 Any toBool( const OUString& rValue )
110 Any aValue;
111 sal_Bool bValue;
112 if( SvXMLUnitConverter::convertBool( bValue, rValue ) )
114 aValue <<= ( bValue ? true : false );
116 return aValue;
119 void XFormsSubmissionContext::HandleAttribute( sal_uInt16 nToken,
120 const OUString& rValue )
122 switch( nToken )
124 case XML_ID:
125 lcl_setValue( mxSubmission, OUSTRING("ID"), rValue );
126 break;
127 case XML_BIND:
128 lcl_setValue( mxSubmission, OUSTRING("Bind"), rValue );
129 break;
130 case XML_REF:
131 lcl_setValue( mxSubmission, OUSTRING("Ref"), rValue );
132 break;
133 case XML_ACTION:
134 lcl_setValue( mxSubmission, OUSTRING("Action"), rValue );
135 break;
136 case XML_METHOD:
137 lcl_setValue( mxSubmission, OUSTRING("Method"), rValue );
138 break;
139 case XML_VERSION:
140 lcl_setValue( mxSubmission, OUSTRING("Version"), rValue );
141 break;
142 case XML_INDENT:
143 lcl_setValue( mxSubmission, OUSTRING("Indent"), toBool( rValue ) );
144 break;
145 case XML_MEDIATYPE:
146 lcl_setValue( mxSubmission, OUSTRING("MediaType"), rValue );
147 break;
148 case XML_ENCODING:
149 lcl_setValue( mxSubmission, OUSTRING("Encoding"), rValue );
150 break;
151 case XML_OMIT_XML_DECLARATION:
152 lcl_setValue( mxSubmission, OUSTRING("OmitXmlDeclaration"),
153 toBool( rValue ) );
154 break;
155 case XML_STANDALONE:
156 lcl_setValue( mxSubmission, OUSTRING("Standalone"), toBool( rValue ) );
157 break;
158 case XML_CDATA_SECTION_ELEMENTS:
159 lcl_setValue( mxSubmission, OUSTRING("CDataSectionElement"), rValue );
160 break;
161 case XML_REPLACE:
162 lcl_setValue( mxSubmission, OUSTRING("Replace"), rValue );
163 break;
164 case XML_SEPARATOR:
165 lcl_setValue( mxSubmission, OUSTRING("Separator"), rValue );
166 break;
167 case XML_INCLUDENAMESPACEPREFIXES:
168 lcl_setValue( mxSubmission, OUSTRING("IncludeNamespacePrefixes"), rValue );
169 break;
170 default:
171 DBG_ERROR( "unknown attribute" );
172 break;
176 /** will be called for each child element */
177 SvXMLImportContext* XFormsSubmissionContext::HandleChild(
178 sal_uInt16,
179 sal_uInt16,
180 const OUString&,
181 const Reference<XAttributeList>& )
183 DBG_ERROR( "no children supported" );
184 return NULL;