Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
solo
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Administrator
solo
Commits
f498788d
Commit
f498788d
authored
Apr 16, 2014
by
Liang Ding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#11755
需要拉 latke 1.0.10-SNAPSHOT 进行构建,latke 1.0.10 预计本周五发布
parent
1caf8219
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
81 additions
and
174 deletions
+81
-174
core/src/main/java/org/b3log/solo/processor/renderer/ConsoleRenderer.java
...va/org/b3log/solo/processor/renderer/ConsoleRenderer.java
+5
-9
core/src/main/java/org/b3log/solo/service/InitService.java
core/src/main/java/org/b3log/solo/service/InitService.java
+35
-39
core/src/main/java/org/b3log/solo/service/PreferenceMgmtService.java
...in/java/org/b3log/solo/service/PreferenceMgmtService.java
+14
-31
core/src/main/java/org/b3log/solo/util/Skins.java
core/src/main/java/org/b3log/solo/util/Skins.java
+26
-94
pom.xml
pom.xml
+1
-1
No files found.
core/src/main/java/org/b3log/solo/processor/renderer/ConsoleRenderer.java
View file @
f498788d
...
@@ -18,9 +18,8 @@ package org.b3log.solo.processor.renderer;
...
@@ -18,9 +18,8 @@ package org.b3log.solo.processor.renderer;
import
freemarker.template.Configuration
;
import
freemarker.template.Configuration
;
import
freemarker.template.Template
;
import
freemarker.template.Template
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
org.b3log.latke.logging.Level
;
import
javax.servlet.ServletContext
;
import
org.b3log.latke.logging.Logger
;
import
org.b3log.latke.logging.Logger
;
import
org.b3log.latke.servlet.HTTPRequestContext
;
import
org.b3log.latke.servlet.HTTPRequestContext
;
import
org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer
;
import
org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer
;
...
@@ -32,7 +31,7 @@ import org.b3log.solo.SoloServletListener;
...
@@ -32,7 +31,7 @@ import org.b3log.solo.SoloServletListener;
* renderer for administrator console and initialization rendering.
* renderer for administrator console and initialization rendering.
*
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.
0.1, Nov 17, 2013
* @version 1.0.
1.1, Apr 15, 2014
* @since 0.4.1
* @since 0.4.1
*/
*/
public
final
class
ConsoleRenderer
extends
AbstractFreeMarkerRenderer
{
public
final
class
ConsoleRenderer
extends
AbstractFreeMarkerRenderer
{
...
@@ -50,13 +49,10 @@ public final class ConsoleRenderer extends AbstractFreeMarkerRenderer {
...
@@ -50,13 +49,10 @@ public final class ConsoleRenderer extends AbstractFreeMarkerRenderer {
static
{
static
{
TEMPLATE_CFG
=
new
Configuration
();
TEMPLATE_CFG
=
new
Configuration
();
TEMPLATE_CFG
.
setDefaultEncoding
(
"UTF-8"
);
TEMPLATE_CFG
.
setDefaultEncoding
(
"UTF-8"
);
try
{
final
String
webRootPath
=
SoloServletListener
.
getWebRoot
();
TEMPLATE_CFG
.
setDirectoryForTemplateLoading
(
new
File
(
webRootPath
));
final
ServletContext
servletContext
=
SoloServletListener
.
getServletContext
();
}
catch
(
final
IOException
e
)
{
LOGGER
.
log
(
Level
.
ERROR
,
e
.
getMessage
(),
e
);
TEMPLATE_CFG
.
setServletContextForTemplateLoading
(
servletContext
,
""
);
}
}
}
@Override
@Override
...
...
core/src/main/java/org/b3log/solo/service/InitService.java
View file @
f498788d
...
@@ -16,13 +16,12 @@
...
@@ -16,13 +16,12 @@
package
org
.
b3log
.
solo
.
service
;
package
org
.
b3log
.
solo
.
service
;
import
java.io.File
;
import
java.io.IOException
;
import
java.text.ParseException
;
import
java.text.ParseException
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.Set
;
import
javax.inject.Inject
;
import
javax.inject.Inject
;
import
javax.servlet.ServletContext
;
import
org.apache.commons.lang.StringEscapeUtils
;
import
org.apache.commons.lang.StringEscapeUtils
;
import
org.apache.commons.lang.time.DateFormatUtils
;
import
org.apache.commons.lang.time.DateFormatUtils
;
import
org.apache.commons.lang.time.DateUtils
;
import
org.apache.commons.lang.time.DateUtils
;
...
@@ -62,7 +61,7 @@ import org.json.JSONObject;
...
@@ -62,7 +61,7 @@ import org.json.JSONObject;
* B3log Solo initialization service.
* B3log Solo initialization service.
*
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.
1.7, Jun 28, 2013
* @version 1.0.
2.7, Apr 15, 2014
* @since 0.4.0
* @since 0.4.0
*/
*/
@Service
@Service
...
@@ -168,24 +167,24 @@ public class InitService {
...
@@ -168,24 +167,24 @@ public class InitService {
/**
/**
* Initializes B3log Solo.
* Initializes B3log Solo.
*
*
* <p>
* <p>
* Initializes the followings in sequence:
* Initializes the followings in sequence:
*
<ol>
* <ol>
*
<li>Statistic.</li>
* <li>Statistic.</li>
*
<li>Preference.</li>
* <li>Preference.</li>
*
<li>Administrator.</li>
* <li>Administrator.</li>
*
</ol>
* </ol>
* </p>
* </p>
*
*
* <p>
* <p>
*
We will try to initialize B3log Solo 3 times at most.
* We will try to initialize B3log Solo 3 times at most.
* </p>
* </p>
*
*
* <p>
* <p>
*
Posts "Hello World!" article and its comment while B3log Solo initialized.
* Posts "Hello World!" article and its comment while B3log Solo initialized.
* </p>
* </p>
*
*
* @param requestJSONObject the specified request json object, for example,
* @param requestJSONObject the specified request json object, for example,
* <pre>
* <pre>
* {
* {
...
@@ -194,6 +193,7 @@ public class InitService {
...
@@ -194,6 +193,7 @@ public class InitService {
* "userPassword": "", // Unhashed
* "userPassword": "", // Unhashed
* }
* }
* </pre>
* </pre>
*
* @throws ServiceException service exception
* @throws ServiceException service exception
*/
*/
public
void
init
(
final
JSONObject
requestJSONObject
)
throws
ServiceException
{
public
void
init
(
final
JSONObject
requestJSONObject
)
throws
ServiceException
{
...
@@ -323,7 +323,7 @@ public class InitService {
...
@@ -323,7 +323,7 @@ public class InitService {
/**
/**
* Adds the specified "Hello World" article.
* Adds the specified "Hello World" article.
*
*
* @param article the specified "Hello World" article
* @param article the specified "Hello World" article
* @return generated article id
* @return generated article id
* @throws RepositoryException repository exception
* @throws RepositoryException repository exception
...
@@ -380,6 +380,7 @@ public class InitService {
...
@@ -380,6 +380,7 @@ public class InitService {
* ....
* ....
* }
* }
* </pre>
* </pre>
*
* @throws RepositoryException repository exception
* @throws RepositoryException repository exception
*/
*/
public
void
archiveDate
(
final
JSONObject
article
)
throws
RepositoryException
{
public
void
archiveDate
(
final
JSONObject
article
)
throws
RepositoryException
{
...
@@ -457,7 +458,7 @@ public class InitService {
...
@@ -457,7 +458,7 @@ public class InitService {
}
}
/**
/**
* Initializes administrator with the specified request json object, and
* Initializes administrator with the specified request json object, and
* then logins it.
* then logins it.
*
*
* @param requestJSONObject the specified request json object, for example,
* @param requestJSONObject the specified request json object, for example,
...
@@ -468,6 +469,7 @@ public class InitService {
...
@@ -468,6 +469,7 @@ public class InitService {
* "userPassowrd": "" // Unhashed
* "userPassowrd": "" // Unhashed
* }
* }
* </pre>
* </pre>
*
* @throws Exception exception
* @throws Exception exception
*/
*/
private
void
initAdmin
(
final
JSONObject
requestJSONObject
)
throws
Exception
{
private
void
initAdmin
(
final
JSONObject
requestJSONObject
)
throws
Exception
{
...
@@ -513,7 +515,7 @@ public class InitService {
...
@@ -513,7 +515,7 @@ public class InitService {
/**
/**
* Initializes reply notification template.
* Initializes reply notification template.
*
*
* @throws Exception exception
* @throws Exception exception
*/
*/
private
void
initReplyNotificationTemplate
()
throws
Exception
{
private
void
initReplyNotificationTemplate
()
throws
Exception
{
...
@@ -574,7 +576,7 @@ public class InitService {
...
@@ -574,7 +576,7 @@ public class InitService {
ret
.
put
(
Skin
.
SKIN_DIR_NAME
,
skinDirName
);
ret
.
put
(
Skin
.
SKIN_DIR_NAME
,
skinDirName
);
final
String
skinName
=
Skin
s
.
getSkinName
(
skinDirName
);
final
String
skinName
=
Latke
s
.
getSkinName
(
skinDirName
);
ret
.
put
(
Skin
.
SKIN_NAME
,
skinName
);
ret
.
put
(
Skin
.
SKIN_NAME
,
skinName
);
...
@@ -586,7 +588,7 @@ public class InitService {
...
@@ -586,7 +588,7 @@ public class InitService {
skinArray
.
put
(
skin
);
skinArray
.
put
(
skin
);
final
String
name
=
Skin
s
.
getSkinName
(
dirName
);
final
String
name
=
Latke
s
.
getSkinName
(
dirName
);
skin
.
put
(
Skin
.
SKIN_NAME
,
name
);
skin
.
put
(
Skin
.
SKIN_NAME
,
name
);
skin
.
put
(
Skin
.
SKIN_DIR_NAME
,
dirName
);
skin
.
put
(
Skin
.
SKIN_DIR_NAME
,
dirName
);
...
@@ -594,15 +596,9 @@ public class InitService {
...
@@ -594,15 +596,9 @@ public class InitService {
ret
.
put
(
Skin
.
SKINS
,
skinArray
.
toString
());
ret
.
put
(
Skin
.
SKINS
,
skinArray
.
toString
());
try
{
final
ServletContext
servletContext
=
SoloServletListener
.
getServletContext
();
final
String
webRootPath
=
SoloServletListener
.
getWebRoot
();
final
String
skinPath
=
webRootPath
+
Skin
.
SKINS
+
"/"
+
skinDirName
;
Templates
.
MAIN_CFG
.
setDirectoryForTemplateLoading
(
new
File
(
skinPath
));
Templates
.
MAIN_CFG
.
setServletContextForTemplateLoading
(
servletContext
,
skinDirName
);
}
catch
(
final
IOException
e
)
{
LOGGER
.
log
(
Level
.
ERROR
,
"Loads skins error!"
,
e
);
throw
new
IllegalStateException
(
e
);
}
TimeZones
.
setTimeZone
(
INIT_TIME_ZONE_ID
);
TimeZones
.
setTimeZone
(
INIT_TIME_ZONE_ID
);
...
@@ -616,7 +612,7 @@ public class InitService {
...
@@ -616,7 +612,7 @@ public class InitService {
/**
/**
* Sets archive date article repository with the specified archive date article repository.
* Sets archive date article repository with the specified archive date article repository.
*
*
* @param archiveDateArticleRepository the specified archive date article repository
* @param archiveDateArticleRepository the specified archive date article repository
*/
*/
public
void
setArchiveDateArticleRepository
(
final
ArchiveDateArticleRepository
archiveDateArticleRepository
)
{
public
void
setArchiveDateArticleRepository
(
final
ArchiveDateArticleRepository
archiveDateArticleRepository
)
{
...
@@ -625,7 +621,7 @@ public class InitService {
...
@@ -625,7 +621,7 @@ public class InitService {
/**
/**
* Sets archive date repository with the specified archive date repository.
* Sets archive date repository with the specified archive date repository.
*
*
* @param archiveDateRepository the specified archive date repository
* @param archiveDateRepository the specified archive date repository
*/
*/
public
void
setArchiveDateRepository
(
final
ArchiveDateRepository
archiveDateRepository
)
{
public
void
setArchiveDateRepository
(
final
ArchiveDateRepository
archiveDateRepository
)
{
...
@@ -634,7 +630,7 @@ public class InitService {
...
@@ -634,7 +630,7 @@ public class InitService {
/**
/**
* Sets the article repository with the specified article repository.
* Sets the article repository with the specified article repository.
*
*
* @param articleRepository the specified article repository
* @param articleRepository the specified article repository
*/
*/
public
void
setArticleRepository
(
final
ArticleRepository
articleRepository
)
{
public
void
setArticleRepository
(
final
ArticleRepository
articleRepository
)
{
...
@@ -643,7 +639,7 @@ public class InitService {
...
@@ -643,7 +639,7 @@ public class InitService {
/**
/**
* Sets the user repository with the specified user repository.
* Sets the user repository with the specified user repository.
*
*
* @param userRepository the specified user repository
* @param userRepository the specified user repository
*/
*/
public
void
setUserRepository
(
final
UserRepository
userRepository
)
{
public
void
setUserRepository
(
final
UserRepository
userRepository
)
{
...
@@ -652,7 +648,7 @@ public class InitService {
...
@@ -652,7 +648,7 @@ public class InitService {
/**
/**
* Sets the preference repository with the specified preference repository.
* Sets the preference repository with the specified preference repository.
*
*
* @param preferenceRepository the specified preference repository
* @param preferenceRepository the specified preference repository
*/
*/
public
void
setPreferenceRepository
(
final
PreferenceRepository
preferenceRepository
)
{
public
void
setPreferenceRepository
(
final
PreferenceRepository
preferenceRepository
)
{
...
@@ -661,7 +657,7 @@ public class InitService {
...
@@ -661,7 +657,7 @@ public class InitService {
/**
/**
* Sets the statistic repository with the specified statistic repository.
* Sets the statistic repository with the specified statistic repository.
*
*
* @param statisticRepository the specified statistic repository
* @param statisticRepository the specified statistic repository
*/
*/
public
void
setStatisticRepository
(
final
StatisticRepository
statisticRepository
)
{
public
void
setStatisticRepository
(
final
StatisticRepository
statisticRepository
)
{
...
@@ -670,7 +666,7 @@ public class InitService {
...
@@ -670,7 +666,7 @@ public class InitService {
/**
/**
* Sets the tag repository with the specified tag repository.
* Sets the tag repository with the specified tag repository.
*
*
* @param tagRepository the specified tag repository
* @param tagRepository the specified tag repository
*/
*/
public
void
setTagRepository
(
final
TagRepository
tagRepository
)
{
public
void
setTagRepository
(
final
TagRepository
tagRepository
)
{
...
@@ -679,7 +675,7 @@ public class InitService {
...
@@ -679,7 +675,7 @@ public class InitService {
/**
/**
* Sets the tag article repository with the specified tag article repository.
* Sets the tag article repository with the specified tag article repository.
*
*
* @param tagArticleRepository the specified tag article repository
* @param tagArticleRepository the specified tag article repository
*/
*/
public
void
setTagArticleRepository
(
final
TagArticleRepository
tagArticleRepository
)
{
public
void
setTagArticleRepository
(
final
TagArticleRepository
tagArticleRepository
)
{
...
@@ -688,7 +684,7 @@ public class InitService {
...
@@ -688,7 +684,7 @@ public class InitService {
/**
/**
* Sets the comment repository with the specified comment repository.
* Sets the comment repository with the specified comment repository.
*
*
* @param commentRepository the specified comment repository
* @param commentRepository the specified comment repository
*/
*/
public
void
setCommentRepository
(
final
CommentRepository
commentRepository
)
{
public
void
setCommentRepository
(
final
CommentRepository
commentRepository
)
{
...
@@ -697,16 +693,16 @@ public class InitService {
...
@@ -697,16 +693,16 @@ public class InitService {
/**
/**
* Sets the language service with the specified language service.
* Sets the language service with the specified language service.
*
*
* @param langPropsService the specified language service
* @param langPropsService the specified language service
*/
*/
public
void
setLangPropsService
(
final
LangPropsService
langPropsService
)
{
public
void
setLangPropsService
(
final
LangPropsService
langPropsService
)
{
this
.
langPropsService
=
langPropsService
;
this
.
langPropsService
=
langPropsService
;
}
}
/**
/**
* Sets the plugin manager with the specified plugin manager.
* Sets the plugin manager with the specified plugin manager.
*
*
* @param pluginManager the specified plugin manager
* @param pluginManager the specified plugin manager
*/
*/
public
void
setPluginManager
(
final
PluginManager
pluginManager
)
{
public
void
setPluginManager
(
final
PluginManager
pluginManager
)
{
...
...
core/src/main/java/org/b3log/solo/service/PreferenceMgmtService.java
View file @
f498788d
...
@@ -16,20 +16,17 @@
...
@@ -16,20 +16,17 @@
package
org
.
b3log
.
solo
.
service
;
package
org
.
b3log
.
solo
.
service
;
import
java.io.IOException
;
import
org.b3log.latke.service.LangPropsService
;
import
org.b3log.latke.service.LangPropsService
;
import
org.b3log.solo.util.TimeZones
;
import
org.b3log.solo.util.TimeZones
;
import
org.b3log.solo.util.Skins
;
import
org.b3log.solo.util.Skins
;
import
org.json.JSONException
;
import
java.io.File
;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.Locale
;
import
java.util.Locale
;
import
java.util.Set
;
import
java.util.Set
;
import
javax.inject.Inject
;
import
javax.inject.Inject
;
import
javax.servlet.ServletContext
;
import
org.b3log.latke.Latkes
;
import
org.b3log.latke.Latkes
;
import
org.b3log.latke.logging.Level
;
import
org.b3log.latke.logging.Level
;
import
org.b3log.latke.logging.Logger
;
import
org.b3log.latke.logging.Logger
;
import
org.b3log.latke.repository.RepositoryException
;
import
org.b3log.latke.repository.Transaction
;
import
org.b3log.latke.repository.Transaction
;
import
org.b3log.latke.service.ServiceException
;
import
org.b3log.latke.service.ServiceException
;
import
org.b3log.latke.service.annotation.Service
;
import
org.b3log.latke.service.annotation.Service
;
...
@@ -48,7 +45,6 @@ import static org.b3log.solo.model.Skin.SKINS;
...
@@ -48,7 +45,6 @@ import static org.b3log.solo.model.Skin.SKINS;
import
static
org
.
b3log
.
solo
.
model
.
Skin
.
SKIN_DIR_NAME
;
import
static
org
.
b3log
.
solo
.
model
.
Skin
.
SKIN_DIR_NAME
;
import
static
org
.
b3log
.
solo
.
model
.
Skin
.
SKIN_NAME
;
import
static
org
.
b3log
.
solo
.
model
.
Skin
.
SKIN_NAME
;
import
static
org
.
b3log
.
solo
.
util
.
Skins
.
getSkinDirNames
;
import
static
org
.
b3log
.
solo
.
util
.
Skins
.
getSkinDirNames
;
import
static
org
.
b3log
.
solo
.
util
.
Skins
.
getSkinName
;
import
static
org
.
b3log
.
solo
.
util
.
Skins
.
setDirectoryForTemplateLoading
;
import
static
org
.
b3log
.
solo
.
util
.
Skins
.
setDirectoryForTemplateLoading
;
...
@@ -56,7 +52,7 @@ import static org.b3log.solo.util.Skins.setDirectoryForTemplateLoading;
...
@@ -56,7 +52,7 @@ import static org.b3log.solo.util.Skins.setDirectoryForTemplateLoading;
* Preference management service.
* Preference management service.
*
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.
0.7, Jul 18, 2013
* @version 1.0.
1.7, Apr 15, 2014
* @since 0.4.0
* @since 0.4.0
*/
*/
@Service
@Service
...
@@ -81,7 +77,7 @@ public class PreferenceMgmtService {
...
@@ -81,7 +77,7 @@ public class PreferenceMgmtService {
/**
/**
* Loads skins for the specified preference and initializes templates loading.
* Loads skins for the specified preference and initializes templates loading.
*
*
* <p>
* <p>
* If the skins directory has been changed, persists the change into preference.
* If the skins directory has been changed, persists the change into preference.
* </p>
* </p>
...
@@ -101,7 +97,7 @@ public class PreferenceMgmtService {
...
@@ -101,7 +97,7 @@ public class PreferenceMgmtService {
for
(
final
String
dirName
:
skinDirNames
)
{
for
(
final
String
dirName
:
skinDirNames
)
{
final
JSONObject
skin
=
new
JSONObject
();
final
JSONObject
skin
=
new
JSONObject
();
final
String
name
=
getSkinName
(
dirName
);
final
String
name
=
Latkes
.
getSkinName
(
dirName
);
if
(
null
==
name
)
{
if
(
null
==
name
)
{
LOGGER
.
log
(
Level
.
WARN
,
"The directory[{0}] does not contain any skin, ignored it"
,
dirName
);
LOGGER
.
log
(
Level
.
WARN
,
"The directory[{0}] does not contain any skin, ignored it"
,
dirName
);
...
@@ -159,7 +155,7 @@ public class PreferenceMgmtService {
...
@@ -159,7 +155,7 @@ public class PreferenceMgmtService {
/**
/**
* Updates the reply notification template with the specified reply notification template.
* Updates the reply notification template with the specified reply notification template.
*
*
* @param replyNotificationTemplate the specified reply notification template
* @param replyNotificationTemplate the specified reply notification template
* @throws ServiceException service exception
* @throws ServiceException service exception
*/
*/
...
@@ -201,7 +197,7 @@ public class PreferenceMgmtService {
...
@@ -201,7 +197,7 @@ public class PreferenceMgmtService {
try
{
try
{
final
String
skinDirName
=
preference
.
getString
(
Skin
.
SKIN_DIR_NAME
);
final
String
skinDirName
=
preference
.
getString
(
Skin
.
SKIN_DIR_NAME
);
final
String
skinName
=
Skin
s
.
getSkinName
(
skinDirName
);
final
String
skinName
=
Latke
s
.
getSkinName
(
skinDirName
);
preference
.
put
(
Skin
.
SKIN_NAME
,
skinName
);
preference
.
put
(
Skin
.
SKIN_NAME
,
skinName
);
final
Set
<
String
>
skinDirNames
=
Skins
.
getSkinDirNames
();
final
Set
<
String
>
skinDirNames
=
Skins
.
getSkinDirNames
();
...
@@ -212,15 +208,11 @@ public class PreferenceMgmtService {
...
@@ -212,15 +208,11 @@ public class PreferenceMgmtService {
skinArray
.
put
(
skin
);
skinArray
.
put
(
skin
);
final
String
name
=
Skin
s
.
getSkinName
(
dirName
);
final
String
name
=
Latke
s
.
getSkinName
(
dirName
);
skin
.
put
(
Skin
.
SKIN_NAME
,
name
);
skin
.
put
(
Skin
.
SKIN_NAME
,
name
);
skin
.
put
(
Skin
.
SKIN_DIR_NAME
,
dirName
);
skin
.
put
(
Skin
.
SKIN_DIR_NAME
,
dirName
);
}
}
final
String
webRootPath
=
SoloServletListener
.
getWebRoot
();
final
String
skinPath
=
webRootPath
+
Skin
.
SKINS
+
"/"
+
skinDirName
;
LOGGER
.
log
(
Level
.
DEBUG
,
"Skin path[{0}]"
,
skinPath
);
preference
.
put
(
Skin
.
SKINS
,
skinArray
.
toString
());
preference
.
put
(
Skin
.
SKINS
,
skinArray
.
toString
());
...
@@ -250,23 +242,14 @@ public class PreferenceMgmtService {
...
@@ -250,23 +242,14 @@ public class PreferenceMgmtService {
transaction
.
commit
();
transaction
.
commit
();
Templates
.
MAIN_CFG
.
setDirectoryForTemplateLoading
(
new
File
(
skinPath
));
final
ServletContext
servletContext
=
SoloServletListener
.
getServletContext
();
}
catch
(
final
JSONException
e
)
{
if
(
transaction
.
isActive
())
{
Templates
.
MAIN_CFG
.
setServletContextForTemplateLoading
(
servletContext
,
skinDirName
);
transaction
.
rollback
();
}
catch
(
final
Exception
e
)
{
}
LOGGER
.
log
(
Level
.
ERROR
,
"Updates preference failed"
,
e
);
throw
new
ServiceException
(
langPropsService
.
get
(
"updateFailLabel"
));
}
catch
(
final
RepositoryException
e
)
{
if
(
transaction
.
isActive
())
{
transaction
.
rollback
();
}
LOGGER
.
log
(
Level
.
ERROR
,
"Updates preference failed"
,
e
);
throw
new
ServiceException
(
langPropsService
.
get
(
"updateFailLabel"
));
}
catch
(
final
IOException
e
)
{
if
(
transaction
.
isActive
())
{
if
(
transaction
.
isActive
())
{
transaction
.
rollback
();
transaction
.
rollback
();
}
}
LOGGER
.
log
(
Level
.
ERROR
,
"Updates preference failed"
,
e
);
LOGGER
.
log
(
Level
.
ERROR
,
"Updates preference failed"
,
e
);
throw
new
ServiceException
(
langPropsService
.
get
(
"updateFailLabel"
));
throw
new
ServiceException
(
langPropsService
.
get
(
"updateFailLabel"
));
}
}
...
@@ -276,7 +259,7 @@ public class PreferenceMgmtService {
...
@@ -276,7 +259,7 @@ public class PreferenceMgmtService {
/**
/**
* Sets the preference repository with the specified preference repository.
* Sets the preference repository with the specified preference repository.
*
*
* @param preferenceRepository the specified preference repository
* @param preferenceRepository the specified preference repository
*/
*/
public
void
setPreferenceRepository
(
final
PreferenceRepository
preferenceRepository
)
{
public
void
setPreferenceRepository
(
final
PreferenceRepository
preferenceRepository
)
{
...
@@ -285,7 +268,7 @@ public class PreferenceMgmtService {
...
@@ -285,7 +268,7 @@ public class PreferenceMgmtService {
/**
/**
* Sets the language service with the specified language service.
* Sets the language service with the specified language service.
*
*
* @param langPropsService the specified language service
* @param langPropsService the specified language service
*/
*/
public
void
setLangPropsService
(
final
LangPropsService
langPropsService
)
{
public
void
setLangPropsService
(
final
LangPropsService
langPropsService
)
{
...
...
core/src/main/java/org/b3log/solo/util/Skins.java
View file @
f498788d
...
@@ -16,16 +16,14 @@
...
@@ -16,16 +16,14 @@
package
org
.
b3log
.
solo
.
util
;
package
org
.
b3log
.
solo
.
util
;
import
java.io.File
;
import
java.io.FileFilter
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Properties
;
import
java.util.Properties
;
import
java.util.Set
;
import
java.util.Set
;
import
org.b3log.latke.Keys
;
import
javax.servlet.ServletContext
;
import
org.b3log.latke.Latkes
;
import
org.b3log.latke.Latkes
;
import
org.b3log.latke.ioc.LatkeBeanManager
;
import
org.b3log.latke.ioc.LatkeBeanManager
;
import
org.b3log.latke.ioc.Lifecycle
;
import
org.b3log.latke.ioc.Lifecycle
;
...
@@ -38,14 +36,13 @@ import org.b3log.latke.util.Locales;
...
@@ -38,14 +36,13 @@ import org.b3log.latke.util.Locales;
import
org.b3log.latke.util.Stopwatchs
;
import
org.b3log.latke.util.Stopwatchs
;
import
org.b3log.latke.util.freemarker.Templates
;
import
org.b3log.latke.util.freemarker.Templates
;
import
org.b3log.solo.SoloServletListener
;
import
org.b3log.solo.SoloServletListener
;
import
static
org
.
b3log
.
solo
.
model
.
Skin
.*;
/**
/**
* Skin utilities.
* Skin utilities.
*
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.
2.6, Jun 12, 2012
* @version 1.0.
3.6, Apr 15, 2014
* @since 0.3.1
* @since 0.3.1
*/
*/
public
final
class
Skins
{
public
final
class
Skins
{
...
@@ -66,13 +63,13 @@ public final class Skins {
...
@@ -66,13 +63,13 @@ public final class Skins {
private
Skins
()
{}
private
Skins
()
{}
/**
/**
* Fills the specified data model with the current skink's (WebRoot/skins/${skinName}/lang/lang_xx_XX.properties) and
* Fills the specified data model with the current skink's (WebRoot/skins/${skinName}/lang/lang_xx_XX.properties) and
* core language (WebRoot/WEB-INF/classes/lang_xx_XX.properties) configurations.
* core language (WebRoot/WEB-INF/classes/lang_xx_XX.properties) configurations.
*
*
* @param localeString the specified locale string
* @param localeString the specified locale string
* @param currentSkinDirName the specified current skin directory name
* @param currentSkinDirName the specified current skin directory name
* @param dataModel the specified data model
* @param dataModel the specified data model
* @throws ServiceException service exception
* @throws ServiceException service exception
*/
*/
public
static
void
fillLangs
(
final
String
localeString
,
final
String
currentSkinDirName
,
final
Map
<
String
,
Object
>
dataModel
)
public
static
void
fillLangs
(
final
String
localeString
,
final
String
currentSkinDirName
,
final
Map
<
String
,
Object
>
dataModel
)
throws
ServiceException
{
throws
ServiceException
{
...
@@ -88,17 +85,16 @@ public final class Skins {
...
@@ -88,17 +85,16 @@ public final class Skins {
LOGGER
.
log
(
Level
.
INFO
,
"Loading skin [dirName={0}, locale={1}]"
,
new
Object
[]
{
currentSkinDirName
,
localeString
});
LOGGER
.
log
(
Level
.
INFO
,
"Loading skin [dirName={0}, locale={1}]"
,
new
Object
[]
{
currentSkinDirName
,
localeString
});
langs
=
new
HashMap
<
String
,
String
>();
langs
=
new
HashMap
<
String
,
String
>();
final
String
webRootPath
=
SoloServletListener
.
getWebRoot
();
final
String
language
=
Locales
.
getLanguage
(
localeString
);
final
String
language
=
Locales
.
getLanguage
(
localeString
);
final
String
country
=
Locales
.
getCountry
(
localeString
);
final
String
country
=
Locales
.
getCountry
(
localeString
);
final
ServletContext
servletContext
=
SoloServletListener
.
getServletContext
();
final
InputStream
inputStream
=
servletContext
.
getResourceAsStream
(
"/skins/"
+
currentSkinDirName
+
"/lang/lang_"
+
language
+
'_'
+
country
+
".properties"
);
final
Properties
props
=
new
Properties
();
final
Properties
props
=
new
Properties
();
props
.
load
(
props
.
load
(
inputStream
);
new
FileReader
(
webRootPath
+
"skins"
+
File
.
separator
+
currentSkinDirName
+
File
.
separator
+
Keys
.
LANGUAGE
+
File
.
separator
+
Keys
.
LANGUAGE
+
'_'
+
language
+
'_'
+
country
+
".properties"
));
final
Set
<
Object
>
keys
=
props
.
keySet
();
final
Set
<
Object
>
keys
=
props
.
keySet
();
for
(
final
Object
key
:
keys
)
{
for
(
final
Object
key
:
keys
)
{
...
@@ -111,7 +107,7 @@ public final class Skins {
...
@@ -111,7 +107,7 @@ public final class Skins {
}
}
dataModel
.
putAll
(
langs
);
// Fills the current skin's language configurations
dataModel
.
putAll
(
langs
);
// Fills the current skin's language configurations
// Fills the core language configurations
// Fills the core language configurations
final
LatkeBeanManager
beanManager
=
Lifecycle
.
getBeanManager
();
final
LatkeBeanManager
beanManager
=
Lifecycle
.
getBeanManager
();
final
LangPropsService
langPropsService
=
beanManager
.
getReference
(
LangPropsServiceImpl
.
class
);
final
LangPropsService
langPropsService
=
beanManager
.
getReference
(
LangPropsServiceImpl
.
class
);
...
@@ -128,109 +124,45 @@ public final class Skins {
...
@@ -128,109 +124,45 @@ public final class Skins {
/**
/**
* Sets the directory for template loading with the specified skin directory
* Sets the directory for template loading with the specified skin directory
* name, and sets the directory for mobile request template loading.
* name, and sets the directory for mobile request template loading.
*
*
* @param skinDirName the specified skin directory name
* @param skinDirName the specified skin directory name
*/
*/
public
static
void
setDirectoryForTemplateLoading
(
final
String
skinDirName
)
{
public
static
void
setDirectoryForTemplateLoading
(
final
String
skinDirName
)
{
try
{
final
ServletContext
servletContext
=
SoloServletListener
.
getServletContext
();
final
String
webRootPath
=
SoloServletListener
.
getWebRoot
();
final
String
skinPath
=
webRootPath
+
SKINS
+
File
.
separator
+
skinDirName
;
Templates
.
MAIN_CFG
.
setDirectoryForTemplateLoading
(
new
File
(
skinPath
));
Templates
.
MAIN_CFG
.
setServletContextForTemplateLoading
(
servletContext
,
"/skins/"
+
skinDirName
);
Templates
.
MOBILE_CFG
.
setServletContextForTemplateLoading
(
servletContext
,
"/skins/mobile"
);
Templates
.
MOBILE_CFG
.
setDirectoryForTemplateLoading
(
new
File
(
webRootPath
+
SKINS
+
File
.
separator
+
"mobile"
));
}
catch
(
final
IOException
e
)
{
LOGGER
.
log
(
Level
.
ERROR
,
"Loads skins error!"
,
e
);
throw
new
IllegalStateException
(
e
);
}
}
}
/**
/**
* Gets all skin directory names. Scans the
* Gets all skin directory names. Scans the /skins/ directory,
* {@linkplain SoloServletListener#getWebRoot() Web root}/skins/ directory,
* using the subdirectory of it as the skin directory name, for example,
* using the subdirectory of it as the skin directory name, for example,
* <pre>
* <pre>
* ${Web root}/skins/
* ${Web root}/skins/
* <b>default</b>/
* <b>default</b>/
* <b>mobile</b>/
* <b>mobile</b>/
* <b>classic</b>/
* <b>classic</b>/
* </pre>
* </pre>.
* Skips files that name starts with . and {@linkplain File#isHidden()
* hidden} files.
*
*
* @return a set of skin name, returns an empty set if not found
* @return a set of skin name, returns an empty set if not found
*/
*/
public
static
Set
<
String
>
getSkinDirNames
()
{
public
static
Set
<
String
>
getSkinDirNames
()
{
final
String
webRootPath
=
SoloServletListener
.
getWebRoot
();
final
ServletContext
servletContext
=
SoloServletListener
.
getServletContext
();
final
File
skins
=
new
File
(
webRootPath
+
"skins"
+
File
.
separator
);
final
File
[]
skinDirs
=
skins
.
listFiles
(
new
FileFilter
()
{
@Override
public
boolean
accept
(
final
File
file
)
{
return
file
.
isDirectory
()
&&
!
file
.
getName
().
startsWith
(
"."
);
}
});
final
Set
<
String
>
ret
=
new
HashSet
<
String
>();
final
Set
<
String
>
ret
=
new
HashSet
<
String
>();
if
(
null
==
skinDirs
)
{
@SuppressWarnings
(
"unchecked"
)
LOGGER
.
error
(
"Skin directory is null"
);
final
Set
<
String
>
resourcePaths
=
servletContext
.
getResourcePaths
(
"/skins"
);
return
ret
;
}
for
(
int
i
=
0
;
i
<
skinDirs
.
length
;
i
++)
{
for
(
final
String
path
:
resourcePaths
)
{
final
File
file
=
skinDirs
[
i
];
if
(
path
.
startsWith
(
"."
))
{
continue
;
}
ret
.
add
(
file
.
getName
(
));
ret
.
add
(
path
.
substring
(
"/skins"
.
length
()
+
1
,
path
.
length
()
-
1
));
}
}
return
ret
;
return
ret
;
}
}
/**
* Gets the skin name for the specified skin directory name. The skin name
* was configured in skin.properties file({@code name} as the key) under
* skin directory specified by the given skin directory name.
*
* @param skinDirName the given skin directory name
* @return skin name, returns {@code null} if not found or error occurs
* @see #getSkinDirNames()
*/
public
static
String
getSkinName
(
final
String
skinDirName
)
{
final
String
webRootPath
=
SoloServletListener
.
getWebRoot
();
final
File
skins
=
new
File
(
webRootPath
+
"skins"
+
File
.
separator
);
final
File
[]
skinDirs
=
skins
.
listFiles
(
new
FileFilter
()
{
@Override
public
boolean
accept
(
final
File
pathname
)
{
return
pathname
.
isDirectory
()
&&
pathname
.
getName
().
equals
(
skinDirName
)
?
true
:
false
;
}
});
if
(
null
==
skinDirs
)
{
LOGGER
.
error
(
"Skin directory is null"
);
return
null
;
}
if
(
1
!=
skinDirs
.
length
)
{
LOGGER
.
log
(
Level
.
ERROR
,
"Skin directory count[{0}]"
,
skinDirs
.
length
);
return
null
;
}
try
{
final
Properties
ret
=
new
Properties
();
final
String
skinPropsPath
=
skinDirs
[
0
].
getPath
()
+
File
.
separator
+
"skin.properties"
;
ret
.
load
(
new
FileReader
(
skinPropsPath
));
return
ret
.
getProperty
(
"name"
);
}
catch
(
final
Exception
e
)
{
LOGGER
.
log
(
Level
.
ERROR
,
"Read skin configuration error[msg={0}]"
,
e
.
getMessage
());
return
null
;
}
}
}
}
pom.xml
View file @
f498788d
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
<properties>
<properties>
<servlet.version>
2.5
</servlet.version>
<servlet.version>
2.5
</servlet.version>
<slf4j.version>
1.7.5
</slf4j.version>
<slf4j.version>
1.7.5
</slf4j.version>
<org.b3log.latke.version>
1.0.
8
</org.b3log.latke.version>
<org.b3log.latke.version>
1.0.
10-SNAPSHOT
</org.b3log.latke.version>
<maven-gae-plugin.version>
0.9.0
</maven-gae-plugin.version>
<maven-gae-plugin.version>
0.9.0
</maven-gae-plugin.version>
<gae.version>
1.8.1.1
</gae.version>
<gae.version>
1.8.1.1
</gae.version>
...
...
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