You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@abdera.apache.org by Danny Ayers <da...@gmail.com> on 2006/08/06 13:47:38 UTC

Conneg & styling PIs

I've got a very crude atom2html.xsl I want to use for display of the
feed in browsers  (though as I type I remember CSS directly on the
Atom format works in most browsers, might be easier for what I've got
in mind). But unless I'm mistaken serving "application/atom+xml" will
cause the browser to hunt for a registered external app.

I'm not sure how much the Accept: header is used in feed readers, but
one thing I'm trying now is the following switch:

if (Accept: includes "application/atom+xml") then
    return feed doc as "application/atom+xml"
else
    insert stylesheet processing instructions into doc
    return as "text/html"

Thing is, as the Abdera API stands right now there's now obvious way
of inserting the PI (bear in mind I've never used Axiom or Stax before
;-)
Suggestions? Or am I missing an obvious reason this isn't a good idea?

btw, I just put together a utility method for sorting entries (by
updated) and if requested trimming to a given number of entries. As
yet untested, so I don't even know if it works let alone whether this
idiom is a good one.
see
http://dannyayers.com/svn/agency/src/org/pragmatron/atommail/Utils.java

Cheers,
Danny.

-- 

http://dannyayers.com

Re: Conneg & styling PIs

Posted by Sam Ruby <ru...@apache.org>.
Garrett Rooney wrote:
> On 8/6/06, James M Snell <ja...@gmail.com> wrote:
>> Heh... already done and checked in. :-)
> 
> Man James, you take all the fun out of trying to recruit new 
> contributors ;-)

Garrett does have a point.

http://www.intertwingly.net/blog/1490.html
http://tinyurl.com/hwfzb#5

- Sam Ruby

Re: Conneg & styling PIs

Posted by James M Snell <ja...@gmail.com>.
Heh... sorry.  I'll try to restrain myself next time.  In fact, Danny,
if you'd like to submit a patch for the getEntry(id) and the other
stuff.. that'd be cool ;-)

- James

Garrett Rooney wrote:
> On 8/6/06, James M Snell <ja...@gmail.com> wrote:
>> Heh... already done and checked in. :-)
> 
> Man James, you take all the fun out of trying to recruit new
> contributors ;-)
> 
> -garrett
> 

Re: Conneg & styling PIs

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On 8/6/06, James M Snell <ja...@gmail.com> wrote:
> Heh... already done and checked in. :-)

Man James, you take all the fun out of trying to recruit new contributors ;-)

-garrett

Re: Conneg & styling PIs

Posted by James M Snell <ja...@gmail.com>.
Heh... already done and checked in. :-)

- James

Garrett Rooney wrote:
> On 8/6/06, James M Snell <ja...@gmail.com> wrote:
>> It would be fairly straightforward to add a
>> addProcessingInstruction(target, value) API to the Document interface.
>> Or, if we want to be a bit more specific, addStylesheet(href).
> 
> I'd certainly be willing to commit a patch adding such functionality
> (either or both of the proposed methods really).  Any interest in
> producing one for us Danny?  Since you're the one who has the need for
> it...  ;-)
> 
> -garrett
> 

Re: Conneg & styling PIs

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On 8/6/06, James M Snell <ja...@gmail.com> wrote:
> It would be fairly straightforward to add a
> addProcessingInstruction(target, value) API to the Document interface.
> Or, if we want to be a bit more specific, addStylesheet(href).

I'd certainly be willing to commit a patch adding such functionality
(either or both of the proposed methods really).  Any interest in
producing one for us Danny?  Since you're the one who has the need for
it...  ;-)

-garrett

Re: Conneg & styling PIs

Posted by James M Snell <ja...@gmail.com>.
It would be fairly straightforward to add a
addProcessingInstruction(target, value) API to the Document interface.
Or, if we want to be a bit more specific, addStylesheet(href).

- James

Garrett Rooney wrote:
> On 8/6/06, James M Snell <ja...@gmail.com> wrote:
>> Danny,
>>
>> There are two things you could do here.
>>
>> 1. Drop down to the Axiom APIs to add the PI (so the browser can apply
>> the transform)
>>
>>     Factory factory = Factory.INSTANCE;
>>     Document<Feed> doc = factory.newDocument();
>>
>>     // drop down to the Axiom interfaces
>>     OMFactory omfactory = (OMFactory) factory;
>>     omfactory.createOMProcessingInstruction(
>>       (OMContainer)doc,
>>       "xml-stylesheet",
>>       "href=\"foo.xslt\"");
>>
>>     // then create the root element
>>     factory.newFeed(doc);
>>
>>     doc.writeTo(System.out);
>>
>>     yields:
>>
>>     <?xml version='1.0' encoding='UTF-8'?>
>>     <?xml-stylesheet href="foo.xslt"?>
>>     <a:feed xmlns:a="http://www.w3.org/2005/Atom"/>
>>
>> 2. Apply the XSLT transform on the server.  You can apply XSLT
>> transforms directly to the Abdera objects.
>>
>>     TransformerFactory factory = TransformerFactory.newInstance();
>>
>>     // Prepare the XSLT
>>     Document xslt = Parser.INSTANCE.parse(
>>       XsltExample.class.getResourceAsStream("/test.xslt"));
>>     AbderaSource xsltSource = new AbderaSource(xslt);
>>     Transformer transformer = factory.newTransformer(xsltSource);
>>
>>     // Now let's get the feed we're going to transform
>>     Document<Feed> feed = Parser.INSTANCE.parse(
>>       XsltExample.class.getResourceAsStream("/simple.xml"));
>>     AbderaSource feedSource = new AbderaSource(feed);
>>
>>     // Transform and output
>>     ByteArrayOutputStream out = new ByteArrayOutputStream();
>>     Result result = new StreamResult(out);
>>     transformer.transform(feedSource, result);
>>     System.out.println(out);
> 
> Should we consider adding some non-axiom-specific way to do this sort
> of thing?  Stylesheets are becoming more and more common in feeds, and
> it would be nice to be able to portably add one to a feed generated by
> Abdera.  Doing so via XSLT seems like an interesting work around, but
> perhaps we should consider adding support for this to the core of the
> system.
> 
> -garrett
> 

Re: Conneg & styling PIs

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On 8/6/06, James M Snell <ja...@gmail.com> wrote:
> Danny,
>
> There are two things you could do here.
>
> 1. Drop down to the Axiom APIs to add the PI (so the browser can apply
> the transform)
>
>     Factory factory = Factory.INSTANCE;
>     Document<Feed> doc = factory.newDocument();
>
>     // drop down to the Axiom interfaces
>     OMFactory omfactory = (OMFactory) factory;
>     omfactory.createOMProcessingInstruction(
>       (OMContainer)doc,
>       "xml-stylesheet",
>       "href=\"foo.xslt\"");
>
>     // then create the root element
>     factory.newFeed(doc);
>
>     doc.writeTo(System.out);
>
>     yields:
>
>     <?xml version='1.0' encoding='UTF-8'?>
>     <?xml-stylesheet href="foo.xslt"?>
>     <a:feed xmlns:a="http://www.w3.org/2005/Atom"/>
>
> 2. Apply the XSLT transform on the server.  You can apply XSLT
> transforms directly to the Abdera objects.
>
>     TransformerFactory factory = TransformerFactory.newInstance();
>
>     // Prepare the XSLT
>     Document xslt = Parser.INSTANCE.parse(
>       XsltExample.class.getResourceAsStream("/test.xslt"));
>     AbderaSource xsltSource = new AbderaSource(xslt);
>     Transformer transformer = factory.newTransformer(xsltSource);
>
>     // Now let's get the feed we're going to transform
>     Document<Feed> feed = Parser.INSTANCE.parse(
>       XsltExample.class.getResourceAsStream("/simple.xml"));
>     AbderaSource feedSource = new AbderaSource(feed);
>
>     // Transform and output
>     ByteArrayOutputStream out = new ByteArrayOutputStream();
>     Result result = new StreamResult(out);
>     transformer.transform(feedSource, result);
>     System.out.println(out);

Should we consider adding some non-axiom-specific way to do this sort
of thing?  Stylesheets are becoming more and more common in feeds, and
it would be nice to be able to portably add one to a feed generated by
Abdera.  Doing so via XSLT seems like an interesting work around, but
perhaps we should consider adding support for this to the core of the
system.

-garrett

Re: Conneg & styling PIs

Posted by James M Snell <ja...@gmail.com>.
Danny,

There are two things you could do here.

1. Drop down to the Axiom APIs to add the PI (so the browser can apply
the transform)

    Factory factory = Factory.INSTANCE;
    Document<Feed> doc = factory.newDocument();

    // drop down to the Axiom interfaces
    OMFactory omfactory = (OMFactory) factory;
    omfactory.createOMProcessingInstruction(
      (OMContainer)doc,
      "xml-stylesheet",
      "href=\"foo.xslt\"");

    // then create the root element
    factory.newFeed(doc);

    doc.writeTo(System.out);

    yields:

    <?xml version='1.0' encoding='UTF-8'?>
    <?xml-stylesheet href="foo.xslt"?>
    <a:feed xmlns:a="http://www.w3.org/2005/Atom"/>

2. Apply the XSLT transform on the server.  You can apply XSLT
transforms directly to the Abdera objects.

    TransformerFactory factory = TransformerFactory.newInstance();

    // Prepare the XSLT
    Document xslt = Parser.INSTANCE.parse(
      XsltExample.class.getResourceAsStream("/test.xslt"));
    AbderaSource xsltSource = new AbderaSource(xslt);
    Transformer transformer = factory.newTransformer(xsltSource);

    // Now let's get the feed we're going to transform
    Document<Feed> feed = Parser.INSTANCE.parse(
      XsltExample.class.getResourceAsStream("/simple.xml"));
    AbderaSource feedSource = new AbderaSource(feed);

    // Transform and output
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Result result = new StreamResult(out);
    transformer.transform(feedSource, result);
    System.out.println(out);


Danny Ayers wrote:
> [snip]
> btw, I just put together a utility method for sorting entries (by
> updated) and if requested trimming to a given number of entries. As
> yet untested, so I don't even know if it works let alone whether this
> idiom is a good one.
> see
> http://dannyayers.com/svn/agency/src/org/pragmatron/atommail/Utils.java
> 

Cool.  I'll take a look either later today or tomorrow.

- James



Re: Conneg & styling PIs

Posted by Danny Ayers <da...@gmail.com>.
PS. I should have googled, found this from January:
[[
A quick survey was conducted as to which readers Accept
application/atom+xml. Sage, Akregator does, FeedDemon doesn't send
Accept at all. We need more people testing different clients.
]]
http://comox.textdrive.com/pipermail/wp-hackers/2006-January/004335.html


-- 

http://dannyayers.com