Commit b4470cb8 by Patryk Czarnik

PDF dla listy produktów

parent 0af1defe
...@@ -5,7 +5,9 @@ import java.io.OutputStream; ...@@ -5,7 +5,9 @@ import java.io.OutputStream;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import javax.servlet.ServletContext;
import javax.ws.rs.WebApplicationException; import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyWriter; import javax.ws.rs.ext.MessageBodyWriter;
...@@ -15,11 +17,14 @@ import sklep.model.ProductList; ...@@ -15,11 +17,14 @@ import sklep.model.ProductList;
@Provider @Provider
public class PDFWriter implements MessageBodyWriter<ProductList> { public class PDFWriter implements MessageBodyWriter<ProductList> {
private static final MediaType PDF_TYPE = new MediaType("application", "pdf");
@Context
private ServletContext servletContext;
@Override @Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
// TODO Auto-generated method stub return type == ProductList.class && PDF_TYPE.isCompatible(mediaType);
return true;
} }
@Override @Override
...@@ -27,20 +32,8 @@ public class PDFWriter implements MessageBodyWriter<ProductList> { ...@@ -27,20 +32,8 @@ public class PDFWriter implements MessageBodyWriter<ProductList> {
MultivaluedMap<String, Object> httpHeaders, OutputStream out) MultivaluedMap<String, Object> httpHeaders, OutputStream out)
throws IOException, WebApplicationException { throws IOException, WebApplicationException {
byte[] bytes = ("%PDF-1.0\n" ObslugaXSL obslugaXSL = new ObslugaXSL(servletContext);
+ "1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj 2 0 obj<</Type/Pages/Kids[3 0 R]/Count 1>>endobj 3 0 obj<</Type/Page/MediaBox[0 0 3 3]>>endobj\n" obslugaXSL.wypiszPDF(obj, out);
+ "xref\n"
+ "0 4\n"
+ "0000000000 65535 f\n"
+ "0000000010 00000 n\n"
+ "0000000053 00000 n\n"
+ "0000000102 00000 n\n"
+ "trailer<</Size 4/Root 1 0 R>>\n"
+ "startxref\n"
+ "149\n"
+ "%EOF").getBytes();
out.write(bytes);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment