Example #1
0
  /**
   * Initializes the Splitter.
   *
   * @param key Property-key to use for locating initialization properties.
   * @param type Property-type to use for locating initialization properties.
   * @exception ProcessingException when initialization fails
   */
  public void initialize(String key, String type) throws ProcessingException {

    // Call the abstract super class's initialize method. This initializes
    // the adapterProperties hashtable defined in the super class and
    // retrieves the name and toProcessorNames values from the properties.
    super.initialize(key, type);

    if (Debug.isLevelEnabled(Debug.OBJECT_LIFECYCLE))
      Debug.log(Debug.OBJECT_LIFECYCLE, "Splitter: Initializing.....");

    StringBuffer errorBuffer = new StringBuffer();
    truncHeaderFooter = getRequiredPropertyValue(TRUNCATE_HEADER_FOOTER_PROP, errorBuffer);

    if (Debug.isLevelEnabled(Debug.MSG_DATA))
      Debug.log(Debug.MSG_DATA, "Splitter: truncHeaderFooter? ---->" + truncHeaderFooter);

    String temp = getPropertyValue(FILE_SEPARATOR_PROP);
    if (StringUtils.hasValue(temp)) {
      fileSeparator = StringUtils.replaceSubstrings(temp, "\\r", "\r");
      fileSeparator = StringUtils.replaceSubstrings(fileSeparator, "\\n", "\n");
      if (Debug.isLevelEnabled(Debug.MSG_DATA))
        Debug.log(Debug.MSG_DATA, "Splitter: fileSeparator---->" + fileSeparator);
    }

    try {
      splitLength = Integer.parseInt(getRequiredPropertyValue(SPLIT_LENGTH_PROP, errorBuffer));

      if (Debug.isLevelEnabled(Debug.MSG_DATA))
        Debug.log(Debug.MSG_DATA, "Splitter: splitLength---->" + splitLength);
    } catch (NumberFormatException nx) {
      throw new ProcessingException("ERROR: Splitter: The SPLIT_LENGTH " + "must be a number.");
    }

    if (splitLength <= 0) {
      throw new ProcessingException(
          "ERROR: Splitter: The SPLIT_LENGTH " + "must be greater than zero.");
    }

    if (errorBuffer.length() > 0) {
      String errMsg = errorBuffer.toString();

      Debug.log(Debug.ALL_ERRORS, errMsg);

      throw new ProcessingException(errMsg);
    }
  }