public boolean isAcceptable(Transferable transferable, Point point) {
      int row = getPropertiesTable().rowAtPoint(point);
      if (row >= 0) {
        int column = getPropertiesTable().columnAtPoint(point);
        if (column != 1) {
          return false;
        }

        if (!getPropertiesTable().isCellEditable(row, column)) {
          return false;
        }
      } else if (!(getHolder() instanceof MutableTestPropertyHolder)) {
        return false;
      }

      DataFlavor[] flavors = transferable.getTransferDataFlavors();
      for (int i = 0; i < flavors.length; i++) {
        DataFlavor flavor = flavors[i];
        if (flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType)) {
          try {
            Object modelItem = transferable.getTransferData(flavor);
            if (modelItem instanceof PropertyModelItem
                && ((PropertyModelItem) modelItem).getProperty().getModelItem()
                    != getHolder().getModelItem()) {
              return PropertyExpansionUtils.canExpandProperty(
                  getHolder().getModelItem(), ((PropertyModelItem) modelItem).getProperty());
            }
          } catch (Exception ex) {
            SoapUI.logError(ex);
          }
        }
      }

      return false;
    }
  public String resolveProperty(
      PropertyExpansionContext context, String name, boolean globalOverride) {
    String result =
        ResolverUtils.checkForExplicitReference(
            name,
            PropertyExpansion.GLOBAL_REFERENCE,
            PropertyExpansionUtils.getGlobalProperties(),
            context,
            false);
    if (result != null) {
      return result;
    }

    result =
        ResolverUtils.checkForExplicitReference(
            name,
            PropertyExpansion.SYSTEM_REFERENCE,
            systemPropertyHolder,
            context,
            globalOverride);
    if (result != null) {
      return result;
    }

    result =
        ResolverUtils.checkForExplicitReference(
            name,
            PropertyExpansion.ENV_REFERENCE,
            environmentPropertyHolder,
            context,
            globalOverride);
    if (result != null) {
      return result;
    }

    // if not, check for explicit global property (stupid 1.7.6 syntax that
    // should be removed..)
    if (name.length() > 2
        && name.charAt(0) == PropertyExpansion.PROPERTY_SEPARATOR
        && name.charAt(1) == PropertyExpansion.PROPERTY_SEPARATOR) {
      return PropertyExpansionUtils.getGlobalProperty(name.substring(2));
    } else {
      return PropertyExpansionUtils.getGlobalProperty(name);
    }
  }
  public PropertyExpansion[] getPropertyExpansions() {
    List<PropertyExpansion> result = new ArrayList<PropertyExpansion>();

    result.addAll(
        PropertyExpansionUtils.extractPropertyExpansions(
            getAssertable().getModelItem(), this, "token"));

    return result.toArray(new PropertyExpansion[result.size()]);
  }
Beispiel #4
0
  /*
   * (non-Javadoc)
   *
   * @see com.eviware.soapui.SoapUICore#saveSettings()
   */
  public String saveSettings() throws Exception {
    PropertyExpansionUtils.saveGlobalProperties();
    SecurityScanUtil.saveGlobalSecuritySettings();
    isSavingSettings = true;
    try {
      if (settingsFile == null) {
        settingsFile = getRoot() + File.separatorChar + DEFAULT_SETTINGS_FILE;
      }

      // Save settings to root or user.home
      File file = new File(settingsFile);
      if (!file.canWrite()) {
        file = new File(new File(System.getProperty("user.home", ".")), DEFAULT_SETTINGS_FILE);
      }

      SoapuiSettingsDocumentConfig settingsDocument =
          (SoapuiSettingsDocumentConfig) this.settingsDocument.copy();
      String password = settings.getString(SecuritySettings.SHADOW_PASSWORD, null);

      if (password != null && password.length() > 0) {
        try {
          byte[] data = settingsDocument.xmlText().getBytes();
          String encryptionAlgorithm = "des3";
          byte[] encryptedData = OpenSSL.encrypt(encryptionAlgorithm, password.toCharArray(), data);
          settingsDocument.setSoapuiSettings(null);
          settingsDocument.getSoapuiSettings().setEncryptedContent(encryptedData);
          settingsDocument.getSoapuiSettings().setEncryptedContentAlgorithm(encryptionAlgorithm);
        } catch (UnsupportedEncodingException e) {
          log.error("Encryption error", e);
        } catch (IOException e) {
          log.error("Encryption error", e);
        } catch (GeneralSecurityException e) {
          log.error("Encryption error", e);
        }
      }

      FileOutputStream out = new FileOutputStream(file);
      settingsDocument.save(out);
      out.flush();
      out.close();
      log.info("Settings saved to [" + file.getAbsolutePath() + "]");
      lastSettingsLoad = file.lastModified();
      return file.getAbsolutePath();
    } finally {
      isSavingSettings = false;
    }
  }
    public void drop(DropTargetDropEvent dtde) {
      if (!isAcceptable(dtde.getTransferable(), dtde.getLocation())) {
        dtde.rejectDrop();
      } else {
        try {
          Transferable transferable = dtde.getTransferable();
          Object transferData =
              transferable.getTransferData(transferable.getTransferDataFlavors()[0]);
          if (transferData instanceof PropertyModelItem) {
            dtde.acceptDrop(dtde.getDropAction());
            PropertyModelItem modelItem = (PropertyModelItem) transferData;

            String xpath = modelItem.getXPath();
            if (xpath == null && XmlUtils.seemsToBeXml(modelItem.getProperty().getValue())) {
              xpath =
                  UISupport.selectXPath(
                      "Create PropertyExpansion",
                      "Select XPath below",
                      modelItem.getProperty().getValue(),
                      null);

              if (xpath != null) {
                xpath =
                    PropertyExpansionUtils.shortenXPathForPropertyExpansion(
                        xpath, modelItem.getProperty().getValue());
              }
            }

            PropertyExpansion propertyExpansion =
                new PropertyExpansionImpl(modelItem.getProperty(), xpath);

            Point point = dtde.getLocation();
            int column = getPropertiesTable().columnAtPoint(point);
            int row = getPropertiesTable().rowAtPoint(point);

            if (row == -1) {
              if (holder instanceof MutableTestPropertyHolder) {
                MutableTestPropertyHolder mtph = (MutableTestPropertyHolder) holder;
                String name =
                    UISupport.prompt(
                        "Specify unique name of property",
                        "Add Property",
                        modelItem.getProperty().getName());
                while (name != null && mtph.hasProperty(name)) {
                  name =
                      UISupport.prompt(
                          "Specify unique name of property",
                          "Add Property",
                          modelItem.getProperty().getName());
                }

                if (name != null) {
                  mtph.addProperty(name).setValue(propertyExpansion.toString());
                }
              }
            } else {
              getPropertiesTable().setValueAt(propertyExpansion.toString(), row, column);
            }

            dtde.dropComplete(true);
          }
        } catch (Exception e) {
          SoapUI.logError(e);
        }
      }
    }