Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
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.
15 : : *
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).
21 : : *
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.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "XFormsSubmissionContext.hxx"
31 : :
32 : : #include "xformsapi.hxx"
33 : :
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>
40 : :
41 : : #include <sax/tools/converter.hxx>
42 : :
43 : : #include <com/sun/star/container/XNameContainer.hpp>
44 : : #include <com/sun/star/xforms/XModel.hpp>
45 : :
46 : : #include <tools/debug.hxx>
47 : :
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;
53 : :
54 : : using namespace com::sun::star::uno;
55 : : using namespace xmloff::token;
56 : :
57 : :
58 : :
59 : :
60 : : static struct SvXMLTokenMapEntry aAttributeMap[] =
61 : : {
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
78 : : };
79 : :
80 : 0 : XFormsSubmissionContext::XFormsSubmissionContext(
81 : : SvXMLImport& rImport,
82 : : sal_uInt16 nPrefix,
83 : : const OUString& rLocalName,
84 : : const Reference<XPropertySet>& xModel ) :
85 : : TokenContext( rImport, nPrefix, rLocalName, aAttributeMap, aEmptyMap ),
86 : 0 : mxSubmission()
87 : : {
88 : : // register submission with model
89 : : DBG_ASSERT( xModel.is(), "need model" );
90 [ # # ]: 0 : Reference<XModel> xXModel( xModel, UNO_QUERY );
91 : : DBG_ASSERT( xXModel.is(), "need XModel" );
92 [ # # ][ # # ]: 0 : mxSubmission = xXModel->createSubmission().get();
[ # # ][ # # ]
93 : : DBG_ASSERT( mxSubmission.is(), "can't create submission" );
94 [ # # ][ # # ]: 0 : xXModel->getSubmissions()->insert( makeAny( mxSubmission ) );
[ # # ][ # # ]
[ # # ]
95 : 0 : }
96 : :
97 : 0 : XFormsSubmissionContext::~XFormsSubmissionContext()
98 : : {
99 [ # # ]: 0 : }
100 : :
101 : 0 : Any toBool( const OUString& rValue )
102 : : {
103 : 0 : Any aValue;
104 : 0 : bool bValue(false);
105 [ # # ][ # # ]: 0 : if (::sax::Converter::convertBool( bValue, rValue ))
106 : : {
107 [ # # ]: 0 : aValue <<= ( bValue ? true : false );
108 : : }
109 : 0 : return aValue;
110 : : }
111 : :
112 : 0 : void XFormsSubmissionContext::HandleAttribute( sal_uInt16 nToken,
113 : : const OUString& rValue )
114 : : {
115 [ # # # # : 0 : switch( nToken )
# # # # #
# # # # #
# # ]
116 : : {
117 : : case XML_ID:
118 [ # # ]: 0 : lcl_setValue( mxSubmission, OUSTRING("ID"), rValue );
119 : 0 : break;
120 : : case XML_BIND:
121 [ # # ]: 0 : lcl_setValue( mxSubmission, OUSTRING("Bind"), rValue );
122 : 0 : break;
123 : : case XML_REF:
124 [ # # ]: 0 : lcl_setValue( mxSubmission, OUSTRING("Ref"), rValue );
125 : 0 : break;
126 : : case XML_ACTION:
127 [ # # ]: 0 : lcl_setValue( mxSubmission, OUSTRING("Action"), rValue );
128 : 0 : break;
129 : : case XML_METHOD:
130 [ # # ]: 0 : lcl_setValue( mxSubmission, OUSTRING("Method"), rValue );
131 : 0 : break;
132 : : case XML_VERSION:
133 [ # # ]: 0 : lcl_setValue( mxSubmission, OUSTRING("Version"), rValue );
134 : 0 : break;
135 : : case XML_INDENT:
136 [ # # ][ # # ]: 0 : lcl_setValue( mxSubmission, OUSTRING("Indent"), toBool( rValue ) );
137 : 0 : break;
138 : : case XML_MEDIATYPE:
139 [ # # ]: 0 : lcl_setValue( mxSubmission, OUSTRING("MediaType"), rValue );
140 : 0 : break;
141 : : case XML_ENCODING:
142 [ # # ]: 0 : lcl_setValue( mxSubmission, OUSTRING("Encoding"), rValue );
143 : 0 : break;
144 : : case XML_OMIT_XML_DECLARATION:
145 : : lcl_setValue( mxSubmission, OUSTRING("OmitXmlDeclaration"),
146 [ # # ][ # # ]: 0 : toBool( rValue ) );
147 : 0 : break;
148 : : case XML_STANDALONE:
149 [ # # ][ # # ]: 0 : lcl_setValue( mxSubmission, OUSTRING("Standalone"), toBool( rValue ) );
150 : 0 : break;
151 : : case XML_CDATA_SECTION_ELEMENTS:
152 [ # # ]: 0 : lcl_setValue( mxSubmission, OUSTRING("CDataSectionElement"), rValue );
153 : 0 : break;
154 : : case XML_REPLACE:
155 [ # # ]: 0 : lcl_setValue( mxSubmission, OUSTRING("Replace"), rValue );
156 : 0 : break;
157 : : case XML_SEPARATOR:
158 [ # # ]: 0 : lcl_setValue( mxSubmission, OUSTRING("Separator"), rValue );
159 : 0 : break;
160 : : case XML_INCLUDENAMESPACEPREFIXES:
161 [ # # ]: 0 : lcl_setValue( mxSubmission, OUSTRING("IncludeNamespacePrefixes"), rValue );
162 : 0 : break;
163 : : default:
164 : : OSL_FAIL( "unknown attribute" );
165 : 0 : break;
166 : : }
167 : 0 : }
168 : :
169 : : /** will be called for each child element */
170 : 0 : SvXMLImportContext* XFormsSubmissionContext::HandleChild(
171 : : sal_uInt16,
172 : : sal_uInt16,
173 : : const OUString&,
174 : : const Reference<XAttributeList>& )
175 : : {
176 : : OSL_FAIL( "no children supported" );
177 : 0 : return NULL;
178 : : }
179 : :
180 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|