Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
alx_java2b_20250412
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
alx_java2b_20250412
Commits
ae50d112
Commit
ae50d112
authored
May 11, 2025
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PDFWriter - wersja pełna
parent
ab4ad38c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
7 deletions
+16
-7
PdfWriter.java
PC26-RestSerwer/src/main/java/sklep/rest/ext/PdfWriter.java
+15
-6
sklep-fo.xsl
PC26-RestSerwer/src/main/webapp/WEB-INF/sklep-fo.xsl
+1
-1
No files found.
PC26-RestSerwer/src/main/java/sklep/rest/ext/PdfWriter.java
View file @
ae50d112
...
@@ -12,10 +12,11 @@ import jakarta.ws.rs.core.MediaType;
...
@@ -12,10 +12,11 @@ import jakarta.ws.rs.core.MediaType;
import
jakarta.ws.rs.core.MultivaluedMap
;
import
jakarta.ws.rs.core.MultivaluedMap
;
import
jakarta.ws.rs.ext.MessageBodyWriter
;
import
jakarta.ws.rs.ext.MessageBodyWriter
;
import
jakarta.ws.rs.ext.Provider
;
import
jakarta.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
...
@@ -23,17 +24,25 @@ public class PdfWriter implements MessageBodyWriter<ProductList> {
...
@@ -23,17 +24,25 @@ 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
output
)
MultivaluedMap
<
String
,
Object
>
httpHeaders
,
OutputStream
output
)
throws
IOException
,
WebApplicationException
{
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
obslugaXSL
=
new
ObslugaXSL
(
servletContext
);
obslugaXSL
.
wypiszPDF
(
obj
,
output
);
obslugaXSL
.
wypiszPDF
(
obj
,
output
);
}
}
}
}
PC26-RestSerwer/src/main/webapp/WEB-INF/sklep-fo.xsl
View file @
ae50d112
...
@@ -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