protected String getLogBuffer(
      VariableSpace space, String logChannelId, LogStatus status, String limit) {

    StringBuffer buffer = KettleLogStore.getAppender().getBuffer(logChannelId, true);

    if (Const.isEmpty(limit)) {
      String defaultLimit = space.getVariable(Const.KETTLE_LOG_SIZE_LIMIT, null);
      if (!Const.isEmpty(defaultLimit)) {
        limit = defaultLimit;
      }
    }

    // See if we need to limit the amount of rows
    //
    int nrLines = Const.isEmpty(limit) ? -1 : Const.toInt(space.environmentSubstitute(limit), -1);

    if (nrLines > 0) {
      int start = buffer.length() - 1;
      for (int i = 0; i < nrLines && start > 0; i++) {
        start = buffer.lastIndexOf(Const.CR, start - 1);
      }
      if (start > 0) {
        buffer.delete(0, start + Const.CR.length());
      }
    }

    return buffer.append(Const.CR + status.getStatus().toUpperCase() + Const.CR).toString();
  }
  // Listen to the Variable... button
  public static final String getVariableName(Shell shell, VariableSpace space) {
    String keys[] = space.listVariables();
    Arrays.sort(keys);

    int size = keys.length;
    String key[] = new String[size];
    String val[] = new String[size];
    String str[] = new String[size];

    for (int i = 0; i < keys.length; i++) {
      key[i] = keys[i];
      val[i] = space.getVariable(key[i]);
      str[i] = key[i] + "  [" + val[i] + "]";
    }

    EnterSelectionDialog esd =
        new EnterSelectionDialog(
            shell,
            str,
            Messages.getString("System.Dialog.SelectEnvironmentVar.Title"),
            Messages.getString("System.Dialog.SelectEnvironmentVar.Message"));
    esd.clearModal();
    if (esd.open() != null) {
      int nr = esd.getSelectionNr();
      String var = key[nr];

      return var;
    } else {
      return null;
    }
  }
  public void setVariables(VariableSpace space) {
    this.variables = new HashMap<String, String>();

    for (String name : space.listVariables()) {
      String value = space.getVariable(name);
      this.variables.put(name, value);
    }
  }
Ejemplo n.º 4
0
 /** @return the connectionName */
 public String getActualConnectionName() {
   String name = space.environmentSubstitute(connectionName);
   if (Const.isEmpty(name)) {
     name = space.getVariable(getConnectionNameVariable());
   }
   if (Const.isEmpty(name)) return null;
   else return name;
 }
Ejemplo n.º 5
0
  /** @return the tableName */
  public String getActualTableName() {
    if (!Const.isEmpty(tableName)) return space.environmentSubstitute(tableName);

    String name = space.getVariable(getTableNameVariable());
    if (Const.isEmpty(name)) {
      return null;
    } else {
      return name;
    }
  }
  /** @return the schemaName */
  public String getActualSchemaName() {
    if (!Const.isEmpty(schemaName)) {
      return space.environmentSubstitute(schemaName);
    }

    String name = space.getVariable(getSchemaNameVariable());
    if (Const.isEmpty(name)) {
      return null;
    } else {
      return name;
    }
  }
  public void getUsedVariables(JobMeta jobMeta) {
    Properties sp = new Properties();
    VariableSpace space = Variables.getADefaultVariableSpace();

    String[] keys = space.listVariables();
    for (int i = 0; i < keys.length; i++) {
      sp.put(keys[i], space.getVariable(keys[i]));
    }

    List<String> vars = jobMeta.getUsedVariables();
    if (vars != null && vars.size() > 0) {
      HashMap<String, String> newVariables = new HashMap<String, String>();

      for (int i = 0; i < vars.size(); i++) {
        String varname = vars.get(i);
        if (!varname.startsWith(Const.INTERNAL_VARIABLE_PREFIX)) {
          newVariables.put(varname, Const.NVL(variables.get(varname), sp.getProperty(varname, "")));
        }
      }
      // variables.clear();
      variables.putAll(newVariables);
    }
  }
  /**
   * This factory returns a FileSystemConfigBuilder. Custom FileSystemConfigBuilders can be created
   * by implementing the {@link IKettleFileSystemConfigBuilder} or overriding the {@link
   * KettleGenericFileSystemConfigBuilder}
   *
   * @see FileSystemConfigBuilder
   * @param varSpace A Kettle variable space for resolving VFS config parameters
   * @param scheme The VFS scheme (FILE, HTTP, SFTP, etc...)
   * @return A FileSystemConfigBuilder that can translate Kettle variables into VFS config
   *     parameters
   * @throws IOException
   */
  public static IKettleFileSystemConfigBuilder getConfigBuilder(
      VariableSpace varSpace, String scheme) throws IOException {
    IKettleFileSystemConfigBuilder result = null;

    // Attempt to load the Config Builder from a variable: vfs.config.parser = class
    String parserClass =
        varSpace.getVariable("vfs." + scheme + ".config.parser"); // $NON-NLS-1$ //$NON-NLS-2$

    if (parserClass != null) {
      try {
        Class<?> configBuilderClass =
            KettleFileSystemConfigBuilderFactory.class.getClassLoader().loadClass(parserClass);
        Method mGetInstance = configBuilderClass.getMethod("getInstance"); // $NON-NLS-1$
        if ((mGetInstance != null)
            && (IKettleFileSystemConfigBuilder.class.isAssignableFrom(
                mGetInstance.getReturnType()))) {
          result = (IKettleFileSystemConfigBuilder) mGetInstance.invoke(null);
        } else {
          result = (IKettleFileSystemConfigBuilder) configBuilderClass.newInstance();
        }
      } catch (Exception e) {
        // Failed to load custom parser. Throw exception.
        throw new IOException(
            BaseMessages.getString(PKG, "CustomVfsSettingsParser.Log.FailedToLoad")); // $NON-NLS-1$
      }
    } else {
      // No custom parser requested, load default
      if (scheme.equalsIgnoreCase("sftp")) { // $NON-NLS-1$
        result = KettleSftpFileSystemConfigBuilder.getInstance();
      } else {
        result = KettleGenericFileSystemConfigBuilder.getInstance();
      }
    }

    return result;
  }
Ejemplo n.º 9
0
 public String getVariable(String variableName) {
   return variables.getVariable(variableName);
 }
Ejemplo n.º 10
0
 public String getVariable(String variableName, String defaultValue) {
   return variables.getVariable(variableName, defaultValue);
 }