Esempio n. 1
0
  public static Node iri(Node nv, String baseIRI) {
    if (nv.isURI()) return nv;

    if (nv.isBlank()) {
      // Skolemization of blank nodes to IRIs : Don't ask, just don't ask.
      String x = nv.getBlankNodeLabel();
      return Node.createURI("_:" + x);
    }

    if (nv.isLiteral() && nv.getLiteralDatatype() == null && nv.getLiteralLanguage().equals("")) {
      // Plain literal
      IRI iri = null;
      String iriStr = nv.getLiteralLexicalForm();

      // Level of checking?
      if (baseIRI != null) {
        IRI base = iriFactory.create(baseIRI);
        iri = base.create(iriStr);
      } else iri = iriFactory.create(iriStr);

      if (!iri.isAbsolute()) throw new ExprEvalException("Relative IRI string: " + iriStr);
      if (warningsForIRIs && iri.hasViolation(false)) {
        String msg = "unknown violation from IRI library";
        Iterator<Violation> iter = iri.violations(false);
        if (iter.hasNext()) {
          Violation viol = iter.next();
          msg = viol.getShortMessage();
        }
        Log.warn(NodeFunctions.class, "Bad IRI: " + msg + ": " + iri);
      }
      return Node.createURI(iri.toString());
    }
    throw new ExprEvalException("Can't make an IRI from " + nv);
  }
 /**
  * @param baseDir A prefix of all URLs accessed through this factory.
  * @param zip To open a URL remove the baseDir from the URL and get the named file from the zip.
  */
 public TestInputStreamFactory(IRI baseDir, String propDir) {
   createMe =
       "new TestInputStreamFactory(URI.create(\""
           + baseDir.toString()
           + "\"),\""
           + propDir
           + "\")";
   base = baseDir;
   mapBase = null;
   this.zip = null;
   property = propDir.endsWith("/") ? propDir : propDir + "/";
 }
  private Object open(IRI uri, boolean in) {

    IRI relative = uri.isAbsolute() ? base.relativize(uri, IRIRelativize.CHILD) : uri;

    if (relative.isAbsolute())
      throw new IllegalArgumentException(
          "This  TestInputStreamFactory only knows about '" + base + "'.");

    String relPath = relative.toString();
    if (relPath.length() - relPath.lastIndexOf('.') > 5) {
      relPath = relPath + ".rdf";
      relative = iriFactory.create(relPath);
    }

    if (mapBase != null) {
      // System.out.println("LazyURL: " + relative + " " + mapBase);
      try {
        URL url = mapBase.create(relative).toURL();
        if (!in) {
          if (url.getProtocol().equalsIgnoreCase("file"))
            return new FileOutputStream(url.getFile());
          throw new IllegalArgumentException("Can only save to file: scheme");
        }
        return new LazyURLInputStream(url);
      } catch (MalformedURLException e) {
        throw new JenaException(e);
      } catch (IOException e) {
        e.printStackTrace();
        throw new JenaException(e);
      }
    }
    if (!in) throw new IllegalArgumentException("Can only save to URLs");

    if (zip != null) return new LazyZipEntryInputStream(zip, relPath);
    else return TestInputStreamFactory.getInputStream(property + relPath);
  }
Esempio n. 4
0
 protected String resolve(Taint taintMe, AbsXMLContext x, String uri) throws SAXParseException {
   IRI ref = x.resolveAsURI(arp, taintMe, uri);
   //        checkBadURI(taintMe,ref);
   return ref.toString();
 }
 public boolean savable() {
   return mapBase != null && mapBase.getScheme().equalsIgnoreCase("file");
 }