Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Backend
Commits
6ac9343a
Commit
6ac9343a
authored
Oct 10, 2013
by
Matija Obreza
Browse files
Load articles from default language if necessary
parent
8f51aae1
Changes
8
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys2/server/service/ContentService.java
View file @
6ac9343a
...
...
@@ -41,7 +41,7 @@ public interface ContentService {
* @param locale
* @return
*/
Article
getArticle
(
Class
<?>
clazz
,
Long
id
,
String
slug
,
Locale
locale
);
Article
getArticle
(
Class
<?>
clazz
,
Long
id
,
String
slug
,
Locale
locale
,
boolean
useDefault
);
Article
getArticle
(
EntityId
entity
,
String
slug
,
Locale
locale
);
...
...
@@ -50,9 +50,21 @@ public interface ContentService {
*
* @param slug
* @param locale
* @param useDefault
* Load article from default language
* @return
*/
Article
getGlobalArticle
(
String
slug
,
Locale
locale
);
Article
getGlobalArticle
(
String
slug
,
Locale
locale
,
boolean
useDefault
);
/**
* Loads a global article in the specified locale, or when not found the
* default locale
*
* @param string
* @param locale
* @return
*/
Article
getGlobalArticle
(
String
string
,
Locale
locale
);
Page
<
Article
>
listArticles
(
Pageable
pageable
);
...
...
@@ -81,4 +93,10 @@ public interface ContentService {
void
deleteActivityPost
(
long
id
);
/**
* Returns default locale
*
* @return
*/
Locale
getDefaultLocale
();
}
src/main/java/org/genesys2/server/service/impl/ContentServiceImpl.java
View file @
6ac9343a
...
...
@@ -57,6 +57,11 @@ public class ContentServiceImpl implements ContentService {
@Autowired
private
HtmlSanitizer
htmlSanitizer
;
@Override
public
Locale
getDefaultLocale
()
{
return
Locale
.
getDefault
();
}
@Override
public
List
<
ActivityPost
>
lastNews
()
{
PageRequest
page
=
new
PageRequest
(
0
,
10
,
Direction
.
DESC
,
"postDate"
);
...
...
@@ -74,19 +79,31 @@ public class ContentServiceImpl implements ContentService {
articleRepository
.
save
(
articles
);
}
@Override
public
Article
getGlobalArticle
(
String
slug
,
Locale
locale
,
boolean
useDefault
)
{
return
getArticle
(
Article
.
class
,
null
,
slug
,
locale
,
useDefault
);
}
/**
* Get article, use default locale if required
*/
@Override
public
Article
getGlobalArticle
(
String
slug
,
Locale
locale
)
{
return
getArticle
(
Article
.
class
,
null
,
slug
,
locale
);
return
get
Global
Article
(
slug
,
locale
,
true
);
}
@Override
public
Article
getArticle
(
EntityId
entity
,
String
slug
,
Locale
locale
)
{
return
getArticle
(
entity
.
getClass
(),
entity
.
getId
(),
slug
,
locale
);
return
getArticle
(
entity
.
getClass
(),
entity
.
getId
(),
slug
,
locale
,
true
);
}
@Override
public
Article
getArticle
(
Class
<?>
clazz
,
Long
id
,
String
slug
,
Locale
locale
)
{
return
articleRepository
.
findByClassPkAndTargetIdAndSlugAndLang
(
getClassPk
(
clazz
),
id
,
slug
,
locale
.
getLanguage
());
public
Article
getArticle
(
Class
<?>
clazz
,
Long
id
,
String
slug
,
Locale
locale
,
boolean
useDefault
)
{
Article
article
=
articleRepository
.
findByClassPkAndTargetIdAndSlugAndLang
(
getClassPk
(
clazz
),
id
,
slug
,
locale
.
getLanguage
());
if
(
article
==
null
&&
useDefault
&&
!
locale
.
getLanguage
().
equals
(
getDefaultLocale
().
getLanguage
()))
{
article
=
articleRepository
.
findByClassPkAndTargetIdAndSlugAndLang
(
getClassPk
(
clazz
),
id
,
slug
,
getDefaultLocale
().
getLanguage
());
}
return
article
;
}
@Override
...
...
@@ -147,7 +164,7 @@ public class ContentServiceImpl implements ContentService {
@Transactional
(
readOnly
=
false
)
@PreAuthorize
(
"hasRole('ADMINISTRATOR')"
)
public
Article
updateArticle
(
Class
<?>
clazz
,
Long
id
,
String
slug
,
String
title
,
String
body
,
Locale
locale
)
{
Article
article
=
getArticle
(
clazz
,
id
,
slug
,
locale
);
Article
article
=
getArticle
(
clazz
,
id
,
slug
,
locale
,
false
);
if
(
article
==
null
||
!
article
.
getLang
().
equals
(
locale
.
getLanguage
()))
{
article
=
new
Article
();
article
.
setClassPk
(
ensureClassPK
(
clazz
));
...
...
src/main/java/org/genesys2/server/servlet/controller/ArticleController.java
View file @
6ac9343a
...
...
@@ -57,7 +57,7 @@ public class ArticleController extends BaseController {
public
String
edit
(
ModelMap
model
,
@PathVariable
(
value
=
"url"
)
String
slug
)
{
_logger
.
debug
(
"Editing article "
+
slug
);
Article
article
=
contentService
.
getGlobalArticle
(
slug
,
getLocale
());
Article
article
=
contentService
.
getGlobalArticle
(
slug
,
getLocale
()
,
false
);
if
(
article
==
null
)
{
article
=
new
Article
();
article
.
setSlug
(
slug
);
...
...
src/main/resources/content/language.properties
View file @
6ac9343a
...
...
@@ -53,6 +53,7 @@ pagination.previous-page=< Previous
# Language
locale.language.change
=
Change locale
i18n.content-not-translated
=
The content is not available in your language. Please contact us if you can help!
# Languages (Do not translate)
locale.language.en
=
English
...
...
src/main/webapp/WEB-INF/jsp/content/article.jsp
View file @
6ac9343a
...
...
@@ -13,7 +13,11 @@
</h1>
</c:if>
<div
class=
""
>
<c:if
test=
"
${
article
.
lang
!=
pageContext
.
response
.
locale
.
language
}
"
>
<%@include
file=
"/WEB-INF/jsp/not-translated.jsp"
%>
</c:if>
<div
class=
"article"
dir=
"${article.lang=='fa' || article.lang=='ar' ? 'rtl' : 'ltr'}"
>
<security:authorize
access=
"hasRole('ADMINISTRATOR')"
>
<a
href=
"
<c:url
value=
"/content/${article.slug}/edit"
/>
"
class=
"close"
>
<spring:message
code=
"edit"
/>
...
...
src/main/webapp/WEB-INF/jsp/content/include/blurp-display.jsp
View file @
6ac9343a
<%@include
file=
"/WEB-INF/jsp/init.jsp"
%>
<div
class=
"free-text blurp"
>
<div
class=
"free-text blurp"
dir=
"${blurp.lang=='fa' || blurp.lang=='ar' ? 'rtl' : 'ltr'}"
>
<c:out
value=
"
${
blurp
.
body
}
"
escapeXml=
"false"
/>
</div>
<c:if
test=
"
${
blurp
!=
null
&&
blurp
.
lang
!=
pageContext
.
response
.
locale
.
language
}
"
>
<%@include
file=
"/WEB-INF/jsp/not-translated.jsp"
%>
</c:if>
src/main/webapp/WEB-INF/jsp/not-translated.jsp
0 → 100644
View file @
6ac9343a
<%@include
file=
"/WEB-INF/jsp/init.jsp"
%>
<div
class=
"alert alert-warning translationmissing"
>
<spring:message
code=
"i18n.content-not-translated"
/>
</div>
src/main/webapp/html/css/custom.css
View file @
6ac9343a
...
...
@@ -515,7 +515,7 @@ tr.acn .sel.picked {
vertical-align
:
top
;
}
.form-behind
.editor
{
/*
.form-behind .editor {
display: none;
}
...
...
@@ -525,4 +525,8 @@ tr.acn .sel.picked {
.form-behind.editing .display {
display: none;
}
*/
.translationmissing
{
padding
:
0.3em
;
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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