| /** |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| */ |
| package org.eclipse.osbp.utils.session; |
| |
| import java.net.URI; |
| |
| import org.osgi.framework.FrameworkUtil; |
| |
| import com.vaadin.server.Page; |
| import com.vaadin.server.VaadinService; |
| |
| public class UriPath { |
| |
| /** |
| * @return the theme name of the current vaadin application, which can be used inside a uri |
| */ |
| public static String getThemeName() { |
| try { |
| return VaadinService.getCurrent().getConfiguredTheme(VaadinService.getCurrentRequest()); |
| } |
| catch (Exception e) { |
| return null; |
| } |
| } |
| |
| /** |
| * @return [<code>protocol</code>]<code>://</code>[<code>host</code>](<code>:</code>[<code>port</code>]) |
| */ |
| public static String getProtocolHostPort() { |
| URI location = Page.getCurrent().getLocation(); |
| String retcode = location.getScheme() + "://" +location.getHost(); |
| if (location.getPort() > 0) { |
| retcode += ":"+location.getPort(); |
| } |
| return retcode; |
| } |
| |
| /** |
| * see also {@link #getAbsoluteBasicResourceUri(String) |
| * @param classInBundle a class residing in the bundle |
| * @return the absolute basic resource uri, which can be used by a browser <b><u>without</u> the protocol, host and port</b> |
| */ |
| public static String getAbsoluteBasicResourceUri(Class<?> classInBundle) { |
| try { |
| return getAbsoluteBasicResourceUri(FrameworkUtil.getBundle(classInBundle).getSymbolicName()); |
| } |
| catch (Exception e) { |
| return null; |
| } |
| } |
| |
| /** |
| * see also {@link #getAbsoluteBasicResourceUri(String, Class)<br> |
| * The absolute basic uri defined by the bundle given will be generated! |
| * @param symbolicBundleName the symbolic bundle name, where the requested resource should reside |
| * @return the absolute uri, which can be used by a browser |
| */ |
| public static String getAbsoluteBasicResourceUri(String symbolicBundleName) { |
| try { |
| return |
| getProtocolHostPort() + |
| VaadinService.getCurrentRequest().getContextPath() + |
| "/VAADIN/themes/" + |
| getThemeName() + |
| "/plugin/" + |
| symbolicBundleName + |
| "/"; |
| } |
| catch (Exception e) { |
| return null; |
| } |
| } |
| } |