Commit ae50d112 by Patryk Czarnik

PDFWriter - wersja pełna

parent ab4ad38c
......@@ -12,10 +12,11 @@ import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.ext.MessageBodyWriter;
import jakarta.ws.rs.ext.Provider;
import sklep.model.Product;
import sklep.model.ProductList;
@Provider
public class PdfWriter implements MessageBodyWriter<ProductList> {
public class PdfWriter implements MessageBodyWriter<Object> {
private static final MediaType PDF_TYPE = new MediaType("application", "pdf");
@Context
......@@ -23,17 +24,25 @@ public class PdfWriter implements MessageBodyWriter<ProductList> {
@Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return (type == ProductList.class) && PDF_TYPE.isCompatible(mediaType);
return (type == ProductList.class || type == Product.class) && PDF_TYPE.isCompatible(mediaType);
}
@Override
public void writeTo(ProductList obj, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
public void writeTo(Object obj, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, OutputStream output)
throws IOException, WebApplicationException {
String fileName = "products.pdf";
if (obj instanceof Product) {
Product product = (Product) obj;
// fileName = product.getProductName().replace(' ', '_') + ".pdf";
fileName = String.format("product%04d.pdf", product.getProductId());
}
// httpHeaders.add("Content-Disposition", "attachment;filename=" + fileName);
httpHeaders.add("Content-Disposition", "inline;filename=" + fileName);
ObslugaXSL obslugaXSL = new ObslugaXSL(servletContext);
obslugaXSL.wypiszPDF(obj, output);
}
}
......@@ -37,7 +37,7 @@
border-color="#2233AA">
<fo:block font-weight="bold" font-size="14pt"
margin-bottom="1em" color="#FF2244">
<xsl:apply-templates select="name" />
<xsl:apply-templates select="product-name" />
</fo:block>
<fo:block font-weight="bold" color="green">
<xsl:text>Cena: </xsl:text>
......
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