// $Id: AskJena.java,v 1.6 2003/09/29 23:24:21 jderoo Exp $
// PxButton | build | javac -O *.java |

import java.io.*;
import java.net.*;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.mem.*;

public class AskJena {

  public static final String fromWeb(String in) {
    if (in.endsWith(".owl.n3")) in = in.substring(0, in.length() - 3);
    else if (in.endsWith(".n3")) in = in.substring(0, in.length() - 3) + ".rdf";
    if (Euler.trace || Euler.debug) System.err.println("AskJena " + in);
    String b = in;
    Model m = new ModelMem();
    RDFReader r = m.getReader("RDF/XML");
    try {
      URL url = new URL(in);
      r.read(m, in);
    }
    catch (Exception e) {
      try {
        File f = new File(in);
        b = "file:///" + f.getCanonicalPath().replace('\\', '/');
        r.read(m, new FileInputStream(in), b);
      }
      catch (Exception ex) {
        return "\n";        
      }
    }
    RDFWriter w = m.getWriter("N3");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
      w.write(m, new PrintWriter(baos), b);
    }
    catch (Exception e) {
      return "\n";        
    }
    return baos.toString();
  }
}
