001: /*
002: * $Id: StdKunststoffPackager.java 588 2004-02-20 09:01:39Z jponge $
003: * IzPack
004: * Copyright (C) 2001-2004 Julien Ponge
005: *
006: * File : StdKunststoffPackager.java
007: * Description : The standard Kunststoff installer packager class.
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.ZipInputStream;
035:
036: /**
037: * The standard installer class, using the Kunststoff L&F.
038: *
039: * @author Julien Ponge
040: */
041: public class StdKunststoffPackager extends StdPackager {
042:
043: /**
044: * The constructor.
045: *
046: * @param outputFilename The output filename.
047: * @param plistener The packager listener.
048: * @exception Exception Description of the Exception
049: */
050: public StdKunststoffPackager(String outputFilename,
051: PackagerListener plistener) throws Exception {
052: super (outputFilename, plistener);
053:
054: // Copies the Kunststoff library
055: sendMsg("Copying the Kunststoff library ...");
056: InputStream istream = getClass().getResourceAsStream(
057: "/lib/kunststoff.jar");
058: ZipInputStream skeleton_is;
059: if (istream != null) {
060: skeleton_is = new ZipInputStream(istream);
061: } else {
062: skeleton_is = new JarInputStream(new FileInputStream(
063: Compiler.IZPACK_HOME + "lib" + File.separator
064: + "kunststoff.jar"));
065: }
066:
067: ZipEntry zentry;
068:
069: while ((zentry = skeleton_is.getNextEntry()) != null) {
070: // ugly hack: may not add a directory twice, therefore add no directories
071: if (zentry.isDirectory())
072: continue;
073:
074: // Puts a new entry
075: outJar.putNextEntry(new ZipEntry(zentry.getName()));
076:
077: // Copy the data
078: copyStream(skeleton_is, outJar);
079:
080: outJar.closeEntry();
081: skeleton_is.closeEntry();
082: }
083:
084: }
085:
086: /**
087: * Tells the packager to finish the job.
088: *
089: * @exception Exception Description of the Exception
090: */
091: public void finish() throws Exception {
092: // Usefull stuff
093: DataOutputStream datOut;
094: ObjectOutputStream objOut;
095: int size;
096: int i;
097:
098: sendMsg("Finishing the enpacking ...");
099:
100: // Writes the installation kind information
101: outJar.putNextEntry(new ZipEntry("kind"));
102: datOut = new DataOutputStream(outJar);
103: datOut.writeUTF("standard-kunststoff");
104: datOut.flush();
105: outJar.closeEntry();
106:
107: // Writes the packs informations
108: outJar.putNextEntry(new ZipEntry("packs.info"));
109: objOut = new ObjectOutputStream(outJar);
110: size = packs.size();
111: objOut.writeInt(size);
112: for (i = 0; i < size; i++)
113: objOut.writeObject(packs.get(i));
114: objOut.flush();
115: outJar.closeEntry();
116:
117: // Writes the langpacks informations
118: outJar.putNextEntry(new ZipEntry("langpacks.info"));
119: datOut = new DataOutputStream(outJar);
120: size = langpacks.size();
121: datOut.writeInt(size);
122: for (i = 0; i < size; i++)
123: datOut.writeUTF((String) langpacks.get(i));
124: datOut.flush();
125: outJar.closeEntry();
126:
127: // Closes the stream
128: outJar.flush();
129: outJar.close();
130:
131: sendStop();
132: }
133: }
|