Search in sources :

Example 1 with HttpLaunchable

use of org.eclipse.wst.server.core.util.HttpLaunchable in project webtools.servertools by eclipse.

the class GenericServerLaunchableAdapterDelegate method prepareHttpLaunchable.

/**
 * @param moduleObject
 * @param delegate
 * @return object
 */
private Object prepareHttpLaunchable(IModuleArtifact moduleObject, ServerDelegate delegate) {
    try {
        URL url = ((IURLProvider) delegate).getModuleRootURL(moduleObject.getModule());
        // $NON-NLS-1$
        Trace.trace("root: " + url);
        if (moduleObject instanceof Servlet) {
            Servlet servlet = (Servlet) moduleObject;
            if (servlet.getAlias() != null) {
                String path = servlet.getAlias();
                if (// $NON-NLS-1$
                path.startsWith("/"))
                    path = path.substring(1);
                url = new URL(url, path);
            } else
                // $NON-NLS-1$
                url = new URL(url, "servlet/" + servlet.getServletClassName());
        } else if (moduleObject instanceof WebResource) {
            WebResource resource = (WebResource) moduleObject;
            String path = resource.getPath().toString();
            // $NON-NLS-1$
            Trace.trace("path: " + path);
            if (// $NON-NLS-1$
            path != null && path.startsWith("/") && path.length() > 0)
                path = path.substring(1);
            if (path != null && path.length() > 0)
                url = new URL(url, path);
        }
        return new HttpLaunchable(url);
    } catch (Exception e) {
        // $NON-NLS-1$
        Trace.trace("Error getting URL for " + moduleObject, e);
        return null;
    }
}
Also used : HttpLaunchable(org.eclipse.wst.server.core.util.HttpLaunchable) Servlet(org.eclipse.jst.server.core.Servlet) WebResource(org.eclipse.wst.server.core.util.WebResource) URL(java.net.URL)

Example 2 with HttpLaunchable

use of org.eclipse.wst.server.core.util.HttpLaunchable in project webtools.servertools by eclipse.

the class PreviewLaunchableAdapterDelegate method getLaunchable.

/*
	 * @see LaunchableAdapterDelegate#getLaunchable(IServer, IModuleArtifact)
	 */
public Object getLaunchable(IServer server, IModuleArtifact moduleArtifact) throws CoreException {
    if (server == null || moduleArtifact == null)
        return null;
    PreviewServer server2 = (PreviewServer) server.loadAdapter(PreviewServer.class, null);
    if (server2 == null)
        return null;
    try {
        URL url = server2.getModuleRootURL(moduleArtifact.getModule());
        if (moduleArtifact instanceof WebResource) {
            WebResource resource = (WebResource) moduleArtifact;
            String path = resource.getPath().toString();
            if (path.startsWith("/"))
                path = path.substring(1);
            url = new URL(url.toExternalForm() + "/" + path);
        }
        return new HttpLaunchable(url);
    } catch (Exception e) {
        Trace.trace(Trace.SEVERE, "Error in launchable adapter", e);
    }
    return null;
}
Also used : HttpLaunchable(org.eclipse.wst.server.core.util.HttpLaunchable) WebResource(org.eclipse.wst.server.core.util.WebResource) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException)

Example 3 with HttpLaunchable

use of org.eclipse.wst.server.core.util.HttpLaunchable in project webtools.servertools by eclipse.

the class PreviewLaunchableAdapterDelegate method getLaunchable.

/*
	 * @see LaunchableAdapterDelegate#getLaunchable(IServer, IModuleArtifact)
	 */
public Object getLaunchable(IServer server, IModuleArtifact moduleArtifact) throws CoreException {
    if (server == null || moduleArtifact == null)
        return null;
    PreviewServer server2 = (PreviewServer) server.loadAdapter(PreviewServer.class, null);
    if (server2 == null)
        return null;
    try {
        URL url = server2.getModuleRootURL(moduleArtifact.getModule());
        if (moduleArtifact instanceof WebResource) {
            WebResource resource = (WebResource) moduleArtifact;
            String path = resource.getPath().toString();
            if (path.startsWith("/"))
                path = path.substring(1);
            url = new URL(url.toExternalForm() + "/" + path);
        }
        return new HttpLaunchable(url);
    } catch (Exception e) {
        Trace.trace(Trace.SEVERE, "Error in launchable adapter", e);
    }
    return null;
}
Also used : HttpLaunchable(org.eclipse.wst.server.core.util.HttpLaunchable) WebResource(org.eclipse.wst.server.core.util.WebResource) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException)

Example 4 with HttpLaunchable

use of org.eclipse.wst.server.core.util.HttpLaunchable in project webtools.servertools by eclipse.

the class WebLaunchableClient method launch.

/*
	 * @see ClientDelegate#launch(ILaunchable)
	 */
public IStatus launch(IServer server, Object launchable, String launchMode, ILaunch launch) {
    HttpLaunchable http = (HttpLaunchable) launchable;
    try {
        IWorkbenchBrowserSupport browserSupport = ServerUIPlugin.getInstance().getWorkbench().getBrowserSupport();
        IWebBrowser browser = browserSupport.createBrowser(IWorkbenchBrowserSupport.LOCATION_BAR | IWorkbenchBrowserSupport.NAVIGATION_BAR, null, null, null);
        browser.openURL(http.getURL());
        return Status.OK_STATUS;
    } catch (Exception e) {
        if (Trace.SEVERE) {
            Trace.trace(Trace.STRING_SEVERE, "Error opening browser", e);
        }
        return new Status(IStatus.ERROR, ServerUIPlugin.PLUGIN_ID, e.getMessage(), e);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) HttpLaunchable(org.eclipse.wst.server.core.util.HttpLaunchable) IWorkbenchBrowserSupport(org.eclipse.ui.browser.IWorkbenchBrowserSupport) IWebBrowser(org.eclipse.ui.browser.IWebBrowser)

Example 5 with HttpLaunchable

use of org.eclipse.wst.server.core.util.HttpLaunchable in project webtools.servertools by eclipse.

the class HttpLaunchableAdapterDelegate method getLaunchable.

/*
	 * @see LaunchableAdapterDelegate#getLaunchable(IServer, IModuleArtifact)
	 */
public Object getLaunchable(IServer server, IModuleArtifact moduleArtifact) throws CoreException {
    if (server == null || moduleArtifact == null)
        return null;
    HttpServer server2 = (HttpServer) server.loadAdapter(HttpServer.class, null);
    if (server2 == null)
        return null;
    try {
        URL url = server2.getModuleRootURL(moduleArtifact.getModule());
        if (moduleArtifact instanceof WebResource) {
            WebResource resource = (WebResource) moduleArtifact;
            String path = resource.getPath().toString();
            if (path.startsWith("/"))
                path = path.substring(1);
            url = new URL(url.toExternalForm() + "/" + path);
        }
        return new HttpLaunchable(url);
    } catch (Exception e) {
        Trace.trace(Trace.SEVERE, "Error in launchable adapter", e);
    }
    return null;
}
Also used : HttpLaunchable(org.eclipse.wst.server.core.util.HttpLaunchable) WebResource(org.eclipse.wst.server.core.util.WebResource) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

HttpLaunchable (org.eclipse.wst.server.core.util.HttpLaunchable)6 URL (java.net.URL)5 WebResource (org.eclipse.wst.server.core.util.WebResource)5 CoreException (org.eclipse.core.runtime.CoreException)3 Servlet (org.eclipse.jst.server.core.Servlet)2 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 IWebModule (org.eclipse.jst.server.core.IWebModule)1 IWebBrowser (org.eclipse.ui.browser.IWebBrowser)1 IWorkbenchBrowserSupport (org.eclipse.ui.browser.IWorkbenchBrowserSupport)1