001: /*
002: * $Id: WebKunststoffPackager.java 674 2004-05-12 22:48:49Z mchenryc $
003: * IzPack
004: * Copyright (C) 2001-2004 Julien Ponge
005: *
006: * File : WebKunststoffPackager.java
007: * Description : The web installer packager class with the Kunststoff L&F support.
008: * Author's email : julien@izforge.com
009: * Author's Website : http://www.izforge.com
010: *
011: * This program is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU General Public License
013: * as published by the Free Software Foundation; either version 2
014: * of the License, or any later version.
015: *
016: * This program is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
019: * GNU General Public License for more details.
020: *
021: * You should have received a copy of the GNU General Public License
022: * along with this program; if not, write to the Free Software
023: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
024: */
025: package com.izforge.izpack.compiler;
026:
027: import java.io.DataOutputStream;
028: import java.io.File;
029: import java.io.FileInputStream;
030: import java.io.InputStream;
031: import java.io.ObjectOutputStream;
032: import java.util.jar.JarInputStream;
033: import java.util.zip.ZipEntry;
034: import java.util.zip.ZipException;
035: import java.util.zip.ZipInputStream;
036:
037: /**
038: * Web installer class with the Kunststoff L&F support.
039: *
040: * @author Julien Ponge
041: */
042: public class WebKunststoffPackager extends WebPackager {
043:
044: /**
045: * The constructor.
046: *
047: * @param outputFilename The output filename.
048: * @param plistener The packager listener.
049: * @exception Exception Description of the Exception
050: */
051: public WebKunststoffPackager(String outputFilename,
052: PackagerListener plistener) throws Exception {
053: super (outputFilename, plistener);
054:
055: // Copies the Kunststoff library
056: sendMsg("Copying the Kunststoff library ...");
057: InputStream istream = getClass().getResourceAsStream(
058: "/lib/kunststoff.jar");
059: ZipInputStream skeleton_is;
060: if (istream != null) {
061: skeleton_is = new ZipInputStream(istream);
062: } else {
063: skeleton_is = new JarInputStream(new FileInputStream(
064: Compiler.IZPACK_HOME + "lib" + File.separator
065: + "kunststoff.jar"));
066: }
067:
068: ZipEntry zentry;
069:
070: while ((zentry = skeleton_is.getNextEntry()) != null) {
071: // Puts a new entry
072: try {
073: outJar.putNextEntry(new ZipEntry(zentry.getName()));
074: // Copy the data
075: copyStream(skeleton_is, outJar);
076:
077: outJar.closeEntry();
078: skeleton_is.closeEntry();
079: } catch (ZipException x) {
080: /* Hopefully only duplicate entries cause this error. This is needed
081: * because the skeleton has already been copied in (including classes
082: * in the 'com/' directory) and copying the kunststoff installer tries
083: * to add an entry for the 'com/' directory also, which fails because
084: * it already exists. */
085: }
086: }
087: }
088:
089: /**
090: * Tells the packager to finish the job (misc writings, cleanups, closings ,
091: * ...).
092: *
093: * @exception Exception Description of the Exception
094: */
095: public void finish() throws Exception {
096: // Usefull stuff
097: DataOutputStream datOut;
098: ObjectOutputStream objOut;
099: int size;
100: int i;
101:
102: sendMsg("Finishing the enpacking ...");
103:
104: // Writes the installation kind information
105: outJar.putNextEntry(new ZipEntry("kind"));
106: datOut = new DataOutputStream(outJar);
107: datOut.writeUTF("web-kunststoff");
108: datOut.flush();
109: outJar.closeEntry();
110:
111: // Writes the packs informations
112: outJar.putNextEntry(new ZipEntry("packs.info"));
113: objOut = new ObjectOutputStream(outJar);
114: size = packs.size();
115: objOut.writeInt(size);
116: for (i = 0; i < size; i++)
117: objOut.writeObject(packs.get(i));
118: objOut.flush();
119: outJar.closeEntry();
120:
121: // Writes the langpacks informations
122: outJar.putNextEntry(new ZipEntry("langpacks.info"));
123: datOut = new DataOutputStream(outJar);
124: size = langpacks.size();
125: datOut.writeInt(size);
126: for (i = 0; i < size; i++)
127: datOut.writeUTF((String) langpacks.get(i));
128: datOut.flush();
129: outJar.closeEntry();
130:
131: // Closes the stream
132: outJar.flush();
133: outJar.close();
134: webJar.flush();
135: webJar.close();
136:
137: sendStop();
138: }
139: }
|