Skip to content

Commit e3838d7

Browse files
committed
JFinal 1.1.4 Release
1 parent a10db08 commit e3838d7

22 files changed

+275
-83
lines changed

src/com/jfinal/config/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public void setMainRenderFactory(IMainRenderFactory mainRenderFactory) {
284284
throw new IllegalArgumentException("mainRenderFactory can not be null.");
285285

286286
this.viewType = ViewType.OTHER;
287-
RenderFactory.setmainRenderFactory(mainRenderFactory);
287+
RenderFactory.setMainRenderFactory(mainRenderFactory);
288288
}
289289
}
290290

src/com/jfinal/config/Interceptors.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ final public class Interceptors {
2727

2828
private final List<Interceptor> interceptorList = new ArrayList<Interceptor>();
2929

30-
public Interceptors add(Interceptor defaultInterceptor) {
31-
if (defaultInterceptor != null)
32-
this.interceptorList.add(defaultInterceptor);
30+
public Interceptors add(Interceptor globalInterceptor) {
31+
if (globalInterceptor != null)
32+
this.interceptorList.add(globalInterceptor);
3333
return this;
3434
}
3535

src/com/jfinal/core/Config.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.jfinal.config.Plugins;
2424
import com.jfinal.config.Handlers;
2525
import com.jfinal.config.Interceptors;
26+
import com.jfinal.log.Logger;
2627
import com.jfinal.plugin.IPlugin;
2728

2829
class Config {
@@ -32,6 +33,7 @@ class Config {
3233
private static final Plugins plugins = new Plugins();
3334
private static final Interceptors interceptors = new Interceptors();
3435
private static final Handlers handlers = new Handlers();
36+
private static Logger log;
3537

3638
// prevent new Config();
3739
private Config() {
@@ -41,7 +43,7 @@ private Config() {
4143
* Config order: constant, route, plugin, interceptor, handler
4244
*/
4345
static void configJFinal(JFinalConfig jfinalConfig) {
44-
jfinalConfig.configConstant(constants);
46+
jfinalConfig.configConstant(constants); initLoggerFactory();
4547
jfinalConfig.configRoute(routes);
4648
jfinalConfig.configPlugin(plugins); startPlugins(); // very important!!!
4749
jfinalConfig.configInterceptor(interceptors);
@@ -75,15 +77,20 @@ private static void startPlugins() {
7577
try {
7678
boolean success = plugin.start();
7779
if (!success) {
78-
System.err.println("Plugin start error: " + plugin.getClass().getName());
80+
log.error("Plugin start error: " + plugin.getClass().getName());
7981
throw new RuntimeException("Plugin start error: " + plugin.getClass().getName());
8082
}
8183
}
8284
catch (Exception e) {
83-
System.err.println("Plugin start error: " + plugin.getClass().getName());
85+
log.error("Plugin start error: " + plugin.getClass().getName(), e);
8486
throw new RuntimeException("Plugin start error: " + plugin.getClass().getName(), e);
8587
}
8688
}
8789
}
8890
}
91+
92+
private static void initLoggerFactory() {
93+
log = Logger.getLogger(Config.class);
94+
JFinalFilter.initLogger();
95+
}
8996
}

src/com/jfinal/core/Const.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
*/
2525
public interface Const {
2626

27-
String JFINAL_VERSION = "1.1.3";
27+
String JFINAL_VERSION = "1.1.4";
2828

2929
ViewType DEFAULT_VIEW_TYPE = ViewType.FREE_MARKER;
3030

3131
String DEFAULT_ENCODING = "utf-8";
3232

33-
String DEFAULT_URL_PARA_SEPARATOR = "-"; // before 1.1.2 is "_";
33+
String DEFAULT_URL_PARA_SEPARATOR = "-";
3434

3535
String DEFAULT_FILE_CONTENT_TYPE = "application/octet-stream";
3636

src/com/jfinal/core/Controller.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ public String getPara(String name) {
110110
}
111111

112112
/**
113-
* Returns the value of a request parameter as a String, or null if the parameter does not exist.
113+
* Returns the value of a request parameter as a String, or default value if the parameter does not exist.
114114
* @param name a String specifying the name of the parameter
115115
* @param defaultValue a String value be returned when the value of parameter is null
116116
* @return a String representing the single value of the parameter
117117
*/
118118
public String getPara(String name, String defaultValue) {
119119
String result = request.getParameter(name);
120-
return result != null ? result : defaultValue;
120+
return result != null && !"".equals(result) ? result : defaultValue;
121121
}
122122

123123
/**

src/com/jfinal/core/JFinal.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,12 @@ boolean init(JFinalConfig jfinalConfig, ServletContext servletContext) {
6262

6363
initPathUtil();
6464

65-
Config.configJFinal(jfinalConfig);
65+
Config.configJFinal(jfinalConfig); // start plugin and init logger factory in this method
6666
constants = Config.getConstants();
6767

6868
initActionMapping();
6969
initHandler();
7070
initRender();
71-
initLoggerFactory();
7271
initActiveRecord();
7372
initOreillyCos();
7473
initI18n();
@@ -125,10 +124,6 @@ private void initRender() {
125124
renderFactory.init(constants, servletContext);
126125
}
127126

128-
private void initLoggerFactory() {
129-
JFinalFilter.initLogger();
130-
}
131-
132127
private void initActionMapping() {
133128
actionMapping = new ActionMapping(Config.getRoutes(), Config.getInterceptors());
134129
actionMapping.buildActionMapping();

src/com/jfinal/ext/handler/ContextPathHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* Provide a context path to view if you need.
2626
* <br>
2727
* Example:<br>
28-
* In JFinalFilter: handlers.add(new ContextPathHandler("BASE_PATH"));<br>
28+
* In JFinalFilter: handlers.add(new ContextPathHandler("CONTEXT_PATH"));<br>
2929
* in freemarker: <img src="${BASE_PATH}/images/logo.png" />
3030
*/
3131
public class ContextPathHandler extends Handler {

src/com/jfinal/ext/interceptor/SessionInViewInterceptor.java

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package com.jfinal.ext.interceptor;
1818

1919
import java.util.Enumeration;
20+
import java.util.HashMap;
21+
import java.util.Map;
2022
import javax.servlet.ServletContext;
2123
import javax.servlet.http.HttpSession;
2224
import com.jfinal.aop.Interceptor;
@@ -28,35 +30,43 @@
2830
*/
2931
public class SessionInViewInterceptor implements Interceptor {
3032

33+
private boolean createSession = false;
34+
35+
public SessionInViewInterceptor() {
36+
}
37+
38+
public SessionInViewInterceptor(boolean createSession) {
39+
this.createSession = createSession;
40+
}
41+
42+
@SuppressWarnings({"rawtypes", "unchecked"})
3143
public void intercept(ActionInvocation ai) {
3244
ai.invoke();
3345

3446
Controller c = ai.getController();
35-
HttpSession hs = c.getSession(false);
47+
HttpSession hs = c.getSession(createSession);
3648
if (hs != null) {
37-
c.setAttr("session", new JFinalSession(hs));
49+
Map session = new JFinalSession(hs);
50+
for (Enumeration<String> names=hs.getAttributeNames(); names.hasMoreElements();) {
51+
String name = names.nextElement();
52+
session.put(name, hs.getAttribute(name));
53+
}
54+
c.setAttr("session", session);
3855
}
3956
}
4057
}
4158

42-
@SuppressWarnings({"deprecation", "rawtypes"})
43-
class JFinalSession implements HttpSession {
44-
45-
/**
46-
* Added by JFinal for FreeMarker and Beetl.
47-
*/
48-
public Object get(String key) {
49-
return s.getAttribute(key);
50-
}
59+
@SuppressWarnings({"deprecation", "serial", "rawtypes"})
60+
class JFinalSession extends HashMap implements HttpSession {
5161

5262
private HttpSession s;
5363

5464
public JFinalSession(HttpSession session) {
5565
this.s = session;
5666
}
5767

58-
public Object getAttribute(String arg0) {
59-
return s.getAttribute(arg0);
68+
public Object getAttribute(String key) {
69+
return s.getAttribute(key);
6070
}
6171

6272
public Enumeration getAttributeNames() {
@@ -87,8 +97,8 @@ public javax.servlet.http.HttpSessionContext getSessionContext() {
8797
return s.getSessionContext();
8898
}
8999

90-
public Object getValue(String arg0) {
91-
return s.getValue(arg0);
100+
public Object getValue(String key) {
101+
return s.getValue(key);
92102
}
93103

94104
public String[] getValueNames() {
@@ -103,40 +113,35 @@ public boolean isNew() {
103113
return s.isNew();
104114
}
105115

106-
public void putValue(String arg0, Object arg1) {
107-
s.putValue(arg0, arg1);
116+
public void putValue(String key, Object value) {
117+
s.putValue(key, value);
108118
}
109119

110-
public void removeAttribute(String arg0) {
111-
s.removeAttribute(arg0);
120+
public void removeAttribute(String key) {
121+
s.removeAttribute(key);
112122
}
113123

114-
public void removeValue(String arg0) {
115-
s.removeValue(arg0);
124+
public void removeValue(String key) {
125+
s.removeValue(key);
116126
}
117127

118-
public void setAttribute(String arg0, Object arg1) {
119-
s.setAttribute(arg0, arg1);
128+
public void setAttribute(String key, Object value) {
129+
s.setAttribute(key, value);
120130
}
121131

122-
public void setMaxInactiveInterval(int arg0) {
123-
s.setMaxInactiveInterval(arg0);
132+
public void setMaxInactiveInterval(int maxInactiveInterval) {
133+
s.setMaxInactiveInterval(maxInactiveInterval);
124134
}
125135
}
126136

127-
//@SuppressWarnings({"rawtypes", "unchecked"})
128-
//public void intercept(ActionInvocation ai) {
129-
// ai.invoke();
130-
//
131-
// Controller c = ai.getController();
132-
// HttpSession hs = c.getSession(false);
133-
// if (hs != null) {
134-
// Map session = new HashMap();
135-
// for (Enumeration<String> names=hs.getAttributeNames(); names.hasMoreElements();) {
136-
// String name = names.nextElement();
137-
// session.put(name, hs.getAttribute(name));
138-
// }
139-
// c.setAttr("session", session);
140-
// }
141-
//}
142-
137+
/*
138+
public void intercept(ActionInvocation ai) {
139+
ai.invoke();
140+
141+
Controller c = ai.getController();
142+
HttpSession hs = c.getSession(createSession);
143+
if (hs != null) {
144+
c.setAttr("session", new JFinalSession(hs));
145+
}
146+
}
147+
*/

src/com/jfinal/util/SessionIdGenerator.java renamed to src/com/jfinal/ext/util/SessionIdGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.jfinal.util;
17+
package com.jfinal.ext.util;
1818

1919
import java.security.SecureRandom;
2020
import java.util.Random;

src/com/jfinal/i18n/I18N.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ private I18N() {
5252
}
5353

5454
public static I18N me() {
55-
if (me == null) {
55+
if (me == null)
5656
synchronized (I18N.class) {
57-
me = new I18N();
57+
if (me == null)
58+
me = new I18N();
5859
}
59-
}
6060
return me;
6161
}
6262

src/com/jfinal/plugin/activerecord/ActiveRecordPlugin.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
*/
3232
public class ActiveRecordPlugin implements IPlugin {
3333

34+
private static boolean isStarted = false;
3435
private static DataSource dataSource;
3536
private static IDataSourceProvider dataSourceProvider;
3637
private static final List<TableInfo> tableMappings = new ArrayList<TableInfo>();
@@ -56,6 +57,11 @@ public ActiveRecordPlugin setShowSql(boolean showSql) {
5657
return this;
5758
}
5859

60+
public ActiveRecordPlugin setMapFactory(IMapFactory mapFactory) {
61+
DbKit.setMapFactory(mapFactory);
62+
return this;
63+
}
64+
5965
public ActiveRecordPlugin(IDataSourceProvider dataSourceProvider) {
6066
ActiveRecordPlugin.dataSourceProvider = dataSourceProvider;
6167
}
@@ -85,20 +91,23 @@ public ActiveRecordPlugin addMapping(String tableName, Class<? extends Model<?>>
8591
}
8692

8793
public boolean start() {
88-
if (dataSourceProvider != null) {
94+
if (isStarted)
95+
return true;
96+
97+
if (dataSourceProvider != null)
8998
dataSource = dataSourceProvider.getDataSource();
90-
}
9199

92-
if (dataSource == null){
100+
if (dataSource == null)
93101
throw new RuntimeException("ActiveRecord start error: ActiveRecordPlugin need DataSource or DataSourceProvider");
94-
}
95102

96103
DbKit.setDataSource(dataSource);
97104

105+
isStarted = true;
98106
return TableInfoBuilder.buildTableInfo(tableMappings);
99107
}
100108

101109
public boolean stop() {
110+
isStarted = false;
102111
return true;
103112
}
104113
}

0 commit comments

Comments
 (0)