1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
;
44 using namespace com::sun::star::uno
;
45 using namespace xmloff::token
;
50 static struct SvXMLTokenMapEntry aAttributeMap
[] =
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
),
70 XFormsSubmissionContext::XFormsSubmissionContext(
73 const OUString
& rLocalName
,
74 const Reference
<XModel2
>& xModel
) :
75 TokenContext( rImport
, nPrefix
, rLocalName
, aAttributeMap
, aEmptyMap
),
78 // register submission with model
79 DBG_ASSERT( xModel
.is(), "need model" );
80 mxSubmission
= xModel
->createSubmission().get();
81 DBG_ASSERT( mxSubmission
.is(), "can't create submission" );
82 xModel
->getSubmissions()->insert( makeAny( mxSubmission
) );
85 XFormsSubmissionContext::~XFormsSubmissionContext()
89 Any
toBool( const OUString
& rValue
)
93 if (::sax::Converter::convertBool( bValue
, rValue
))
95 aValue
<<= ( bValue
? true : false );
100 void XFormsSubmissionContext::HandleAttribute( sal_uInt16 nToken
,
101 const OUString
& rValue
)
106 xforms_setValue( mxSubmission
, "ID", rValue
);
109 xforms_setValue( mxSubmission
, "Bind", rValue
);
112 xforms_setValue( mxSubmission
, "Ref", rValue
);
115 xforms_setValue( mxSubmission
, "Action", rValue
);
118 xforms_setValue( mxSubmission
, "Method", rValue
);
121 xforms_setValue( mxSubmission
, "Version", rValue
);
124 xforms_setValue( mxSubmission
, "Indent", toBool( rValue
) );
127 xforms_setValue( mxSubmission
, "MediaType", rValue
);
130 xforms_setValue( mxSubmission
, "Encoding", rValue
);
132 case XML_OMIT_XML_DECLARATION
:
133 xforms_setValue( mxSubmission
, "OmitXmlDeclaration",
137 xforms_setValue( mxSubmission
, "Standalone", toBool( rValue
) );
139 case XML_CDATA_SECTION_ELEMENTS
:
140 xforms_setValue( mxSubmission
, "CDataSectionElement", rValue
);
143 xforms_setValue( mxSubmission
, "Replace", rValue
);
146 xforms_setValue( mxSubmission
, "Separator", rValue
);
148 case XML_INCLUDENAMESPACEPREFIXES
:
149 xforms_setValue( mxSubmission
, "IncludeNamespacePrefixes", rValue
);
152 OSL_FAIL( "unknown attribute" );
157 /** will be called for each child element */
158 SvXMLImportContext
* XFormsSubmissionContext::HandleChild(
162 const Reference
<XAttributeList
>& )
164 OSL_FAIL( "no children supported" );
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */