LibreOffice Module xmloff (master) 1
XFormsInstanceContext.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
22
23#include <DomBuilderContext.hxx>
24
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>
32
33#include <xmloff/xmltoken.hxx>
34#include <xmloff/xmlimp.hxx>
35#include <xmloff/xmlerror.hxx>
37
38
40using com::sun::star::uno::Any;
42using com::sun::star::xforms::XModel2;
43using com::sun::star::beans::PropertyValue;
44using com::sun::star::xml::sax::XAttributeList;
45
48
50 SvXMLImport& rImport,
51 const Reference<XModel2> & xModel ) :
52 TokenContext( rImport ),
54{
55 SAL_WARN_IF( !mxModel.is(), "xmloff", "need model" );
56}
57
58css::uno::Reference< css::xml::sax::XFastContextHandler > XFormsInstanceContext::createFastChildContext(
59 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
60{
61 SvXMLImportContext* pContext = nullptr;
62
63 // only the first element child of an xforms:instance element
64 // is used as an instance. The other children remainder must be
65 // ignored.
66 if( mxInstance.is() )
67 {
68 const OUString& rLocalName = SvXMLImport::getNameFromToken( nElement );
70 }
71 else
72 {
73 // create new DomBuilderContext. Save reference to tree in Model.
74 DomBuilderContext* pInstance = new DomBuilderContext( GetImport(), nElement );
75 mxInstance = pInstance->getTree();
76 pContext = pInstance;
77 }
78
79 SAL_WARN_IF( pContext == nullptr, "xmloff", "no context!" );
80 return pContext;
81
82}
83
84css::uno::Reference< css::xml::sax::XFastContextHandler > XFormsInstanceContext::createUnknownChildContext(
85 const OUString & rNamespace, const OUString &rName, const css::uno::Reference< css::xml::sax::XFastAttributeList > & /*Attribs*/)
86{
87 SvXMLImportContext* pContext = nullptr;
88
89 // only the first element child of an xforms:instance element
90 // is used as an instance. The other children remainder must be
91 // ignored.
92 if( mxInstance.is() )
93 {
95 }
96 else
97 {
98 // create new DomBuilderContext. Save reference to tree in Model.
99 DomBuilderContext* pInstance = new DomBuilderContext( GetImport(), rNamespace, rName );
100 mxInstance = pInstance->getTree();
101 pContext = pInstance;
102 }
103
104 SAL_WARN_IF( pContext == nullptr, "xmloff", "no context!" );
105 return pContext;
106
107}
108
110{
111 Sequence<PropertyValue> aSequence( 3 );
112 PropertyValue* pSequence = aSequence.getArray();
113 pSequence[0].Name = "Instance";
114 pSequence[0].Value <<= mxInstance;
115 pSequence[1].Name = "ID";
116 pSequence[1].Value <<= msId;
117 pSequence[2].Name = "URL";
118 pSequence[2].Value <<= msURL;
119
120 mxModel->getInstances()->insert( Any( aSequence ) );
121}
122
123void XFormsInstanceContext::endUnknownElement(const OUString & /*Namespace*/, const OUString & /*Name*/)
124{
125 Sequence<PropertyValue> aSequence( 3 );
126 PropertyValue* pSequence = aSequence.getArray();
127 pSequence[0].Name = "Instance";
128 pSequence[0].Value <<= mxInstance;
129 pSequence[1].Name = "ID";
130 pSequence[1].Value <<= msId;
131 pSequence[2].Name = "URL";
132 pSequence[2].Value <<= msURL;
133
134 mxModel->getInstances()->insert( Any( aSequence ) );
135}
136
138{
139 switch( aIter.getToken() & TOKEN_MASK )
140 {
141 case XML_SRC:
142 msURL = aIter.toString();
143 break;
144 case XML_ID:
145 msId = aIter.toString();
146 break;
147 default:
148 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
149 assert( false && "this should not happen" );
150 break;
151 }
152}
153
155 sal_Int32,
157{
158 assert( false && "to be handled by CreateChildContext" );
159 return nullptr;
160}
161
162/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::frame::XModel2 > mxModel
DomBuilderContext creates a DOM tree suitable for in-memory processing of XML data from a sequence of...
css::uno::Reference< css::xml::dom::XDocument > getTree()
access the DOM tree
This class deliberately does not support XWeak, to improve performance when loading large documents.
Definition: xmlictxt.hxx:48
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:60
static const OUString & getNameFromToken(sal_Int32 nToken)
Definition: xmlimp.cxx:1950
void SetError(sal_Int32 nId, const css::uno::Sequence< OUString > &rMsgParams, const OUString &rExceptionMessage, const css::uno::Reference< css::xml::sax::XLocator > &rLocator)
Record an error condition that occurred during import.
handle attributes through an SvXMLTokenMap
css::uno::Reference< css::xml::dom::XDocument > mxInstance
virtual SvXMLImportContext * HandleChild(sal_Int32 nElementToken, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
will be called for each child element
XFormsInstanceContext(SvXMLImport &rImport, const css::uno::Reference< css::xforms::XModel2 > &xModel)
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
virtual void SAL_CALL endUnknownElement(const OUString &Namespace, const OUString &Name) override
css::uno::Reference< css::xforms::XModel2 > mxModel
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
call HandleChild for each child element in the token map; create a warning for all others.
virtual void HandleAttribute(const sax_fastparser::FastAttributeList::FastAttributeIter &aIter) override
will be called for each attribute
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createUnknownChildContext(const OUString &Namespace, const OUString &Name, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
#define SAL_WARN_IF(condition, area, stream)
Reference< XModel > xModel
#define XMLERROR_XFORMS_ONLY_ONE_INSTANCE_ELEMENT
Definition: xmlerror.hxx:61
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:114
constexpr sal_Int32 TOKEN_MASK
Definition: xmlimp.hxx:94