| 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 |
|
| 21 |
#include "XFormsInstanceContext.hxx" |
| 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/xforms/XModel2.hpp> |
| 30 |
|
| 31 |
#include <xmloff/xmltoken.hxx> |
| 32 |
#include <xmloff/xmlimp.hxx> |
| 33 |
#include <xmloff/xmlerror.hxx> |
| 34 |
|
| 35 |
|
| 36 |
using com::sun::star::uno::Reference; |
| 37 |
using com::sun::star::uno::Any; |
| 38 |
using com::sun::star::uno::Sequence; |
| 39 |
using com::sun::star::xforms::XModel2; |
| 40 |
using com::sun::star::beans::PropertyValue; |
| 41 |
|
| 42 |
using xmloff::token::XML_SRC; |
| 43 |
using xmloff::token::XML_ID; |
| 44 |
|
| 45 |
XFormsInstanceContext::XFormsInstanceContext( |
| 46 |
SvXMLImport& rImport, |
| 47 |
const Reference<XModel2> & xModel ) : |
| 48 |
TokenContext( rImport ), |
| 49 |
mxModel( xModel ) |
| 50 |
{ |
| 51 |
SAL_WARN_IF( !mxModel.is(), "xmloff", "need model" ); |
| 52 |
} |
| 53 |
|
| 54 |
css::uno::Reference< css::xml::sax::XFastContextHandler > XFormsInstanceContext::createFastChildContext( |
| 55 |
sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) |
| 56 |
{ |
| 57 |
SvXMLImportContext* pContext = nullptr; |
| 58 |
|
| 59 |
// only the first element child of an xforms:instance element |
| 60 |
// is used as an instance. The other children remainder must be |
| 61 |
// ignored. |
| 62 |
if( mxInstance.is() ) |
| 63 |
{ |
| 64 |
const OUString& rLocalName = SvXMLImport::getNameFromToken( nElement ); |
| 65 |
GetImport().SetError( XMLERROR_XFORMS_ONLY_ONE_INSTANCE_ELEMENT, rLocalName ); |
| 66 |
} |
| 67 |
else |
| 68 |
{ |
| 69 |
// create new DomBuilderContext. Save reference to tree in Model. |
| 70 |
DomBuilderContext* pInstance = new DomBuilderContext( GetImport(), nElement ); |
| 71 |
mxInstance = pInstance->getTree(); |
| 72 |
pContext = pInstance; |
| 73 |
} |
| 74 |
|
| 75 |
SAL_WARN_IF( pContext == nullptr, "xmloff", "no context!" ); |
| 76 |
return pContext; |
| 77 |
|
| 78 |
} |
| 79 |
|
| 80 |
css::uno::Reference< css::xml::sax::XFastContextHandler > XFormsInstanceContext::createUnknownChildContext( |
| 81 |
const OUString & rNamespace, const OUString &rName, const css::uno::Reference< css::xml::sax::XFastAttributeList > & /*Attribs*/) |
| 82 |
{ |
| 83 |
SvXMLImportContext* pContext = nullptr; |
| 84 |
|
| 85 |
// only the first element child of an xforms:instance element |
| 86 |
// is used as an instance. The other children remainder must be |
| 87 |
// ignored. |
| 88 |
if( mxInstance.is() ) |
| 89 |
{ |
| 90 |
GetImport().SetError( XMLERROR_XFORMS_ONLY_ONE_INSTANCE_ELEMENT, rName ); |
| 91 |
} |
| 92 |
else |
| 93 |
{ |
| 94 |
// create new DomBuilderContext. Save reference to tree in Model. |
| 95 |
DomBuilderContext* pInstance = new DomBuilderContext( GetImport(), rNamespace, rName ); |
| 96 |
mxInstance = pInstance->getTree(); |
| 97 |
pContext = pInstance; |
| 98 |
} |
| 99 |
|
| 100 |
SAL_WARN_IF( pContext == nullptr, "xmloff", "no context!" ); |
| 101 |
return pContext; |
| 102 |
|
| 103 |
} |
| 104 |
|
| 105 |
void XFormsInstanceContext::endFastElement(sal_Int32 ) |
| 106 |
{ |
| 107 |
Sequence<PropertyValue> aSequence( 3 ); |
| 108 |
PropertyValue* pSequence = aSequence.getArray(); |
| 109 |
pSequence[0].Name = "Instance"; |
| 110 |
pSequence[0].Value <<= mxInstance; |
| 111 |
pSequence[1].Name = "ID"; |
| 112 |
pSequence[1].Value <<= msId; |
| 113 |
pSequence[2].Name = "URL"; |
| 114 |
pSequence[2].Value <<= msURL; |
| 115 |
|
| 116 |
mxModel->getInstances()->insert( Any( aSequence ) ); |
| 117 |
} |
| 118 |
|
| 119 |
void XFormsInstanceContext::endUnknownElement(const OUString & /*Namespace*/, const OUString & /*Name*/) |
| 120 |
{ |
| 121 |
Sequence<PropertyValue> aSequence( 3 ); |
| 122 |
PropertyValue* pSequence = aSequence.getArray(); |
| 123 |
pSequence[0].Name = "Instance"; |
| 124 |
pSequence[0].Value <<= mxInstance; |
| 125 |
pSequence[1].Name = "ID"; |
| 126 |
pSequence[1].Value <<= msId; |
| 127 |
pSequence[2].Name = "URL"; |
| 128 |
pSequence[2].Value <<= msURL; |
| 129 |
|
| 130 |
mxModel->getInstances()->insert( Any( aSequence ) ); |
| 131 |
} |
| 132 |
|
| 133 |
void XFormsInstanceContext::HandleAttribute(const sax_fastparser::FastAttributeList::FastAttributeIter & aIter ) |
| 134 |
{ |
| 135 |
switch( aIter.getToken() & TOKEN_MASK ) |
| 136 |
{ |
| 137 |
case XML_SRC: |
| 138 |
msURL = aIter.toString(); |
| 139 |
break; |
| 140 |
case XML_ID: |
| 141 |
msId = aIter.toString(); |
| 142 |
break; |
| 143 |
default: |
| 144 |
XMLOFF_WARN_UNKNOWN("xmloff", aIter); |
| 145 |
assert( false && "this should not happen" ); |
| 146 |
break; |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
SvXMLImportContext* XFormsInstanceContext::HandleChild( |
| 151 |
sal_Int32, |
| 152 |
const Reference<css::xml::sax::XFastAttributeList>& ) |
| 153 |
{ |
| 154 |
assert( false && "to be handled by CreateChildContext" ); |
| 155 |
return nullptr; |
| 156 |
} |
| 157 |
|
| 158 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |