Same page, two different content-types

View: New views
2 Messages — Rating Filter:   Alert me  

Same page, two different content-types

by Alfie Kirkpatrick :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi, I'd like to have the same page class return two different content
types depending on circumstances. Is this possible? The existing
ContentTypeWorker modifies the component model which is immutable at
runtime.

 

In particular (and I realise this is a hack), I want to use locale to
decide between HTML and XML rendering for a page.

 

Thanks,

Alfie.


Re: Same page, two different content-types

by Toby Hobson-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Alfie

I guess you could use a url rewrite:

public class MyAccount {
 ...
}

@ContentType("text/xml")
public class MyAccountXML extends MyAccount {

}

public static void
contributeURLRewriter(OrderedConfiguration<URLRewriterRule> configuration) {
    URLRewriterRule rule = new URLRewriterRule() {

        public Request process(Request request, URLRewriteContext context) {
            if (request.getHeader("User-Agent").indexOf("XML only browser")
> 0) {
                final String path = request.getPath();
                request = new SimpleRequestWrapper(request, path + "XML");
            }
            return request;
        }

        public RewriteRuleApplicability applicability() {
            return RewriteRuleApplicability.INBOUND;
        }

    };

    configuration.add("rule", rule);
}

Not very nice but it might work for you!

Toby

2009/11/3 Alfie Kirkpatrick <Alfie.Kirkpatrick@...>

> Hi, I'd like to have the same page class return two different content
> types depending on circumstances. Is this possible? The existing
> ContentTypeWorker modifies the component model which is immutable at
> runtime.
>
>
>
> In particular (and I realise this is a hack), I want to use locale to
> decide between HTML and XML rendering for a page.
>
>
>
> Thanks,
>
> Alfie.
>
>