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
b4470cb8
Commit
b4470cb8
authored
Dec 11, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PDF dla listy produktów
parent
0af1defe
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
17 deletions
+10
-17
PDFWriter.java
PC35-RestSerwer/src/main/java/rest/ext/PDFWriter.java
+10
-17
No files found.
PC35-RestSerwer/src/main/java/rest/ext/PDFWriter.java
View file @
b4470cb8
...
@@ -5,7 +5,9 @@ import java.io.OutputStream;
...
@@ -5,7 +5,9 @@ import java.io.OutputStream;
import
java.lang.annotation.Annotation
;
import
java.lang.annotation.Annotation
;
import
java.lang.reflect.Type
;
import
java.lang.reflect.Type
;
import
javax.servlet.ServletContext
;
import
javax.ws.rs.WebApplicationException
;
import
javax.ws.rs.WebApplicationException
;
import
javax.ws.rs.core.Context
;
import
javax.ws.rs.core.MediaType
;
import
javax.ws.rs.core.MediaType
;
import
javax.ws.rs.core.MultivaluedMap
;
import
javax.ws.rs.core.MultivaluedMap
;
import
javax.ws.rs.ext.MessageBodyWriter
;
import
javax.ws.rs.ext.MessageBodyWriter
;
...
@@ -15,11 +17,14 @@ import sklep.model.ProductList;
...
@@ -15,11 +17,14 @@ import sklep.model.ProductList;
@Provider
@Provider
public
class
PDFWriter
implements
MessageBodyWriter
<
ProductList
>
{
public
class
PDFWriter
implements
MessageBodyWriter
<
ProductList
>
{
private
static
final
MediaType
PDF_TYPE
=
new
MediaType
(
"application"
,
"pdf"
);
@Context
private
ServletContext
servletContext
;
@Override
@Override
public
boolean
isWriteable
(
Class
<?>
type
,
Type
genericType
,
Annotation
[]
annotations
,
MediaType
mediaType
)
{
public
boolean
isWriteable
(
Class
<?>
type
,
Type
genericType
,
Annotation
[]
annotations
,
MediaType
mediaType
)
{
// TODO Auto-generated method stub
return
type
==
ProductList
.
class
&&
PDF_TYPE
.
isCompatible
(
mediaType
);
return
true
;
}
}
@Override
@Override
...
@@ -27,20 +32,8 @@ public class PDFWriter implements MessageBodyWriter<ProductList> {
...
@@ -27,20 +32,8 @@ public class PDFWriter implements MessageBodyWriter<ProductList> {
MultivaluedMap
<
String
,
Object
>
httpHeaders
,
OutputStream
out
)
MultivaluedMap
<
String
,
Object
>
httpHeaders
,
OutputStream
out
)
throws
IOException
,
WebApplicationException
{
throws
IOException
,
WebApplicationException
{
byte
[]
bytes
=
(
"%PDF-1.0\n"
ObslugaXSL
obslugaXSL
=
new
ObslugaXSL
(
servletContext
);
+
"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"
obslugaXSL
.
wypiszPDF
(
obj
,
out
);
+
"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