Search in sources :

Example 1 with WebResource

use of org.eclipse.wst.server.core.util.WebResource 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 WebResource

use of org.eclipse.wst.server.core.util.WebResource 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 WebResource

use of org.eclipse.wst.server.core.util.WebResource 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 WebResource

use of org.eclipse.wst.server.core.util.WebResource in project webtools.sourceediting by eclipse.

the class StaticWebDeployableObjectAdapterUtil method getModuleObject.

public static IModuleArtifact getModuleObject(Object obj) {
    IResource resource = null;
    if (obj instanceof IResource)
        resource = (IResource) obj;
    else if (obj instanceof IAdaptable)
        resource = ((IAdaptable) obj).getAdapter(IResource.class);
    if (resource == null)
        return null;
    if (resource instanceof IProject) {
        IProject project = (IProject) resource;
        if (hasInterestedComponents(project))
            // $NON-NLS-1$
            return new WebResource(getModule(project), new Path(""));
        return null;
    }
    IProject project = ProjectUtilities.getProject(resource);
    if (project != null && !hasInterestedComponents(project))
        return null;
    IVirtualComponent comp = ComponentCore.createComponent(project);
    // determine path
    IPath rootPath = comp.getRootFolder().getProjectRelativePath();
    IPath resourcePath = resource.getProjectRelativePath();
    // Check to make sure the resource is under the webApplication directory
    if (resourcePath.matchingFirstSegments(rootPath) != rootPath.segmentCount())
        return null;
    // Do not allow resource under the web-inf directory
    resourcePath = resourcePath.removeFirstSegments(rootPath.segmentCount());
    if (resourcePath.segmentCount() > 1 && resourcePath.segment(0).equals(INFO_DIRECTORY))
        return null;
    if (shouldExclude(resource))
        return null;
    // return Web resource type
    return new WebResource(getModule(project), resourcePath);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IAdaptable(org.eclipse.core.runtime.IAdaptable) IPath(org.eclipse.core.runtime.IPath) WebResource(org.eclipse.wst.server.core.util.WebResource) IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 5 with WebResource

use of org.eclipse.wst.server.core.util.WebResource 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

WebResource (org.eclipse.wst.server.core.util.WebResource)6 URL (java.net.URL)5 HttpLaunchable (org.eclipse.wst.server.core.util.HttpLaunchable)5 CoreException (org.eclipse.core.runtime.CoreException)3 Servlet (org.eclipse.jst.server.core.Servlet)2 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 IWebModule (org.eclipse.jst.server.core.IWebModule)1 IVirtualComponent (org.eclipse.wst.common.componentcore.resources.IVirtualComponent)1