Commit f498788d authored by Liang Ding's avatar Liang Ding

#11755

需要拉 latke 1.0.10-SNAPSHOT 进行构建,latke 1.0.10 预计本周五发布
parent 1caf8219
...@@ -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
......
...@@ -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
...@@ -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 {
...@@ -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 {
...@@ -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 {
...@@ -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 = Skins.getSkinName(skinDirName); final String skinName = Latkes.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 = Skins.getSkinName(dirName); final String name = Latkes.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);
......
...@@ -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
...@@ -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);
...@@ -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 = Skins.getSkinName(skinDirName); final String skinName = Latkes.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 = Skins.getSkinName(dirName); final String name = Latkes.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"));
} }
......
...@@ -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 {
...@@ -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) {
...@@ -132,105 +128,41 @@ public final class Skins { ...@@ -132,105 +128,41 @@ public final class Skins {
* @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.MOBILE_CFG.setDirectoryForTemplateLoading(new File(webRootPath + SKINS + File.separator + "mobile")); Templates.MAIN_CFG.setServletContextForTemplateLoading(servletContext, "/skins/" + skinDirName);
} catch (final IOException e) { Templates.MOBILE_CFG.setServletContextForTemplateLoading(servletContext, "/skins/mobile");
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 (final String path : resourcePaths) {
if (path.startsWith(".")) {
continue;
} }
for (int i = 0; i < skinDirs.length; i++) { ret.add(path.substring("/skins".length() + 1, path.length() - 1));
final File file = skinDirs[i];
ret.add(file.getName());
} }
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;
}
}
} }
...@@ -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>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment