LibreOffice Module xmloff (master)  1
XFormsModelContext.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 
21 #include "XFormsModelContext.hxx"
22 
23 #include "XFormsBindContext.hxx"
26 #include "SchemaContext.hxx"
27 #include "xformsapi.hxx"
28 
29 #include <xmloff/xmlimp.hxx>
30 #include <xmloff/xmlnamespace.hxx>
31 #include <xmloff/namespacemap.hxx>
32 #include <xmloff/xmltoken.hxx>
33 #include <xmloff/xmlerror.hxx>
34 
35 #include <osl/diagnose.h>
36 
37 #include <com/sun/star/util/XUpdatable.hpp>
38 #include <com/sun/star/xforms/XModel2.hpp>
39 
40 
41 using com::sun::star::xml::sax::XAttributeList;
42 using com::sun::star::util::XUpdatable;
43 using namespace com::sun::star::uno;
44 using namespace xmloff::token;
45 
46 
48 {
50  TOKEN_MAP_ENTRY( NONE, SCHEMA ),
52 };
53 
55 {
56  TOKEN_MAP_ENTRY( XFORMS, INSTANCE ),
57  TOKEN_MAP_ENTRY( XFORMS, BIND ),
58  TOKEN_MAP_ENTRY( XFORMS, SUBMISSION ),
59  TOKEN_MAP_ENTRY( XSD, SCHEMA ),
61 };
62 
63 
65  sal_uInt16 nPrefix,
66  const OUString& rLocalName ) :
67  TokenContext( rImport, nPrefix, rLocalName, aAttributes, aChildren ),
69 {
70 }
71 
73  sal_uInt16 nToken,
74  const OUString& rValue )
75 {
76  switch( nToken )
77  {
78  case XML_ID:
79  mxModel->setPropertyValue( "ID", makeAny( rValue ) );
80  break;
81  case XML_SCHEMA:
83  break;
84  default:
85  OSL_FAIL( "this should not happen" );
86  break;
87  }
88 }
89 
91  sal_uInt16 nToken,
92  sal_uInt16 nPrefix,
93  const OUString& rLocalName,
95 {
96  SvXMLImportContext* pContext = nullptr;
97 
98  switch( nToken )
99  {
100  case XML_INSTANCE:
101  pContext = new XFormsInstanceContext( GetImport(), nPrefix, rLocalName,
102  mxModel );
103  break;
104  case XML_BIND:
105  pContext = new XFormsBindContext( GetImport(), nPrefix, rLocalName,
106  mxModel );
107  break;
108  case XML_SUBMISSION:
109  pContext = new XFormsSubmissionContext( GetImport(), nPrefix,
110  rLocalName, mxModel );
111  break;
112  case XML_SCHEMA:
113  pContext = new SchemaContext(
114  GetImport(), nPrefix, rLocalName, mxModel->getDataTypeRepository() );
115  break;
116  default:
117  OSL_FAIL( "Boooo!" );
118  break;
119  }
120 
121  return pContext;
122 }
123 
125 {
126  // update before putting model into document
127  Reference<XUpdatable> xUpdate( mxModel, UNO_QUERY );
128  if( xUpdate.is() )
129  xUpdate->update();
130 
131  GetImport().initXForms();
132  xforms_addXFormsModel( GetImport().GetModel(), mxModel );
133 }
134 
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define ID
import the xforms:binding element
XFormsModelContext(SvXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLName)
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
css::uno::Reference< css::frame::XModel2 > mxModel
virtual void EndElement() override
EndElement is called before a context will be destructed, but after an elements context has been pars...
NONE
#define XML_TOKEN_MAP_END
Definition: xmltkmap.hxx:33
const SvXMLTokenMapEntry aChildren[]
css::uno::Any const & rValue
Definition: ImageStyle.hxx:38
#define TOKEN_MAP_ENTRY(NAMESPACE, TOKEN)
handle attributes through an SvXMLTokenMap
Reference< XModel2 > xforms_createXFormsModel()
Definition: xformsapi.cxx:61
css::uno::Reference< css::xforms::XModel2 > mxModel
virtual SvXMLImportContext * HandleChild(sal_uInt16 nToken, sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
will be called for each child element
import the data type declarations from an xsd:schema element
import the xforms:instance element
void xforms_addXFormsModel(const Reference< frame::XModel > &xDocument, const Reference< xforms::XModel2 > &xModel)
Definition: xformsapi.cxx:68
import the xforms:submission element
virtual void HandleAttribute(sal_uInt16 nToken, const OUString &rValue) override
will be called for each attribute
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
const SvXMLTokenMapEntry aAttributes[]
Handling of tokens in XML:
void SetError(sal_Int32 nId, const css::uno::Sequence< OUString > &rMsgParams, const OUString &rExceptionMessage, const css::uno::Reference< css::xml::sax::XLocator > &rLocator)
Record an error condition that occurred during import.
virtual void initXForms()
Definition: xmlimp.cxx:1909
#define XMLERROR_XFORMS_NO_SCHEMA_SUPPORT
Definition: xmlerror.hxx:59
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)