My favorites
▼
|
Sign in
jmesa
Table Rendering API
Project Home
Downloads
Wiki
Issues
Source
Export to GitHub
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
328
attachment: SpringThemePropertiesPreferences.java
(2.5 KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package org.jmesa.core.preference;
import static org.jmesa.util.AssertUtils.notNull;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.jmesa.web.HttpServletRequestSpringWebContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.NoSuchMessageException;
import org.springframework.web.servlet.support.RequestContext;
/**
* @author Nicola Caragnano
*/
public final class SpringThemePropertiesPreferences implements Preferences {
private final Logger logger = LoggerFactory.getLogger(SpringThemePropertiesPreferences.class);
private final RequestContext requestContext;
private static DefaultPropertiesLoader DEFAULT_PROPERTIES_HOLDER = new DefaultPropertiesLoader();
public SpringThemePropertiesPreferences(HttpServletRequestSpringWebContext webContext) {
notNull("The web context is required.", webContext);
requestContext = new RequestContext(webContext.getBackingObject());
}
@Override
public String getPreference(String code) {
String defaultProperty = DEFAULT_PROPERTIES_HOLDER.properties.getProperty(code);
String themeProperty = null;
try {
themeProperty = requestContext.getThemeMessage(code);
} catch(NoSuchMessageException ex) {
logger.warn(String.format("Property with code %s not found in theme properties", code));
}
logger.debug(String.format("Default property value for code %s is %s, theme property value is %s",
code, defaultProperty, themeProperty));
return themeProperty != null ? themeProperty : defaultProperty;
}
private static class DefaultPropertiesLoader {
private static final String JMESA_PROPERTIES = "jmesa.properties";
private static final Logger logger = LoggerFactory.getLogger(SpringThemePropertiesPreferences.class);
private Properties properties = new Properties();
public DefaultPropertiesLoader() {
try {
InputStream resourceAsStream = this.getClass().getResourceAsStream(JMESA_PROPERTIES);
try {
properties.load(resourceAsStream);
} finally {
try {
resourceAsStream.close();
} catch (IOException e) {
logger.error("Could not close the JMesa default preferences.", e);
}
}
} catch (IOException e) {
logger.error("Could not load the JMesa preferences.", e);
}
}
}
}
Powered by
Google Project Hosting