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.jetspeed.deployment.impl;
018:
019: import java.io.File;
020: import java.io.IOException;
021: import java.io.InputStream;
022: import java.util.zip.ZipEntry;
023: import java.util.zip.ZipFile;
024:
025: import org.apache.jetspeed.deployment.DeploymentObject;
026:
027: /**
028: * <p>
029: * DeploymentObject
030: * </p>
031: *
032: * @author <a href="mailto:weaver@apache.org">Scott T. Weaver </a>
033: * @version $Id: StandardDeploymentObject.java 516448 2007-03-09 16:25:47Z ate $
034: */
035: public class StandardDeploymentObject implements DeploymentObject {
036: protected File deploymentObject;
037: protected ZipFile zipFile;
038:
039: /**
040: * @throws IOException
041: */
042: public StandardDeploymentObject(File deploymentObject)
043: throws FileNotDeployableException {
044: if (verifyExtension(deploymentObject)) {
045: this .deploymentObject = deploymentObject;
046: } else {
047: throw new FileNotDeployableException("File type for "
048: + deploymentObject.getName()
049: + " is not supported by StandardDeploymentObject.");
050: }
051:
052: }
053:
054: /**
055: * <p>
056: * close
057: * </p>
058: *
059: * @see org.apache.jetspeed.deployment.DeploymentObject#close()
060: * @throws IOException
061: */
062: public void close() throws IOException {
063: if (zipFile != null) {
064: zipFile.close();
065: zipFile = null;
066: }
067: }
068:
069: /**
070: * <p>
071: * getConfiguration
072: * </p>
073: *
074: * @see org.apache.jetspeed.deployment.DeploymentObject#getConfiguration(java.lang.String)
075: * @param configPath
076: * @return
077: * @throws IOException
078: */
079: public InputStream getConfiguration(String configPath)
080: throws IOException {
081: ZipFile zipFile = getZipFile();
082: ZipEntry entry = zipFile.getEntry(configPath);
083: if (entry != null) {
084: return zipFile.getInputStream(entry);
085: }
086: return null;
087: }
088:
089: /**
090: * <p>
091: * getName
092: * </p>
093: *
094: * @see org.apache.jetspeed.deployment.DeploymentObject#getName()
095: * @return
096: */
097: public String getName() {
098: return deploymentObject.getName();
099: }
100:
101: /**
102: * <p>
103: * getPath
104: * </p>
105: *
106: * @see org.apache.jetspeed.deployment.DeploymentObject#getPath()
107: * @return
108: */
109: public String getPath() {
110: return deploymentObject.getAbsolutePath();
111: }
112:
113: public ZipFile getZipFile() throws IOException {
114: if (zipFile == null) {
115: zipFile = new ZipFile(deploymentObject);
116: }
117: return zipFile;
118: }
119:
120: public File getFile() {
121: return deploymentObject;
122: }
123:
124: protected boolean verifyExtension(File file) {
125: String fileName = file.getName();
126: int dot = fileName.lastIndexOf('.');
127: if (dot != -1) {
128: String ext = fileName.substring(dot);
129: return ext.equals(".war") || ext.equals(".jar")
130: || ext.equals(".zip");
131: } else {
132: return false;
133: }
134: }
135:
136: }
|