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