001: /*
002: * CmdExport.java
003: *
004: * Created on November 14, 2001, 1:27 PM
005: */
006:
007: package com.sun.portal.desktop.deployment;
008:
009: import java.util.Vector;
010: import java.util.HashMap;
011:
012: import java.io.PrintStream;
013: import java.io.File;
014:
015: import com.sun.portal.desktop.dp.DPPropertyHolder;
016:
017: /**
018: *
019: * @author yabob
020: * @version
021: */
022: public class CmdExport {
023:
024: public static void doExport(boolean verbose, boolean modify,
025: String parfile, DPRootSpecifier dpr, String ss,
026: Vector expfiles, PrintStream out) throws ParFileException {
027:
028: ParFileBuilder pfb = new ParFileBuilder(verbose, out);
029:
030: // If we're modifying the file, build from the old one first, then let
031: // the new entries overwrite any old ones. This builds up a list of
032: // internal pointers to ZipEntry's in the old file.
033:
034: if (modify) {
035: ParFile oldpf = ParFile.makeParFile(parfile);
036: ParManifest oldmf = oldpf.getParManifest();
037: oldmf.transferFileEntries(pfb, oldpf);
038: }
039:
040: // Make our context, and process expfiles, adding entries from them. We handle duplicate
041: // names here, as ParFileBuilder is intended to allow merging of entries.
042:
043: ProviderPackageContext ppctx = new DPBasedPPCtx(dpr, ss);
044: HashMap namecheck = new HashMap();
045: for (int i = 0; i < expfiles.size(); ++i) {
046: String fn = (String) expfiles.elementAt(i);
047: ExportFile xpf = ExportFile.makeExportFile(fn, dpr.getDN(),
048: ppctx);
049: String nm = xpf.getDPEntryName();
050: if (namecheck.get(nm) != null) {
051: Object tok[] = { nm };
052: throw new ParFileException("errorExportDupEntry", tok);
053: }
054: namecheck.put(nm, nm);
055: xpf.addEntry(pfb);
056: }
057:
058: // If modifying, stream out to a temp file, so that we don't clobber the data in our old
059: // file, then rename it.
060:
061: if (modify) {
062: File tf = null;
063: String tfn = null;
064:
065: try {
066: tf = File.createTempFile("parexp", "par");
067: tfn = tf.getAbsolutePath();
068: } catch (Exception ex) {
069: throw new ParFileException("errorTempFile", ex);
070: }
071:
072: pfb.makeParFile(tfn);
073: pfb.clear();
074:
075: try {
076: tf.renameTo(new File(parfile));
077: } catch (Exception ex) {
078: Object tok[] = { tfn };
079: System.err.println(Par.getLocalizedString(
080: "msgFailedRename", tok));
081: }
082:
083: return;
084: }
085:
086: // Not modifying. Just stream out to our file directly.
087:
088: pfb.makeParFile(parfile);
089: }
090:
091: /**
092: * @param args the command line arguments
093: */
094: public static void main(String args[]) {
095:
096: CmdOpts opts = CmdOpts.parseOpts(args, CmdOpts.STD_BOTH,
097: CmdOpts.REM_REQUIRED, Par
098: .getLocalizedString("usageExport"), "rpdsvm");
099: if (opts != null) {
100: try {
101: doExport(opts.verbose(), opts.modify(), opts.parfile(),
102: opts.dproot(), opts.staticsub(), opts
103: .remaining(), System.out);
104: } catch (Exception ex) {
105: opts.produceErrorMessage(ex);
106: }
107: }
108:
109: System.exit(0);
110: }
111: }
|