On Jan 5, 2009, at 10:50 AM, Vincent Massol wrote:
On Jan 5, 2009, at 10:44 AM, Fabio Mancinelli wrote:
Sergiu Dumitriu wrote:
Modified: sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/ PageResource.java =================================================================== + /* Represent */ + if (variant.getMediaType().equals(MediaType.TEXT_XML)) { + return new StringRepresentation (Utils.toXml(DomainObjectFactory.createPage(getRequest(), doc)), + MediaType.APPLICATION_XML); + } else if (variant.getMediaType().equals(MediaType.TEXT_PLAIN)) { + return new StringRepresentation(doc.getContent(), MediaType.TEXT_PLAIN); + }
This if-else looks bad. What will happen when we support more formats? PDF, XAR, HTML, RTF, zip, RDF...
We add more if/elses.
We can add methods for representing every media type in the case when the if/else bodies start to be too complicated but I don't see how to do it (this is also the way it's done in the RESTlet tutorial).
Maybe we can use reflection in order to call methods like Represent_TEXT_XML, Represent_TEXT_PLAIN, etc.
Do you have an alternative idea?
Use components with a role representing the mediatype.
I meant role-hint. Thanks -Vincent http://xwiki.com http://massol.net http://xwiki.org