W3C Document reader is needed only in freemarkerdor
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Sun, 25 Oct 2009 14:54:58 +0100
changeset 1346544ad908b05
parent 133 d83dc9d624e8
child 135 232e42153945
W3C Document reader is needed only in freemarkerdor
freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/W3CDocumentReader.java
freemarkerdor/src/main/resources/META-INF/services/javax.ws.rs.ext.MessageBodyReader
webidor/src/main/java/cz/xelfi/quoridor/webidor/W3CDocumentReader.java
webidor/src/main/resources/META-INF/services/javax.ws.rs.ext.MessageBodyReader
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/W3CDocumentReader.java	Sun Oct 25 14:54:58 2009 +0100
     1.3 @@ -0,0 +1,46 @@
     1.4 +/*
     1.5 + * To change this template, choose Tools | Templates
     1.6 + * and open the template in the editor.
     1.7 + */
     1.8 +
     1.9 +package cz.xelfi.quoridor.freemarkerdor;
    1.10 +
    1.11 +import java.io.IOException;
    1.12 +import java.io.InputStream;
    1.13 +import java.lang.annotation.Annotation;
    1.14 +import java.lang.reflect.Type;
    1.15 +import javax.ws.rs.Consumes;
    1.16 +import javax.ws.rs.WebApplicationException;
    1.17 +import javax.ws.rs.core.MediaType;
    1.18 +import javax.ws.rs.core.MultivaluedMap;
    1.19 +import javax.ws.rs.ext.Provider;
    1.20 +import javax.xml.parsers.DocumentBuilder;
    1.21 +import javax.xml.parsers.DocumentBuilderFactory;
    1.22 +import javax.xml.parsers.ParserConfigurationException;
    1.23 +import org.w3c.dom.Document;
    1.24 +import org.xml.sax.SAXException;
    1.25 +
    1.26 +/**
    1.27 + *
    1.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    1.29 + */
    1.30 +@Provider
    1.31 +@Consumes(MediaType.TEXT_XML)
    1.32 +public class W3CDocumentReader implements javax.ws.rs.ext.MessageBodyReader<Document> {
    1.33 +    public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
    1.34 +        return type == Document.class;
    1.35 +    }
    1.36 +
    1.37 +    public Document readFrom(Class<Document> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
    1.38 +        try {
    1.39 +            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    1.40 +            DocumentBuilder builder = factory.newDocumentBuilder();
    1.41 +            return builder.parse(entityStream);
    1.42 +        } catch (ParserConfigurationException ex) {
    1.43 +            throw new WebApplicationException(ex);
    1.44 +        } catch (SAXException ex) {
    1.45 +            throw new WebApplicationException(ex);
    1.46 +        }
    1.47 +    }
    1.48 +
    1.49 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/freemarkerdor/src/main/resources/META-INF/services/javax.ws.rs.ext.MessageBodyReader	Sun Oct 25 14:54:58 2009 +0100
     2.3 @@ -0,0 +1,1 @@
     2.4 +cz.xelfi.quoridor.freemarkerdor.W3CDocumentReader
     3.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/W3CDocumentReader.java	Sun Oct 25 14:51:37 2009 +0100
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,46 +0,0 @@
     3.4 -/*
     3.5 - * To change this template, choose Tools | Templates
     3.6 - * and open the template in the editor.
     3.7 - */
     3.8 -
     3.9 -package cz.xelfi.quoridor.webidor;
    3.10 -
    3.11 -import java.io.IOException;
    3.12 -import java.io.InputStream;
    3.13 -import java.lang.annotation.Annotation;
    3.14 -import java.lang.reflect.Type;
    3.15 -import javax.ws.rs.Consumes;
    3.16 -import javax.ws.rs.WebApplicationException;
    3.17 -import javax.ws.rs.core.MediaType;
    3.18 -import javax.ws.rs.core.MultivaluedMap;
    3.19 -import javax.ws.rs.ext.Provider;
    3.20 -import javax.xml.parsers.DocumentBuilder;
    3.21 -import javax.xml.parsers.DocumentBuilderFactory;
    3.22 -import javax.xml.parsers.ParserConfigurationException;
    3.23 -import org.w3c.dom.Document;
    3.24 -import org.xml.sax.SAXException;
    3.25 -
    3.26 -/**
    3.27 - *
    3.28 - * @author Jaroslav Tulach <jtulach@netbeans.org>
    3.29 - */
    3.30 -@Provider
    3.31 -@Consumes(MediaType.TEXT_XML)
    3.32 -public class W3CDocumentReader implements javax.ws.rs.ext.MessageBodyReader<Document> {
    3.33 -    public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
    3.34 -        return type == Document.class;
    3.35 -    }
    3.36 -
    3.37 -    public Document readFrom(Class<Document> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
    3.38 -        try {
    3.39 -            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    3.40 -            DocumentBuilder builder = factory.newDocumentBuilder();
    3.41 -            return builder.parse(entityStream);
    3.42 -        } catch (ParserConfigurationException ex) {
    3.43 -            throw new WebApplicationException(ex);
    3.44 -        } catch (SAXException ex) {
    3.45 -            throw new WebApplicationException(ex);
    3.46 -        }
    3.47 -    }
    3.48 -
    3.49 -}
     4.1 --- a/webidor/src/main/resources/META-INF/services/javax.ws.rs.ext.MessageBodyReader	Sun Oct 25 14:51:37 2009 +0100
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,1 +0,0 @@
     4.4 -cz.xelfi.quoridor.webidor.W3CDocumentReader