Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jh-boot
Project
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
Jan Hrabal
jh-boot
Commits
11d159bd
Commit
11d159bd
authored
Oct 08, 2019
by
Jan Hrabal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
31bd2fe9
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
135 additions
and
66 deletions
+135
-66
JhBootApplication.java
src/main/java/com/jh/boot/JhBootApplication.java
+8
-12
HibernateLoaderTemplateService.java
.../com/jh/boot/template/HibernateLoaderTemplateService.java
+62
-0
HibernateTemplateLoader.java
...in/java/com/jh/boot/template/HibernateTemplateLoader.java
+21
-0
HibernateTemplateRepository.java
...ava/com/jh/boot/template/HibernateTemplateRepository.java
+10
-0
Template.java
src/main/java/com/jh/boot/template/Template.java
+9
-6
TemplateEngine.java
src/main/java/com/jh/boot/template/TemplateEngine.java
+2
-3
TemplateLoader.java
src/main/java/com/jh/boot/template/TemplateLoader.java
+2
-1
TemplateValuesConfig.java
src/main/java/com/jh/boot/template/TemplateValuesConfig.java
+20
-0
HandlebarsTemplateEngine.java
...jh/boot/template/handlebars/HandlebarsTemplateEngine.java
+1
-36
TemplateLoader.java
src/main/java/com/jh/common/template/TemplateLoader.java
+0
-8
No files found.
src/main/java/com/jh/boot/JhBootApplication.java
View file @
11d159bd
...
@@ -6,12 +6,11 @@ import org.springframework.context.annotation.Bean;
...
@@ -6,12 +6,11 @@ import org.springframework.context.annotation.Bean;
import
com.jh.boot.email.LocalEmailService
;
import
com.jh.boot.email.LocalEmailService
;
import
com.jh.boot.security.utils.TemplateEmailAuthServiceListener
;
import
com.jh.boot.security.utils.TemplateEmailAuthServiceListener
;
import
com.jh.boot.template.HibernateTemplateLoader
;
import
com.jh.boot.template.HibernateLoaderTemplateService
;
import
com.jh.boot.template.TemplateEngine
;
import
com.jh.boot.template.TemplateEngine
;
import
com.jh.boot.template.TemplateLoader
;
import
com.jh.boot.template.TemplateLoader
;
import
com.jh.boot.template.TemplateService
;
import
com.jh.boot.template.TemplateService
;
import
com.jh.boot.template.customizable.CustomizableLabelsService
;
import
com.jh.boot.template.customizable.CustomizableTemplateLoader
;
import
com.jh.boot.template.customizable.CustomizableTemplateService
;
import
com.jh.boot.template.handlebars.HandlebarsTemplateEngine
;
import
com.jh.boot.template.handlebars.HandlebarsTemplateEngine
;
public
class
JhBootApplication
{
public
class
JhBootApplication
{
...
@@ -36,19 +35,16 @@ public class JhBootApplication {
...
@@ -36,19 +35,16 @@ public class JhBootApplication {
}
}
@Bean
@Bean
@ConditionalOnMissingBean
(
Template
Service
.
class
)
@ConditionalOnMissingBean
(
Template
Loader
.
class
)
public
Template
Service
templateService
()
{
public
Template
Loader
templateLoader
()
{
return
new
CustomizableTemplateService
();
return
new
HibernateTemplateLoader
();
}
}
@Bean
@Bean
public
CustomizableLabelsService
labelsService
()
{
@ConditionalOnMissingBean
(
TemplateService
.
class
)
return
new
CustomizableLabelsService
();
public
TemplateService
templateService
()
{
return
new
HibernateLoaderTemplateService
();
}
}
@Bean
public
TemplateLoader
templateLoader
()
{
return
new
CustomizableTemplateLoader
();
}
}
}
src/main/java/com/jh/boot/template/HibernateLoaderTemplateService.java
0 → 100644
View file @
11d159bd
package
com
.
jh
.
boot
.
template
;
import
java.io.StringWriter
;
import
java.util.HashMap
;
import
java.util.Locale
;
import
java.util.Map
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.transaction.annotation.Transactional
;
public
class
HibernateLoaderTemplateService
implements
TemplateService
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
HibernateLoaderTemplateService
.
class
);
private
TemplateLoader
loader
;
private
TemplateEngine
engine
;
private
TemplateValuesConfig
valuesConfig
;
@Override
@Transactional
public
String
evaluate
(
String
templateCode
,
Map
<
String
,
Object
>
data
,
Locale
locale
)
{
Template
t
=
loader
.
loadTemplate
(
templateCode
,
locale
);
if
(
t
==
null
)
{
LOG
.
warn
(
"Cannot find template {}"
,
templateCode
);
return
null
;
}
Map
<
String
,
Object
>
values
=
new
HashMap
<
String
,
Object
>();
values
.
putAll
(
data
);
if
(
valuesConfig
!=
null
)
{
values
.
putAll
(
valuesConfig
.
getValues
());
}
String
content
=
t
.
getTemplate
();
StringWriter
sw
=
new
StringWriter
();
engine
.
evaluate
(
sw
,
content
,
values
);
return
sw
.
toString
();
}
@Autowired
public
void
setLoader
(
TemplateLoader
loader
)
{
this
.
loader
=
loader
;
}
@Autowired
public
void
setEngine
(
TemplateEngine
engine
)
{
this
.
engine
=
engine
;
}
@Autowired
public
void
setValuesConfig
(
TemplateValuesConfig
valuesConfig
)
{
this
.
valuesConfig
=
valuesConfig
;
}
}
src/main/java/com/jh/boot/template/HibernateTemplateLoader.java
0 → 100644
View file @
11d159bd
package
com
.
jh
.
boot
.
template
;
import
java.util.Locale
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.transaction.annotation.Transactional
;
public
class
HibernateTemplateLoader
implements
TemplateLoader
{
@Autowired
private
HibernateTemplateRepository
repository
;
@Override
@Transactional
public
Template
loadTemplate
(
String
code
,
Locale
locale
)
{
// TODO Auto-generated method stub
return
null
;
}
}
src/main/java/com/jh/boot/template/HibernateTemplateRepository.java
0 → 100644
View file @
11d159bd
package
com
.
jh
.
boot
.
template
;
import
org.springframework.stereotype.Repository
;
import
com.jh.boot.jpa.AbstractHibernateRepository
;
@Repository
public
class
HibernateTemplateRepository
extends
AbstractHibernateRepository
{
}
src/main/java/com/jh/boot/template/Template.java
View file @
11d159bd
...
@@ -13,12 +13,15 @@ public class Template extends AbstractIdEntity {
...
@@ -13,12 +13,15 @@ public class Template extends AbstractIdEntity {
@Column
(
name
=
"CODE"
)
@Column
(
name
=
"CODE"
)
private
String
code
;
private
String
code
;
@Column
(
name
=
"
NAME
"
)
@Column
(
name
=
"
LAYOUT
"
)
private
String
name
;
private
String
layout
;
@Column
(
name
=
"TEMPLATE"
)
@Column
(
name
=
"TEMPLATE"
)
private
String
template
;
private
String
template
;
@Column
(
name
=
"LOCALE"
)
private
String
locale
;
public
Template
()
{
public
Template
()
{
super
();
super
();
}
}
...
@@ -36,12 +39,12 @@ public class Template extends AbstractIdEntity {
...
@@ -36,12 +39,12 @@ public class Template extends AbstractIdEntity {
this
.
code
=
code
;
this
.
code
=
code
;
}
}
public
String
get
Name
()
{
public
String
get
Layout
()
{
return
name
;
return
layout
;
}
}
public
void
set
Name
(
String
name
)
{
public
void
set
Layout
(
String
name
)
{
this
.
name
=
name
;
this
.
layout
=
name
;
}
}
public
String
getTemplate
()
{
public
String
getTemplate
()
{
...
...
src/main/java/com/jh/boot/template/TemplateEngine.java
View file @
11d159bd
...
@@ -5,7 +5,5 @@ import java.util.Map;
...
@@ -5,7 +5,5 @@ import java.util.Map;
public
interface
TemplateEngine
{
public
interface
TemplateEngine
{
void
evaluate
(
Writer
writer
,
String
templateCode
,
Map
<
String
,
Object
>
data
);
void
evaluate
(
Writer
writer
,
String
templateContent
,
Map
<
String
,
Object
>
data
);
void
evaluateInline
(
Writer
writer
,
String
template
,
Map
<
String
,
Object
>
data
);
}
}
\ No newline at end of file
src/main/java/com/jh/boot/template/TemplateLoader.java
View file @
11d159bd
package
com
.
jh
.
boot
.
template
;
package
com
.
jh
.
boot
.
template
;
import
java.util.Locale
;
public
interface
TemplateLoader
{
public
interface
TemplateLoader
{
Template
loadTemplate
(
String
code
);
Template
loadTemplate
(
String
code
,
Locale
locale
);
}
}
src/main/java/com/jh/boot/template/TemplateValuesConfig.java
0 → 100644
View file @
11d159bd
package
com
.
jh
.
boot
.
template
;
import
java.util.Map
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
@ConfigurationProperties
(
prefix
=
"template"
)
public
class
TemplateValuesConfig
{
private
Map
<
String
,
String
>
values
;
public
Map
<
String
,
String
>
getValues
()
{
return
values
;
}
public
void
setValues
(
Map
<
String
,
String
>
values
)
{
this
.
values
=
values
;
}
}
src/main/java/com/jh/boot/template/handlebars/HandlebarsTemplateEngine.java
View file @
11d159bd
...
@@ -72,8 +72,6 @@ public class HandlebarsTemplateEngine implements TemplateEngine {
...
@@ -72,8 +72,6 @@ public class HandlebarsTemplateEngine implements TemplateEngine {
private
Handlebars
handlebars
;
private
Handlebars
handlebars
;
private
TemplateLoader
templateLoader
;
/**
/**
* Initializes instance.
* Initializes instance.
...
@@ -151,33 +149,7 @@ public class HandlebarsTemplateEngine implements TemplateEngine {
...
@@ -151,33 +149,7 @@ public class HandlebarsTemplateEngine implements TemplateEngine {
@Override
@Override
public
void
evaluate
(
Writer
writer
,
String
templateCode
,
Map
<
String
,
Object
>
data
)
{
public
void
evaluate
(
Writer
writer
,
String
template
,
Map
<
String
,
Object
>
data
)
{
String
name
=
"template://"
+
templateCode
;
Template
template
=
useCache
?
templateCache
.
get
(
name
)
:
null
;
if
(
template
==
null
)
{
com
.
jh
.
boot
.
template
.
Template
t
=
templateLoader
.
loadTemplate
(
templateCode
);
if
(
t
==
null
)
{
// throw new RuntimeException(String.format("Template %s not found", templateCode));
return
;
//TODO log warning
}
try
{
template
=
handlebars
.
compileInline
(
t
.
getTemplate
());
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"Cannot evaluate template"
,
e
);
}
if
(
useCache
)
{
templateCache
.
put
(
name
,
template
);
}
}
evaluateTemplate
(
template
,
data
,
writer
);
}
@Override
public
void
evaluateInline
(
Writer
writer
,
String
template
,
Map
<
String
,
Object
>
data
)
{
String
name
=
"inline://"
+
template
;
String
name
=
"inline://"
+
template
;
Template
t
=
useCache
?
templateCache
.
get
(
name
)
:
null
;
Template
t
=
useCache
?
templateCache
.
get
(
name
)
:
null
;
...
@@ -221,12 +193,5 @@ public class HandlebarsTemplateEngine implements TemplateEngine {
...
@@ -221,12 +193,5 @@ public class HandlebarsTemplateEngine implements TemplateEngine {
this
.
useCache
=
useCache
;
this
.
useCache
=
useCache
;
}
}
@Autowired
public
void
setTemplateLoader
(
TemplateLoader
templateLoader
)
{
this
.
templateLoader
=
templateLoader
;
}
}
}
src/main/java/com/jh/common/template/TemplateLoader.java
deleted
100644 → 0
View file @
31bd2fe9
package
com
.
jh
.
common
.
template
;
public
interface
TemplateLoader
{
String
loadTemplate
(
String
templateName
);
}
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