Exemplo n.º 1
0
  public static TranslationPath[] parse(String aPathExpression)
      throws InvalidLanguageTagException, InvalidLanguagePathException {
    int len = aPathExpression.length();
    if (aPathExpression.charAt(0) != '(') {
      throw new InvalidLanguagePathException(
          "Translation path must start with '(': " + aPathExpression);
    }
    if (aPathExpression.charAt(1) != '(') {
      throw createInvalidPathException(aPathExpression);
    }
    if (aPathExpression.charAt(len - 1) != ')') {
      throw new InvalidLanguagePathException("Translation path must end with ')'.");
    }
    if (aPathExpression.charAt(len - 2) != ')') {
      throw createInvalidPathException(aPathExpression);
    }
    String expression = aPathExpression.substring(2, len - 2);

    ArrayList<TranslationPath> list = new ArrayList<TranslationPath>();
    for (String path : expression.split("\\) ?\\(")) {
      ArrayList<Language> languages = new ArrayList<Language>();
      for (String language : path.split(" ")) {
        languages.add(Language.parse(language));
      }
      list.add(new TranslationPath(languages.toArray(new Language[0])));
    }
    return list.toArray(new TranslationPath[0]);
  }