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
0af1defe
Commit
0af1defe
authored
Dec 11, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PDFWriter - zwracanie "minimalnego PDFa"
parent
32a3396e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
0 deletions
+81
-0
RProductPDF.java
PC35-RestSerwer/src/main/java/rest/RProductPDF.java
+35
-0
PDFWriter.java
PC35-RestSerwer/src/main/java/rest/ext/PDFWriter.java
+46
-0
No files found.
PC35-RestSerwer/src/main/java/rest/RProductPDF.java
0 → 100644
View file @
0af1defe
package
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"
)
@Produces
(
"application/pdf"
)
public
class
RProductPDF
{
@GET
public
ProductList
readAllProducts
()
throws
DBException
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
return
new
ProductList
(
productDAO
.
readAll
());
}
}
@Path
(
"/{id}"
)
@GET
public
Product
readOneProduct
(
@PathParam
(
"id"
)
int
productId
)
throws
DBException
,
RecordNotFound
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
return
productDAO
.
findById
(
productId
);
}
}
}
PC35-RestSerwer/src/main/java/rest/ext/PDFWriter.java
0 → 100644
View file @
0af1defe
package
rest
.
ext
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.lang.annotation.Annotation
;
import
java.lang.reflect.Type
;
import
javax.ws.rs.WebApplicationException
;
import
javax.ws.rs.core.MediaType
;
import
javax.ws.rs.core.MultivaluedMap
;
import
javax.ws.rs.ext.MessageBodyWriter
;
import
javax.ws.rs.ext.Provider
;
import
sklep.model.ProductList
;
@Provider
public
class
PDFWriter
implements
MessageBodyWriter
<
ProductList
>
{
@Override
public
boolean
isWriteable
(
Class
<?>
type
,
Type
genericType
,
Annotation
[]
annotations
,
MediaType
mediaType
)
{
// TODO Auto-generated method stub
return
true
;
}
@Override
public
void
writeTo
(
ProductList
obj
,
Class
<?>
type
,
Type
genericType
,
Annotation
[]
annotations
,
MediaType
mediaType
,
MultivaluedMap
<
String
,
Object
>
httpHeaders
,
OutputStream
out
)
throws
IOException
,
WebApplicationException
{
byte
[]
bytes
=
(
"%PDF-1.0\n"
+
"1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj 2 0 obj<</Type/Pages/Kids[3 0 R]/Count 1>>endobj 3 0 obj<</Type/Page/MediaBox[0 0 3 3]>>endobj\n"
+
"xref\n"
+
"0 4\n"
+
"0000000000 65535 f\n"
+
"0000000010 00000 n\n"
+
"0000000053 00000 n\n"
+
"0000000102 00000 n\n"
+
"trailer<</Size 4/Root 1 0 R>>\n"
+
"startxref\n"
+
"149\n"
+
"%EOF"
).
getBytes
();
out
.
write
(
bytes
);
}
}
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