2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-07-06 17:28:37 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2005-02-11 15:34:28 +00:00
|
|
|
|
2013-08-16 11:08:32 +03:00
|
|
|
#include <config_folders.h>
|
2006-09-16 11:29:29 +00:00
|
|
|
|
2005-02-11 15:34:28 +00:00
|
|
|
#include <com/sun/star/uri/XVndSunStarScriptUrl.hpp>
|
2012-10-12 08:57:24 +02:00
|
|
|
#include <com/sun/star/uri/UriReferenceFactory.hpp>
|
2014-03-04 08:41:53 -03:00
|
|
|
#include <cppuhelper/supportsservice.hxx>
|
2005-02-11 15:34:28 +00:00
|
|
|
#include <rtl/ustrbuf.hxx>
|
2014-11-14 22:52:35 +01:00
|
|
|
#include <osl/diagnose.h>
|
2005-02-11 15:34:28 +00:00
|
|
|
#include "URIHelper.hxx"
|
|
|
|
|
|
|
|
namespace func_provider
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace uno = ::com::sun::star::uno;
|
|
|
|
namespace ucb = ::com::sun::star::ucb;
|
|
|
|
namespace lang = ::com::sun::star::lang;
|
|
|
|
namespace uri = ::com::sun::star::uri;
|
|
|
|
namespace script = ::com::sun::star::script;
|
|
|
|
|
|
|
|
static const char SHARE[] = "share";
|
2011-10-21 17:18:13 +02:00
|
|
|
static const char SHARE_URI[] = "vnd.sun.star.expand:$BRAND_BASE_DIR";
|
2005-02-11 15:34:28 +00:00
|
|
|
|
|
|
|
static const char SHARE_UNO_PACKAGES[] = "share:uno_packages";
|
2008-12-11 12:57:12 +00:00
|
|
|
static const char SHARE_UNO_PACKAGES_URI[] =
|
|
|
|
"vnd.sun.star.expand:$UNO_SHARED_PACKAGES_CACHE";
|
2005-02-11 15:34:28 +00:00
|
|
|
|
|
|
|
static const char USER[] = "user";
|
|
|
|
static const char USER_URI[] =
|
2013-08-16 11:08:32 +03:00
|
|
|
"vnd.sun.star.expand:${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE( "bootstrap") "::UserInstallation}";
|
2005-02-11 15:34:28 +00:00
|
|
|
|
|
|
|
static const char USER_UNO_PACKAGES[] = "user:uno_packages";
|
|
|
|
static const char USER_UNO_PACKAGES_DIR[] =
|
|
|
|
"/user/uno_packages/cache";
|
|
|
|
|
|
|
|
static const char DOCUMENT[] = "document";
|
|
|
|
static const char TDOC_SCHEME[] = "vnd.sun.star.tdoc";
|
|
|
|
|
|
|
|
ScriptingFrameworkURIHelper::ScriptingFrameworkURIHelper(
|
|
|
|
const uno::Reference< uno::XComponentContext >& xContext)
|
|
|
|
throw( uno::RuntimeException )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2012-11-02 17:46:30 +02:00
|
|
|
m_xSimpleFileAccess = ucb::SimpleFileAccess::create(xContext);
|
2005-02-11 15:34:28 +00:00
|
|
|
}
|
|
|
|
catch (uno::Exception&)
|
|
|
|
{
|
2011-03-12 14:27:45 +01:00
|
|
|
OSL_FAIL("Scripting Framework error initialising XSimpleFileAccess");
|
2005-02-11 15:34:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2012-10-12 08:57:24 +02:00
|
|
|
m_xUriReferenceFactory = uri::UriReferenceFactory::create( xContext );
|
2005-02-11 15:34:28 +00:00
|
|
|
}
|
|
|
|
catch (uno::Exception&)
|
|
|
|
{
|
2011-03-12 14:27:45 +01:00
|
|
|
OSL_FAIL("Scripting Framework error initialising XUriReferenceFactory");
|
2005-02-11 15:34:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ScriptingFrameworkURIHelper::~ScriptingFrameworkURIHelper()
|
|
|
|
{
|
|
|
|
// currently does nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL
|
|
|
|
ScriptingFrameworkURIHelper::initialize(
|
|
|
|
const uno::Sequence < uno::Any >& args )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw ( uno::Exception, uno::RuntimeException, std::exception )
|
2005-02-11 15:34:28 +00:00
|
|
|
{
|
|
|
|
if ( args.getLength() != 2 ||
|
2014-05-11 10:37:30 +02:00
|
|
|
args[0].getValueType() != ::cppu::UnoType<OUString>::get() ||
|
|
|
|
args[1].getValueType() != ::cppu::UnoType<OUString>::get() )
|
2005-02-11 15:34:28 +00:00
|
|
|
{
|
2014-05-23 12:03:21 +02:00
|
|
|
throw uno::RuntimeException( "ScriptingFrameworkURIHelper got invalid argument list" );
|
2005-02-11 15:34:28 +00:00
|
|
|
}
|
|
|
|
|
2014-01-21 21:53:19 +01:00
|
|
|
if ( !(args[0] >>= m_sLanguage) || !(args[1] >>= m_sLocation) )
|
2005-02-11 15:34:28 +00:00
|
|
|
{
|
2014-05-23 12:03:21 +02:00
|
|
|
throw uno::RuntimeException( "ScriptingFrameworkURIHelper error parsing args" );
|
2005-02-11 15:34:28 +00:00
|
|
|
}
|
|
|
|
|
2013-11-15 11:05:19 +02:00
|
|
|
SCRIPTS_PART = "/Scripts/";
|
2005-02-11 15:34:28 +00:00
|
|
|
SCRIPTS_PART = SCRIPTS_PART.concat( m_sLanguage.toAsciiLowerCase() );
|
|
|
|
|
|
|
|
if ( !initBaseURI() )
|
|
|
|
{
|
2014-05-23 12:03:21 +02:00
|
|
|
throw uno::RuntimeException( "ScriptingFrameworkURIHelper cannot find script directory" );
|
2005-02-11 15:34:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ScriptingFrameworkURIHelper::initBaseURI()
|
|
|
|
{
|
|
|
|
OUString uri, test;
|
|
|
|
bool bAppendScriptsPart = false;
|
|
|
|
|
2014-12-15 10:15:16 +01:00
|
|
|
if ( m_sLocation == USER )
|
2005-02-11 15:34:28 +00:00
|
|
|
{
|
2013-11-15 11:05:19 +02:00
|
|
|
test = USER;
|
|
|
|
uri = USER_URI;
|
2005-02-11 15:34:28 +00:00
|
|
|
bAppendScriptsPart = true;
|
|
|
|
}
|
2014-12-15 10:15:16 +01:00
|
|
|
else if ( m_sLocation == USER_UNO_PACKAGES )
|
2005-02-11 15:34:28 +00:00
|
|
|
{
|
2013-11-15 11:05:19 +02:00
|
|
|
test = "uno_packages";
|
2014-12-18 13:29:52 +01:00
|
|
|
uri = OUStringLiteral(USER_URI) + USER_UNO_PACKAGES_DIR;
|
2005-02-11 15:34:28 +00:00
|
|
|
}
|
2014-12-15 10:15:16 +01:00
|
|
|
else if (m_sLocation == SHARE)
|
2005-02-11 15:34:28 +00:00
|
|
|
{
|
2013-11-15 11:05:19 +02:00
|
|
|
test = SHARE;
|
|
|
|
uri = SHARE_URI;
|
2005-02-11 15:34:28 +00:00
|
|
|
bAppendScriptsPart = true;
|
|
|
|
}
|
2014-12-15 10:15:16 +01:00
|
|
|
else if (m_sLocation == SHARE_UNO_PACKAGES)
|
2005-02-11 15:34:28 +00:00
|
|
|
{
|
2013-11-15 11:05:19 +02:00
|
|
|
test = "uno_packages";
|
|
|
|
uri = SHARE_UNO_PACKAGES_URI;
|
2005-02-11 15:34:28 +00:00
|
|
|
}
|
2013-10-25 16:43:20 +02:00
|
|
|
else if (m_sLocation.startsWith(TDOC_SCHEME))
|
2005-02-11 15:34:28 +00:00
|
|
|
{
|
|
|
|
m_sBaseURI = m_sLocation.concat( SCRIPTS_PART );
|
2013-11-15 11:05:19 +02:00
|
|
|
m_sLocation = DOCUMENT;
|
2005-02-11 15:34:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !m_xSimpleFileAccess->exists( uri ) ||
|
|
|
|
!m_xSimpleFileAccess->isFolder( uri ) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uno::Sequence< OUString > children =
|
|
|
|
m_xSimpleFileAccess->getFolderContents( uri, true );
|
|
|
|
|
|
|
|
for ( sal_Int32 i = 0; i < children.getLength(); i++ )
|
|
|
|
{
|
|
|
|
OUString child = children[i];
|
|
|
|
sal_Int32 idx = child.lastIndexOf(test);
|
|
|
|
|
|
|
|
// OSL_TRACE("Trying: %s", PRTSTR(child));
|
|
|
|
// OSL_TRACE("idx=%d, testlen=%d, children=%d",
|
|
|
|
// idx, test.getLength(), child.getLength());
|
|
|
|
|
|
|
|
if ( idx != -1 && (idx + test.getLength()) == child.getLength() )
|
|
|
|
{
|
|
|
|
// OSL_TRACE("FOUND PATH: %s", PRTSTR(child));
|
|
|
|
if ( bAppendScriptsPart )
|
|
|
|
{
|
|
|
|
m_sBaseURI = child.concat( SCRIPTS_PART );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_sBaseURI = child;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString
|
|
|
|
ScriptingFrameworkURIHelper::getLanguagePart(const OUString& rStorageURI)
|
|
|
|
{
|
|
|
|
OUString result;
|
|
|
|
|
|
|
|
sal_Int32 idx = rStorageURI.indexOf(m_sBaseURI);
|
|
|
|
sal_Int32 len = m_sBaseURI.getLength() + 1;
|
|
|
|
|
|
|
|
if ( idx != -1 )
|
|
|
|
{
|
|
|
|
result = rStorageURI.copy(idx + len);
|
|
|
|
result = result.replace('/', '|');
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString
|
|
|
|
ScriptingFrameworkURIHelper::getLanguagePath(const OUString& rLanguagePart)
|
|
|
|
{
|
|
|
|
OUString result;
|
|
|
|
result = rLanguagePart.replace('|', '/');
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString SAL_CALL
|
|
|
|
ScriptingFrameworkURIHelper::getScriptURI(const OUString& rStorageURI)
|
2014-02-25 21:31:58 +01:00
|
|
|
throw( lang::IllegalArgumentException, uno::RuntimeException, std::exception )
|
2005-02-11 15:34:28 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUStringBuffer buf(120);
|
2005-02-11 15:34:28 +00:00
|
|
|
|
|
|
|
buf.appendAscii("vnd.sun.star.script:");
|
|
|
|
buf.append(getLanguagePart(rStorageURI));
|
|
|
|
buf.appendAscii("?language=");
|
|
|
|
buf.append(m_sLanguage);
|
|
|
|
buf.appendAscii("&location=");
|
|
|
|
buf.append(m_sLocation);
|
|
|
|
|
|
|
|
return buf.makeStringAndClear();
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString SAL_CALL
|
|
|
|
ScriptingFrameworkURIHelper::getStorageURI(const OUString& rScriptURI)
|
2014-02-25 21:31:58 +01:00
|
|
|
throw( lang::IllegalArgumentException, uno::RuntimeException, std::exception )
|
2005-02-11 15:34:28 +00:00
|
|
|
{
|
|
|
|
OUString sLanguagePart;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
uno::Reference < uri::XVndSunStarScriptUrl > xURI(
|
|
|
|
m_xUriReferenceFactory->parse( rScriptURI ), uno::UNO_QUERY_THROW );
|
|
|
|
sLanguagePart = xURI->getName();
|
|
|
|
}
|
|
|
|
catch ( uno::Exception& )
|
|
|
|
{
|
|
|
|
throw lang::IllegalArgumentException(
|
2012-06-02 20:19:28 -05:00
|
|
|
OUString("Script URI not valid"),
|
2005-02-11 15:34:28 +00:00
|
|
|
uno::Reference< uno::XInterface >(), 1 );
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUStringBuffer buf(120);
|
2005-02-11 15:34:28 +00:00
|
|
|
buf.append(m_sBaseURI);
|
2013-12-13 11:10:10 +02:00
|
|
|
buf.append("/");
|
2005-02-11 15:34:28 +00:00
|
|
|
buf.append(getLanguagePath(sLanguagePart));
|
|
|
|
|
|
|
|
OUString result = buf.makeStringAndClear();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString SAL_CALL
|
|
|
|
ScriptingFrameworkURIHelper::getRootStorageURI()
|
2014-02-25 21:31:58 +01:00
|
|
|
throw( uno::RuntimeException, std::exception )
|
2005-02-11 15:34:28 +00:00
|
|
|
{
|
|
|
|
return m_sBaseURI;
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString SAL_CALL
|
|
|
|
ScriptingFrameworkURIHelper::getImplementationName()
|
2014-02-25 21:31:58 +01:00
|
|
|
throw( uno::RuntimeException, std::exception )
|
2005-02-11 15:34:28 +00:00
|
|
|
{
|
2012-06-02 20:19:28 -05:00
|
|
|
return OUString(
|
|
|
|
"com.sun.star.script.provider.ScriptURIHelper" );
|
2005-02-11 15:34:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL
|
|
|
|
ScriptingFrameworkURIHelper::supportsService( const OUString& serviceName )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw( uno::RuntimeException, std::exception )
|
2005-02-11 15:34:28 +00:00
|
|
|
{
|
2014-03-04 08:41:53 -03:00
|
|
|
return cppu::supportsService( this, serviceName );
|
2005-02-11 15:34:28 +00:00
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
uno::Sequence< OUString > SAL_CALL
|
2005-02-11 15:34:28 +00:00
|
|
|
ScriptingFrameworkURIHelper::getSupportedServiceNames()
|
2014-02-25 21:31:58 +01:00
|
|
|
throw( uno::RuntimeException, std::exception )
|
2005-02-11 15:34:28 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString serviceNameList[] = {
|
|
|
|
OUString(
|
2012-06-02 20:19:28 -05:00
|
|
|
"com.sun.star.script.provider.ScriptURIHelper" ) };
|
2005-02-11 15:34:28 +00:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
uno::Sequence< OUString > serviceNames = uno::Sequence <
|
|
|
|
OUString > ( serviceNameList, 1 );
|
2005-02-11 15:34:28 +00:00
|
|
|
|
|
|
|
return serviceNames;
|
|
|
|
}
|
|
|
|
}
|
2010-10-12 15:53:47 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|