FileDocCategorySizeDatePackage
MakeZipProto.javaAPI DocGlassfish v2 API8974Fri May 04 22:32:08 BST 2007com.sun.enterprise.util

MakeZipProto

public class MakeZipProto extends Object
This class is a utility intended to ease the conversion of Solaris package definitions defined in a prototype_com file into a file listing needed to drive the creation of a zip file. Each Solaris package (e.g. SUNWasuo) contains a prototype_com file that defines the files that make up that package. There are corresponding prototype_com.win2k and prototype_com.unix files the define the file listing for the zip files. These zip files are used for the evaluation installer on Solaris and the mainstream and evaluation installers on Win2K. This utility helps create the prototype_com.win2k and prototype_com.uniz files from the prototype_com file. For and example see iplanet/ias/server/src/pkg/SUNWasu. WARNING: This file is temporarily checked in here and really belongs more as part of the installer/build system; however, the installer is compiled with an older JDK version, and will not compile this file due to replaceAll.

Fields Summary
Constructors Summary
Methods Summary
protected static voidfilesetElement(org.w3c.dom.Node filesetNode, java.util.ArrayList fileList)

        NamedNodeMap attributes = filesetNode.getAttributes();
        Node includes = attributes.getNamedItem("includes");
        if (includes != null) {
	        StringTokenizer tok = new StringTokenizer(includes.getNodeValue());
            while (tok.hasMoreTokens()) {
	            fileList.add(tok.nextToken());
            }
        }
        ArrayList removeList = new ArrayList();
        Node excludes = attributes.getNamedItem("excludes");
        if (excludes != null) {
	        StringTokenizer tok = new StringTokenizer(excludes.getNodeValue());
            while (tok.hasMoreTokens()) {
	            removeList.add(tok.nextToken());
            }
        }
        for (int i = 0; i < fileList.size(); i++) {
            if (removeList.contains(fileList.get(i))) {
                fileList.remove(i--);
            }
        }
    
public static voidmain(java.lang.String[] args)

	    if (args.length != 1) {
	    	System.out.println("usage: MakeZipProto xmlFile");
	    } else {
		    String xmlFile = args[0];
		    try {
                parseXML(xmlFile);
			    //translate(inFile, outFile);
		    } catch (Exception ex) {
			    ex.printStackTrace();
		    }
	    }
    
public static java.lang.Stringparse(java.lang.String line)

	    String result = line.trim();
	    //skip empty lines
	    if (result.length() == 0) {
	    	return null;
	    }
	    //skip comments
	    if (result.startsWith("#")) {
		    return null;
	    }
	    //skip directories
	    if (result.startsWith("d ")) {
		    return null;
	    }
	    //skip included packaging files
	    if (result.startsWith("i ")) {
		    return null;
	    }
	    //process normal files
	    if (result.startsWith("f ")) {
		    return parseFile(result);
	    }
	    return result;
    
public static java.lang.StringparseFile(java.lang.String line)

	    StringTokenizer tok = new StringTokenizer(line);
	    tok.nextToken();
	    tok.nextToken();
	    String result = tok.nextToken().replaceAll("\\$ASINSTDIR/", "");
	    int pos = result.indexOf("=");
	    if (pos > 0) {
		    return result.substring(pos + 1);
	    } 
	    return result;
    
protected static voidparseXML(java.lang.String fileName)

        DocumentBuilder builder  = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        FileInputStream source = new FileInputStream(fileName);
        Document document = builder.parse(source);
        NodeList nodeList = document.getElementsByTagName("zipfile");
        if (nodeList != null) {
		    for (int i = 0; i < nodeList.getLength(); i++) {
                Node node = nodeList.item(i);
                zipfileElement(node);
            }
        }
    
protected static java.util.ArrayListreadInputFile(java.lang.String in)

        ArrayList result = new ArrayList();
        BufferedReader reader = null;
	    try {
    	    reader = new BufferedReader(new FileReader(in));
		    String line = null;
		    String newLine = null;
		    while (true) {
			    line = reader.readLine();
			    if (line == null) {
				    break;
			    }
			    newLine = parse(line);
			    if (newLine != null) {
                    result.add(newLine);
                }
			}
            return result;
	    } finally {
	    	try {
                if (reader != null) {
			        reader.close();
                }
		    } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    
protected static voidwriteOutputFile(java.lang.String out, java.util.ArrayList fileList)

        BufferedWriter writer = null;
	    try {
	        writer = new BufferedWriter(new FileWriter(out, false));
            for (int i = 0; i < fileList.size(); i++) {
				writer.write((String)fileList.get(i));
				writer.newLine();
			}
	    } finally {
		    try {
                if (writer != null) {
			        writer.close();
                }
		    } catch (Exception ex) {
                ex.printStackTrace();
            }
	    }	
    
protected static voidzipfileElement(org.w3c.dom.Node zipfileNode)

        NamedNodeMap attributes = zipfileNode.getAttributes();
        String inputFile = attributes.getNamedItem("input").getNodeValue();
        System.out.println("inputFile = " + inputFile);
        String outputFile = attributes.getNamedItem("output").getNodeValue();
        System.out.println("output = " + outputFile);
        ArrayList fileList = readInputFile(inputFile);
        for (int i = 0; i < fileList.size(); i++) {
            System.out.println("fileList before " + i + " = " + 
               fileList.get(i));
        }
        NodeList children = zipfileNode.getChildNodes();
        for (int j = 0; j < children.getLength(); j++) {
            Node childNode = children.item(j);
            if (childNode.getNodeName().equals("fileset")) {
                filesetElement(childNode, fileList);
            } 
        }
        for (int i = 0; i < fileList.size(); i++) {
            System.out.println("fileList after " + i + " = " + 
               fileList.get(i));
        }
        writeOutputFile(outputFile, fileList);