01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.pluto.util.assemble.war;
18:
19: import java.io.File;
20: import java.io.FileInputStream;
21: import java.io.FileOutputStream;
22: import java.io.IOException;
23: import java.util.jar.JarInputStream;
24: import java.util.jar.JarOutputStream;
25: import java.util.jar.Manifest;
26:
27: import org.apache.pluto.util.UtilityException;
28: import org.apache.pluto.util.assemble.AbstractArchiveAssembler;
29: import org.apache.pluto.util.assemble.AssemblerConfig;
30: import org.apache.pluto.util.assemble.io.JarStreamingAssembly;
31:
32: /**
33: *
34: * @version 1.0
35: * @since Nov 8, 2004
36: */
37: public class WarAssembler extends AbstractArchiveAssembler {
38: // Constructor -------------------------------------------------------------
39:
40: /**
41: * Default no-arg constructor.
42: */
43: public WarAssembler() {
44: // Do nothing.
45: }
46:
47: // Assembler Impl ----------------------------------------------------------
48:
49: public void assembleInternal(AssemblerConfig config)
50: throws UtilityException, IOException {
51:
52: this .assembleWar(config.getSource(), config.getDestination(),
53: config.getDispatchServletClass());
54:
55: }
56:
57: /**
58: * Reads the source JAR copying entries to the dest JAR. The web.xml and portlet.xml are cached
59: * and after the entire archive is copied (minus the web.xml) a re-written web.xml is generated
60: * and written to the destination JAR.
61: */
62: protected void assembleWar(File source, File dest,
63: String dispatchServletClass) throws IOException {
64: final JarInputStream jarIn = new JarInputStream(
65: new FileInputStream(source));
66: //Create the output JAR stream, copying the Manifest
67: final Manifest manifest = jarIn.getManifest();
68: //TODO add pluto notes to the Manifest?
69: final JarOutputStream jarOut = new JarOutputStream(
70: new FileOutputStream(dest), manifest);
71:
72: try {
73: JarStreamingAssembly.assembleStream(jarIn, jarOut,
74: dispatchServletClass);
75: } finally {
76: jarIn.close();
77: jarOut.close();
78: }
79: }
80:
81: }
|