001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.pluto.util.install.file.tomcat5;
018:
019: import java.io.File;
020: import java.io.FileWriter;
021: import java.io.IOException;
022: import java.util.Iterator;
023: import java.util.List;
024: import java.util.Map;
025:
026: import org.apache.pluto.util.install.InstallationConfig;
027: import org.apache.pluto.util.install.file.FileSystemInstaller;
028:
029: public class Tomcat5FileSystemInstaller extends FileSystemInstaller {
030:
031: //
032: // PortalInstaller Interface
033: //
034:
035: /**
036: * Determine whether or not this is a valid Tomcat 5.x installation.
037: * @param installDir the proposed TOMCAT BASE directory
038: * @return true if and only if <code>conf/server.xml</code> and
039: * <code>conf/catalina.properties exist.</code>
040: */
041: public boolean isValidInstallationDirectory(File installDir) {
042: File serverConfig = new File(installDir, "conf/server.xml");
043: File catalinaProps = new File(installDir,
044: "conf/catalina.properties");
045: return serverConfig.exists() && catalinaProps.exists();
046: }
047:
048: //
049: // FileSystemInstaller Implementation
050: //
051:
052: public void writeConfiguration(InstallationConfig config)
053: throws IOException {
054:
055: File contextConfigurationDirectory = getConfigurationDir(config);
056: if (!contextConfigurationDirectory.exists()) {
057: contextConfigurationDirectory.mkdirs();
058: }
059:
060: Iterator it = config.getPortletApplications().entrySet()
061: .iterator();
062: while (it.hasNext()) {
063: Map.Entry entry = (Map.Entry) it.next();
064: String context = entry.getKey().toString();
065: File portletApp = (File) entry.getValue();
066:
067: String deployed = "../"
068: + config.getServerConfig().getDomain() + "/"
069: + portletApp.getName();
070: String contents = getPortletApplicationConfig(context,
071: deployed);
072: FileWriter out = new FileWriter(new File(
073: contextConfigurationDirectory, context + ".xml"));
074: out.write(contents);
075: out.flush();
076: out.close();
077: }
078:
079: File xmlFile = new File(contextConfigurationDirectory, config
080: .getPortalContextPath()
081: + ".xml");
082:
083: FileWriter out = new FileWriter(xmlFile);
084: out.write(getPortalApplicationConfig(config));
085: out.flush();
086: out.close();
087: }
088:
089: protected File getEndorsedDir(InstallationConfig config) {
090: File installationDirectory = config.getInstallationDirectory();
091: return new File(installationDirectory, "common/endorsed");
092: }
093:
094: protected File getSharedDir(InstallationConfig config) {
095: File installationDirectory = config.getInstallationDirectory();
096: // Tomcat 5 provides commons-logging-api. Should be a nicer way
097: // for installers to indicate what dependencies are provided by the
098: // servlet container.
099: if (new File(config.getInstallationDirectory(),
100: "bin/commons-logging-api.jar").exists()) {
101: for (Iterator iter = config.getSharedDependencies()
102: .iterator(); iter.hasNext();) {
103: File dep = (File) iter.next();
104: if (dep.getPath().indexOf("commons-logging-api") != -1) {
105: iter.remove();
106: }
107: }
108: }
109: return new File(installationDirectory, "shared/lib");
110: }
111:
112: protected File getWebAppDir(InstallationConfig config) {
113: File installationDirectory = config.getInstallationDirectory();
114: return new File(installationDirectory, config.getServerConfig()
115: .getDomain());
116: }
117:
118: //
119: // Helpers
120: //
121:
122: protected File getConfigurationDir(InstallationConfig config) {
123: File installationDirectory = config.getInstallationDirectory();
124: String engine = "Catalina";
125: String host = config.getServerConfig().getHost();
126: return new File(installationDirectory, "conf/" + engine + "/"
127: + host);
128: }
129:
130: private String getPortalApplicationConfig(InstallationConfig config) {
131: String war = "../" + config.getServerConfig().getDomain() + "/"
132: + config.getPortalApplication().getName();
133: String contextPath = config.getPortalContextPath();
134: return getConfigContents(war, contextPath);
135: }
136:
137: private String getPortletApplicationConfig(String contextPath,
138: String file) {
139: return getConfigContents(file, contextPath);
140: }
141:
142: private String getConfigContents(String war, String contextPath) {
143: StringBuffer contents = new StringBuffer();
144: contents.append("<Context ").append("path=\"").append(
145: contextPath).append("\" ").append("docBase=\"").append(
146: war).append("\" ").append("crossContext=\"true\">")
147: .append("</Context>");
148: return contents.toString();
149: }
150: }
|