Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java_dzienna_15_09
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_dzienna_15_09
Commits
e5f29427
Commit
e5f29427
authored
Oct 07, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PDFWriter - obsługa pojedynczych
parent
4e016afe
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
4 deletions
+17
-4
RProductsPDF.java
PC34-RestSerwer/src/main/java/sklep/rest/RProductsPDF.java
+12
-0
PDFWriter.java
PC34-RestSerwer/src/main/java/sklep/rest/ext/PDFWriter.java
+5
-4
No files found.
PC34-RestSerwer/src/main/java/sklep/rest/RProductsPDF.java
View file @
e5f29427
...
...
@@ -2,11 +2,14 @@ package sklep.rest;
import
javax.ws.rs.GET
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.PathParam
;
import
javax.ws.rs.Produces
;
import
sklep.db.DBConnection
;
import
sklep.db.DBException
;
import
sklep.db.ProductDAO
;
import
sklep.db.RecordNotFound
;
import
sklep.model.Product
;
import
sklep.model.ProductList
;
@Path
(
"/products.pdf"
)
...
...
@@ -20,4 +23,13 @@ public class RProductsPDF {
return
new
ProductList
(
productDAO
.
readAll
());
}
}
@GET
@Path
(
"/{id}"
)
public
Product
readOne
(
@PathParam
(
"id"
)
int
productId
)
throws
DBException
,
RecordNotFound
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
return
productDAO
.
findById
(
productId
);
}
}
}
PC34-RestSerwer/src/main/java/sklep/rest/ext/PDFWriter.java
View file @
e5f29427
...
...
@@ -13,10 +13,11 @@ import javax.ws.rs.core.MultivaluedMap;
import
javax.ws.rs.ext.MessageBodyWriter
;
import
javax.ws.rs.ext.Provider
;
import
sklep.model.Product
;
import
sklep.model.ProductList
;
@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"
);
@Context
...
...
@@ -24,15 +25,15 @@ 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
lista
,
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
{
ObslugaXSL
obslugaXSL
=
new
ObslugaXSL
(
servletContext
);
obslugaXSL
.
wypiszPDF
(
lista
,
output
);
obslugaXSL
.
wypiszPDF
(
obj
,
output
);
}
}
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