merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / xforms / XFormsModelContext.cxx
blob91941bdb698d325457c09f799c13c875c18f8ee3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XFormsModelContext.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
34 #include "XFormsModelContext.hxx"
36 #include "XFormsBindContext.hxx"
37 #include "XFormsSubmissionContext.hxx"
38 #include "XFormsInstanceContext.hxx"
39 #include "SchemaContext.hxx"
40 #include "xformsapi.hxx"
42 #include <xmloff/xmlimp.hxx>
43 #include "xmlnmspe.hxx"
44 #include <xmloff/nmspmap.hxx>
45 #include <xmloff/xmltoken.hxx>
46 #include "xmlerror.hxx"
48 #include <com/sun/star/beans/XPropertySet.hpp>
49 #include <com/sun/star/xml/dom/XDocument.hpp>
50 #include <com/sun/star/util/XUpdatable.hpp>
51 #include <com/sun/star/xforms/XModel.hpp>
53 #include <tools/debug.hxx>
56 using rtl::OUString;
57 using com::sun::star::xml::sax::XAttributeList;
58 using com::sun::star::beans::XPropertySet;
59 using com::sun::star::util::XUpdatable;
60 using namespace com::sun::star::uno;
61 using namespace xmloff::token;
66 static SvXMLTokenMapEntry aAttributes[] =
68 TOKEN_MAP_ENTRY( NONE, ID ),
69 TOKEN_MAP_ENTRY( NONE, SCHEMA ),
70 XML_TOKEN_MAP_END
73 static SvXMLTokenMapEntry aChildren[] =
75 TOKEN_MAP_ENTRY( XFORMS, INSTANCE ),
76 TOKEN_MAP_ENTRY( XFORMS, BIND ),
77 TOKEN_MAP_ENTRY( XFORMS, SUBMISSION ),
78 TOKEN_MAP_ENTRY( XSD, SCHEMA ),
79 XML_TOKEN_MAP_END
83 XFormsModelContext::XFormsModelContext( SvXMLImport& rImport,
84 USHORT nPrefix,
85 const OUString& rLocalName ) :
86 TokenContext( rImport, nPrefix, rLocalName, aAttributes, aChildren ),
87 mxModel( lcl_createXFormsModel() )
91 XFormsModelContext::~XFormsModelContext()
96 Reference<XPropertySet> XFormsModelContext::getModel()
98 return mxModel;
102 void XFormsModelContext::HandleAttribute(
103 sal_uInt16 nToken,
104 const OUString& rValue )
106 switch( nToken )
108 case XML_ID:
109 mxModel->setPropertyValue( OUSTRING("ID"), makeAny( rValue ) );
110 break;
111 case XML_SCHEMA:
112 GetImport().SetError( XMLERROR_XFORMS_NO_SCHEMA_SUPPORT );
113 break;
114 default:
115 DBG_ERROR( "this should not happen" );
116 break;
120 SvXMLImportContext* XFormsModelContext::HandleChild(
121 sal_uInt16 nToken,
122 sal_uInt16 nPrefix,
123 const OUString& rLocalName,
124 const Reference<XAttributeList>& )
126 SvXMLImportContext* pContext = NULL;
128 switch( nToken )
130 case XML_INSTANCE:
131 pContext = new XFormsInstanceContext( GetImport(), nPrefix, rLocalName,
132 mxModel );
133 break;
134 case XML_BIND:
135 pContext = new XFormsBindContext( GetImport(), nPrefix, rLocalName,
136 mxModel );
137 break;
138 case XML_SUBMISSION:
139 pContext = new XFormsSubmissionContext( GetImport(), nPrefix,
140 rLocalName, mxModel );
141 break;
142 case XML_SCHEMA:
143 pContext = new SchemaContext(
144 GetImport(), nPrefix, rLocalName,
145 Reference<com::sun::star::xforms::XModel>( mxModel,
146 UNO_QUERY_THROW )
147 ->getDataTypeRepository() );
148 break;
149 default:
150 DBG_ERROR( "Boooo!" );
151 break;
154 return pContext;
157 void XFormsModelContext::EndElement()
159 // update before putting model into document
160 Reference<XUpdatable> xUpdate( mxModel, UNO_QUERY );
161 if( xUpdate.is() )
162 xUpdate->update();
164 GetImport().initXForms();
165 lcl_addXFormsModel( GetImport().GetModel(), getModel() );