コード例 #1
0
ファイル: TDTEngine.java プロジェクト: max90727/fosstrak
  /**
   * Translates the input string of a specified input level to a specified outbound level of the
   * same coding scheme. For example, the input string value may be a tag-encoding URI and the
   * outbound level specified by string outboundlevel may be BINARY, in which case the return value
   * is a binary representation expressed as a string.
   *
   * <p>Note that this version of the method requires that the user specify the input level, rather
   * than searching for it. However it still automatically finds the scheme used.
   *
   * @param input input tag coding
   * @param inputLevel level such as BINARY, or TAG_ENCODING.
   * @param tagLength tag length such as VALUE_64 or VALUE_96.
   * @param inputParameters a map with any additional properties.
   * @param outputLevel required output level.
   * @return output tag coding
   */
  public String convert(
      String input,
      LevelTypeList inputLevel,
      TagLengthList tagLength,
      Map<String, String> inputParameters,
      LevelTypeList outputLevel) {

    PrefixMatch match = findPrefixMatch(input, tagLength, inputLevel);

    return convertLevel(match.getScheme(), match.getLevel(), input, inputParameters, outputLevel);
  }
コード例 #2
0
ファイル: TDTEngine.java プロジェクト: max90727/fosstrak
  /**
   * The convert method translates a String input to a specified outbound level of the same coding
   * scheme. For example, the input string value may be a tag-encoding URI and the outbound level
   * specified by string outboundlevel may be BINARY, in which case the return value is a binary
   * representation expressed as a string.
   *
   * @param input the identifier to be converted.
   * @param inputParameters additional parameters which need to be provided because they cannot
   *     always be determined from the input value alone. Examples include the taglength,
   *     companyprefixlength and filter values.
   * @param outputLevel the outbound level required for the ouput. Permitted values include BINARY,
   *     TAG_ENCODING, PURE_IDENTITY, LEGACY and ONS_HOSTNAME.
   * @return the identifier converted to the output level.
   */
  public String convert(
      String input, Map<String, String> inputParameters, LevelTypeList outputLevel) {

    TagLengthList tagLength = null;
    if (inputParameters.containsKey("taglength")) {
      // in principle, the user should provide a
      // TagLengthList object in the parameter list.
      String s = inputParameters.get("taglength");
      tagLength = TagLengthList.valueOf(s);
    }

    PrefixMatch match = findPrefixMatch(input, tagLength);

    return convertLevel(match.getScheme(), match.getLevel(), input, inputParameters, outputLevel);
  }
コード例 #3
0
ファイル: TDTEngine.java プロジェクト: max90727/fosstrak
 /** Given an input string, level, and optionally a tag length, find a matching prefix. */
 private PrefixMatch findPrefixMatch(
     String input, TagLengthList tagLength, LevelTypeList level_type) {
   List<PrefixMatch> match_list = new ArrayList<PrefixMatch>();
   PrefixTree<PrefixMatch> tree = prefix_tree_map.get(level_type);
   assert tree != null;
   List<PrefixMatch> list = tree.search(input);
   if (!list.isEmpty()) {
     if (tagLength == null) match_list.addAll(list);
     else {
       for (PrefixMatch match : list)
         if (match.getScheme().getTagLength() == tagLength) match_list.add(match);
     }
   }
   if (match_list.isEmpty())
     throw new TDTException("No schemes or levels matched the input value");
   else if (match_list.size() > 1)
     throw new TDTException("More than one scheme/level matched the input value");
   else return match_list.get(0);
 }