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