Exemplo n.º 1
0
 @Override
 public IRI resolveSilent(final String uriStr) {
   if (resolvedIRIs == null) return iriFactory.create(uriStr);
   Callable<IRI> filler = () -> iriFactory.create(uriStr);
   IRI iri = resolvedIRIs.getOrFill(uriStr, filler);
   return iri;
 }
Exemplo n.º 2
0
  /*
   * No exception thrown by this method.
   */
  private static IRI resolveIRI(String relStr, String baseStr) {
    IRI i = iriFactory.create(relStr);
    if (i.isAbsolute())
      // removes excess . segments
      return globalResolver.getBaseIRI().create(i);

    IRI base = iriFactory.create(baseStr);

    if ("file".equalsIgnoreCase(base.getScheme())) return globalResolver.getBaseIRI().create(i);
    return base.create(i);
  }
Exemplo n.º 3
0
 /** The current global resolver based on the working directory */
 static {
   IRI cwd;
   try {
     cwd = iriFactory.construct(globalBase);
   } catch (IRIException e) {
     System.err.println("Unexpected IRIException in initializer: " + e.getMessage());
     cwd = iriFactory.create("file:///");
     e.printStackTrace(System.err);
   }
   globalResolver = new IRIResolverSync(IRIResolver.create(cwd));
 }
Exemplo n.º 4
0
  static {
    // These two are from IRIFactory.iriImplementation() ...
    iriFactory.useSpecificationIRI(true);
    iriFactory.useSchemeSpecificRules("*", true);

    // Allow relative references for file: URLs.
    iriFactory.setSameSchemeRelativeReferences("file");

    // Convert "SHOULD" to warning (default is "error").
    // iriFactory.shouldViolation(false,true);

    if (ShowResolverSetup) {
      System.out.println("---- Default settings ----");
      printSetting(iriFactory);
    }

    setErrorWarning(iriFactory, ViolationCodes.UNREGISTERED_IANA_SCHEME, false, false);

    // Turn off?? (ignored in CheckerIRI.iriViolations anyway).
    // setErrorWarning(iriFactory, ViolationCodes.LOWERCASE_PREFERRED, false, false) ;
    // setErrorWarning(iriFactory, ViolationCodes.PERCENT_ENCODING_SHOULD_BE_UPPERCASE, false,
    // false) ;
    // setErrorWarning(iriFactory, ViolationCodes.SCHEME_PATTERN_MATCH_FAILED, false, false) ;

    // NFC tests are not well understood by general developers and these cause confusion.
    // See JENA-864
    // iriFactory.setIsError(ViolationCodes.NOT_NFC, false) ;
    // iriFactory.setIsError(ViolationCodes.NOT_NFKC, false) ;
    // iriFactory.setIsWarning(ViolationCodes.NOT_NFC, false) ;
    // iriFactory.setIsWarning(ViolationCodes.NOT_NFKC, false) ;

    // ** Applies to various unicode blocks.
    // setErrorWarning(iriFactory, ViolationCodes.COMPATIBILITY_CHARACTER, false, false) ;

    // This causes test failures.
    // The tests catch warnings and a warning is expected.
    // testing/RIOT/Lang/TurtleStd/turtle-eval-bad-02.ttl and 03 and TriG
    //   > as \u003C  and < \u003E
    // Default is error=true, warning=false.
    // Test pass with error=false, warning=true.
    // setErrorWarning(iriFactory, ViolationCodes.UNWISE_CHARACTER, false, false) ;
    setErrorWarning(iriFactory, ViolationCodes.UNDEFINED_UNICODE_CHARACTER, false, false);

    if (ShowResolverSetup) {
      System.out.println("---- After initialization ----");
      printSetting(iriFactory);
    }
  }
Exemplo n.º 5
0
  @Override
  protected JsonObject execute(ValidationAction action) {
    JsonBuilder obj = new JsonBuilder();
    obj.startObject();

    String args[] = getArgs(action, paramIRI);
    if (args.length == 0) ServletOps.errorBadRequest("No IRIs supplied");

    obj.key(jIRIs);
    obj.startArray();

    for (String iriStr : args) {
      obj.startObject();
      obj.key(jIRI).value(iriStr);

      IRI iri = iriFactory.create(iriStr);

      List<String> errors = new ArrayList<>();
      List<String> warnings = new ArrayList<>();

      if (iri.isRelative()) warnings.add("Relative IRI: " + iriStr);

      Iterator<Violation> vIter = iri.violations(true);
      for (; vIter.hasNext(); ) {
        Violation v = vIter.next();
        String str = v.getShortMessage();
        if (v.isError()) errors.add(str);
        else warnings.add(str);
      }

      obj.key(jErrors);
      obj.startArray();
      for (String msg : errors) obj.value(msg);
      obj.finishArray();

      obj.key(jWarnings);
      obj.startArray();
      for (String msg : warnings) obj.value(msg);
      obj.finishArray();

      obj.finishObject();
    }

    obj.finishArray();

    obj.finishObject();
    return obj.build().getAsObject();
  }
Exemplo n.º 6
0
 /** Parse an IRI (does not resolve it) - throws exception on a bad IRI */
 public static IRI parseIRIex(String iriStr) throws IRIException {
   return iriFactory.construct(iriStr);
 }
Exemplo n.º 7
0
 /** Parse an IRI (does not resolve it) */
 public static IRI parseIRI(String iriStr) {
   return iriFactory.create(iriStr);
 }
Exemplo n.º 8
0
 private static void printErrorWarning(PrintStream ps, IRIFactory factory, int code) {
   String x = PatternCompiler.errorCodeName(code);
   ps.printf("%-40s : E:%-5s W:%-5s\n", x, factory.isError(code), factory.isWarning(code));
 }
Exemplo n.º 9
0
 /**
  * Set the error/warnign state of a violation code.
  *
  * @param factory IRIFactory
  * @param code ViolationCodes constant
  * @param isError Whether it is to be treated an error.
  * @param isWarning Whether it is to be treated a warning.
  */
 private static void setErrorWarning(
     IRIFactory factory, int code, boolean isError, boolean isWarning) {
   factory.setIsError(code, isError);
   factory.setIsWarning(code, isWarning);
 }