Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include "XFormsSubmissionContext.hxx"
22 :
23 : #include "xformsapi.hxx"
24 :
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>
31 :
32 : #include <sax/tools/converter.hxx>
33 :
34 : #include <com/sun/star/container/XNameContainer.hpp>
35 : #include <com/sun/star/xforms/XModel2.hpp>
36 :
37 : #include <tools/debug.hxx>
38 :
39 : using com::sun::star::beans::XPropertySet;
40 : using com::sun::star::container::XNameContainer;
41 : using com::sun::star::xml::sax::XAttributeList;
42 : using com::sun::star::xforms::XModel2;
43 :
44 : using namespace com::sun::star::uno;
45 : using namespace xmloff::token;
46 :
47 :
48 :
49 :
50 : static const struct SvXMLTokenMapEntry aAttributeMap[] =
51 : {
52 : TOKEN_MAP_ENTRY( NONE, ID ),
53 : TOKEN_MAP_ENTRY( NONE, BIND ),
54 : TOKEN_MAP_ENTRY( NONE, REF ),
55 : TOKEN_MAP_ENTRY( NONE, ACTION ),
56 : TOKEN_MAP_ENTRY( NONE, METHOD ),
57 : TOKEN_MAP_ENTRY( NONE, VERSION ),
58 : TOKEN_MAP_ENTRY( NONE, INDENT ),
59 : TOKEN_MAP_ENTRY( NONE, MEDIATYPE ),
60 : TOKEN_MAP_ENTRY( NONE, ENCODING ),
61 : TOKEN_MAP_ENTRY( NONE, OMIT_XML_DECLARATION ),
62 : TOKEN_MAP_ENTRY( NONE, STANDALONE ),
63 : TOKEN_MAP_ENTRY( NONE, CDATA_SECTION_ELEMENTS ),
64 : TOKEN_MAP_ENTRY( NONE, REPLACE ),
65 : TOKEN_MAP_ENTRY( NONE, SEPARATOR ),
66 : TOKEN_MAP_ENTRY( NONE, INCLUDENAMESPACEPREFIXES ),
67 : XML_TOKEN_MAP_END
68 : };
69 :
70 0 : XFormsSubmissionContext::XFormsSubmissionContext(
71 : SvXMLImport& rImport,
72 : sal_uInt16 nPrefix,
73 : const OUString& rLocalName,
74 : const Reference<XModel2>& xModel ) :
75 : TokenContext( rImport, nPrefix, rLocalName, aAttributeMap, aEmptyMap ),
76 0 : mxSubmission()
77 : {
78 : // register submission with model
79 : DBG_ASSERT( xModel.is(), "need model" );
80 0 : mxSubmission = xModel->createSubmission().get();
81 : DBG_ASSERT( mxSubmission.is(), "can't create submission" );
82 0 : xModel->getSubmissions()->insert( makeAny( mxSubmission ) );
83 0 : }
84 :
85 0 : XFormsSubmissionContext::~XFormsSubmissionContext()
86 : {
87 0 : }
88 :
89 0 : Any toBool( const OUString& rValue )
90 : {
91 0 : Any aValue;
92 0 : bool bValue(false);
93 0 : if (::sax::Converter::convertBool( bValue, rValue ))
94 : {
95 0 : aValue <<= bValue;
96 : }
97 0 : return aValue;
98 : }
99 :
100 0 : void XFormsSubmissionContext::HandleAttribute( sal_uInt16 nToken,
101 : const OUString& rValue )
102 : {
103 0 : switch( nToken )
104 : {
105 : case XML_ID:
106 0 : xforms_setValue( mxSubmission, "ID", rValue );
107 0 : break;
108 : case XML_BIND:
109 0 : xforms_setValue( mxSubmission, "Bind", rValue );
110 0 : break;
111 : case XML_REF:
112 0 : xforms_setValue( mxSubmission, "Ref", rValue );
113 0 : break;
114 : case XML_ACTION:
115 0 : xforms_setValue( mxSubmission, "Action", rValue );
116 0 : break;
117 : case XML_METHOD:
118 0 : xforms_setValue( mxSubmission, "Method", rValue );
119 0 : break;
120 : case XML_VERSION:
121 0 : xforms_setValue( mxSubmission, "Version", rValue );
122 0 : break;
123 : case XML_INDENT:
124 0 : xforms_setValue( mxSubmission, "Indent", toBool( rValue ) );
125 0 : break;
126 : case XML_MEDIATYPE:
127 0 : xforms_setValue( mxSubmission, "MediaType", rValue );
128 0 : break;
129 : case XML_ENCODING:
130 0 : xforms_setValue( mxSubmission, "Encoding", rValue );
131 0 : break;
132 : case XML_OMIT_XML_DECLARATION:
133 : xforms_setValue( mxSubmission, "OmitXmlDeclaration",
134 0 : toBool( rValue ) );
135 0 : break;
136 : case XML_STANDALONE:
137 0 : xforms_setValue( mxSubmission, "Standalone", toBool( rValue ) );
138 0 : break;
139 : case XML_CDATA_SECTION_ELEMENTS:
140 0 : xforms_setValue( mxSubmission, "CDataSectionElement", rValue );
141 0 : break;
142 : case XML_REPLACE:
143 0 : xforms_setValue( mxSubmission, "Replace", rValue );
144 0 : break;
145 : case XML_SEPARATOR:
146 0 : xforms_setValue( mxSubmission, "Separator", rValue );
147 0 : break;
148 : case XML_INCLUDENAMESPACEPREFIXES:
149 0 : xforms_setValue( mxSubmission, "IncludeNamespacePrefixes", rValue );
150 0 : break;
151 : default:
152 : OSL_FAIL( "unknown attribute" );
153 0 : break;
154 : }
155 0 : }
156 :
157 : /** will be called for each child element */
158 0 : SvXMLImportContext* XFormsSubmissionContext::HandleChild(
159 : sal_uInt16,
160 : sal_uInt16,
161 : const OUString&,
162 : const Reference<XAttributeList>& )
163 : {
164 : OSL_FAIL( "no children supported" );
165 0 : return NULL;
166 : }
167 :
168 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|