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 "XFormsInstanceContext.hxx" 32 33 #include "DomBuilderContext.hxx" 34 #include "xformsapi.hxx" 35 36 #include <rtl/ustring.hxx> 37 #include <com/sun/star/uno/Reference.hxx> 38 #include <com/sun/star/beans/XPropertySet.hpp> 39 #include <com/sun/star/beans/PropertyValue.hpp> 40 #include <com/sun/star/xml/dom/XDocument.hpp> 41 #include <com/sun/star/xforms/XModel.hpp> 42 #include <tools/debug.hxx> 43 44 #include <xmloff/xmlnmspe.hxx> 45 #include <xmloff/xmltoken.hxx> 46 #include <xmloff/xmlimp.hxx> 47 #include <xmloff/xmlerror.hxx> 48 #include <xmloff/nmspmap.hxx> 49 50 51 using rtl::OUString; 52 using com::sun::star::uno::Reference; 53 using com::sun::star::uno::makeAny; 54 using com::sun::star::uno::UNO_QUERY; 55 using com::sun::star::uno::Sequence; 56 using com::sun::star::xforms::XModel; 57 using com::sun::star::beans::XPropertySet; 58 using com::sun::star::beans::PropertyValue; 59 using com::sun::star::xml::sax::XAttributeList; 60 61 using xmloff::token::IsXMLToken; 62 using xmloff::token::XML_INSTANCE; 63 using xmloff::token::XML_SRC; 64 using xmloff::token::XML_ID; 65 66 static SvXMLTokenMapEntry aAttributes[] = 67 { 68 TOKEN_MAP_ENTRY( NONE, SRC ), 69 TOKEN_MAP_ENTRY( NONE, ID ), 70 XML_TOKEN_MAP_END 71 }; 72 73 XFormsInstanceContext::XFormsInstanceContext( 74 SvXMLImport& rImport, 75 sal_uInt16 nPrefix, 76 const OUString& rLocalName, 77 Reference<XPropertySet> xModel ) : 78 TokenContext( rImport, nPrefix, rLocalName, aAttributes, aEmptyMap ), 79 mxModel( Reference<XModel>( xModel, UNO_QUERY ) ) 80 { 81 DBG_ASSERT( mxModel.is(), "need model" ); 82 } 83 84 XFormsInstanceContext::~XFormsInstanceContext() 85 { 86 } 87 88 SvXMLImportContext* XFormsInstanceContext::CreateChildContext( 89 sal_uInt16 nPrefix, 90 const OUString& rLocalName, 91 const Reference<XAttributeList>& ) 92 { 93 SvXMLImportContext* pContext = NULL; 94 95 // only the first element child of an xforms:instance element 96 // is used as an instance. The other children remainder must be 97 // ignored. 98 if( mxInstance.is() ) 99 { 100 GetImport().SetError( XMLERROR_XFORMS_ONLY_ONE_INSTANCE_ELEMENT, rLocalName ); 101 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); 102 } 103 else 104 { 105 // create new DomBuilderContext. Save reference to tree in Model. 106 DomBuilderContext* pInstance = 107 new DomBuilderContext( GetImport(), nPrefix, rLocalName ); 108 mxInstance = pInstance->getTree(); 109 pContext = pInstance; 110 } 111 112 DBG_ASSERT( pContext != NULL, "no context!" ); 113 return pContext; 114 115 } 116 117 void XFormsInstanceContext::EndElement() 118 { 119 Sequence<PropertyValue> aSequence( 3 ); 120 PropertyValue* pSequence = aSequence.getArray(); 121 pSequence[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("Instance") ); 122 pSequence[0].Value <<= mxInstance; 123 pSequence[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("ID") ); 124 pSequence[1].Value <<= msId; 125 pSequence[2].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("URL") ); 126 pSequence[2].Value <<= msURL; 127 128 mxModel->getInstances()->insert( makeAny( aSequence ) ); 129 } 130 131 132 void XFormsInstanceContext::HandleAttribute( 133 sal_uInt16 nToken, 134 const rtl::OUString& rValue ) 135 { 136 switch( nToken ) 137 { 138 case XML_SRC: 139 msURL = rValue; 140 break; 141 case XML_ID: 142 msId = rValue; 143 break; 144 default: 145 DBG_ERROR( "should not happen" ); 146 break; 147 } 148 } 149 150 SvXMLImportContext* XFormsInstanceContext::HandleChild( 151 sal_uInt16, 152 sal_uInt16, 153 const OUString&, 154 const Reference<XAttributeList>& ) 155 { 156 DBG_ERROR( "to be handled by CreateChildContext" ); 157 return NULL; 158 } 159