Bump for 3.6-28
[LibreOffice.git] / xmloff / source / xforms / XFormsSubmissionContext.cxx
blob18c1fe5d3529ce5ae969d17c67b049f076080b4d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "XFormsSubmissionContext.hxx"
32 #include "xformsapi.hxx"
34 #include <xmloff/xmlimp.hxx>
35 #include "xmloff/xmlerror.hxx"
36 #include <xmloff/xmltoken.hxx>
37 #include <xmloff/xmltkmap.hxx>
38 #include "xmloff/xmlnmspe.hxx"
39 #include <xmloff/nmspmap.hxx>
41 #include <sax/tools/converter.hxx>
43 #include <com/sun/star/container/XNameContainer.hpp>
44 #include <com/sun/star/xforms/XModel.hpp>
46 #include <tools/debug.hxx>
48 using rtl::OUString;
49 using com::sun::star::beans::XPropertySet;
50 using com::sun::star::container::XNameContainer;
51 using com::sun::star::xml::sax::XAttributeList;
52 using com::sun::star::xforms::XModel;
54 using namespace com::sun::star::uno;
55 using namespace xmloff::token;
60 static struct SvXMLTokenMapEntry aAttributeMap[] =
62 TOKEN_MAP_ENTRY( NONE, ID ),
63 TOKEN_MAP_ENTRY( NONE, BIND ),
64 TOKEN_MAP_ENTRY( NONE, REF ),
65 TOKEN_MAP_ENTRY( NONE, ACTION ),
66 TOKEN_MAP_ENTRY( NONE, METHOD ),
67 TOKEN_MAP_ENTRY( NONE, VERSION ),
68 TOKEN_MAP_ENTRY( NONE, INDENT ),
69 TOKEN_MAP_ENTRY( NONE, MEDIATYPE ),
70 TOKEN_MAP_ENTRY( NONE, ENCODING ),
71 TOKEN_MAP_ENTRY( NONE, OMIT_XML_DECLARATION ),
72 TOKEN_MAP_ENTRY( NONE, STANDALONE ),
73 TOKEN_MAP_ENTRY( NONE, CDATA_SECTION_ELEMENTS ),
74 TOKEN_MAP_ENTRY( NONE, REPLACE ),
75 TOKEN_MAP_ENTRY( NONE, SEPARATOR ),
76 TOKEN_MAP_ENTRY( NONE, INCLUDENAMESPACEPREFIXES ),
77 XML_TOKEN_MAP_END
80 // helper function; see below
81 void lcl_fillNamespaceContainer( const SvXMLNamespaceMap&,
82 Reference<XNameContainer>& );
84 XFormsSubmissionContext::XFormsSubmissionContext(
85 SvXMLImport& rImport,
86 sal_uInt16 nPrefix,
87 const OUString& rLocalName,
88 const Reference<XPropertySet>& xModel ) :
89 TokenContext( rImport, nPrefix, rLocalName, aAttributeMap, aEmptyMap ),
90 mxSubmission()
92 // register submission with model
93 DBG_ASSERT( xModel.is(), "need model" );
94 Reference<XModel> xXModel( xModel, UNO_QUERY );
95 DBG_ASSERT( xXModel.is(), "need XModel" );
96 mxSubmission = xXModel->createSubmission().get();
97 DBG_ASSERT( mxSubmission.is(), "can't create submission" );
98 xXModel->getSubmissions()->insert( makeAny( mxSubmission ) );
101 XFormsSubmissionContext::~XFormsSubmissionContext()
105 Any toBool( const OUString& rValue )
107 Any aValue;
108 bool bValue(false);
109 if (::sax::Converter::convertBool( bValue, rValue ))
111 aValue <<= ( bValue ? true : false );
113 return aValue;
116 void XFormsSubmissionContext::HandleAttribute( sal_uInt16 nToken,
117 const OUString& rValue )
119 switch( nToken )
121 case XML_ID:
122 lcl_setValue( mxSubmission, OUSTRING("ID"), rValue );
123 break;
124 case XML_BIND:
125 lcl_setValue( mxSubmission, OUSTRING("Bind"), rValue );
126 break;
127 case XML_REF:
128 lcl_setValue( mxSubmission, OUSTRING("Ref"), rValue );
129 break;
130 case XML_ACTION:
131 lcl_setValue( mxSubmission, OUSTRING("Action"), rValue );
132 break;
133 case XML_METHOD:
134 lcl_setValue( mxSubmission, OUSTRING("Method"), rValue );
135 break;
136 case XML_VERSION:
137 lcl_setValue( mxSubmission, OUSTRING("Version"), rValue );
138 break;
139 case XML_INDENT:
140 lcl_setValue( mxSubmission, OUSTRING("Indent"), toBool( rValue ) );
141 break;
142 case XML_MEDIATYPE:
143 lcl_setValue( mxSubmission, OUSTRING("MediaType"), rValue );
144 break;
145 case XML_ENCODING:
146 lcl_setValue( mxSubmission, OUSTRING("Encoding"), rValue );
147 break;
148 case XML_OMIT_XML_DECLARATION:
149 lcl_setValue( mxSubmission, OUSTRING("OmitXmlDeclaration"),
150 toBool( rValue ) );
151 break;
152 case XML_STANDALONE:
153 lcl_setValue( mxSubmission, OUSTRING("Standalone"), toBool( rValue ) );
154 break;
155 case XML_CDATA_SECTION_ELEMENTS:
156 lcl_setValue( mxSubmission, OUSTRING("CDataSectionElement"), rValue );
157 break;
158 case XML_REPLACE:
159 lcl_setValue( mxSubmission, OUSTRING("Replace"), rValue );
160 break;
161 case XML_SEPARATOR:
162 lcl_setValue( mxSubmission, OUSTRING("Separator"), rValue );
163 break;
164 case XML_INCLUDENAMESPACEPREFIXES:
165 lcl_setValue( mxSubmission, OUSTRING("IncludeNamespacePrefixes"), rValue );
166 break;
167 default:
168 OSL_FAIL( "unknown attribute" );
169 break;
173 /** will be called for each child element */
174 SvXMLImportContext* XFormsSubmissionContext::HandleChild(
175 sal_uInt16,
176 sal_uInt16,
177 const OUString&,
178 const Reference<XAttributeList>& )
180 OSL_FAIL( "no children supported" );
181 return NULL;
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */