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>
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
),
71 XFormsSubmissionContext::XFormsSubmissionContext(
74 const OUString
& rLocalName
,
75 const Reference
<XModel2
>& xModel
) :
76 TokenContext( rImport
, nPrefix
, rLocalName
, aAttributeMap
, aEmptyMap
),
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
)
94 if (::sax::Converter::convertBool( bValue
, rValue
))
101 void XFormsSubmissionContext::HandleAttribute( sal_uInt16 nToken
,
102 const OUString
& rValue
)
107 xforms_setValue( mxSubmission
, "ID", rValue
);
110 xforms_setValue( mxSubmission
, "Bind", rValue
);
113 xforms_setValue( mxSubmission
, "Ref", rValue
);
116 xforms_setValue( mxSubmission
, "Action", rValue
);
119 xforms_setValue( mxSubmission
, "Method", rValue
);
122 xforms_setValue( mxSubmission
, "Version", rValue
);
125 xforms_setValue( mxSubmission
, "Indent", toBool( rValue
) );
128 xforms_setValue( mxSubmission
, "MediaType", rValue
);
131 xforms_setValue( mxSubmission
, "Encoding", rValue
);
133 case XML_OMIT_XML_DECLARATION
:
134 xforms_setValue( mxSubmission
, "OmitXmlDeclaration",
138 xforms_setValue( mxSubmission
, "Standalone", toBool( rValue
) );
140 case XML_CDATA_SECTION_ELEMENTS
:
141 xforms_setValue( mxSubmission
, "CDataSectionElement", rValue
);
144 xforms_setValue( mxSubmission
, "Replace", rValue
);
147 xforms_setValue( mxSubmission
, "Separator", rValue
);
149 case XML_INCLUDENAMESPACEPREFIXES
:
150 xforms_setValue( mxSubmission
, "IncludeNamespacePrefixes", rValue
);
153 OSL_FAIL( "unknown attribute" );
158 /** will be called for each child element */
159 SvXMLImportContext
* XFormsSubmissionContext::HandleChild(
163 const Reference
<XAttributeList
>& )
165 OSL_FAIL( "no children supported" );
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */