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
469aa517
Commit
469aa517
authored
Aug 20, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PDFWriter - wersja dla jednego produktu
parent
f9f065c4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
1 deletions
+76
-1
PDFWriter.java
PC32-RestSerwer/src/main/java/sklep/rest/ext/PDFWriter.java
+39
-0
RProductsPDF.java
...RestSerwer/src/main/java/sklep/rest/ext/RProductsPDF.java
+36
-0
sklep-fo.xsl
PC32-RestSerwer/src/main/webapp/WEB-INF/sklep-fo.xsl
+1
-1
No files found.
PC32-RestSerwer/src/main/java/sklep/rest/ext/PDFWriter.java
0 → 100644
View file @
469aa517
package
sklep
.
rest
.
ext
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.lang.annotation.Annotation
;
import
java.lang.reflect.Type
;
import
jakarta.servlet.ServletContext
;
import
jakarta.ws.rs.WebApplicationException
;
import
jakarta.ws.rs.core.Context
;
import
jakarta.ws.rs.core.MediaType
;
import
jakarta.ws.rs.core.MultivaluedMap
;
import
jakarta.ws.rs.ext.MessageBodyWriter
;
import
jakarta.ws.rs.ext.Provider
;
import
sklep.model.Product
;
@Provider
public
class
PDFWriter
implements
MessageBodyWriter
<
Product
>
{
private
static
final
MediaType
PDF_TYPE
=
new
MediaType
(
"application"
,
"pdf"
);
@Context
private
ServletContext
servletContext
;
@Override
public
boolean
isWriteable
(
Class
<?>
type
,
Type
genericType
,
Annotation
[]
annotations
,
MediaType
mediaType
)
{
return
type
==
Product
.
class
&&
PDF_TYPE
.
isCompatible
(
mediaType
);
}
@Override
public
void
writeTo
(
Product
product
,
Class
<?>
type
,
Type
genericType
,
Annotation
[]
annotations
,
MediaType
mediaType
,
MultivaluedMap
<
String
,
Object
>
httpHeaders
,
OutputStream
output
)
throws
IOException
,
WebApplicationException
{
ObslugaXSL
obslugaXSL
=
new
ObslugaXSL
(
servletContext
);
obslugaXSL
.
wypiszPDF
(
product
,
output
);
}
}
PC32-RestSerwer/src/main/java/sklep/rest/ext/RProductsPDF.java
0 → 100644
View file @
469aa517
package
sklep
.
rest
.
ext
;
import
java.util.List
;
import
jakarta.ws.rs.GET
;
import
jakarta.ws.rs.Path
;
import
jakarta.ws.rs.PathParam
;
import
jakarta.ws.rs.Produces
;
import
sklep.db.DBConnection
;
import
sklep.db.DBException
;
import
sklep.db.ProductDAO
;
import
sklep.db.RecordNotFound
;
import
sklep.model.Product
;
@Path
(
"/products.pdf"
)
@Produces
(
"application/pdf"
)
public
class
RProductsPDF
{
@GET
public
List
<
Product
>
readAll
()
throws
DBException
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
return
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
);
}
}
}
PC32-RestSerwer/src/main/webapp/WEB-INF/sklep-fo.xsl
View file @
469aa517
...
...
@@ -37,7 +37,7 @@
border-color=
"#2233AA"
>
<fo:block
font-weight=
"bold"
font-size=
"14pt"
margin-bottom=
"1em"
color=
"#FF2244"
>
<xsl:apply-templates
select=
"
product-
name"
/>
<xsl:apply-templates
select=
"name"
/>
</fo:block>
<fo:block
font-weight=
"bold"
color=
"green"
>
<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