001: /* *****************************************************************************
002: * CompressFlashFile.java
003: * ****************************************************************************/
004:
005: /* J_LZ_COPYRIGHT_BEGIN *******************************************************
006: * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
007: * Use is subject to license terms. *
008: * J_LZ_COPYRIGHT_END *********************************************************/
009:
010: package org.openlaszlo.sc;
011:
012: import org.openlaszlo.utils.FileUtils;
013: import org.openlaszlo.utils.StringUtils;
014: import org.openlaszlo.compiler.FontInfo;
015: import org.openlaszlo.iv.flash.api.*;
016: import org.openlaszlo.iv.flash.api.action.*;
017: import org.openlaszlo.iv.flash.api.image.*;
018: import org.openlaszlo.iv.flash.api.sound.*;
019: import org.openlaszlo.iv.flash.api.text.*;
020: import org.openlaszlo.iv.flash.util.*;
021: import org.openlaszlo.iv.flash.cache.*;
022: import org.apache.log4j.*;
023:
024: import java.io.*;
025: import java.util.*;
026:
027: /** Parse a flash 6 file and re-output it with flash 6 zip compression enabled
028: *
029: */
030:
031: public class CompressFlashFile {
032: private static Logger mLogger = Logger
033: .getLogger(CompressFlashFile.class);
034:
035: static public void main(String args[]) {
036: if (args.length != 2) {
037: System.out.println(
038: /* (non-Javadoc)
039: * @i18n.test
040: * @org-mes="usage: compressFlashFile infile outfile"
041: */
042: org.openlaszlo.i18n.LaszloMessages.getMessage(
043: CompressFlashFile.class.getName(), "051018-41"));
044: System.exit(1);
045: }
046: compressFile(args[0], args[1]);
047: }
048:
049: static public void compressFile(String infile, String outfile) {
050: try {
051: FlashFile f = FlashFile.parse(infile);
052: OutputStream out = new FileOutputStream(outfile);
053: FontsCollector fc = new FontsCollector();
054: HashMap fontsTable = new HashMap();
055:
056: java.util.Enumeration defs = f.definitions();
057: while (defs.hasMoreElements()) {
058: FlashDef def = (FlashDef) defs.nextElement();
059: if (def instanceof FontDef) {
060: FontDef fontDef = (FontDef) def;
061: Font font = fontDef.getFont();
062: String bold = ((font.BOLD & font.flags) > 0 ? "bold"
063: : "");
064: String italic = ((font.ITALIC & font.flags) > 0 ? "italic"
065: : "");
066: //System.out.println("Copying font " + font.getFontName()
067: //+ bold + italic);
068: FontDef fdef = fc.addFont(font, null);
069: fdef.setWriteAllChars(true);
070: fdef.setWriteLayout(true);
071: fontsTable.put(font.getFontName() + "::" + bold
072: + italic, font);
073: }
074: }
075: // Set flash 6 compression
076: f.setCompressed(true);
077: writeFlashFile(f, fc, out);
078: } catch (Exception e) {
079: mLogger.error(
080: /* (non-Javadoc)
081: * @i18n.test
082: * @org-mes="exception in CompressFlashFile.compressFile"
083: */
084: org.openlaszlo.i18n.LaszloMessages.getMessage(
085: CompressFlashFile.class.getName(), "051018-82"), e);
086: }
087: }
088:
089: static void writeFlashFile(FlashFile f, FontsCollector fc,
090: OutputStream out) {
091: try {
092: InputStream input;
093: input = f.generate(fc, null, false).getInputStream();
094: FileUtils.send(input, out);
095: input.close();
096: out.close();
097: } catch (Exception e) {
098: mLogger
099: .error(
100: /* (non-Javadoc)
101: * @i18n.test
102: * @org-mes="exception in CompressFlashFile.writeFlashFile"
103: */
104: org.openlaszlo.i18n.LaszloMessages.getMessage(
105: CompressFlashFile.class.getName(),
106: "051018-101"), e);
107: }
108: }
109:
110: }
|