views:

133

answers:

2

I'm trying to use content negotiation to give both a HTML and a RDF/XML representation of a resource on a HTTP server. On the server side this works, i.e.

curl -H "Accept: application/rdf+xml" http://localhost:8182/ontologies/1

will retrieve the correct version. I can also do the same with JavaScript/Dojo:

function downloadOntologyRDF(ontologyId) {
    dojo.xhrGet( {
        url:"${baseUrl}/ontologies/" + ontologyId,
        headers: {"Accept": "application/rdf+xml"},
        timeout: 5000,
        load: function(response, ioArgs) {
            var preNode = document.createElement("pre");
            preNode.appendChild(document.createTextNode(response));
            var foo = new dijit.Dialog({
                title: "RDF",
                content: preNode,
                style: "overflow: auto;"
            });
            foo.show();
            return response;
        },
        error: function(response, ioArgs) {
            alert("Retrieving the RDF version failed: " + response);
            return response;
        }
    });
}

which will display the result in a popup dialog. The point where I am stuck is offering a way to the user to download this version. I would like to have a link on the page that either displays the RDF as a page in the browser or directly opens the save dialog. Is this possible at all without resorting to query parameters or other tricks?

A: 

This page explains how to setup an aspx page that will show the RDF in the browser. It may help you. Although I can't be sure because you haven's specified what you are running on your server.

Building an RSS feed made simple

magnifico
I'm using Java/Restlets, but it doesn't matter: the server side already does its thing as the curl/JS examples show. RSS feeds are considered separate resources with their own URL, what I try to do is to use content negotiation to retrieve a different variant of the same resource.
Peter Becker
A: 

Like cobbal mentions - since you can not set Accept header in the URL itself, you should have additional content negotiation mechanism. Some frameworks allow content type to be set in form

http://example.com/resource;format

Having the format at the end of URL, separated with semicolon. Then, when processing request, it parses out the format part.

In your case it could be something like

http://localhost:8182/ontologies/1;rdf

to server rdf, and no format specified to serve whatever is in your accept headers.

tm_lv
That classifies as "query parameters and other tricks" for me ;-) But let me just accept this answer as a long version of "no".
Peter Becker
at the time of writing i thought that semicolon is a good idea but it brings more trouble and not much of elegance in the business - you have to parse it or configure in the routing table and it gets nasty fast. for me at the end i went with a parameter localhost:8182/ontologies/1?format=rdf
tm_lv