Ejemplo n.º 1
0
  // If you don't need any file initialization or postprocessing, you only need this one routine
  public CheckCLDR handleCheck(
      String path, String fullPath, String value, Options options, List<CheckStatus> result) {
    // it helps performance to have a quick reject of most paths
    if (fullPath == null) return this; // skip paths that we don't have
    if (fullPath.indexOf("casing") < 0) return this;

    // pick up the casing attributes from the full path
    parts.set(fullPath);

    Case caseTest = Case.mixed;
    for (int i = 0; i < parts.size(); ++i) {
      String casingValue = parts.getAttributeValue(i, "casing");
      if (casingValue == null) {
        continue;
      }
      caseTest = Case.forString(casingValue);
      if (caseTest == Case.verbatim) {
        return this; // we're done
      }
    }

    String newValue = value;
    switch (caseTest) {
      case lowercase_words:
        newValue = UCharacter.toLowerCase(uLocale, value);
        break;
      case titlecase_words:
        newValue = UCharacter.toTitleCase(uLocale, value, null);
        break;
      case titlecase_firstword:
        newValue = TitleCaseFirst(uLocale, value);
        break;
      default:
        break;
    }
    if (!newValue.equals(value)) {
      // the following is how you signal an error or warning (or add a demo....)
      result.add(
          new CheckStatus()
              .setCause(this)
              .setMainType(CheckStatus.errorType)
              .setSubtype(Subtype.incorrectCasing)
              // typically warningType or errorType
              .setMessage(
                  "Casing incorrect: either should have casing=\"verbatim\" or be <{0}>",
                  new Object[] {newValue})); // the message; can be MessageFormat with arguments
    }
    return this;
  }
Ejemplo n.º 2
0
  private String addIndexInfo(PrintWriter index, String path, String transID) {
    parts.set(path);
    Map<String, String> attributes = parts.findAttributes("transform");
    if (attributes == null) return null; // error, not a transform file
    String source = attributes.get("source");
    String target = attributes.get("target");
    String variant = attributes.get("variant");
    String direction = attributes.get("direction");
    String alias = attributes.get("alias");
    String backwardAlias = attributes.get("backwardAlias");
    String visibility = attributes.get("visibility");

    String status = "internal".equals(visibility) ? "internal" : "file";

    fileCount++;

    String id = source + "-" + target;
    String rid = target + "-" + source;
    String filename = source + "_" + target;
    if (variant != null) {
      id += "/" + variant;
      rid += "/" + variant;
      filename += "_" + variant;
    }
    filename += ".txt";

    if (direction.equals("both") || direction.equals("forward")) {
      if (verbose) {
        System.out.println("    " + id + "    " + filename + "    " + "FORWARD");
      }
      if (alias != null) {
        for (String ali : alias.trim().split("\\s+")) {
          addAlias(index, ali, id);
        }
      }
      index.println("        " + id + " {");
      index.println("            " + status + " {");
      index.println("                resource:process(transliterator) {\"" + filename + "\"}");
      index.println("                direction {\"FORWARD\"}");
      index.println("            }");
      index.println("        }");
    }
    if (direction.equals("both") || direction.equals("backward")) {
      if (verbose) {
        System.out.println("    " + rid + "    " + filename + "    " + "REVERSE");
      }
      if (backwardAlias != null) {
        for (String bali : backwardAlias.trim().split("\\s+")) {
          addAlias(index, bali, rid);
        }
      }
      index.println("        " + rid + " {");
      index.println("            " + status + " {");
      index.println("                resource:process(transliterator) {\"" + filename + "\"}");
      index.println("                direction {\"REVERSE\"}");
      index.println("            }");
      index.println("        }");
    }
    index.println();
    return filename;
  }