home *** CD-ROM | disk | FTP | other *** search
/ PC User 2001 August / APC_Aug2001_CD2.iso / features / j2sdk / files / linux / j2sdklin.bin / jdk1.3.1 / lib / htmlconverter.jar / HTMLConverter.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-05-06  |  6.2 KB  |  198 lines

  1. import java.awt.Window;
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.io.InputStream;
  5. import java.util.Enumeration;
  6. import java.util.Vector;
  7. import sun.plugin.converter.ResourceHandler;
  8. import sun.plugin.converter.engine.DefaultSet;
  9. import sun.plugin.converter.engine.PluginConverter;
  10. import sun.plugin.converter.gui.ConverterGUI;
  11. import sun.plugin.converter.util.CommandLine;
  12. import sun.plugin.converter.util.FlexFilter;
  13. import sun.plugin.converter.util.NotDirectoryException;
  14.  
  15. public class HTMLConverter {
  16.    private CommandLine cmdLine;
  17.    private FlexFilter fileFilter = new FlexFilter();
  18.    private PluginConverter converter = null;
  19.    private DefaultSet set = null;
  20.    private File logFile = null;
  21.    private String sourceStr = null;
  22.    private String backupStr = null;
  23.    private String destStr = null;
  24.    private String tempStr = null;
  25.    private String logStr = null;
  26.    private String sep = System.getProperty("file.separator");
  27.    // $FF: synthetic field
  28.    static Class class$HTMLConverter;
  29.  
  30.    public HTMLConverter(String[] var1) {
  31.       this.cmdLine = new CommandLine(var1);
  32.       if (this.cmdLine.justHelp()) {
  33.          this.showHelp();
  34.          System.exit(0);
  35.       }
  36.  
  37.       if (this.cmdLine.doGUI()) {
  38.          this.processWithGUI();
  39.       } else {
  40.          this.processCommandLine();
  41.       }
  42.  
  43.    }
  44.  
  45.    private void processWithGUI() {
  46.       ConverterGUI var1 = new ConverterGUI();
  47.       ((Window)var1).pack();
  48.       var1.setVisible(true);
  49.    }
  50.  
  51.    private void processCommandLine() {
  52.       try {
  53.          this.converter = new PluginConverter(this.cmdLine.isLogFile(), this.cmdLine.showProgress());
  54.          this.converter.setConvertSet(this.set = new DefaultSet());
  55.          this.converter.setCommandLine(true);
  56.       } catch (FileNotFoundException var4) {
  57.          System.out.println(ResourceHandler.getMessage("notemplate_dialog.info0") + PluginConverter.getDefaultTemplateFileName() + ResourceHandler.getMessage("notemplate_dialog.info1"));
  58.       }
  59.  
  60.       try {
  61.          Vector var1 = this.cmdLine.getFileSpecs();
  62.          Enumeration var2 = var1.elements();
  63.  
  64.          while(var2.hasMoreElements()) {
  65.             this.fileFilter.addDescriptor((String)var2.nextElement());
  66.          }
  67.  
  68.          if (this.cmdLine.doSubDirs()) {
  69.             this.fileFilter.setFilesOnly(false);
  70.             this.converter.setRecurse(true);
  71.          }
  72.  
  73.          if (this.cmdLine.showProgress()) {
  74.             this.converter.setShowProgressStdOut(true);
  75.          }
  76.  
  77.          this.setSource();
  78.          this.setDest();
  79.          this.setBack();
  80.          this.setTemp();
  81.          this.setLog();
  82.          Enumeration var3 = this.set.getFilesEnumeration();
  83.          if (this.set.getFileCount() == 0) {
  84.             System.out.println(ResourceHandler.getMessage("plugin_converter.nofiles"));
  85.             System.exit(0);
  86.          } else if (this.cmdLine.justSimulate()) {
  87.             this.simulate(var3);
  88.          } else {
  89.             this.converter.startConversion();
  90.          }
  91.       } catch (IndexOutOfBoundsException var5) {
  92.          this.showHelp();
  93.          System.exit(0);
  94.       }
  95.  
  96.    }
  97.  
  98.    private void showHelp() {
  99.       System.out.println(ResourceHandler.getMessage("plugin_converter.help_message"));
  100.    }
  101.  
  102.    public static boolean checkTrue(String var0) {
  103.       var0 = var0.trim().toUpperCase();
  104.       return var0.equals("TRUE") || var0.equals("T") || var0.equals("YES") || var0.equals("Y");
  105.    }
  106.  
  107.    private void setSource() {
  108.       this.sourceStr = this.cmdLine.getSourceDir();
  109.       if (this.sourceStr != null) {
  110.          try {
  111.             File var1 = new File(this.sourceStr);
  112.             this.set.setSourcePath(var1, this.fileFilter);
  113.          } catch (NotDirectoryException var2) {
  114.             System.out.println(((Throwable)var2).getMessage());
  115.             System.exit(0);
  116.          }
  117.       } else {
  118.          this.set.setFiles(this.fileFilter);
  119.       }
  120.  
  121.    }
  122.  
  123.    private void setDest() {
  124.       this.destStr = this.cmdLine.getDestDir();
  125.       if (this.destStr != null) {
  126.          File var1 = new File(this.destStr);
  127.          this.set.setDestinationPath(var1);
  128.       } else {
  129.          this.set.setDestinationPath(this.set.getDefaultDestPath());
  130.       }
  131.  
  132.    }
  133.  
  134.    private void setBack() {
  135.       this.backupStr = this.cmdLine.getBackupDir();
  136.       if (this.backupStr != null) {
  137.          File var1 = new File(this.backupStr);
  138.          this.set.setBackupPath(var1);
  139.       } else {
  140.          this.set.setBackupPath(this.set.getDefaultBackupPath());
  141.       }
  142.  
  143.    }
  144.  
  145.    private void setTemp() {
  146.       this.tempStr = this.cmdLine.getTemplateDir();
  147.       if (this.tempStr != null) {
  148.          try {
  149.             InputStream var1 = (class$HTMLConverter == null ? (class$HTMLConverter = class$("HTMLConverter")) : class$HTMLConverter).getClassLoader().getResourceAsStream(this.tempStr);
  150.             this.converter.setTemplateFilePath(this.tempStr);
  151.          } catch (FileNotFoundException var2) {
  152.             System.out.println(ResourceHandler.getMessage("nottemplatefile_dialog.info2") + ":  " + this.tempStr);
  153.          }
  154.       }
  155.  
  156.    }
  157.  
  158.    private void setLog() {
  159.       this.logStr = this.cmdLine.getLogFile();
  160.       if (this.logStr != null) {
  161.          this.logFile = new File(this.logStr);
  162.          this.converter.setLogFile(this.logFile);
  163.       }
  164.  
  165.    }
  166.  
  167.    private void simulate(Enumeration var1) {
  168.       System.out.println(ResourceHandler.getMessage("plugin_converter.files"));
  169.  
  170.       while(var1.hasMoreElements()) {
  171.          System.out.println(this.set.getSourcePath() + this.sep + (String)var1.nextElement());
  172.       }
  173.  
  174.       System.out.println("\n" + ResourceHandler.getMessage("plugin_converter.backup_path") + ":\t" + this.set.getBackupPath());
  175.       if (this.logFile != null) {
  176.          System.out.println(ResourceHandler.getMessage("plugin_converter.log_path") + ":\t" + (this.cmdLine.getLogFile() == null ? this.converter.getDefaultLogFile().getAbsolutePath() : this.logFile.getAbsolutePath()));
  177.       }
  178.  
  179.       System.out.println("\n" + ResourceHandler.getMessage("plugin_converter.template_file") + ":\t" + this.converter.getTemplateFilePath());
  180.       System.out.println(ResourceHandler.getMessage("plugin_converter.process_subdirs") + ":\t" + this.converter.isRecurse());
  181.       System.out.println(ResourceHandler.getMessage("plugin_converter.show_progress") + ":\t" + this.converter.isShowProgressStdOut());
  182.       System.out.println("");
  183.    }
  184.  
  185.    public static void main(String[] var0) {
  186.       new HTMLConverter(var0);
  187.    }
  188.  
  189.    // $FF: synthetic method
  190.    static Class class$(String var0) {
  191.       try {
  192.          return Class.forName(var0);
  193.       } catch (ClassNotFoundException var2) {
  194.          throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  195.       }
  196.    }
  197. }
  198.