Beispiel #1
0
  // {{{ getTargetName() method
  private String getTargetName(Object session, VFS vfs, String path, String baseName)
      throws IOException {
    if (behavior == Behavior.OVERWRITE) {
      // We want to overwrite, no need to check anything
      return baseName;
    }

    String s = MiscUtilities.constructPath(target, baseName);
    VFSFile file = vfs._getFile(session, s, comp);
    if (file == null) {
      // The target file do not exist, perfect
      return baseName;
    }
    if (behavior == Behavior.SKIP) return null;

    String extension = MiscUtilities.getFileExtension(baseName);
    String nameNoExtension = MiscUtilities.getBaseName(baseName);
    for (int i = 1; i < 1000; i++) {
      String name = nameNoExtension + "-copy-" + i;
      if (extension != null) name += extension;
      s = MiscUtilities.constructPath(path, name);
      file = vfs._getFile(session, s, comp);
      if (file == null) return name;
    }
    return null;
  } // }}}
    @Override
    public void actionPerformed(ActionEvent evt) {
      if (pluginModel.isDownloadingList()) return;

      boolean downloadSource = jEdit.getBooleanProperty("plugin-manager.downloadSource");
      boolean installUser = jEdit.getBooleanProperty("plugin-manager.installUser");
      Roster roster = new Roster();
      String installDirectory;
      if (installUser) {
        installDirectory = MiscUtilities.constructPath(jEdit.getSettingsDirectory(), "jars");
      } else {
        installDirectory = MiscUtilities.constructPath(jEdit.getJEditHome(), "jars");
      }

      int length = pluginModel.entries.size();
      int instcount = 0;
      for (int i = 0; i < length; i++) {
        Entry entry = (Entry) pluginModel.entries.get(i);
        if (entry.install) {
          entry.plugin.install(roster, installDirectory, downloadSource);
          if (updates)
            entry
                .plugin
                .getCompatibleBranch()
                .satisfyDependencies(roster, installDirectory, downloadSource);
          instcount++;
        }
      }

      if (roster.isEmpty()) return;

      boolean cancel = false;
      if (updates && roster.getOperationCount() > instcount)
        if (GUIUtilities.confirm(
                window,
                "install-plugins.depend",
                null,
                JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.WARNING_MESSAGE)
            == JOptionPane.CANCEL_OPTION) cancel = true;

      if (!cancel) {
        new PluginManagerProgress(window, roster);

        roster.performOperationsInAWTThread(window);
        pluginModel.update();
      }
    }
  // {{{ savePrintSpec() method
  private static void savePrintSpec() {
    // String settings = jEdit.getSettingsDirectory();
    // if(settings == null)
    // return;
    String settings = ".jedit"; // $NON-NLS-1$

    String printSpecPath = MiscUtilities.constructPath(settings, "printspec"); // $NON-NLS-1$
    File filePrintSpec = new File(printSpecPath);
    ObjectOutputStream obOut = null;
    try {
      FileOutputStream fileOut = new FileOutputStream(filePrintSpec);
      obOut = new ObjectOutputStream(fileOut);
      obOut.writeObject(format);
      // for backwards compatibility, the color variable is stored also as
      // a property
      Chromaticity cc = (Chromaticity) format.get(Chromaticity.class);
      if (cc != null) {
        jEdit.setBooleanProperty(
            "print.color", //$NON-NLS-1$
            cc.getValue() == Chromaticity.COLOR.getValue());
      }
    } catch (Exception e) {
      new Warning(Resources.get(WarningStrings.FAILED_PRINT_SETTINGS_SAVE), e);
    } finally {
      if (obOut != null) {
        try {
          obOut.close();
        } catch (IOException e) {
          new Warning(Resources.get(WarningStrings.FAILED_OUTSTREAM_CLOSE), e);
        }
      }
    }
  }
  // {{{ loadDirectory() method
  public void loadDirectory(
      final Object node, String path, final boolean addToHistory, final Runnable delayedAWTTask) {
    path = MiscUtilities.constructPath(browser.getDirectory(), path);
    VFS vfs = VFSManager.getVFSForPath(path);

    Object session = vfs.createVFSSession(path, this);
    if (session == null) {
      if (delayedAWTTask != null) ThreadUtilities.runInDispatchThread(delayedAWTTask);
      return;
    }

    if (node == null) {
      parentDirectories.setListData(new Object[] {new LoadingPlaceholder()});
    }

    final Object[] loadInfo = new Object[2];
    Runnable awtRunnable =
        new Runnable() {
          public void run() {
            browser.directoryLoaded(node, loadInfo, addToHistory);
            if (delayedAWTTask != null) delayedAWTTask.run();
          }
        };
    ThreadUtilities.runInBackground(
        new ListDirectoryBrowserTask(browser, session, vfs, path, loadInfo, awtRunnable));
  } // }}}
Beispiel #5
0
  // {{{ getPrintJob() method
  private static PrinterJob getPrintJob(String jobName) {
    job = PrinterJob.getPrinterJob();

    format = new HashPrintRequestAttributeSet();

    String settings = jEdit.getSettingsDirectory();
    if (settings != null) {
      String printSpecPath = MiscUtilities.constructPath(settings, "printspec");
      File filePrintSpec = new File(printSpecPath);

      if (filePrintSpec.exists()) {
        try {
          FileInputStream fileIn = new FileInputStream(filePrintSpec);
          ObjectInputStream obIn = new ObjectInputStream(fileIn);
          format = (HashPrintRequestAttributeSet) obIn.readObject();
        } catch (Exception e) {
          Log.log(Log.ERROR, BufferPrinter1_4.class, e);
        }
        // for backwards compatibility, the color variable is stored also as a property
        if (jEdit.getBooleanProperty("print.color")) format.add(Chromaticity.COLOR);
        else format.add(Chromaticity.MONOCHROME);

        // no need to always keep the same job name for every printout.
        format.add(new JobName(jobName, null));
      }
    }

    return job;
  } // }}}
Beispiel #6
0
 // {{{ copy() method
 private void copy(
     Object vfsSession, VFS vfs, String sourcePath, String sourceName, String targetPath)
     throws IOException, InterruptedException {
   String name = getTargetName(vfsSession, vfs, targetPath, sourceName);
   if (name == null) {
     return;
   }
   String targetName = MiscUtilities.constructPath(targetPath, name);
   CountDownLatch latch = new CountDownLatch(1);
   ThreadUtilities.runInBackground(new CopyFileWorker(comp, sourcePath, targetName, latch));
   latch.await();
 } // }}}
  private static PrinterJob getPrintJob(String jobName) {
    job = PrinterJob.getPrinterJob();

    format = new HashPrintRequestAttributeSet();

    String settings = ".jedit"; // $NON-NLS-1$
    jEdit.getSettingsDirectory();
    if (settings != null) {
      String printSpecPath = MiscUtilities.constructPath(settings, "printspec"); // $NON-NLS-1$
      File filePrintSpec = new File(printSpecPath);

      if (filePrintSpec.exists()) {
        try {
          FileInputStream fileIn = new FileInputStream(filePrintSpec);
          ObjectInputStream obIn = new ObjectInputStream(fileIn);
          format = (HashPrintRequestAttributeSet) obIn.readObject();
          obIn.close();
        } catch (Exception e) {
          Log.log(Log.ERROR, ModifiedBufferPrinter1_4.class, e);
        }
        // for backwards compatibility, the color variable is stored
        // also as a property
        // disabled, getBooleanProperty seems not to work as
        // expected, probably because we don't have full jEdit here.

        // if(jEdit.getBooleanProperty("print.color"))
        // #trac 636
        Chromaticity cc = (Chromaticity) format.get(Chromaticity.class);
        if (cc != null) {
          jEdit.setBooleanProperty(
              "print.color", //$NON-NLS-1$
              cc.getValue() == Chromaticity.COLOR.getValue());
        } else {
          // default if no value was set before.
          jEdit.setBooleanProperty("print.color", true); // $NON-NLS-1$
        }
        // no need to always keep the same job label for every printout.
        format.add(new JobName(jobName, null));
      }
    }

    return job;
  } // }}}
Beispiel #8
0
  // {{{ savePrintSpec() method
  private static void savePrintSpec() {
    String settings = jEdit.getSettingsDirectory();
    if (settings == null) return;

    String printSpecPath = MiscUtilities.constructPath(settings, "printspec");
    File filePrintSpec = new File(printSpecPath);

    try {
      FileOutputStream fileOut = new FileOutputStream(filePrintSpec);
      ObjectOutputStream obOut = new ObjectOutputStream(fileOut);
      obOut.writeObject(format);
      // for backwards compatibility, the color variable is stored also as a property
      Chromaticity cc = (Chromaticity) format.get(Chromaticity.class);
      if (cc != null)
        jEdit.setBooleanProperty("print.color", cc.getValue() == Chromaticity.COLOR.getValue());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Beispiel #9
0
  /**
   * Copy a file to another using VFS.
   *
   * @param progress the progress observer. It could be null if you don't want to monitor progress.
   *     If not null you should probably launch this command in a WorkThread
   * @param sourceVFS the source VFS
   * @param sourceSession the VFS session
   * @param sourcePath the source path
   * @param targetVFS the target VFS
   * @param targetSession the target session
   * @param targetPath the target path
   * @param comp comp The component that will parent error dialog boxes
   * @param canStop could this copy be stopped ?
   * @return true if the copy was successful
   * @throws IOException IOException If an I/O error occurs
   * @since jEdit 4.3pre3
   */
  public static boolean copy(
      ProgressObserver progress,
      VFS sourceVFS,
      Object sourceSession,
      String sourcePath,
      VFS targetVFS,
      Object targetSession,
      String targetPath,
      Component comp,
      boolean canStop)
      throws IOException {
    if (progress != null) progress.setStatus("Initializing");

    InputStream in = null;
    OutputStream out = null;
    try {
      VFSFile sourceVFSFile = sourceVFS._getFile(sourceSession, sourcePath, comp);
      if (sourceVFSFile == null) throw new FileNotFoundException(sourcePath);
      if (progress != null) {
        progress.setMaximum(sourceVFSFile.getLength());
      }
      VFSFile targetVFSFile = targetVFS._getFile(targetSession, targetPath, comp);
      if (targetVFSFile.getType() == VFSFile.DIRECTORY) {
        if (targetVFSFile.getPath().equals(sourceVFSFile.getPath())) return false;
        targetPath = MiscUtilities.constructPath(targetPath, sourceVFSFile.getName());
      }
      in =
          new BufferedInputStream(
              sourceVFS._createInputStream(sourceSession, sourcePath, false, comp));
      out =
          new BufferedOutputStream(targetVFS._createOutputStream(targetSession, targetPath, comp));
      boolean copyResult = IOUtilities.copyStream(IOBUFSIZE, progress, in, out, canStop);
      VFSManager.sendVFSUpdate(targetVFS, targetPath, true);
      return copyResult;
    } finally {
      IOUtilities.closeQuietly(in);
      IOUtilities.closeQuietly(out);
    }
  }
  /**
   * Recursively encrypts or decrypts all files given to the method and all files in directories
   * given to the method.
   *
   * @param relativePath The relative from the initial directory up to the current one, for
   *     encryption or decryption into another directory to be able to rebuild the directory
   *     structure
   * @param files The files and directories to encrypt or decrypt
   * @return Whether all encryption or decryption was fine
   */
  @CheckReturnValue(explanation = "If false is returned, something went wrong")
  private boolean cryptFiles(@NonNull String relativePath, @NonNull VFSFile... files) {
    for (VFSFile file : files) {
      VFS vfs = file.getVFS();
      VFS newVfs = null;
      String path = file.getPath();
      Object session = vfs.createVFSSession(path, this);
      Object sessionNew = null;
      Object sessionNewParent = null;
      InputStream in = null;
      ByteArrayInputStream bais = null;
      OutputStream out = null;
      ByteArrayOutputStream baos = null;
      try {
        if (FILE == file.getType()) {
          in = vfs._createInputStream(session, path, false, this);
          baos = new ByteArrayOutputStream();
          if (!IOUtilities.copyStream(null, in, baos, false)) {
            GUIUtilities.error(
                this,
                encrypt
                    ? "cipher.error.error-while-encrypting-file"
                    : "cipher.error.error-while-decrypting-file",
                new Object[] {path});
            continue;
          }
          baos.flush();
          byte[] cryptResult;
          synchronized (cipher) {
            if (encrypt) {
              cipher.setRawData(baos.toByteArray());
            } else {
              cipher.setEncryptedData(baos.toByteArray());
            }
            cipher.setEntropy(password);
            cipher.setAdditionalInformation(additionalInformation);
            if (encrypt) {
              cryptResult = cipher.encryptToByteArray();
            } else {
              cryptResult = cipher.decryptToByteArray();
            }
          }
          if (null == cryptResult) {
            GUIUtilities.error(
                this,
                encrypt
                    ? "cipher.error.error-while-encrypting-file"
                    : "cipher.error.error-while-decrypting-file",
                new Object[] {path});
            continue;
          }
          bais = new ByteArrayInputStream(cryptResult);
          String newPath;
          switch (newFileHandling) {
            case OVERWRITE:
              newPath = path;
              newVfs = vfs;
              break;

            case OTHER_DIRECTORY:
              if (0 < relativePath.length()) {
                newPath = MiscUtilities.constructPath(directoryTextField.getText(), relativePath);
              } else {
                newPath = directoryTextField.getText();
              }
              newPath = MiscUtilities.constructPath(newPath, file.getName());
              newVfs = VFSManager.getVFSForPath(newPath);
              break;

            case SUFFIX:
              newPath = path + suffixTextField.getText();
              newVfs = vfs;
              break;

            default:
              throw new InternalError(
                  "missing case branch for NewFileHandling: " + newFileHandling);
          }
          String newPathParent = MiscUtilities.getParentOfPath(newPath);
          sessionNewParent = newVfs.createVFSSession(newPathParent, this);
          newVfs._mkdir(sessionNewParent, newPathParent, this);
          sessionNew = newVfs.createVFSSession(newPath, this);
          out = newVfs._createOutputStream(sessionNew, newPath, this);
          if (!IOUtilities.copyStream(null, bais, out, false)) {
            GUIUtilities.error(
                this,
                encrypt
                    ? "cipher.error.error-while-encrypting-file"
                    : "cipher.error.error-while-decrypting-file",
                new Object[] {path});
            continue;
          }
          VFSManager.sendVFSUpdate(newVfs, newPath, true);
        } else {
          String newRelativePath;
          if (0 < relativePath.length()) {
            newRelativePath = MiscUtilities.concatPath(relativePath, file.getName());
          } else {
            newRelativePath = file.getName();
          }
          if (!cryptFiles(newRelativePath, vfs._listFiles(session, path, this))) {
            return false;
          }
        }
      } catch (IOException ioe) {
        Log.log(ERROR, this, ioe);
        new TextAreaDialog(
            this,
            encrypt
                ? "cipher.error.error-while-encrypting-files"
                : "cipher.error.error-while-decrypting-files",
            ioe);
        return false;
      } finally {
        try {
          vfs._endVFSSession(session, this);
        } catch (IOException ioe) {
          // just ignore it, we are not interested
        }
        try {
          if (null != newVfs) {
            newVfs._endVFSSession(sessionNew, this);
          }
        } catch (IOException ioe) {
          // just ignore it, we are not interested
        }
        try {
          if (null != newVfs) {
            newVfs._endVFSSession(sessionNewParent, this);
          }
        } catch (IOException ioe) {
          // just ignore it, we are not interested
        }
        try {
          if (null != out) {
            out.flush();
          }
        } catch (IOException ioe) {
          // just ignore it, we are not interested
        }
        IOUtilities.closeQuietly(in);
        IOUtilities.closeQuietly(bais);
        IOUtilities.closeQuietly(out);
        IOUtilities.closeQuietly(baos);
      }
    }
    return true;
  }
Beispiel #11
0
  /**
   * Creates a new help viewer for the specified URL.
   *
   * @param url The URL
   */
  public HelpViewer(String url) {
    super(jEdit.getProperty("helpviewer.title"));

    setIconImage(GUIUtilities.getEditorIcon());

    try {
      baseURL =
          new File(MiscUtilities.constructPath(jEdit.getJEditHome(), "doc")).toURL().toString();
    } catch (MalformedURLException mu) {
      Log.log(Log.ERROR, this, mu);
      // what to do?
    }

    ActionHandler actionListener = new ActionHandler();

    JTabbedPane tabs = new JTabbedPane();
    tabs.addTab(jEdit.getProperty("helpviewer.toc.label"), toc = new HelpTOCPanel(this));
    tabs.addTab(jEdit.getProperty("helpviewer.search.label"), new HelpSearchPanel(this));
    tabs.setMinimumSize(new Dimension(0, 0));

    JPanel rightPanel = new JPanel(new BorderLayout());

    Box toolBar = new Box(BoxLayout.X_AXIS);
    // toolBar.setFloatable(false);

    toolBar.add(title = new JLabel());
    toolBar.add(Box.createGlue());
    historyModel = new HelpHistoryModel(25);
    back = new HistoryButton(HistoryButton.BACK, historyModel);
    back.addActionListener(actionListener);
    toolBar.add(back);
    forward = new HistoryButton(HistoryButton.FORWARD, historyModel);
    forward.addActionListener(actionListener);
    toolBar.add(forward);
    back.setPreferredSize(forward.getPreferredSize());
    rightPanel.add(BorderLayout.NORTH, toolBar);

    viewer = new JEditorPane();
    viewer.setEditable(false);
    viewer.addHyperlinkListener(new LinkHandler());
    viewer.setFont(new Font("Monospaced", Font.PLAIN, 12));
    viewer.addPropertyChangeListener(new PropertyChangeHandler());
    viewer.addKeyListener(new KeyHandler());

    viewerScrollPane = new JScrollPane(viewer);

    rightPanel.add(BorderLayout.CENTER, viewerScrollPane);

    splitter =
        new JSplitPane(
            JSplitPane.HORIZONTAL_SPLIT,
            jEdit.getBooleanProperty("appearance.continuousLayout"),
            tabs,
            rightPanel);
    splitter.setBorder(null);

    getContentPane().add(BorderLayout.CENTER, splitter);

    historyModel.addHelpHistoryModelListener(this);
    historyUpdated();

    gotoURL(url, true, 0);

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    getRootPane().setPreferredSize(new Dimension(750, 500));

    pack();
    GUIUtilities.loadGeometry(this, "helpviewer");
    GUIUtilities.addSizeSaver(this, "helpviewer");

    EditBus.addToBus(this);

    setVisible(true);

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            splitter.setDividerLocation(jEdit.getIntegerProperty("helpviewer.splitter", 250));
            viewer.requestFocus();
          }
        });
  } // }}}
Beispiel #12
0
 /**
  * Returns a temporary file name based on the given path.
  *
  * <p>By default jEdit first saves a file to <code>#<i>name</i>#save#</code> and then renames it
  * to the original file. However some virtual file systems might not support the <code>#</code>
  * character in filenames, so this method permits the VFS to override this behavior.
  *
  * <p>If this method returns <code>null</code>, two stage save will not be used for that
  * particular file (introduced in jEdit 4.3pre1).
  *
  * @param path The path name
  * @since jEdit 4.1pre7
  */
 public String getTwoStageSaveName(String path) {
   return MiscUtilities.constructPath(getParentOfPath(path), '#' + getFileName(path) + "#save#");
 } // }}}