Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: c074d8cc454c36e17cfe8232e9b2258cd223927b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*******************************************************************************
 * Copyright (c) 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - Initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.server.preview.adapter.internal.core;

import java.net.URL;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jst.server.preview.adapter.internal.Trace;
import org.eclipse.wst.server.core.IModuleArtifact;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.model.LaunchableAdapterDelegate;
import org.eclipse.wst.server.core.util.HttpLaunchable;
import org.eclipse.wst.server.core.util.WebResource;

public class PreviewLaunchableAdapterDelegate extends LaunchableAdapterDelegate {
	/*
	 * @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;
	}
}

Back to the top