Exemplo n.º 1
0
  private void doGet(OutputStream os, String url) throws IOException {
    if ("/".equals(url)) url = "/index.html";

    List<String> headers = new ArrayList<String>();
    headers.add("HTTP/1.1 200 OK\r\n");

    byte[] content = fm.get(url);

    if (content == null) {
      returnStatusCode(404, os);
      return;
    }

    ProcessorsList pl = new ProcessorsList();
    pl.add(new Compressor(6));
    // pl.add(new Chunker(30)); // comment
    content = pl.process(content, headers);

    if (content == null) {
      returnStatusCode(500, os);
      return;
    }

    // uncomment next line
    headers.add("Content-Length: " + content.length + "\r\n");
    headers.add("Connection: close\r\n\r\n");
    os.write(getBinaryHeaders(headers));
    os.write(content);
  }
Exemplo n.º 2
0
 /**
  * Load a model or attached a persistent store (but not a database).
  *
  * @deprecated Use FileManager.get().loadModel(urlStr, lang)
  * @param urlStr The URL or file name of the model
  * @param lang The language of the data - if null, the system guesses
  */
 @Deprecated
 public static Model loadModel(String urlStr, String lang) {
   try {
     return FileManager.get().loadModel(urlStr, lang);
   } catch (JenaException ex) {
     return null;
   }
 }
Exemplo n.º 3
0
 /**
  * Load a model from a file into a model.
  *
  * @deprecated Use FileManager.get().readModel(model, urlStr, lang) instead
  * @param model Model to read into
  * @param urlStr URL (or filename) to read from
  * @param lang Null mean guess based on the URI String
  * @return Returns the model passed in.
  */
 @Deprecated
 public static Model loadModel(Model model, String urlStr, String lang) {
   try {
     return FileManager.get().readModel(model, urlStr, null, lang);
   } catch (Exception e) {
     LoggerFactory.getLogger(ModelLoader.class).warn("No such data source: " + urlStr);
     return null;
   }
 }
Exemplo n.º 4
0
  /**
   * Load a model or attached a persistent store. Tries to guess syntax type. Database paramters
   * only needed if its a database.
   *
   * @param urlStr The URL or file name of the model
   * @param lang The language of the data - if null, the system guesses
   * @param dbUser Database user name (for RDB/JDBC)
   * @param dbPassword Database password (for RDB/JDBC)
   * @param modelName The name of the model
   * @param dbType Database type (e.g. MySQL)
   * @param driver JDBC driver to load.
   * @return Model
   */
  public static Model loadModel(
      String urlStr,
      String lang,
      String dbUser,
      String dbPassword,
      String modelName,
      String dbType,
      String driver) {
    // Wild guess at the language!
    if (lang == null) lang = guessLang(urlStr);

    if (lang == null) lang = FileUtils.langXML;

    if (lang.equals(FileUtils.langBDB)) {
      // @@ temporarily not supported
      LoggerFactory.getLogger(ModelLoader.class).error("Failed to open Berkeley database");
      return null;
      /*
      // URL had better be a file!
      if ( basename != null )
          urlStr = basename+File.separator+urlStr ;

      String dirBDB = getDirname(urlStr) ;
      if ( dirBDB == null || dirBDB.length() == 0)
             dirBDB = "." ;
      urlStr = getBasename(urlStr) ;

      log.debug("BDB: file="+urlStr+", dir="+dirBDB+", basename="+basename) ;

      try {
          Model model = new ModelBdb(new StoreBdbF(dirBDB, urlStr)) ;
          return model ;
      } catch (JenaException rdfEx)
      {
          log.severe("Failed to open Berkeley database", rdfEx) ;
          System.exit(1) ;
      }
      */
    }

    if (lang.equals(FileUtils.langSQL))
      return connectToDB(urlStr, dbUser, dbPassword, modelName, dbType, driver);

    // Its a files.
    // Language is N3, RDF/XML or N-TRIPLE
    Model m = ModelFactory.createDefaultModel();

    //        m.setReaderClassName(FileUtils.langXML,
    // com.hp.hpl.jena.rdf.arp.JenaReader.class.getName());
    //        m.setReaderClassName(FileUtils.langXMLAbbrev,
    // com.hp.hpl.jena.rdf.arp.JenaReader.class.getName());

    // Default.
    // m.setReaderClassName(langNTriple, com.hp.hpl.jena.rdf.arp.NTriple.class.getName()) ;

    try {
      FileManager.get().readModel(m, urlStr, null, lang);
    } catch (JenaException rdfEx) {
      log.warn("Error loading data source", rdfEx);
      return null;
    }
    return m;
  }