Пример #1
0
  /**
   * Descripción de Método
   *
   * @return
   */
  private boolean openAttachment() {
    int index = cbContent.getSelectedIndex();
    byte[] data = m_attachment.getEntryData(index);

    if (data == null) {
      return false;
    }

    try {
      String fileName = System.getProperty("java.io.tmpdir") + m_attachment.getEntryName(index);
      File tempFile = new File(fileName);

      m_attachment.getEntryFile(index, tempFile);

      if (isWindows()) {

        // Runtime.getRuntime().exec ("rundll32 url.dll,FileProtocolHandler " + url);

        Process p =
            Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL \"" + tempFile + "\"");

        // p.waitFor();

        return true;
      } else if (isMac()) {
        String[] cmdArray = new String[] {"open", tempFile.getAbsolutePath()};
        Process p = Runtime.getRuntime().exec(cmdArray);

        // p.waitFor();

        return true;
      } else // other OS
      {
      }
    } catch (Exception e) {
      log.log(Level.SEVERE, "openFile", e);
    }

    return false;
  } // openFile
Пример #2
0
  /** Descripción de Método */
  private void saveAttachmentToFile() {
    int index = cbContent.getSelectedIndex();

    log.info("index=" + index);

    if (m_attachment.getEntryCount() < index) {
      return;
    }

    String fileName = getFileName(index);
    String ext = fileName.substring(fileName.lastIndexOf("."));

    log.config("Ext=" + ext);

    JFileChooser chooser = new JFileChooser();

    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
    chooser.setDialogTitle(Msg.getMsg(Env.getCtx(), "AttachmentSave"));

    File f = new File(fileName);

    chooser.setSelectedFile(f);

    // Show dialog

    int returnVal = chooser.showSaveDialog(this);

    if (returnVal != JFileChooser.APPROVE_OPTION) {
      return;
    }

    File saveFile = chooser.getSelectedFile();

    if (saveFile == null) {
      return;
    }

    log.config("Save to " + saveFile.getAbsolutePath());
    m_attachment.getEntryFile(index, saveFile);
  } // saveAttachmentToFile