| 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/xmltoken.hxx> |
| 27 |
|
| 28 |
#include <sax/tools/converter.hxx> |
| 29 |
|
| 30 |
#include <com/sun/star/xforms/XModel2.hpp> |
| 31 |
|
| 32 |
#include <sal/log.hxx> |
| 33 |
|
| 34 |
using com::sun::star::xforms::XModel2; |
| 35 |
|
| 36 |
using namespace com::sun::star::uno; |
| 37 |
using namespace xmloff::token; |
| 38 |
|
| 39 |
|
| 40 |
XFormsSubmissionContext::XFormsSubmissionContext( |
| 41 |
SvXMLImport& rImport, |
| 42 |
const Reference<XModel2>& xModel ) : |
| 43 |
TokenContext( rImport ) |
| 44 |
{ |
| 45 |
// register submission with model |
| 46 |
SAL_WARN_IF( !xModel.is(), "xmloff", "need model" ); |
| 47 |
mxSubmission = xModel->createSubmission().get(); |
| 48 |
SAL_WARN_IF( !mxSubmission.is(), "xmloff", "can't create submission" ); |
| 49 |
xModel->getSubmissions()->insert( Any( mxSubmission ) ); |
| 50 |
} |
| 51 |
|
| 52 |
namespace { |
| 53 |
|
| 54 |
Any toBool( std::string_view rValue ) |
| 55 |
{ |
| 56 |
Any aValue; |
| 57 |
bool bValue(false); |
| 58 |
if (::sax::Converter::convertBool( bValue, rValue )) |
| 59 |
{ |
| 60 |
aValue <<= bValue; |
| 61 |
} |
| 62 |
return aValue; |
| 63 |
} |
| 64 |
|
| 65 |
} // namespace |
| 66 |
|
| 67 |
void XFormsSubmissionContext::HandleAttribute( const sax_fastparser::FastAttributeList::FastAttributeIter & aIter ) |
| 68 |
{ |
| 69 |
switch( aIter.getToken() & TOKEN_MASK ) |
| 70 |
{ |
| 71 |
case XML_ID: |
| 72 |
xforms_setValue( mxSubmission, u"ID"_ustr, aIter.toString() ); |
| 73 |
break; |
| 74 |
case XML_BIND: |
| 75 |
xforms_setValue( mxSubmission, u"Bind"_ustr, aIter.toString() ); |
| 76 |
break; |
| 77 |
case XML_REF: |
| 78 |
xforms_setValue( mxSubmission, u"Ref"_ustr, aIter.toString() ); |
| 79 |
break; |
| 80 |
case XML_ACTION: |
| 81 |
xforms_setValue( mxSubmission, u"Action"_ustr, aIter.toString() ); |
| 82 |
break; |
| 83 |
case XML_METHOD: |
| 84 |
xforms_setValue( mxSubmission, u"Method"_ustr, aIter.toString() ); |
| 85 |
break; |
| 86 |
case XML_VERSION: |
| 87 |
xforms_setValue( mxSubmission, u"Version"_ustr, aIter.toString() ); |
| 88 |
break; |
| 89 |
case XML_INDENT: |
| 90 |
xforms_setValue( mxSubmission, u"Indent"_ustr, toBool( aIter.toView() ) ); |
| 91 |
break; |
| 92 |
case XML_MEDIATYPE: |
| 93 |
xforms_setValue( mxSubmission, u"MediaType"_ustr, aIter.toString() ); |
| 94 |
break; |
| 95 |
case XML_ENCODING: |
| 96 |
xforms_setValue( mxSubmission, u"Encoding"_ustr, aIter.toString() ); |
| 97 |
break; |
| 98 |
case XML_OMIT_XML_DECLARATION: |
| 99 |
xforms_setValue( mxSubmission, u"OmitXmlDeclaration"_ustr, |
| 100 |
toBool( aIter.toView() ) ); |
| 101 |
break; |
| 102 |
case XML_STANDALONE: |
| 103 |
xforms_setValue( mxSubmission, u"Standalone"_ustr, toBool( aIter.toView() ) ); |
| 104 |
break; |
| 105 |
case XML_CDATA_SECTION_ELEMENTS: |
| 106 |
xforms_setValue( mxSubmission, u"CDataSectionElement"_ustr, aIter.toString() ); |
| 107 |
break; |
| 108 |
case XML_REPLACE: |
| 109 |
xforms_setValue( mxSubmission, u"Replace"_ustr, aIter.toString() ); |
| 110 |
break; |
| 111 |
case XML_SEPARATOR: |
| 112 |
xforms_setValue( mxSubmission, u"Separator"_ustr, aIter.toString() ); |
| 113 |
break; |
| 114 |
case XML_INCLUDENAMESPACEPREFIXES: |
| 115 |
xforms_setValue( mxSubmission, u"IncludeNamespacePrefixes"_ustr, aIter.toString() ); |
| 116 |
break; |
| 117 |
default: |
| 118 |
XMLOFF_WARN_UNKNOWN("xmloff", aIter); |
| 119 |
assert( false && "unknown attribute" ); |
| 120 |
break; |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
/** will be called for each child element */ |
| 125 |
SvXMLImportContext* XFormsSubmissionContext::HandleChild( |
| 126 |
sal_Int32, |
| 127 |
const Reference<css::xml::sax::XFastAttributeList>& ) |
| 128 |
{ |
| 129 |
assert( false && "no children supported" ); |
| 130 |
return nullptr; |
| 131 |
} |
| 132 |
|
| 133 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |