Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "XFormsBindContext.hxx"
31 : :
32 : : #include "xformsapi.hxx"
33 : :
34 : : #include <xmloff/xmlimp.hxx>
35 : : #include "xmloff/xmlerror.hxx"
36 : : #include <xmloff/xmltoken.hxx>
37 : : #include <xmloff/xmltkmap.hxx>
38 : : #include "xmloff/xmlnmspe.hxx"
39 : : #include <xmloff/nmspmap.hxx>
40 : :
41 : : #include <com/sun/star/container/XNameContainer.hpp>
42 : : #include <com/sun/star/xforms/XModel.hpp>
43 : :
44 : : #include <tools/debug.hxx>
45 : :
46 : : using rtl::OUString;
47 : : using com::sun::star::beans::XPropertySet;
48 : : using com::sun::star::uno::Reference;
49 : : using com::sun::star::uno::makeAny;
50 : : using com::sun::star::uno::UNO_QUERY;
51 : : using com::sun::star::uno::UNO_QUERY_THROW;
52 : : using com::sun::star::container::XNameContainer;
53 : : using com::sun::star::xml::sax::XAttributeList;
54 : : using com::sun::star::xforms::XModel;
55 : : using namespace xmloff::token;
56 : :
57 : :
58 : :
59 : :
60 : : static struct SvXMLTokenMapEntry aAttributeMap[] =
61 : : {
62 : : TOKEN_MAP_ENTRY( NONE, NODESET ),
63 : : TOKEN_MAP_ENTRY( NONE, ID ),
64 : : TOKEN_MAP_ENTRY( NONE, READONLY ),
65 : : TOKEN_MAP_ENTRY( NONE, RELEVANT ),
66 : : TOKEN_MAP_ENTRY( NONE, REQUIRED ),
67 : : TOKEN_MAP_ENTRY( NONE, CONSTRAINT ),
68 : : TOKEN_MAP_ENTRY( NONE, CALCULATE ),
69 : : TOKEN_MAP_ENTRY( NONE, TYPE ),
70 : : XML_TOKEN_MAP_END
71 : : };
72 : :
73 : : // helper function; see below
74 : : void lcl_fillNamespaceContainer( const SvXMLNamespaceMap&,
75 : : Reference<XNameContainer>& );
76 : :
77 : 0 : XFormsBindContext::XFormsBindContext(
78 : : SvXMLImport& rImport,
79 : : sal_uInt16 nPrefix,
80 : : const OUString& rLocalName,
81 : : const Reference<XPropertySet>& xModel ) :
82 : : TokenContext( rImport, nPrefix, rLocalName, aAttributeMap, aEmptyMap ),
83 : : mxModel( xModel, UNO_QUERY_THROW ),
84 [ # # ][ # # ]: 0 : mxBinding( NULL )
85 : : {
86 : : // attach binding to model
87 [ # # ][ # # ]: 0 : mxBinding = mxModel->createBinding();
[ # # ]
88 : : DBG_ASSERT( mxBinding.is(), "can't create binding" );
89 [ # # ][ # # ]: 0 : mxModel->getBindings()->insert( makeAny( mxBinding ) );
[ # # ][ # # ]
[ # # ]
90 : 0 : }
91 : :
92 : 0 : XFormsBindContext::~XFormsBindContext()
93 : : {
94 [ # # ]: 0 : }
95 : :
96 : 0 : void XFormsBindContext::HandleAttribute( sal_uInt16 nToken,
97 : : const OUString& rValue )
98 : : {
99 [ # # # # : 0 : switch( nToken )
# # # #
# ]
100 : : {
101 : : case XML_NODESET:
102 [ # # ]: 0 : lcl_setValue( mxBinding, OUSTRING("BindingExpression"), rValue );
103 : 0 : break;
104 : : case XML_ID:
105 [ # # ]: 0 : lcl_setValue( mxBinding, OUSTRING("BindingID"), rValue );
106 : 0 : break;
107 : : case XML_READONLY:
108 [ # # ]: 0 : lcl_setValue( mxBinding, OUSTRING("ReadonlyExpression"), rValue );
109 : 0 : break;
110 : : case XML_RELEVANT:
111 [ # # ]: 0 : lcl_setValue( mxBinding, OUSTRING("RelevantExpression"), rValue );
112 : 0 : break;
113 : : case XML_REQUIRED:
114 [ # # ]: 0 : lcl_setValue( mxBinding, OUSTRING("RequiredExpression"), rValue );
115 : 0 : break;
116 : : case XML_CONSTRAINT:
117 [ # # ]: 0 : lcl_setValue( mxBinding, OUSTRING("ConstraintExpression"), rValue );
118 : 0 : break;
119 : : case XML_CALCULATE:
120 [ # # ]: 0 : lcl_setValue( mxBinding, OUSTRING("CalculateExpression"), rValue );
121 : 0 : break;
122 : : case XML_TYPE:
123 : : lcl_setValue( mxBinding, OUSTRING("Type"),
124 : 0 : makeAny( lcl_getTypeName( mxModel->getDataTypeRepository(),
125 : 0 : GetImport().GetNamespaceMap(),
126 [ # # ][ # # ]: 0 : rValue ) ) );
[ # # ][ # # ]
127 : 0 : break;
128 : : default:
129 : : OSL_FAIL( "should not happen" );
130 : 0 : break;
131 : : }
132 : 0 : }
133 : :
134 : 0 : void XFormsBindContext::StartElement(
135 : : const Reference<XAttributeList>& xAttributeList )
136 : : {
137 : : // we need to register the namespaces
138 : : Reference<XNameContainer> xContainer(
139 [ # # ]: 0 : mxBinding->getPropertyValue( OUSTRING("BindingNamespaces") ),
140 [ # # ][ # # ]: 0 : UNO_QUERY );
[ # # ]
141 : :
142 : : DBG_ASSERT( xContainer.is(), "binding should have a namespace container" );
143 [ # # ]: 0 : if( xContainer.is() )
144 [ # # ]: 0 : lcl_fillNamespaceContainer( GetImport().GetNamespaceMap(), xContainer);
145 : :
146 : : // call super-class for attribute handling
147 [ # # ]: 0 : TokenContext::StartElement( xAttributeList );
148 : 0 : }
149 : :
150 : : /** will be called for each child element */
151 : 0 : SvXMLImportContext* XFormsBindContext::HandleChild(
152 : : sal_uInt16,
153 : : sal_uInt16,
154 : : const OUString&,
155 : : const Reference<XAttributeList>& )
156 : : {
157 : : OSL_FAIL( "no children supported" );
158 : 0 : return NULL;
159 : : }
160 : :
161 : :
162 : 0 : void lcl_fillNamespaceContainer(
163 : : const SvXMLNamespaceMap& aMap,
164 : : Reference<XNameContainer>& xContainer )
165 : : {
166 : 0 : sal_uInt16 nKeyIter = aMap.GetFirstKey();
167 [ # # ]: 0 : do
168 : : {
169 : : // get prefix and namespace
170 : 0 : const OUString& sPrefix = aMap.GetPrefixByKey( nKeyIter );
171 : 0 : const OUString& sNamespace = aMap.GetNameByKey( nKeyIter );
172 : :
173 : : // as a hack, we will ignore our own 'default' namespaces
174 : : DBG_ASSERT( !sPrefix.isEmpty(), "no prefix?" );
175 [ # # ][ # # ]: 0 : if( sPrefix.getStr()[0] != sal_Unicode( '_' ) &&
[ # # ]
176 : : nKeyIter >= XML_OLD_NAMESPACE_META_IDX )
177 : : {
178 : : // insert prefix (use replace if already known)
179 [ # # ]: 0 : if( xContainer->hasByName( sPrefix ) )
180 [ # # ]: 0 : xContainer->replaceByName( sPrefix, makeAny( sNamespace ) );
181 : : else
182 [ # # ]: 0 : xContainer->insertByName( sPrefix, makeAny( sNamespace ) );
183 : : }
184 : :
185 : : // proceed to next
186 : 0 : nKeyIter = aMap.GetNextKey( nKeyIter );
187 : : }
188 : : while( nKeyIter != XML_NAMESPACE_UNKNOWN );
189 : 0 : }
190 : :
191 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|