Bump version to 24.04.3.4
[LibreOffice.git] / xmloff / source / xforms / XFormsInstanceContext.cxx
blobe6e6ec2a2fa48f0ae5c1d0af400654d2bce01afc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
25 #include <rtl/ustring.hxx>
26 #include <sal/log.hxx>
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <com/sun/star/beans/PropertyValue.hpp>
29 #include <com/sun/star/xml/dom/XDocument.hpp>
30 #include <com/sun/star/xforms/XModel2.hpp>
31 #include <osl/diagnose.h>
33 #include <xmloff/xmltoken.hxx>
34 #include <xmloff/xmlimp.hxx>
35 #include <xmloff/xmlerror.hxx>
36 #include <xmloff/namespacemap.hxx>
39 using com::sun::star::uno::Reference;
40 using com::sun::star::uno::Any;
41 using com::sun::star::uno::Sequence;
42 using com::sun::star::xforms::XModel2;
43 using com::sun::star::beans::PropertyValue;
45 using xmloff::token::XML_SRC;
46 using xmloff::token::XML_ID;
48 XFormsInstanceContext::XFormsInstanceContext(
49 SvXMLImport& rImport,
50 const Reference<XModel2> & xModel ) :
51 TokenContext( rImport ),
52 mxModel( xModel )
54 SAL_WARN_IF( !mxModel.is(), "xmloff", "need model" );
57 css::uno::Reference< css::xml::sax::XFastContextHandler > XFormsInstanceContext::createFastChildContext(
58 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
60 SvXMLImportContext* pContext = nullptr;
62 // only the first element child of an xforms:instance element
63 // is used as an instance. The other children remainder must be
64 // ignored.
65 if( mxInstance.is() )
67 const OUString& rLocalName = SvXMLImport::getNameFromToken( nElement );
68 GetImport().SetError( XMLERROR_XFORMS_ONLY_ONE_INSTANCE_ELEMENT, rLocalName );
70 else
72 // create new DomBuilderContext. Save reference to tree in Model.
73 DomBuilderContext* pInstance = new DomBuilderContext( GetImport(), nElement );
74 mxInstance = pInstance->getTree();
75 pContext = pInstance;
78 SAL_WARN_IF( pContext == nullptr, "xmloff", "no context!" );
79 return pContext;
83 css::uno::Reference< css::xml::sax::XFastContextHandler > XFormsInstanceContext::createUnknownChildContext(
84 const OUString & rNamespace, const OUString &rName, const css::uno::Reference< css::xml::sax::XFastAttributeList > & /*Attribs*/)
86 SvXMLImportContext* pContext = nullptr;
88 // only the first element child of an xforms:instance element
89 // is used as an instance. The other children remainder must be
90 // ignored.
91 if( mxInstance.is() )
93 GetImport().SetError( XMLERROR_XFORMS_ONLY_ONE_INSTANCE_ELEMENT, rName );
95 else
97 // create new DomBuilderContext. Save reference to tree in Model.
98 DomBuilderContext* pInstance = new DomBuilderContext( GetImport(), rNamespace, rName );
99 mxInstance = pInstance->getTree();
100 pContext = pInstance;
103 SAL_WARN_IF( pContext == nullptr, "xmloff", "no context!" );
104 return pContext;
108 void XFormsInstanceContext::endFastElement(sal_Int32 )
110 Sequence<PropertyValue> aSequence( 3 );
111 PropertyValue* pSequence = aSequence.getArray();
112 pSequence[0].Name = "Instance";
113 pSequence[0].Value <<= mxInstance;
114 pSequence[1].Name = "ID";
115 pSequence[1].Value <<= msId;
116 pSequence[2].Name = "URL";
117 pSequence[2].Value <<= msURL;
119 mxModel->getInstances()->insert( Any( aSequence ) );
122 void XFormsInstanceContext::endUnknownElement(const OUString & /*Namespace*/, const OUString & /*Name*/)
124 Sequence<PropertyValue> aSequence( 3 );
125 PropertyValue* pSequence = aSequence.getArray();
126 pSequence[0].Name = "Instance";
127 pSequence[0].Value <<= mxInstance;
128 pSequence[1].Name = "ID";
129 pSequence[1].Value <<= msId;
130 pSequence[2].Name = "URL";
131 pSequence[2].Value <<= msURL;
133 mxModel->getInstances()->insert( Any( aSequence ) );
136 void XFormsInstanceContext::HandleAttribute(const sax_fastparser::FastAttributeList::FastAttributeIter & aIter )
138 switch( aIter.getToken() & TOKEN_MASK )
140 case XML_SRC:
141 msURL = aIter.toString();
142 break;
143 case XML_ID:
144 msId = aIter.toString();
145 break;
146 default:
147 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
148 assert( false && "this should not happen" );
149 break;
153 SvXMLImportContext* XFormsInstanceContext::HandleChild(
154 sal_Int32,
155 const Reference<css::xml::sax::XFastAttributeList>& )
157 assert( false && "to be handled by CreateChildContext" );
158 return nullptr;
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */