Hi Monika,

On 24/08/11 21:50, Monika Solanki wrote:
This is the URI
String uri="http://webenemasuno.linkeddata.es/metadata";

from where I am trying to read into a model using

Model m = FileManager.get().loadModel(uri);

I have tried several other ways of loading the model as well, nothing
seems to work. They all throw

ERROR [main] (RDFDefaultErrorHandler.java:44) -
http://webenemasuno.linkeddata.es/metadata(line 1 column 55): White
spaces are required between publicId and systemId.

and program stops execution, which is what I do not want. What am I
missing?
You need to catch the thrown exception. I've attached an example of doing just that. I also set it to show some of the file that it's trying to read, to help with debugging:

>>>>>
Failed to read from http://webenemasuno.linkeddata.es/metadata because: org.xml.sax.SAXParseException; systemId: http://webenemasuno.linkeddata.es/metadata; lineNumber: 1; columnNumber: 55; White spaces are required between publicId and systemId.
First 10 lines from http://webenemasuno.linkeddata.es/metadata
-----------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
 <head>
  <title>Index of /metadata</title>
 </head>
 <body>
<h1>Index of /metadata</h1>
<table><tr><th><img src="/icons/blank.gif" alt="[ICO]"></th><th><a href="?C=N;O=D">Name</a></th><th><a href="?C=M;O=A">Last modified</a></th><th><a href="?C=S;O=A">Size</a></th><th><a href="?C=D;O=A">Description</a></th></tr><tr><th colspan="5"><hr></th></tr> <tr><td valign="top"><img src="/icons/back.gif" alt="[DIR]"></td><td><a href="/">Parent Directory</a></td><td>&nbsp;</td><td align="right"> - </td></tr> <tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td><a href="voidviajero.ttl">voidviajero.ttl</a></td><td align="right">18-Jul-2011 21:48 </td><td align="right">2.0K</td></tr>

Exiting normally, model contains: 0 triples
<<<<<

So this program doesn't exit when it detects an error. It also shows the problem in this particular case: the URI http://webenemasuno.linkeddata.es/metadata resolves to a directory, not a file, so you're seeing the default action from the web server which is to list the files in that directory. You either need to refer to the file you want to load explicitly, or set the .htaccess so that there is a default file which will be served when you HTTP GET that URL.

Ian




--
____________________________________________________________
Ian Dickinson                   Epimorphics Ltd, Bristol, UK
mailto:[email protected]        http://www.epimorphics.com
cell: +44-7786-850536              landline: +44-1275-399069
------------------------------------------------------------
Epimorphics Ltd.  is a limited company registered in England
(no. 7016688). Registered address: Court Lodge, 105 High St,
              Portishead, Bristol BS20 6PT, UK

package example;


import java.io.*;
import java.net.URL;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.shared.JenaException;
import com.hp.hpl.jena.util.FileManager;

public class ReadExample
{
    public static void main( String[] args ) {
        String uri="http://webenemasuno.linkeddata.es/metadata";;
        Model m = ModelFactory.createDefaultModel();

        m.add( readSafely( uri ) );

        System.out.println( "\nExiting normally, model contains: " + m.size() + " triples" );
    }

    private static Model readSafely( String uri ) {
        Model temp = ModelFactory.createDefaultModel();
        try {
            FileManager.get().loadModel(uri);
        }
        catch (JenaException e) {
            System.err.println( "Failed to read from " + uri + " because: " + e.getMessage() );
            // show the first few lines to help debug why it's not working
            showFirstLines( uri, 10 );
        }
        return temp;
    }

    private static void showFirstLines( String uri, int n ) {
        InputStream is = null;
        try {
            is = new URL( uri ).openStream();
            BufferedReader r = new BufferedReader( new InputStreamReader( is ) );
            String line;

            System.err.println( "First " + n + " lines from " + uri );
            System.err.println( "-----------" );

            for (; n > 0 && (line = r.readLine()) != null; n-- ) {
                System.err.println( line );
            }
        }
        catch (IOException e) {
            // ignore
        }
        finally {
            try {is.close();} catch (IOException ignore) {}
        }
    }
}

Reply via email to