1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*63bba73cSAndrew Rist * distributed with this work for additional information
6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at
10*63bba73cSAndrew Rist *
11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist *
13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the
17*63bba73cSAndrew Rist * specific language governing permissions and limitations
18*63bba73cSAndrew Rist * under the License.
19*63bba73cSAndrew Rist *
20*63bba73cSAndrew Rist *************************************************************/
21*63bba73cSAndrew Rist
22*63bba73cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "XFormsModelContext.hxx"
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include "XFormsBindContext.hxx"
30cdf0e10cSrcweir #include "XFormsSubmissionContext.hxx"
31cdf0e10cSrcweir #include "XFormsInstanceContext.hxx"
32cdf0e10cSrcweir #include "SchemaContext.hxx"
33cdf0e10cSrcweir #include "xformsapi.hxx"
34cdf0e10cSrcweir
35cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
36cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
37cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
38cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
39cdf0e10cSrcweir #include "xmloff/xmlerror.hxx"
40cdf0e10cSrcweir
41cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
42cdf0e10cSrcweir #include <com/sun/star/xml/dom/XDocument.hpp>
43cdf0e10cSrcweir #include <com/sun/star/util/XUpdatable.hpp>
44cdf0e10cSrcweir #include <com/sun/star/xforms/XModel.hpp>
45cdf0e10cSrcweir
46cdf0e10cSrcweir #include <tools/debug.hxx>
47cdf0e10cSrcweir
48cdf0e10cSrcweir
49cdf0e10cSrcweir using rtl::OUString;
50cdf0e10cSrcweir using com::sun::star::xml::sax::XAttributeList;
51cdf0e10cSrcweir using com::sun::star::beans::XPropertySet;
52cdf0e10cSrcweir using com::sun::star::util::XUpdatable;
53cdf0e10cSrcweir using namespace com::sun::star::uno;
54cdf0e10cSrcweir using namespace xmloff::token;
55cdf0e10cSrcweir
56cdf0e10cSrcweir
57cdf0e10cSrcweir
58cdf0e10cSrcweir
59cdf0e10cSrcweir static SvXMLTokenMapEntry aAttributes[] =
60cdf0e10cSrcweir {
61cdf0e10cSrcweir TOKEN_MAP_ENTRY( NONE, ID ),
62cdf0e10cSrcweir TOKEN_MAP_ENTRY( NONE, SCHEMA ),
63cdf0e10cSrcweir XML_TOKEN_MAP_END
64cdf0e10cSrcweir };
65cdf0e10cSrcweir
66cdf0e10cSrcweir static SvXMLTokenMapEntry aChildren[] =
67cdf0e10cSrcweir {
68cdf0e10cSrcweir TOKEN_MAP_ENTRY( XFORMS, INSTANCE ),
69cdf0e10cSrcweir TOKEN_MAP_ENTRY( XFORMS, BIND ),
70cdf0e10cSrcweir TOKEN_MAP_ENTRY( XFORMS, SUBMISSION ),
71cdf0e10cSrcweir TOKEN_MAP_ENTRY( XSD, SCHEMA ),
72cdf0e10cSrcweir XML_TOKEN_MAP_END
73cdf0e10cSrcweir };
74cdf0e10cSrcweir
75cdf0e10cSrcweir
XFormsModelContext(SvXMLImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName)76cdf0e10cSrcweir XFormsModelContext::XFormsModelContext( SvXMLImport& rImport,
77cdf0e10cSrcweir sal_uInt16 nPrefix,
78cdf0e10cSrcweir const OUString& rLocalName ) :
79cdf0e10cSrcweir TokenContext( rImport, nPrefix, rLocalName, aAttributes, aChildren ),
80cdf0e10cSrcweir mxModel( lcl_createXFormsModel() )
81cdf0e10cSrcweir {
82cdf0e10cSrcweir }
83cdf0e10cSrcweir
~XFormsModelContext()84cdf0e10cSrcweir XFormsModelContext::~XFormsModelContext()
85cdf0e10cSrcweir {
86cdf0e10cSrcweir }
87cdf0e10cSrcweir
88cdf0e10cSrcweir
getModel()89cdf0e10cSrcweir Reference<XPropertySet> XFormsModelContext::getModel()
90cdf0e10cSrcweir {
91cdf0e10cSrcweir return mxModel;
92cdf0e10cSrcweir }
93cdf0e10cSrcweir
94cdf0e10cSrcweir
HandleAttribute(sal_uInt16 nToken,const OUString & rValue)95cdf0e10cSrcweir void XFormsModelContext::HandleAttribute(
96cdf0e10cSrcweir sal_uInt16 nToken,
97cdf0e10cSrcweir const OUString& rValue )
98cdf0e10cSrcweir {
99cdf0e10cSrcweir switch( nToken )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir case XML_ID:
102cdf0e10cSrcweir mxModel->setPropertyValue( OUSTRING("ID"), makeAny( rValue ) );
103cdf0e10cSrcweir break;
104cdf0e10cSrcweir case XML_SCHEMA:
105cdf0e10cSrcweir GetImport().SetError( XMLERROR_XFORMS_NO_SCHEMA_SUPPORT );
106cdf0e10cSrcweir break;
107cdf0e10cSrcweir default:
108cdf0e10cSrcweir DBG_ERROR( "this should not happen" );
109cdf0e10cSrcweir break;
110cdf0e10cSrcweir }
111cdf0e10cSrcweir }
112cdf0e10cSrcweir
HandleChild(sal_uInt16 nToken,sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> &)113cdf0e10cSrcweir SvXMLImportContext* XFormsModelContext::HandleChild(
114cdf0e10cSrcweir sal_uInt16 nToken,
115cdf0e10cSrcweir sal_uInt16 nPrefix,
116cdf0e10cSrcweir const OUString& rLocalName,
117cdf0e10cSrcweir const Reference<XAttributeList>& )
118cdf0e10cSrcweir {
119cdf0e10cSrcweir SvXMLImportContext* pContext = NULL;
120cdf0e10cSrcweir
121cdf0e10cSrcweir switch( nToken )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir case XML_INSTANCE:
124cdf0e10cSrcweir pContext = new XFormsInstanceContext( GetImport(), nPrefix, rLocalName,
125cdf0e10cSrcweir mxModel );
126cdf0e10cSrcweir break;
127cdf0e10cSrcweir case XML_BIND:
128cdf0e10cSrcweir pContext = new XFormsBindContext( GetImport(), nPrefix, rLocalName,
129cdf0e10cSrcweir mxModel );
130cdf0e10cSrcweir break;
131cdf0e10cSrcweir case XML_SUBMISSION:
132cdf0e10cSrcweir pContext = new XFormsSubmissionContext( GetImport(), nPrefix,
133cdf0e10cSrcweir rLocalName, mxModel );
134cdf0e10cSrcweir break;
135cdf0e10cSrcweir case XML_SCHEMA:
136cdf0e10cSrcweir pContext = new SchemaContext(
137cdf0e10cSrcweir GetImport(), nPrefix, rLocalName,
138cdf0e10cSrcweir Reference<com::sun::star::xforms::XModel>( mxModel,
139cdf0e10cSrcweir UNO_QUERY_THROW )
140cdf0e10cSrcweir ->getDataTypeRepository() );
141cdf0e10cSrcweir break;
142cdf0e10cSrcweir default:
143cdf0e10cSrcweir DBG_ERROR( "Boooo!" );
144cdf0e10cSrcweir break;
145cdf0e10cSrcweir }
146cdf0e10cSrcweir
147cdf0e10cSrcweir return pContext;
148cdf0e10cSrcweir }
149cdf0e10cSrcweir
EndElement()150cdf0e10cSrcweir void XFormsModelContext::EndElement()
151cdf0e10cSrcweir {
152cdf0e10cSrcweir // update before putting model into document
153cdf0e10cSrcweir Reference<XUpdatable> xUpdate( mxModel, UNO_QUERY );
154cdf0e10cSrcweir if( xUpdate.is() )
155cdf0e10cSrcweir xUpdate->update();
156cdf0e10cSrcweir
157cdf0e10cSrcweir GetImport().initXForms();
158cdf0e10cSrcweir lcl_addXFormsModel( GetImport().GetModel(), getModel() );
159cdf0e10cSrcweir }
160