2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2005-02-11 15:34:28 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 09:37:12 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2005-02-11 15:34:28 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2005-02-11 15:34:28 +00:00
|
|
|
*
|
2008-04-11 09:37:12 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2005-02-11 15:34:28 +00:00
|
|
|
*
|
2008-04-11 09:37:12 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2005-02-11 15:34:28 +00:00
|
|
|
*
|
2008-04-11 09:37:12 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2005-02-11 15:34:28 +00:00
|
|
|
*
|
2008-04-11 09:37:12 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2005-02-11 15:34:28 +00:00
|
|
|
*
|
2008-04-11 09:37:12 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2005-02-11 15:34:28 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-16 11:29:29 +00:00
|
|
|
|
2005-02-11 15:34:28 +00:00
|
|
|
#include <com/sun/star/uri/XVndSunStarScriptUrl.hpp>
|
|
|
|
#include <rtl/ustrbuf.hxx>
|
|
|
|
#include "URIHelper.hxx"
|
|
|
|
|
|
|
|
#define PRTSTR(x) ::rtl::OUStringToOString(x, RTL_TEXTENCODING_ASCII_US).pData->buffer
|
|
|
|
|
|
|
|
namespace func_provider
|
|
|
|
{
|
|
|
|
|
|
|
|
using ::rtl::OUString;
|
|
|
|
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[] =
|
2008-12-11 12:57:12 +00:00
|
|
|
"vnd.sun.star.expand:${$BRAND_BASE_DIR/program/" 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
|
|
|
|
{
|
|
|
|
m_xSimpleFileAccess = uno::Reference< ucb::XSimpleFileAccess >(
|
|
|
|
xContext->getServiceManager()->createInstanceWithContext(
|
2010-11-19 19:43:57 +01:00
|
|
|
OUString(RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"com.sun.star.ucb.SimpleFileAccess")),
|
2005-02-11 15:34:28 +00:00
|
|
|
xContext), uno::UNO_QUERY_THROW);
|
|
|
|
}
|
|
|
|
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
|
|
|
|
{
|
|
|
|
m_xUriReferenceFactory = uno::Reference< uri::XUriReferenceFactory >(
|
|
|
|
xContext->getServiceManager()->createInstanceWithContext(
|
2010-11-19 19:43:57 +01:00
|
|
|
OUString(RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"com.sun.star.uri.UriReferenceFactory")),
|
2005-02-11 15:34:28 +00:00
|
|
|
xContext ), uno::UNO_QUERY_THROW );
|
|
|
|
}
|
|
|
|
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 )
|
|
|
|
throw ( uno::Exception, uno::RuntimeException )
|
|
|
|
{
|
|
|
|
if ( args.getLength() != 2 ||
|
|
|
|
args[0].getValueType() != ::getCppuType((const OUString*)NULL) ||
|
|
|
|
args[1].getValueType() != ::getCppuType((const OUString*)NULL) )
|
|
|
|
{
|
2010-11-19 19:43:57 +01:00
|
|
|
throw uno::RuntimeException( OUString(RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"ScriptingFrameworkURIHelper got invalid argument list" )),
|
2005-02-11 15:34:28 +00:00
|
|
|
uno::Reference< uno::XInterface >() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (args[0] >>= m_sLanguage) == sal_False ||
|
|
|
|
(args[1] >>= m_sLocation) == sal_False )
|
|
|
|
{
|
2010-11-19 19:43:57 +01:00
|
|
|
throw uno::RuntimeException( OUString(RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"ScriptingFrameworkURIHelper error parsing args" )),
|
2005-02-11 15:34:28 +00:00
|
|
|
uno::Reference< uno::XInterface >() );
|
|
|
|
}
|
|
|
|
|
2010-11-19 19:43:57 +01:00
|
|
|
SCRIPTS_PART = OUString(RTL_CONSTASCII_USTRINGPARAM("/Scripts/"));
|
2005-02-11 15:34:28 +00:00
|
|
|
SCRIPTS_PART = SCRIPTS_PART.concat( m_sLanguage.toAsciiLowerCase() );
|
|
|
|
|
|
|
|
if ( !initBaseURI() )
|
|
|
|
{
|
2010-11-19 19:43:57 +01:00
|
|
|
throw uno::RuntimeException( OUString(RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"ScriptingFrameworkURIHelper cannot find script directory")),
|
2005-02-11 15:34:28 +00:00
|
|
|
uno::Reference< uno::XInterface >() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ScriptingFrameworkURIHelper::initBaseURI()
|
|
|
|
{
|
|
|
|
OUString uri, test;
|
|
|
|
bool bAppendScriptsPart = false;
|
|
|
|
|
|
|
|
if ( m_sLocation.equalsAscii(USER))
|
|
|
|
{
|
2010-11-19 19:43:57 +01:00
|
|
|
test = OUString(RTL_CONSTASCII_USTRINGPARAM(USER));
|
|
|
|
uri = OUString(RTL_CONSTASCII_USTRINGPARAM(USER_URI));
|
2005-02-11 15:34:28 +00:00
|
|
|
bAppendScriptsPart = true;
|
|
|
|
}
|
|
|
|
else if ( m_sLocation.equalsAscii(USER_UNO_PACKAGES))
|
|
|
|
{
|
2010-11-19 19:43:57 +01:00
|
|
|
test = OUString(RTL_CONSTASCII_USTRINGPARAM("uno_packages"));
|
|
|
|
uri = OUString(RTL_CONSTASCII_USTRINGPARAM(USER_URI));
|
|
|
|
uri = uri.concat(OUString(RTL_CONSTASCII_USTRINGPARAM(USER_UNO_PACKAGES_DIR)));
|
2005-02-11 15:34:28 +00:00
|
|
|
}
|
|
|
|
else if (m_sLocation.equalsAscii(SHARE))
|
|
|
|
{
|
2010-11-19 19:43:57 +01:00
|
|
|
test = OUString(RTL_CONSTASCII_USTRINGPARAM(SHARE));
|
|
|
|
uri = OUString(RTL_CONSTASCII_USTRINGPARAM(SHARE_URI));
|
2005-02-11 15:34:28 +00:00
|
|
|
bAppendScriptsPart = true;
|
|
|
|
}
|
|
|
|
else if (m_sLocation.equalsAscii(SHARE_UNO_PACKAGES))
|
|
|
|
{
|
2010-11-19 19:43:57 +01:00
|
|
|
test = OUString(RTL_CONSTASCII_USTRINGPARAM("uno_packages"));
|
|
|
|
uri = OUString(RTL_CONSTASCII_USTRINGPARAM(SHARE_UNO_PACKAGES_URI));
|
2005-02-11 15:34:28 +00:00
|
|
|
}
|
2010-11-19 19:43:57 +01:00
|
|
|
else if (m_sLocation.indexOf(OUString(RTL_CONSTASCII_USTRINGPARAM(TDOC_SCHEME))) == 0)
|
2005-02-11 15:34:28 +00:00
|
|
|
{
|
|
|
|
m_sBaseURI = m_sLocation.concat( SCRIPTS_PART );
|
2010-11-19 19:43:57 +01:00
|
|
|
m_sLocation = OUString(RTL_CONSTASCII_USTRINGPARAM( 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)
|
|
|
|
throw( lang::IllegalArgumentException, uno::RuntimeException )
|
|
|
|
{
|
|
|
|
::rtl::OUStringBuffer buf(120);
|
|
|
|
|
|
|
|
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)
|
|
|
|
throw( lang::IllegalArgumentException, uno::RuntimeException )
|
|
|
|
{
|
|
|
|
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(
|
2010-11-19 19:43:57 +01:00
|
|
|
OUString(RTL_CONSTASCII_USTRINGPARAM("Script URI not valid")),
|
2005-02-11 15:34:28 +00:00
|
|
|
uno::Reference< uno::XInterface >(), 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
::rtl::OUStringBuffer buf(120);
|
|
|
|
buf.append(m_sBaseURI);
|
2010-11-19 19:43:57 +01:00
|
|
|
buf.append(OUString(RTL_CONSTASCII_USTRINGPARAM("/")));
|
2005-02-11 15:34:28 +00:00
|
|
|
buf.append(getLanguagePath(sLanguagePart));
|
|
|
|
|
|
|
|
OUString result = buf.makeStringAndClear();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString SAL_CALL
|
|
|
|
ScriptingFrameworkURIHelper::getRootStorageURI()
|
|
|
|
throw( uno::RuntimeException )
|
|
|
|
{
|
|
|
|
return m_sBaseURI;
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString SAL_CALL
|
|
|
|
ScriptingFrameworkURIHelper::getImplementationName()
|
|
|
|
throw( uno::RuntimeException )
|
|
|
|
{
|
2010-11-19 19:43:57 +01:00
|
|
|
return OUString(RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"com.sun.star.script.provider.ScriptURIHelper" ));
|
2005-02-11 15:34:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL
|
|
|
|
ScriptingFrameworkURIHelper::supportsService( const OUString& serviceName )
|
|
|
|
throw( uno::RuntimeException )
|
|
|
|
{
|
2010-11-19 19:43:57 +01:00
|
|
|
OUString m_sServiceName(RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"com.sun.star.script.provider.ScriptURIHelper" ));
|
2005-02-11 15:34:28 +00:00
|
|
|
|
|
|
|
if ( serviceName.equals( m_sServiceName ) )
|
|
|
|
{
|
|
|
|
return sal_True;
|
|
|
|
}
|
|
|
|
return sal_False;
|
|
|
|
}
|
|
|
|
|
|
|
|
uno::Sequence< ::rtl::OUString > SAL_CALL
|
|
|
|
ScriptingFrameworkURIHelper::getSupportedServiceNames()
|
|
|
|
throw( uno::RuntimeException )
|
|
|
|
{
|
|
|
|
::rtl::OUString serviceNameList[] = {
|
2010-11-19 19:43:57 +01:00
|
|
|
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"com.sun.star.script.provider.ScriptURIHelper" )) };
|
2005-02-11 15:34:28 +00:00
|
|
|
|
|
|
|
uno::Sequence< ::rtl::OUString > serviceNames = uno::Sequence <
|
|
|
|
::rtl::OUString > ( serviceNameList, 1 );
|
|
|
|
|
|
|
|
return serviceNames;
|
|
|
|
}
|
|
|
|
}
|
2010-10-12 15:53:47 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|