bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / xforms / XFormsSubmissionContext.cxx
blobfb239817106936229595a59079876ced0025acc1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "XFormsSubmissionContext.hxx"
23 #include "xformsapi.hxx"
25 #include <xmloff/xmlimp.hxx>
26 #include <xmloff/xmlerror.hxx>
27 #include <xmloff/xmltoken.hxx>
28 #include <xmloff/xmltkmap.hxx>
29 #include <xmloff/xmlnmspe.hxx>
30 #include <xmloff/nmspmap.hxx>
32 #include <sax/tools/converter.hxx>
34 #include <com/sun/star/container/XNameContainer.hpp>
35 #include <com/sun/star/xforms/XModel2.hpp>
37 #include <tools/debug.hxx>
38 #include <osl/diagnose.h>
40 using com::sun::star::beans::XPropertySet;
41 using com::sun::star::container::XNameContainer;
42 using com::sun::star::xml::sax::XAttributeList;
43 using com::sun::star::xforms::XModel2;
45 using namespace com::sun::star::uno;
46 using namespace xmloff::token;
51 static const struct SvXMLTokenMapEntry aAttributeMap[] =
53 TOKEN_MAP_ENTRY( NONE, ID ),
54 TOKEN_MAP_ENTRY( NONE, BIND ),
55 TOKEN_MAP_ENTRY( NONE, REF ),
56 TOKEN_MAP_ENTRY( NONE, ACTION ),
57 TOKEN_MAP_ENTRY( NONE, METHOD ),
58 TOKEN_MAP_ENTRY( NONE, VERSION ),
59 TOKEN_MAP_ENTRY( NONE, INDENT ),
60 TOKEN_MAP_ENTRY( NONE, MEDIATYPE ),
61 TOKEN_MAP_ENTRY( NONE, ENCODING ),
62 TOKEN_MAP_ENTRY( NONE, OMIT_XML_DECLARATION ),
63 TOKEN_MAP_ENTRY( NONE, STANDALONE ),
64 TOKEN_MAP_ENTRY( NONE, CDATA_SECTION_ELEMENTS ),
65 TOKEN_MAP_ENTRY( NONE, REPLACE ),
66 TOKEN_MAP_ENTRY( NONE, SEPARATOR ),
67 TOKEN_MAP_ENTRY( NONE, INCLUDENAMESPACEPREFIXES ),
68 XML_TOKEN_MAP_END
71 XFormsSubmissionContext::XFormsSubmissionContext(
72 SvXMLImport& rImport,
73 sal_uInt16 nPrefix,
74 const OUString& rLocalName,
75 const Reference<XModel2>& xModel ) :
76 TokenContext( rImport, nPrefix, rLocalName, aAttributeMap, aEmptyMap ),
77 mxSubmission()
79 // register submission with model
80 DBG_ASSERT( xModel.is(), "need model" );
81 mxSubmission = xModel->createSubmission().get();
82 DBG_ASSERT( mxSubmission.is(), "can't create submission" );
83 xModel->getSubmissions()->insert( makeAny( mxSubmission ) );
86 XFormsSubmissionContext::~XFormsSubmissionContext()
90 Any toBool( const OUString& rValue )
92 Any aValue;
93 bool bValue(false);
94 if (::sax::Converter::convertBool( bValue, rValue ))
96 aValue <<= bValue;
98 return aValue;
101 void XFormsSubmissionContext::HandleAttribute( sal_uInt16 nToken,
102 const OUString& rValue )
104 switch( nToken )
106 case XML_ID:
107 xforms_setValue( mxSubmission, "ID", rValue );
108 break;
109 case XML_BIND:
110 xforms_setValue( mxSubmission, "Bind", rValue );
111 break;
112 case XML_REF:
113 xforms_setValue( mxSubmission, "Ref", rValue );
114 break;
115 case XML_ACTION:
116 xforms_setValue( mxSubmission, "Action", rValue );
117 break;
118 case XML_METHOD:
119 xforms_setValue( mxSubmission, "Method", rValue );
120 break;
121 case XML_VERSION:
122 xforms_setValue( mxSubmission, "Version", rValue );
123 break;
124 case XML_INDENT:
125 xforms_setValue( mxSubmission, "Indent", toBool( rValue ) );
126 break;
127 case XML_MEDIATYPE:
128 xforms_setValue( mxSubmission, "MediaType", rValue );
129 break;
130 case XML_ENCODING:
131 xforms_setValue( mxSubmission, "Encoding", rValue );
132 break;
133 case XML_OMIT_XML_DECLARATION:
134 xforms_setValue( mxSubmission, "OmitXmlDeclaration",
135 toBool( rValue ) );
136 break;
137 case XML_STANDALONE:
138 xforms_setValue( mxSubmission, "Standalone", toBool( rValue ) );
139 break;
140 case XML_CDATA_SECTION_ELEMENTS:
141 xforms_setValue( mxSubmission, "CDataSectionElement", rValue );
142 break;
143 case XML_REPLACE:
144 xforms_setValue( mxSubmission, "Replace", rValue );
145 break;
146 case XML_SEPARATOR:
147 xforms_setValue( mxSubmission, "Separator", rValue );
148 break;
149 case XML_INCLUDENAMESPACEPREFIXES:
150 xforms_setValue( mxSubmission, "IncludeNamespacePrefixes", rValue );
151 break;
152 default:
153 OSL_FAIL( "unknown attribute" );
154 break;
158 /** will be called for each child element */
159 SvXMLImportContext* XFormsSubmissionContext::HandleChild(
160 sal_uInt16,
161 sal_uInt16,
162 const OUString&,
163 const Reference<XAttributeList>& )
165 OSL_FAIL( "no children supported" );
166 return NULL;
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */