コード例 #1
0
ファイル: RDFUtil.java プロジェクト: mepcotterell/cs8470-ads
  public static String normalizeURI(String uri) {

    // normalise uri
    URL url = null;
    try {
      url = new URL(uri);
    } catch (Exception e) {
      try {
        if (uri.indexOf(':') == -1) url = new URL("file", null, uri);
      } catch (Exception e2) {
      }
    }
    return url != null ? url.toString() : uri;
  }
コード例 #2
0
ファイル: RDFUtil.java プロジェクト: mepcotterell/cs8470-ads
  /** tries to determine the file name from getSourceURI */
  public static void saveModel(Model m, RDFSerializer s)
      throws FileNotFoundException, IOException, ModelException, SerializationException {

    // URI to filename
    URL url = null;
    try {
      url = new URL(m.getSourceURI());
    } catch (Exception any) {
      throw new ModelException("RDFUtil: cannot determine model file name: " + m.getSourceURI());
    }
    if ("file".equals(url.getProtocol()))
      saveModel(m, url.getFile().replace('/', File.separatorChar), s);
    else
      throw new ModelException("RDFUtil: cannot save to non-file model URI: " + m.getSourceURI());
  }
コード例 #3
0
ファイル: RDFUtil.java プロジェクト: mepcotterell/cs8470-ads
  public static void parse(String fileNameOrURL, RDFParser parser, Model model)
      throws IOException, SAXException, MalformedURLException, ModelException {

    URL url = new URL(normalizeURI(fileNameOrURL));

    // maybe this model is loaded as schema...
    //    Model model = factory.registry().get(url.toString());
    //    if(model != null)
    //      return model;

    // Prepare input source
    model.setSourceURI(url.toString());
    InputStream in = url.openStream();
    InputSource source = new InputSource(in);
    source.setSystemId(url.toString());

    parser.parse(source, new ModelConsumer(model));
    in.close();
  }