001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package acl_data;
028:
029: import java.util.Vector;
030: import java.io.*;
031: import java.security.*;
032: import java.security.cert.CertificateException;
033:
034: /**
035: * Main class implementation
036: */
037: public class Main {
038:
039: /** ACL root DF. */
040: short[] ACLDF = { 0x3f00, 0x5016 }; // MUST be long name
041: /** Output directory */
042: private String outputDataDir = "./output/";
043: private String outputFilesDir = "./output/files/";
044:
045: /** File system. */
046: FileSystem fs;
047: /** Stream for results. */
048: PrintStream src;
049:
050: /**
051: * Main function
052: * @param args program argument - input file name.
053: */
054: public static void main(String[] args) {
055: new Main().run(args);
056: }
057:
058: /**
059: * Check the program argument and start processing.
060: * @param args program argument - input file name.
061: */
062: void run(String[] args) {
063: if (args.length < 1) {
064: System.err.println("No file");
065: }
066: try {
067: if (args.length >= 2) {
068: outputDataDir = args[1];
069: }
070:
071: if (args.length >= 3) {
072: outputFilesDir = args[2];
073: }
074:
075: generateJavaData(generateFiles(args[0]));
076: } catch (Exception e) {
077: e.printStackTrace();
078: }
079: }
080:
081: /**
082: * Generates the data.
083: * @param inl list of generated files
084: * @throws KeyStoreException if this exception occurs
085: * @throws CertificateException if this exception occurs
086: * @throws IOException if this exception occurs
087: * @throws NoSuchAlgorithmException if this exception occurs
088: */
089: public void generateJavaData(Vector inl) throws KeyStoreException,
090: CertificateException, IOException, NoSuchAlgorithmException {
091: String fname;
092: short[] outname;
093: fs = new FileSystem(ACLDF);
094:
095: src = new PrintStream(new FileOutputStream(outputDataDir
096: + "Data.java"));
097:
098: src
099: .print("/*\n"
100: + " * \n"
101: + " *\n"
102: + " * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.\n"
103: + " * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER\n"
104: + " *\n */\n\n");
105: src.print("package com.sun.satsa.aclapplet;\n\n" + "/**\n"
106: + " * This class contains file system.\n */\n"
107: + "public class Data {\n\n");
108:
109: for (int i = 0; i < inl.size(); i++) {
110: fname = (String) inl.elementAt(i);
111: System.out.println(" ... generating " + fname);
112: if (fname == null) {
113: break;
114: }
115: outname = Utils.stringToShorts(fname
116: .substring((outputFilesDir).length()));
117: FileInputStream in = new FileInputStream(fname);
118: byte[] b = new byte[in.available()];
119: in.read(b);
120: fs.addFile(outname, FileSystem.READ, b);
121: }
122:
123: byte[] data = fs.getEncoded();
124:
125: src.println();
126:
127: src.print(" /** Files. */");
128: Utils.writeDataArray(src, "Files", data);
129: src.println("}");
130:
131: src.close();
132: }
133:
134: /**
135: * Returns list of generated files.
136: * @param args input file.
137: * @return vector of generated files.
138: */
139: Vector generateFiles(String args) {
140: ACFile file = ACFile.load(args, outputFilesDir);
141: try {
142: file.createODF();
143: file.createDODF();
144: return file.files;
145: } catch (IOException e) {
146: }
147: return null;
148: }
149:
150: }
|