⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plugindownload.java

📁 java写的多功能文件编辑器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                return;              }              if (!debug) {                //during testing this is commented out.                Jext.setProperty("plugDownload.core.version", String.valueOf(newVersion));              }              hasBooted = true;              downloadList();            }          });          //the file must be ready for the call to buildChainingClassLoader, below, so if threaded there          //is need for special caution: fixed. The buildChainingClassLoader is done by the back-notify Runnable.          //actually, when doing things the right way, the lib download will start together with a progress monitor.        } else { //otherwise, the jar is up-to-date.          hasBooted = true;        }      } catch (IOException ioe) {        //In this case, we can't update the autoUpdate.jar file; but then we use the current one.        System.err.println("Caught exception while trying to update autoUpdate.jar");        ioe.printStackTrace();      }    }    //If for any reason the jar wasn't updated(either for problems or because it was up-to-date) we show    //here the dialog.    downloadList();  }*/  /**   * This method downloads the list of plugins and loads it into the   * AbstractPlugReader(there is an instance which * can be got through   * getUpdater(). It's called by the downloader thread, while its internal   * runnable is called in the AWT thread.   */  private static void downloadList() {    /*try {      Utilities.downloadFile(autoUpdateListUrl, downloadedListPath.getPath(), false, null);    } catch (IOException ioe) {      JOptionPane.showMessageDialog(null,          Jext.getProperty("plugDownload.core.downError.text"),          Jext.getProperty("plugDownload.core.downError.title"),          JOptionPane.ERROR_MESSAGE);      System.err.println("Failed loading of XML!");      ioe.printStackTrace();      return;    }*/    Utilities.downloadFile(autoUpdateListUrl, downloadedListPath.getPath(), false,	new HandlingRunnable() {	  public void run(Object o, Throwable excep) {	    if (excep != null) {	      JOptionPane.showMessageDialog(null,		  Jext.getProperty("plugDownload.core.downError.text"),		  Jext.getProperty("plugDownload.core.downError.title"),		  JOptionPane.ERROR_MESSAGE);	      System.err.println("Failed loading of XML!");	      excep.printStackTrace();	    } else 	      showUpdateWindow();	  }	});  }  /**   * This method loads the list of plugins into the AbstractPlugReader instance which   * can be got through getUpdater().   */  public static boolean loadList() {    Reader reader = null;    if (! downloadedListPath.exists())      return false;    try {      reader = new BufferedReader(new FileReader(downloadedListPath.getPath()));      return getUpdater().loadXml(reader);    } catch (IOException ioe) {      //HERE we must give some user visible output.(I.e. in the GUI). In fact, it happens in the caller method.      System.err.println("Caught exception while trying to download plugin list");      ioe.printStackTrace();      return false;    } finally {      if (reader != null) {        try {          reader.close();        } catch (IOException ioe) {}      }    }  }  private static boolean buildChainingClassLoader() {    //Now, if autoUpdate.jar has been updated, it is in the right place in the user's home;    //otherwise we need to use the default one, in jext/lib dir. Or maybe somewhere else, such as bin,    //since it mustn't be loaded at startup.    //And we build the chaining class loader that will be used to load all resources.    //We build first a ClassLoader which loads the supplied autoUpdate.jar, then    //another one which looks in the downloaded one BUT uses as fallback one    //the first one. The fallback is provided trasparently by the JDK by using    //the fallback classloader as parent of the new one. But this only works for    //resources, since for classes we must fallback not only in the case of ClassNotFoundEx.    try {      defLoader = new JARClassLoader(getDefaultJarPath(), false, null);      loader = defLoader;      System.out.println("DefLoader");    } catch (IOException ioe) {      System.err.println("You haven't installed correctly Jext! The autoUpdate.jar file is missing." +          "It should be in this position: " + getDefaultJarPath());    }    if (downloadedJarPath.exists())      try {        newVerLoader = new JARClassLoader(downloadedJarPath.getPath(), false, defLoader);        loader = newVerLoader;        System.out.println("NewVerLoader");        //here defLoader becomes the father of newVerLoader      } catch (IOException ioe) {        ioe.printStackTrace();        //The file is there, but there could be problems anyway.      }    if (loader == null)      return false;    return true;  }  private static Object getInstanceFromLoader(String className) {    if (loader != null)      try {        return loader.loadClass(className).newInstance();      } catch (InstantiationException ie) {      } catch (IllegalAccessException ie) {      } catch (ClassNotFoundException ie) {        return null;//the class is missing in both chained classLoaders.      }    //if the class was found in newVerLoader, we've tried with it, but it didn't work.    //So we only need trying with defLoader, and only if != loader.    if (defLoader != null && defLoader != loader)      try {        return defLoader.loadClass(className).newInstance();      } catch (InstantiationException ie) {      } catch (IllegalAccessException ie) {      } catch (ClassNotFoundException ie) {      }    return null;  }  private static AbstractPlugReader newUpdater() {    return (AbstractPlugReader) getInstanceFromLoader("PlugReader");  }  public static JPanel newUpdatePanel() {    return (JPanel) getInstanceFromLoader("ChoiceForm");  }  public static AbstractPlugReader getUpdater() {    if (plugReader == null)      plugReader = newUpdater();    return plugReader;  }  public static Reader getDtd() {    return new BufferedReader(new InputStreamReader(loader.getResourceAsStream("pluglist.dtd")));  }  public static JDialog getUpdateWindow() {    return updateWindow;  }  /**   * This method starts the update: downloads the new autoUpdate.jar if needed, and when this is    * done shows the window.   */  public static void startUpdate() {    PluginDesc.initDirectories();    downloadJar();  }  public static void showUpdateWindow() {    if (!buildChainingClassLoader()) {      JOptionPane.showMessageDialog(null,          Jext.getProperty("plugDownload.core.instError.text", new Object[] {getDefaultJarPath()}),          Jext.getProperty("plugDownload.core.instError.title"),          JOptionPane.ERROR_MESSAGE);      return;    }    if (loadList()) {      updateWindow = new JDialog(parentFrame, Jext.getProperty("plugDownload.core.mainWindow.title", "Download plugins"));      JPanel updatePanel = newUpdatePanel();      updateWindow.setContentPane(updatePanel);      if (debug)        updateWindow.addWindowListener(new WindowAdapter() {          public void windowClosing(WindowEvent e) {            System.exit(0);          }        });      updateWindow.pack();      updateWindow.setVisible(true);    } else {      JOptionPane.showMessageDialog(null,          Jext.getProperty("plugDownload.core.downError.text"),          Jext.getProperty("plugDownload.core.downError.title"),          JOptionPane.ERROR_MESSAGE);      System.err.println("Failed loading of XML!");    }  }  public static void main(String[] args) {// for testing    debug = true;    startUpdate();  }  private static class WaitDialog extends JDialog {    WaitDialog() {      super(parentFrame, Jext.getProperty(waitTitleKey, "Wait please!"));      getContentPane().add(new JLabel(Jext.getProperty(waitLabelKey, "Please wait while updating PluginGet...")));      pack();    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -