View Javadoc
1   /*
2    * Copyright (C) 2007-2012 Argeo GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.argeo.slc.support.deploy;
17  
18  import java.io.File;
19  import java.net.MalformedURLException;
20  import java.net.URL;
21  
22  import org.argeo.slc.SlcException;
23  import org.argeo.slc.deploy.TargetData;
24  
25  public class HttpdApplicationTargetData implements TargetData {
26  	private HttpdServer webServer;
27  	private String relativePath;
28  	private String targetRootPath;
29  
30  	public HttpdServer getWebServer() {
31  		return webServer;
32  	}
33  
34  	public void setWebServer(HttpdServer webServer) {
35  		this.webServer = webServer;
36  	}
37  
38  	public String getRelativePath() {
39  		return relativePath;
40  	}
41  
42  	/**
43  	 * If targetRootLocation not set, used to build the targetRootLocation,
44  	 * relative to the webserver base.
45  	 */
46  	public void setRelativePath(String relativePath) {
47  		this.relativePath = relativePath;
48  	}
49  
50  	public String getTargetRootPath() {
51  		return targetRootPath;
52  	}
53  
54  	public void setTargetRootPath(String targetRootPath) {
55  		this.targetRootPath = targetRootPath;
56  	}
57  
58  	public URL getTargetBaseUrl() {
59  		try {
60  			URL wsUrl = getWebServer().getBaseUrl();
61  			// TODO: use URI
62  			return new URL(wsUrl, wsUrl.getFile() + '/' + relativePath);
63  		} catch (MalformedURLException e) {
64  			throw new SlcException("Cannot get base url for " + relativePath, e);
65  		}
66  	}
67  
68  	public File getTargetRootLocation() {
69  		if (targetRootPath != null && !targetRootPath.equals("")) {
70  			return new File(targetRootPath);
71  		} else {
72  			HttpdServerTargetData targetData = (HttpdServerTargetData) getWebServer()
73  					.getTargetData();
74  			String path = targetData.getServerRoot() + File.separator
75  					+ getRelativePath();
76  			return new File(path);
77  		}
78  	}
79  
80  }