Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / xmloff / source / xforms / XFormsBindContext.cxx
blobe0556fa80d2d0a931a7239abec903c26aea25135
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "XFormsBindContext.hxx"
23 #include "xformsapi.hxx"
25 #include <xmloff/xmlimp.hxx>
26 #include <xmloff/xmlerror.hxx>
27 #include <xmloff/xmltoken.hxx>
28 #include <xmloff/xmlnamespace.hxx>
29 #include <xmloff/namespacemap.hxx>
31 #include <com/sun/star/container/XNameContainer.hpp>
32 #include <com/sun/star/xforms/XModel2.hpp>
34 #include <sal/log.hxx>
36 using com::sun::star::uno::Reference;
37 using com::sun::star::uno::Any;
38 using com::sun::star::uno::UNO_QUERY;
39 using com::sun::star::container::XNameContainer;
40 using com::sun::star::xml::sax::XFastAttributeList;
41 using com::sun::star::xforms::XModel2;
42 using namespace xmloff::token;
44 // helper function; see below
45 static void lcl_fillNamespaceContainer( const SvXMLNamespaceMap&,
46 Reference<XNameContainer> const & );
48 XFormsBindContext::XFormsBindContext(
49 SvXMLImport& rImport,
50 const Reference<XModel2>& xModel ) :
51 TokenContext( rImport ),
52 mxModel( xModel )
54 // attach binding to model
55 mxBinding = mxModel->createBinding();
56 SAL_WARN_IF( !mxBinding.is(), "xmloff", "can't create binding" );
57 mxModel->getBindings()->insert( Any( mxBinding ) );
60 void XFormsBindContext::HandleAttribute( const sax_fastparser::FastAttributeList::FastAttributeIter & aIter )
62 switch( aIter.getToken() & TOKEN_MASK )
64 case XML_NODESET:
65 xforms_setValue( mxBinding, u"BindingExpression"_ustr, aIter.toString() );
66 break;
67 case XML_ID:
68 xforms_setValue( mxBinding, u"BindingID"_ustr, aIter.toString() );
69 break;
70 case XML_READONLY:
71 xforms_setValue( mxBinding, u"ReadonlyExpression"_ustr, aIter.toString() );
72 break;
73 case XML_RELEVANT:
74 xforms_setValue( mxBinding, u"RelevantExpression"_ustr, aIter.toString() );
75 break;
76 case XML_REQUIRED:
77 xforms_setValue( mxBinding, u"RequiredExpression"_ustr, aIter.toString() );
78 break;
79 case XML_CONSTRAINT:
80 xforms_setValue( mxBinding, u"ConstraintExpression"_ustr, aIter.toString() );
81 break;
82 case XML_CALCULATE:
83 xforms_setValue( mxBinding, u"CalculateExpression"_ustr, aIter.toString() );
84 break;
85 case XML_TYPE:
86 xforms_setValue( mxBinding, u"Type"_ustr,
87 xforms_getTypeName( mxModel->getDataTypeRepository(),
88 GetImport().GetNamespaceMap(),
89 aIter.toString() ) );
90 break;
91 default:
92 assert( false && "should not happen" );
93 break;
97 void XFormsBindContext::startFastElement(
98 sal_Int32 nElement,
99 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
101 // we need to register the namespaces
102 Reference<XNameContainer> xContainer(
103 mxBinding->getPropertyValue( u"BindingNamespaces"_ustr ),
104 UNO_QUERY );
106 SAL_WARN_IF( !xContainer.is(), "xmloff", "binding should have a namespace container" );
107 if( xContainer.is() )
108 lcl_fillNamespaceContainer( GetImport().GetNamespaceMap(), xContainer);
110 // call super-class for attribute handling
111 TokenContext::startFastElement( nElement, xAttrList );
114 /** will be called for each child element */
115 SvXMLImportContext* XFormsBindContext::HandleChild(
116 sal_Int32,
117 const Reference<XFastAttributeList>& )
119 assert( false && "no children supported" );
120 return nullptr;
124 static void lcl_fillNamespaceContainer(
125 const SvXMLNamespaceMap& aMap,
126 Reference<XNameContainer> const & xContainer )
128 sal_uInt16 nKeyIter = aMap.GetFirstKey();
131 // get prefix and namespace
132 const OUString& sPrefix = aMap.GetPrefixByKey( nKeyIter );
133 const OUString& sNamespace = aMap.GetNameByKey( nKeyIter );
135 // as a hack, we will ignore our own 'default' namespaces
136 SAL_WARN_IF( sPrefix.isEmpty(), "xmloff", "no prefix?" );
137 if( !sPrefix.startsWith("_") &&
138 nKeyIter >= XML_NAMESPACE_META_SO52)
140 // insert prefix (use replace if already known)
141 if( xContainer->hasByName( sPrefix ) )
142 xContainer->replaceByName( sPrefix, Any( sNamespace ) );
143 else
144 xContainer->insertByName( sPrefix, Any( sNamespace ) );
147 // proceed to next
148 nKeyIter = aMap.GetNextKey( nKeyIter );
150 while( nKeyIter != XML_NAMESPACE_UNKNOWN );
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */