LibreOffice Module xmloff (master) 1
XFormsBindContext.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 "XFormsBindContext.hxx"
22
23#include "xformsapi.hxx"
24
25#include <xmloff/xmlimp.hxx>
26#include <xmloff/xmlerror.hxx>
27#include <xmloff/xmltoken.hxx>
28#include <xmloff/xmltkmap.hxx>
31
32#include <com/sun/star/container/XNameContainer.hpp>
33#include <com/sun/star/xforms/XModel2.hpp>
34
35#include <osl/diagnose.h>
36#include <sal/log.hxx>
37
39using com::sun::star::uno::Any;
40using com::sun::star::uno::UNO_QUERY;
41using com::sun::star::container::XNameContainer;
42using com::sun::star::xml::sax::XFastAttributeList;
43using com::sun::star::xforms::XModel2;
44using namespace xmloff::token;
45
46// helper function; see below
49
51 SvXMLImport& rImport,
52 const Reference<XModel2>& xModel ) :
53 TokenContext( rImport ),
55{
56 // attach binding to model
57 mxBinding = mxModel->createBinding();
58 SAL_WARN_IF( !mxBinding.is(), "xmloff", "can't create binding" );
59 mxModel->getBindings()->insert( Any( mxBinding ) );
60}
61
63{
64 switch( aIter.getToken() & TOKEN_MASK )
65 {
66 case XML_NODESET:
67 xforms_setValue( mxBinding, "BindingExpression", aIter.toString() );
68 break;
69 case XML_ID:
70 xforms_setValue( mxBinding, "BindingID", aIter.toString() );
71 break;
72 case XML_READONLY:
73 xforms_setValue( mxBinding, "ReadonlyExpression", aIter.toString() );
74 break;
75 case XML_RELEVANT:
76 xforms_setValue( mxBinding, "RelevantExpression", aIter.toString() );
77 break;
78 case XML_REQUIRED:
79 xforms_setValue( mxBinding, "RequiredExpression", aIter.toString() );
80 break;
81 case XML_CONSTRAINT:
82 xforms_setValue( mxBinding, "ConstraintExpression", aIter.toString() );
83 break;
84 case XML_CALCULATE:
85 xforms_setValue( mxBinding, "CalculateExpression", aIter.toString() );
86 break;
87 case XML_TYPE:
89 xforms_getTypeName( mxModel->getDataTypeRepository(),
90 GetImport().GetNamespaceMap(),
91 aIter.toString() ) );
92 break;
93 default:
94 assert( false && "should not happen" );
95 break;
96 }
97}
98
100 sal_Int32 nElement,
101 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
102{
103 // we need to register the namespaces
104 Reference<XNameContainer> xContainer(
105 mxBinding->getPropertyValue( "BindingNamespaces" ),
106 UNO_QUERY );
107
108 SAL_WARN_IF( !xContainer.is(), "xmloff", "binding should have a namespace container" );
109 if( xContainer.is() )
110 lcl_fillNamespaceContainer( GetImport().GetNamespaceMap(), xContainer);
111
112 // call super-class for attribute handling
113 TokenContext::startFastElement( nElement, xAttrList );
114}
115
118 sal_Int32,
120{
121 assert( false && "no children supported" );
122 return nullptr;
123}
124
125
127 const SvXMLNamespaceMap& aMap,
128 Reference<XNameContainer> const & xContainer )
129{
130 sal_uInt16 nKeyIter = aMap.GetFirstKey();
131 do
132 {
133 // get prefix and namespace
134 const OUString& sPrefix = aMap.GetPrefixByKey( nKeyIter );
135 const OUString& sNamespace = aMap.GetNameByKey( nKeyIter );
136
137 // as a hack, we will ignore our own 'default' namespaces
138 SAL_WARN_IF( sPrefix.isEmpty(), "xmloff", "no prefix?" );
139 if( !sPrefix.startsWith("_") &&
140 nKeyIter >= XML_NAMESPACE_META_SO52)
141 {
142 // insert prefix (use replace if already known)
143 if( xContainer->hasByName( sPrefix ) )
144 xContainer->replaceByName( sPrefix, Any( sNamespace ) );
145 else
146 xContainer->insertByName( sPrefix, Any( sNamespace ) );
147 }
148
149 // proceed to next
150 nKeyIter = aMap.GetNextKey( nKeyIter );
151 }
152 while( nKeyIter != XML_NAMESPACE_UNKNOWN );
153}
154
155/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::frame::XModel2 > mxModel
static void lcl_fillNamespaceContainer(const SvXMLNamespaceMap &, Reference< XNameContainer > const &)
This class deliberately does not support XWeak, to improve performance when loading large documents.
Definition: xmlictxt.hxx:48
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:60
handle attributes through an SvXMLTokenMap
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
call HandleAttribute for each attribute in the token map; create a warning for all others.
virtual SvXMLImportContext * HandleChild(sal_Int32 nElementToken, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
will be called for each child element
const css::uno::Reference< css::xforms::XModel2 > mxModel
css::uno::Reference< css::beans::XPropertySet > mxBinding
XFormsBindContext(SvXMLImport &rImport, const css::uno::Reference< css::xforms::XModel2 > &xModel)
virtual void HandleAttribute(const sax_fastparser::FastAttributeList::FastAttributeIter &aIter) override
will be called for each attribute
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
call HandleAttribute for each attribute in the token map; create a warning for all others.
OUString sPrefix
#define SAL_WARN_IF(condition, area, stream)
const sal_uInt16 XML_NAMESPACE_UNKNOWN
Handling of tokens in XML:
HashMap_OWString_Interface aMap
Reference< XModel > xModel
OUString xforms_getTypeName(const Reference< XDataTypeRepository > &xRepository, const SvXMLNamespaceMap &rNamespaceMap, const OUString &rXMLName)
Definition: xformsapi.cxx:262
void xforms_setValue(const css::uno::Reference< css::beans::XPropertySet > &xPropSet, const OUString &rName, const T &aValue)
Definition: xformsapi.hxx:52
constexpr sal_Int32 TOKEN_MASK
Definition: xmlimp.hxx:95
constexpr sal_uInt16 XML_NAMESPACE_META_SO52