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;
}
}
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;
}
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;
}
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);
}
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;
}
Aggregations