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>
36 #include <xmloff/namespacemap.hxx>
37 
38 
42 using com::sun::star::xforms::XModel2;
43 using com::sun::star::beans::PropertyValue;
44 using com::sun::star::xml::sax::XAttributeList;
45 
48 
50 {
54 };
55 
57  SvXMLImport& rImport,
58  sal_uInt16 nPrefix,
59  const OUString& rLocalName,
60  const Reference<XModel2> & xModel ) :
61  TokenContext( rImport, nPrefix, rLocalName, aAttributes, aEmptyMap ),
62  mxModel( xModel )
63 {
64  SAL_WARN_IF( !mxModel.is(), "xmloff", "need model" );
65 }
66 
68  sal_uInt16 nPrefix,
69  const OUString& rLocalName,
71 {
72  SvXMLImportContext* pContext = nullptr;
73 
74  // only the first element child of an xforms:instance element
75  // is used as an instance. The other children remainder must be
76  // ignored.
77  if( mxInstance.is() )
78  {
80  }
81  else
82  {
83  // create new DomBuilderContext. Save reference to tree in Model.
84  DomBuilderContext* pInstance =
85  new DomBuilderContext( GetImport(), nPrefix, rLocalName );
86  mxInstance = pInstance->getTree();
87  pContext = pInstance;
88  }
89 
90  SAL_WARN_IF( pContext == nullptr, "xmloff", "no context!" );
91  return pContext;
92 
93 }
94 
96 {
97  Sequence<PropertyValue> aSequence( 3 );
98  PropertyValue* pSequence = aSequence.getArray();
99  pSequence[0].Name = "Instance";
100  pSequence[0].Value <<= mxInstance;
101  pSequence[1].Name = "ID";
102  pSequence[1].Value <<= msId;
103  pSequence[2].Name = "URL";
104  pSequence[2].Value <<= msURL;
105 
106  mxModel->getInstances()->insert( makeAny( aSequence ) );
107 }
108 
109 
111  sal_uInt16 nToken,
112  const OUString& rValue )
113 {
114  switch( nToken )
115  {
116  case XML_SRC:
117  msURL = rValue;
118  break;
119  case XML_ID:
120  msId = rValue;
121  break;
122  default:
123  OSL_FAIL( "should not happen" );
124  break;
125  }
126 }
127 
129  sal_uInt16,
130  sal_uInt16,
131  const OUString&,
133 {
134  OSL_FAIL( "to be handled by CreateChildContext" );
135  return nullptr;
136 }
137 
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define ID
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
call HandleChild for each child element in the token map; create a warning for all others...
css::uno::Reference< css::frame::XModel2 > mxModel
virtual void EndElement() override
EndElement is called before a context will be destructed, but after an elements context has been pars...
css::uno::Reference< css::xml::dom::XDocument > mxInstance
NONE
virtual SvXMLImportContext * HandleChild(sal_uInt16 nToken, sal_uInt16 nNamespace, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
will be called for each child element
#define XML_TOKEN_MAP_END
Definition: xmltkmap.hxx:33
css::uno::Any const & rValue
Definition: ImageStyle.hxx:38
DomBuilderContext creates a DOM tree suitable for in-memory processing of XML data from a sequence of...
const SvXMLTokenMapEntry aEmptyMap[1]
#define TOKEN_MAP_ENTRY(NAMESPACE, TOKEN)
handle attributes through an SvXMLTokenMap
XFormsInstanceContext(SvXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLName, const css::uno::Reference< css::xforms::XModel2 > &xModel)
css::uno::Reference< css::xforms::XModel2 > mxModel
const SvXMLTokenMapEntry aAttributes[]
#define XMLERROR_XFORMS_ONLY_ONE_INSTANCE_ELEMENT
Definition: xmlerror.hxx:61
virtual void HandleAttribute(sal_uInt16 nToken, const OUString &rValue) override
will be called for each attribute
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
Any makeAny(Color const &value)
#define SAL_WARN_IF(condition, area, stream)
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.
css::uno::Reference< css::xml::dom::XDocument > getTree()
access the DOM tree
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)