Esempio n. 1
0
  /**
   * Called when decrypting an XML resource inside an opened editor or via a view. The output XML
   * can not be pretty printed since this would break an existing XML signature in the document.
   *
   * @param wizard The Decryption Wizard
   * @throws Exception to indicate any exceptional condition
   */
  private void decryptData(final NewDecryptionWizard wizard) throws Exception {
    final CreateDecryption decryption = new CreateDecryption();

    WizardDialog dialog = new WizardDialog(getActiveWorkbenchWindow().getShell(), wizard);
    dialog.create();
    dialog.open();

    if (dialog.getReturnCode() == Window.OK && wizard.getModel() != null) {
      Job job =
          new Job(Messages.NewDecryptionCommand_0) {
            public IStatus run(final IProgressMonitor monitor) {
              try {
                monitor.beginTask(Messages.NewDecryptionCommand_2, 6);

                Document doc = decryption.decrypt(wizard.getModel(), monitor);

                if (monitor.isCanceled()) {
                  return Status.CANCEL_STATUS;
                }

                if (doc != null) {
                  IEditorInput output =
                      AbstractEditorService.createOutputFile(
                          "decrypted",
                          IConstants.XML_FILE_TYPE_EXTENSION,
                          Utils.docToInputStram(doc));

                  performOpenEditor(output, IOperationsConstants.ID_TEXT_EDITOR);
                }
              } catch (final Exception ex) {
                getActiveWorkbenchWindow()
                    .getShell()
                    .getDisplay()
                    .asyncExec(
                        new Runnable() {
                          public void run() {
                            LogUtil.logError(
                                XSTUIPlugin.getId(), Messages.NewDecryptionCommand_1, ex, true);
                          }
                        });
              } finally {
                monitor.done();
              }

              return Status.OK_STATUS;
            }
          };
      job.setUser(true);
      job.schedule();
    }

    wizard.dispose();
  }
Esempio n. 2
0
  private void createDecryption() {
    try {
      NewDecryptionWizard wizard = new NewDecryptionWizard();
      data = getActiveEditorInputStream();

      wizard.init(data);

      decryptData(wizard);
    } catch (Exception ex) {
      LogUtil.logError(XSTUIPlugin.getId(), Messages.NewDecryptionCommand_1, ex, true);
    }
  }