Re: [xwiki-devs] [xwiki-notifications] r14987 - sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest
fmancinelli (SVN) wrote:
Author: fmancinelli Date: 2008-12-31 11:06:24 +0100 (Wed, 31 Dec 2008) New Revision: 14987
Modified: sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/PageResource.java sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/PagesResource.java sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/SpacesResource.java Log: Added proper error handling and status code setting in response headers.
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... -- Sergiu Dumitriu http://purl.org/net/sergiu/
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? -Fabio
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. Thanks -Vincent http://xwiki.com http://massol.net http://xwiki.org
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
participants (3)
-
Fabio Mancinelli -
Sergiu Dumitriu -
Vincent Massol