Avoid potential negative array index access to cached text.
[LibreOffice.git] / scripting / source / dlgprov / DialogModelProvider.cxx
blobe49ed058d47560b9349f0a2992f1453bd5c46300
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 .
20 #include "DialogModelProvider.hxx"
21 #include "dlgprov.hxx"
22 #include <com/sun/star/resource/XStringResourceManager.hpp>
23 #include <com/sun/star/ucb/SimpleFileAccess.hpp>
25 #include <cppuhelper/supportsservice.hxx>
27 /// anonymous implementation namespace
28 namespace dlgprov {
30 using namespace ::com::sun::star;
31 using namespace awt;
32 using namespace lang;
33 using namespace uno;
34 using namespace script;
35 using namespace beans;
38 DialogModelProvider::DialogModelProvider(Reference< XComponentContext > const & context) :
39 m_xContext(context)
42 // lang::XInitialization:
43 void SAL_CALL DialogModelProvider::initialize(const css::uno::Sequence< uno::Any > & aArguments)
45 if ( aArguments.getLength() != 1 )
46 return;
48 OUString sURL;
49 if ( !( aArguments[ 0 ] >>= sURL ))
50 throw css::lang::IllegalArgumentException();
51 // Try any other URL with SimpleFileAccess
52 Reference< ucb::XSimpleFileAccess3 > xSFI = ucb::SimpleFileAccess::create(m_xContext);
54 try
56 Reference< io::XInputStream > xInput = xSFI->openFileRead( sURL );
57 Reference< resource::XStringResourceManager > xStringResourceManager;
58 if ( xInput.is() )
60 xStringResourceManager = dlgprov::lcl_getStringResourceManager(m_xContext,sURL);
61 Any aDialogSourceURLAny;
62 aDialogSourceURLAny <<= sURL;
64 Reference< frame::XModel > xModel;
65 m_xDialogModel.set( dlgprov::lcl_createDialogModel( m_xContext, xInput , xModel, xStringResourceManager, aDialogSourceURLAny ), UNO_SET_THROW);
66 m_xDialogModelProp.set(m_xDialogModel, UNO_QUERY_THROW);
69 catch( Exception& )
71 //m_sURL = sURL;
74 // container::XElementAccess:
75 uno::Type SAL_CALL DialogModelProvider::getElementType()
77 return m_xDialogModel->getElementType();
80 sal_Bool SAL_CALL DialogModelProvider::hasElements()
82 return m_xDialogModel->hasElements();
85 // container::XNameAccess:
86 uno::Any SAL_CALL DialogModelProvider::getByName(const OUString & aName)
88 return m_xDialogModel->getByName(aName);
91 css::uno::Sequence< OUString > SAL_CALL DialogModelProvider::getElementNames()
93 return m_xDialogModel->getElementNames();
96 sal_Bool SAL_CALL DialogModelProvider::hasByName(const OUString & aName)
98 return m_xDialogModel->hasByName(aName);
101 // container::XNameReplace:
102 void SAL_CALL DialogModelProvider::replaceByName(const OUString & aName, const uno::Any & aElement)
104 m_xDialogModel->replaceByName(aName,aElement);
107 // container::XNameContainer:
108 void SAL_CALL DialogModelProvider::insertByName(const OUString & aName, const uno::Any & aElement)
110 m_xDialogModel->insertByName(aName,aElement);
113 void SAL_CALL DialogModelProvider::removeByName(const OUString & aName)
115 m_xDialogModel->removeByName(aName);
117 uno::Reference< beans::XPropertySetInfo > SAL_CALL DialogModelProvider::getPropertySetInfo( )
119 return m_xDialogModelProp->getPropertySetInfo();
121 void SAL_CALL DialogModelProvider::setPropertyValue( const OUString&, const uno::Any& )
124 uno::Any SAL_CALL DialogModelProvider::getPropertyValue( const OUString& PropertyName )
126 return m_xDialogModelProp->getPropertyValue(PropertyName);
128 void SAL_CALL DialogModelProvider::addPropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& )
131 void SAL_CALL DialogModelProvider::removePropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& )
134 void SAL_CALL DialogModelProvider::addVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& )
137 void SAL_CALL DialogModelProvider::removeVetoableChangeListener( const OUString& ,const uno::Reference< beans::XVetoableChangeListener >& )
141 // com.sun.star.uno.XServiceInfo:
142 OUString SAL_CALL DialogModelProvider::getImplementationName()
144 return "com.sun.star.comp.scripting.DialogModelProvider";
147 sal_Bool SAL_CALL DialogModelProvider::supportsService(OUString const & serviceName)
149 return cppu::supportsService(this, serviceName);
152 css::uno::Sequence< OUString > SAL_CALL DialogModelProvider::getSupportedServiceNames()
154 return { "com.sun.star.awt.UnoControlDialogModelProvider" };
157 } // closing anonymous implementation namespace
159 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
160 scripting_DialogModelProvider_get_implementation(
161 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
163 return cppu::acquire(new dlgprov::DialogModelProvider(context));
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */