Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
javab_20230617
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
javab_20230617
Commits
b6b5a89d
Commit
b6b5a89d
authored
Aug 20, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PDFWriter dla wielu produktów
parent
469aa517
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
6 deletions
+8
-6
PDFWriter.java
PC32-RestSerwer/src/main/java/sklep/rest/ext/PDFWriter.java
+5
-4
RProductsPDF.java
...RestSerwer/src/main/java/sklep/rest/ext/RProductsPDF.java
+3
-2
No files found.
PC32-RestSerwer/src/main/java/sklep/rest/ext/PDFWriter.java
View file @
b6b5a89d
...
@@ -13,9 +13,10 @@ import jakarta.ws.rs.core.MultivaluedMap;
...
@@ -13,9 +13,10 @@ 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.Product
;
import
sklep.model.ProductList
;
@Provider
@Provider
public
class
PDFWriter
implements
MessageBodyWriter
<
Produ
ct
>
{
public
class
PDFWriter
implements
MessageBodyWriter
<
Obje
ct
>
{
private
static
final
MediaType
PDF_TYPE
=
new
MediaType
(
"application"
,
"pdf"
);
private
static
final
MediaType
PDF_TYPE
=
new
MediaType
(
"application"
,
"pdf"
);
@Context
@Context
...
@@ -23,16 +24,16 @@ public class PDFWriter implements MessageBodyWriter<Product> {
...
@@ -23,16 +24,16 @@ public class PDFWriter implements MessageBodyWriter<Product> {
@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
==
Product
.
class
&&
PDF_TYPE
.
isCompatible
(
mediaType
);
return
(
type
==
ProductList
.
class
||
type
==
Product
.
class
)
&&
PDF_TYPE
.
isCompatible
(
mediaType
);
}
}
@Override
@Override
public
void
writeTo
(
Product
product
,
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
)
MultivaluedMap
<
String
,
Object
>
httpHeaders
,
OutputStream
output
)
throws
IOException
,
WebApplicationException
{
throws
IOException
,
WebApplicationException
{
ObslugaXSL
obslugaXSL
=
new
ObslugaXSL
(
servletContext
);
ObslugaXSL
obslugaXSL
=
new
ObslugaXSL
(
servletContext
);
obslugaXSL
.
wypiszPDF
(
product
,
output
);
obslugaXSL
.
wypiszPDF
(
obj
,
output
);
}
}
...
...
PC32-RestSerwer/src/main/java/sklep/rest/ext/RProductsPDF.java
View file @
b6b5a89d
...
@@ -11,16 +11,17 @@ import sklep.db.DBException;
...
@@ -11,16 +11,17 @@ import sklep.db.DBException;
import
sklep.db.ProductDAO
;
import
sklep.db.ProductDAO
;
import
sklep.db.RecordNotFound
;
import
sklep.db.RecordNotFound
;
import
sklep.model.Product
;
import
sklep.model.Product
;
import
sklep.model.ProductList
;
@Path
(
"/products.pdf"
)
@Path
(
"/products.pdf"
)
@Produces
(
"application/pdf"
)
@Produces
(
"application/pdf"
)
public
class
RProductsPDF
{
public
class
RProductsPDF
{
@GET
@GET
public
List
<
Product
>
readAll
()
throws
DBException
{
public
ProductList
readAll
()
throws
DBException
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
ProductDAO
productDAO
=
db
.
productDAO
();
return
productDAO
.
readAll
(
);
return
new
ProductList
(
productDAO
.
readAll
()
);
}
}
}
}
...
...
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