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