LibreOffice Module xmloff (master)  1
XFormsSubmissionContext.cxx
Go to the documentation of this file.
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 
22 
23 #include "xformsapi.hxx"
24 
25 #include <xmloff/xmlimp.hxx>
26 #include <xmloff/xmltoken.hxx>
27 #include <xmloff/xmltkmap.hxx>
28 #include <xmloff/namespacemap.hxx>
29 
30 #include <sax/tools/converter.hxx>
31 
32 #include <com/sun/star/xforms/XModel2.hpp>
33 
34 #include <osl/diagnose.h>
35 #include <sal/log.hxx>
36 
37 using com::sun::star::xml::sax::XAttributeList;
38 using com::sun::star::xforms::XModel2;
39 
40 using namespace com::sun::star::uno;
41 using namespace xmloff::token;
42 
43 
45  SvXMLImport& rImport,
46  const Reference<XModel2>& xModel ) :
47  TokenContext( rImport ),
48  mxSubmission()
49 {
50  // register submission with model
51  SAL_WARN_IF( !xModel.is(), "xmloff", "need model" );
52  mxSubmission = xModel->createSubmission().get();
53  SAL_WARN_IF( !mxSubmission.is(), "xmloff", "can't create submission" );
54  xModel->getSubmissions()->insert( makeAny( mxSubmission ) );
55 }
56 
57 namespace {
58 
59 Any toBool( std::u16string_view rValue )
60 {
61  Any aValue;
62  bool bValue(false);
63  if (::sax::Converter::convertBool( bValue, rValue ))
64  {
65  aValue <<= bValue;
66  }
67  return aValue;
68 }
69 
70 } // namespace
71 
72 void XFormsSubmissionContext::HandleAttribute( sal_Int32 nAttributeToken,
73  const OUString& rValue )
74 {
75  switch( nAttributeToken & TOKEN_MASK )
76  {
77  case XML_ID:
78  xforms_setValue( mxSubmission, "ID", rValue );
79  break;
80  case XML_BIND:
81  xforms_setValue( mxSubmission, "Bind", rValue );
82  break;
83  case XML_REF:
84  xforms_setValue( mxSubmission, "Ref", rValue );
85  break;
86  case XML_ACTION:
87  xforms_setValue( mxSubmission, "Action", rValue );
88  break;
89  case XML_METHOD:
90  xforms_setValue( mxSubmission, "Method", rValue );
91  break;
92  case XML_VERSION:
93  xforms_setValue( mxSubmission, "Version", rValue );
94  break;
95  case XML_INDENT:
96  xforms_setValue( mxSubmission, "Indent", toBool( rValue ) );
97  break;
98  case XML_MEDIATYPE:
99  xforms_setValue( mxSubmission, "MediaType", rValue );
100  break;
101  case XML_ENCODING:
102  xforms_setValue( mxSubmission, "Encoding", rValue );
103  break;
105  xforms_setValue( mxSubmission, "OmitXmlDeclaration",
106  toBool( rValue ) );
107  break;
108  case XML_STANDALONE:
109  xforms_setValue( mxSubmission, "Standalone", toBool( rValue ) );
110  break;
112  xforms_setValue( mxSubmission, "CDataSectionElement", rValue );
113  break;
114  case XML_REPLACE:
115  xforms_setValue( mxSubmission, "Replace", rValue );
116  break;
117  case XML_SEPARATOR:
118  xforms_setValue( mxSubmission, "Separator", rValue );
119  break;
121  xforms_setValue( mxSubmission, "IncludeNamespacePrefixes", rValue );
122  break;
123  default:
124  XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttributeToken, rValue);
125  assert( false && "unknown attribute" );
126  break;
127  }
128 }
129 
132  sal_Int32,
134 {
135  assert( false && "no children supported" );
136  return nullptr;
137 }
138 
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::beans::XPropertySet > mxSubmission
#define XMLOFF_WARN_UNKNOWN_ATTR(area, token, value)
Definition: xmlictxt.hxx:134
css::uno::Any const & rValue
Definition: ImageStyle.hxx:38
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
handle attributes through an SvXMLTokenMap
void xforms_setValue(Reference< XPropertySet > const &xPropertySet, const OUString &rName, const Any &rAny)
Definition: xformsapi.cxx:167
XFormsSubmissionContext(SvXMLImport &rImport, const css::uno::Reference< css::xforms::XModel2 > &xModel)
bool toBool(std::u16string_view rValue)
virtual SvXMLImportContext * HandleChild(sal_Int32 nElementToken, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
will be called for each child element
static bool convertBool(bool &rBool, std::u16string_view rString)
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:45
#define SAL_WARN_IF(condition, area, stream)
Handling of tokens in XML:
constexpr sal_Int32 TOKEN_MASK
Definition: xmlimp.hxx:91
virtual void HandleAttribute(sal_Int32 nAttributeToken, const OUString &rValue) override
will be called for each attribute
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)