Commit 1fbb97f6 by Patryk Czarnik

Poprawki w generowaniu PDF

parent 7632e2c1
......@@ -38,7 +38,7 @@ public class RProducts {
// ale implementacja REST Easy (WildFly/JBoss) zastosuje pierwszy z formatów podanych w adnmotacji.
// Glassfish i WebLogic tak nie robią - wybierają "losowo".
@GET
@Produces({"application/json", "application/xml", "text/plain"})
@Produces({"application/json", "application/xml", "text/plain", "application/pdf"})
public List<Product> readAll() throws DBException {
try(DBConnection db = DBConnection.open()) {
ProductDAO productDAO = db.productDAO();
......@@ -63,7 +63,7 @@ public class RProducts {
}
@GET
@Produces({"application/json", "application/xml", "text/plain"})
@Produces({"application/json", "application/xml", "text/plain", "application/pdf"})
@Path("/{id}")
public Product readOne(@PathParam("id") int productId) throws DBException, RecordNotFound {
try(DBConnection db = DBConnection.open()) {
......
......@@ -32,6 +32,13 @@ public class PDFWriter implements MessageBodyWriter<Object> {
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";
}
// 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="product-name" />
<xsl:apply-templates select="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