1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "XFormsInstanceContext.hxx"
23 #include "DomBuilderContext.hxx"
24 #include "xformsapi.hxx"
26 #include <rtl/ustring.hxx>
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/beans/PropertyValue.hpp>
30 #include <com/sun/star/xml/dom/XDocument.hpp>
31 #include <com/sun/star/xforms/XModel2.hpp>
32 #include <tools/debug.hxx>
34 #include <xmloff/xmlnmspe.hxx>
35 #include <xmloff/xmltoken.hxx>
36 #include <xmloff/xmlimp.hxx>
37 #include <xmloff/xmlerror.hxx>
38 #include <xmloff/nmspmap.hxx>
41 using com::sun::star::uno::Reference
;
42 using com::sun::star::uno::makeAny
;
43 using com::sun::star::uno::UNO_QUERY
;
44 using com::sun::star::uno::Sequence
;
45 using com::sun::star::xforms::XModel2
;
46 using com::sun::star::beans::XPropertySet
;
47 using com::sun::star::beans::PropertyValue
;
48 using com::sun::star::xml::sax::XAttributeList
;
50 using xmloff::token::IsXMLToken
;
51 using xmloff::token::XML_INSTANCE
;
52 using xmloff::token::XML_SRC
;
53 using xmloff::token::XML_ID
;
55 static SvXMLTokenMapEntry aAttributes
[] =
57 TOKEN_MAP_ENTRY( NONE
, SRC
),
58 TOKEN_MAP_ENTRY( NONE
, ID
),
62 XFormsInstanceContext::XFormsInstanceContext(
65 const OUString
& rLocalName
,
66 const Reference
<XModel2
> & xModel
) :
67 TokenContext( rImport
, nPrefix
, rLocalName
, aAttributes
, aEmptyMap
),
70 DBG_ASSERT( mxModel
.is(), "need model" );
73 XFormsInstanceContext::~XFormsInstanceContext()
77 SvXMLImportContext
* XFormsInstanceContext::CreateChildContext(
79 const OUString
& rLocalName
,
80 const Reference
<XAttributeList
>& )
82 SvXMLImportContext
* pContext
= NULL
;
84 // only the first element child of an xforms:instance element
85 // is used as an instance. The other children remainder must be
89 GetImport().SetError( XMLERROR_XFORMS_ONLY_ONE_INSTANCE_ELEMENT
, rLocalName
);
90 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
94 // create new DomBuilderContext. Save reference to tree in Model.
95 DomBuilderContext
* pInstance
=
96 new DomBuilderContext( GetImport(), nPrefix
, rLocalName
);
97 mxInstance
= pInstance
->getTree();
101 DBG_ASSERT( pContext
!= NULL
, "no context!" );
106 void XFormsInstanceContext::EndElement()
108 Sequence
<PropertyValue
> aSequence( 3 );
109 PropertyValue
* pSequence
= aSequence
.getArray();
110 pSequence
[0].Name
= OUString( "Instance" );
111 pSequence
[0].Value
<<= mxInstance
;
112 pSequence
[1].Name
= OUString( "ID" );
113 pSequence
[1].Value
<<= msId
;
114 pSequence
[2].Name
= OUString( "URL" );
115 pSequence
[2].Value
<<= msURL
;
117 mxModel
->getInstances()->insert( makeAny( aSequence
) );
121 void XFormsInstanceContext::HandleAttribute(
123 const OUString
& rValue
)
134 OSL_FAIL( "should not happen" );
139 SvXMLImportContext
* XFormsInstanceContext::HandleChild(
143 const Reference
<XAttributeList
>& )
145 OSL_FAIL( "to be handled by CreateChildContext" );
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */