1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sal/config.h>
22 #include <jvmaccess/classpath.hxx>
27 #include <com/sun/star/lang/IllegalArgumentException.hpp>
28 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
29 #include <com/sun/star/uno/Reference.hxx>
30 #include <com/sun/star/uno/XInterface.hpp>
31 #include <com/sun/star/uri/UriReferenceFactory.hpp>
32 #include <com/sun/star/uri/XVndSunStarExpandUrlReference.hpp>
33 #include <com/sun/star/util/theMacroExpander.hpp>
34 #include <cppuhelper/exc_hlp.hxx>
35 #include <rtl/ustring.hxx>
36 #include <sal/types.h>
40 namespace com::sun::star::uno
{ class XComponentContext
; }
42 jobjectArray
jvmaccess::ClassPath::translateToUrls(
43 css::uno::Reference
< css::uno::XComponentContext
> const & context
,
44 JNIEnv
* environment
, OUString
const & classPath
)
47 assert(environment
!= nullptr);
48 jclass
classUrl(environment
->FindClass("java/net/URL"));
49 if (classUrl
== nullptr) {
53 environment
->GetMethodID(classUrl
, "<init>", "(Ljava/lang/String;)V"));
54 if (ctorUrl
== nullptr) {
57 ::std::vector
< jobject
> urls
;
58 for (::sal_Int32 i
= 0; i
!= -1;) {
59 OUString
url(classPath
.getToken(0, ' ', i
));
61 css::uno::Reference
< css::uri::XVndSunStarExpandUrlReference
>
63 css::uri::UriReferenceFactory::create(context
)->parse(url
),
66 css::uno::Reference
< css::util::XMacroExpander
> expander
=
67 css::util::theMacroExpander::get(context
);
69 url
= expUrl
->expand( expander
);
70 } catch (const css::lang::IllegalArgumentException
& e
) {
71 css::uno::Any anyEx
= cppu::getCaughtException();
72 throw css::lang::WrappedTargetRuntimeException(
73 "com.sun.star.lang.IllegalArgumentException: "
79 arg
.l
= environment
->NewString(
80 reinterpret_cast< jchar
const * >(url
.getStr()),
81 static_cast< jsize
>(url
.getLength()));
82 if (arg
.l
== nullptr) {
85 jobject
o(environment
->NewObjectA(classUrl
, ctorUrl
, &arg
));
92 jobjectArray result
= environment
->NewObjectArray(
93 static_cast< jsize
>(urls
.size()), classUrl
, nullptr);
94 // static_cast is ok, as each element of urls occupied at least one
95 // character of the OUString classPath
96 if (result
== nullptr) {
100 for (auto const& url
: urls
)
102 environment
->SetObjectArrayElement(result
, idx
++, url
);
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */