Removing anything related to JSON from the HTML layer, using natural freemarker's W3C DOM processing capabilities
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
6 package cz.xelfi.quoridor.webidor;
8 import java.io.IOException;
9 import java.io.InputStream;
10 import java.lang.annotation.Annotation;
11 import java.lang.reflect.Type;
12 import javax.ws.rs.Consumes;
13 import javax.ws.rs.WebApplicationException;
14 import javax.ws.rs.core.MediaType;
15 import javax.ws.rs.core.MultivaluedMap;
16 import javax.ws.rs.ext.Provider;
17 import javax.xml.parsers.DocumentBuilder;
18 import javax.xml.parsers.DocumentBuilderFactory;
19 import javax.xml.parsers.ParserConfigurationException;
20 import org.w3c.dom.Document;
21 import org.xml.sax.SAXException;
25 * @author Jaroslav Tulach <jtulach@netbeans.org>
28 @Consumes(MediaType.TEXT_XML)
29 public class W3CDocumentReader implements javax.ws.rs.ext.MessageBodyReader<Document> {
30 public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
31 return type == Document.class;
34 public Document readFrom(Class<Document> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
36 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
37 DocumentBuilder builder = factory.newDocumentBuilder();
38 return builder.parse(entityStream);
39 } catch (ParserConfigurationException ex) {
40 throw new WebApplicationException(ex);
41 } catch (SAXException ex) {
42 throw new WebApplicationException(ex);