Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java_weekendowa_20221008
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
java_weekendowa_20221008
Commits
4d7544b3
Commit
4d7544b3
authored
Dec 11, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PDF - Obsługa też pojedynczych produktów
parent
b4470cb8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
6 deletions
+14
-6
PDFWriter.java
PC35-RestSerwer/src/main/java/rest/ext/PDFWriter.java
+13
-5
sklep-fo.xsl
PC35-RestSerwer/src/main/webapp/WEB-INF/sklep-fo.xsl
+1
-1
No files found.
PC35-RestSerwer/src/main/java/rest/ext/PDFWriter.java
View file @
4d7544b3
...
@@ -13,10 +13,11 @@ import javax.ws.rs.core.MultivaluedMap;
...
@@ -13,10 +13,11 @@ import javax.ws.rs.core.MultivaluedMap;
import
javax.ws.rs.ext.MessageBodyWriter
;
import
javax.ws.rs.ext.MessageBodyWriter
;
import
javax.ws.rs.ext.Provider
;
import
javax.ws.rs.ext.Provider
;
import
sklep.model.Product
;
import
sklep.model.ProductList
;
import
sklep.model.ProductList
;
@Provider
@Provider
public
class
PDFWriter
implements
MessageBodyWriter
<
ProductLis
t
>
{
public
class
PDFWriter
implements
MessageBodyWriter
<
Objec
t
>
{
private
static
final
MediaType
PDF_TYPE
=
new
MediaType
(
"application"
,
"pdf"
);
private
static
final
MediaType
PDF_TYPE
=
new
MediaType
(
"application"
,
"pdf"
);
@Context
@Context
...
@@ -24,16 +25,23 @@ public class PDFWriter implements MessageBodyWriter<ProductList> {
...
@@ -24,16 +25,23 @@ public class PDFWriter implements MessageBodyWriter<ProductList> {
@Override
@Override
public
boolean
isWriteable
(
Class
<?>
type
,
Type
genericType
,
Annotation
[]
annotations
,
MediaType
mediaType
)
{
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
@Override
public
void
writeTo
(
ProductLis
t
obj
,
Class
<?>
type
,
Type
genericType
,
Annotation
[]
annotations
,
MediaType
mediaType
,
public
void
writeTo
(
Objec
t
obj
,
Class
<?>
type
,
Type
genericType
,
Annotation
[]
annotations
,
MediaType
mediaType
,
MultivaluedMap
<
String
,
Object
>
httpHeaders
,
OutputStream
out
)
MultivaluedMap
<
String
,
Object
>
httpHeaders
,
OutputStream
out
put
)
throws
IOException
,
WebApplicationException
{
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
obslugaXSL
=
new
ObslugaXSL
(
servletContext
);
obslugaXSL
.
wypiszPDF
(
obj
,
out
);
obslugaXSL
.
wypiszPDF
(
obj
,
out
put
);
}
}
}
}
PC35-RestSerwer/src/main/webapp/WEB-INF/sklep-fo.xsl
View file @
4d7544b3
...
@@ -37,7 +37,7 @@
...
@@ -37,7 +37,7 @@
border-color=
"#2233AA"
>
border-color=
"#2233AA"
>
<fo:block
font-weight=
"bold"
font-size=
"14pt"
<fo:block
font-weight=
"bold"
font-size=
"14pt"
margin-bottom=
"1em"
color=
"#FF2244"
>
margin-bottom=
"1em"
color=
"#FF2244"
>
<xsl:apply-templates
select=
"name"
/>
<xsl:apply-templates
select=
"
product-
name"
/>
</fo:block>
</fo:block>
<fo:block
font-weight=
"bold"
color=
"green"
>
<fo:block
font-weight=
"bold"
color=
"green"
>
<xsl:text>
Cena:
</xsl:text>
<xsl:text>
Cena:
</xsl:text>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment