aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/pdfas/web/i18n
diff options
context:
space:
mode:
authortknall <tknall@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2009-01-14 11:39:31 +0000
committertknall <tknall@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2009-01-14 11:39:31 +0000
commit95f6c6fe321d33dc8fa9e18c7d96bd9b21ef10cc (patch)
tree98faaac7ffd2a5f11130c1412a6d2b96fa45f09d /src/main/java/at/gv/egiz/pdfas/web/i18n
parent392c2cd13d0fcd24bce22987f454e529637307fc (diff)
downloadpdf-as-3-95f6c6fe321d33dc8fa9e18c7d96bd9b21ef10cc.tar.gz
pdf-as-3-95f6c6fe321d33dc8fa9e18c7d96bd9b21ef10cc.tar.bz2
pdf-as-3-95f6c6fe321d33dc8fa9e18c7d96bd9b21ef10cc.zip
Switching to itext-2.1.5-rev3628.
itext library: minor adjustments for pdf-as Adding new error code (103) for invalid pdfa/1b font configuration. Minor updates for PDF/A support. Support for local MOCCA CCS added. Multi language for web application. Encoding issue for web application fixed by implementing an EncodingFilter. Dynamic sign upload form implemented. Order of input fields for dynamic upload form changed. MOCCA logo added to sign upload form. git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@319 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src/main/java/at/gv/egiz/pdfas/web/i18n')
-rw-r--r--src/main/java/at/gv/egiz/pdfas/web/i18n/LanguageDecoratorMapper.java64
-rw-r--r--src/main/java/at/gv/egiz/pdfas/web/i18n/LocaleParamFilter.java96
-rw-r--r--src/main/java/at/gv/egiz/pdfas/web/i18n/SetLanguageServlet.java59
3 files changed, 135 insertions, 84 deletions
diff --git a/src/main/java/at/gv/egiz/pdfas/web/i18n/LanguageDecoratorMapper.java b/src/main/java/at/gv/egiz/pdfas/web/i18n/LanguageDecoratorMapper.java
index 1db7e3b..c610e42 100644
--- a/src/main/java/at/gv/egiz/pdfas/web/i18n/LanguageDecoratorMapper.java
+++ b/src/main/java/at/gv/egiz/pdfas/web/i18n/LanguageDecoratorMapper.java
@@ -18,9 +18,10 @@ import com.opensymphony.module.sitemesh.mapper.DefaultDecorator;
public class LanguageDecoratorMapper extends AbstractDecoratorMapper {
- public static final String LOCALE_SESSION_KEY = "at.gv.egiz.pdfas.web.i18n:currentLocale";
- private Logger log = Logger.getLogger(LanguageDecoratorMapper.class);
+ private String decoratorParameter = null;
+
+ private static final Logger LOG = Logger.getLogger(LanguageDecoratorMapper.class);
public void init(Config config, Properties properties, DecoratorMapper parent) throws InstantiationException {
super.init(config, properties, parent);
@@ -37,29 +38,42 @@ public class LanguageDecoratorMapper extends AbstractDecoratorMapper {
}
return null;
}
+
+ public static Locale getLocale(HttpServletRequest request, String decoratorParameter) {
+ Locale locale = null;
+ HttpSession session = request.getSession();
+
+ LOG.trace("Looking for locale in session (ID=" + session.getId() + ").");
+ locale = (Locale) session.getAttribute(LocaleParamFilter.LOCALE_SESSION_KEY);
+ if (locale == null) {
+ LOG.debug("Unable to find locale in session. Trying to create new locale based on Accept-Language header entry.");
+ String acceptLanguage = request.getHeader("Accept-Language");
+ if (acceptLanguage != null) {
+ LOG.trace("Accept-Language header entry: " + acceptLanguage);
+ } else {
+ LOG.trace("No header entry found.");
+ }
+ if (acceptLanguage != null && acceptLanguage.length() >= 2) {
+ locale = new Locale(acceptLanguage.substring(0, 2));
+ LOG.debug("New Locale created: " + locale);
+ LOG.trace("Setting language to " + locale.getDisplayLanguage() + ".");
+ session.setAttribute(LocaleParamFilter.LOCALE_SESSION_KEY, locale);
+ }
+ } else {
+ LOG.debug("Locale found: " + locale);
+ }
+
+ return locale;
+ }
public Decorator getDecorator(HttpServletRequest request, Page page) {
+ LOG.trace("SiteMesh language resource decorator mapper invoked.");
+
try {
Decorator result = null;
final Decorator d = super.getDecorator(request, page);
- HttpSession session = request.getSession();
- log.trace("Looking for Locale in session.");
- Locale locale = (Locale) session.getAttribute(LOCALE_SESSION_KEY);
- if (locale == null) {
- log.debug("Unable to find Locale in session. Creating new Locale based on Accept-Language header entry.");
- String acceptLanguage = request.getHeader("Accept-Language");
- if (acceptLanguage != null) {
- log.trace("Accept-Language header entry: " + acceptLanguage);
- } else {
- log.trace("No header entry found.");
- }
- if (acceptLanguage != null && acceptLanguage.length() >= 2) {
- locale = new Locale(acceptLanguage.substring(0, 2));
- log.debug("New Locale created: " + locale);
- }
- } else {
- log.debug("Locale found: " + locale);
- }
+ Locale locale = getLocale(request, this.decoratorParameter);
+
String path;
if (locale != null) {
path = modifyPath(d.getPage(), locale.getLanguage());
@@ -69,7 +83,7 @@ public class LanguageDecoratorMapper extends AbstractDecoratorMapper {
File decFile = new File(config.getServletContext().getRealPath(path));
- log.debug("Looking for decorator \"" + path + "\".");
+ LOG.debug("Looking for decorator \"" + path + "\".");
if (decFile.isFile()) {
result = new DefaultDecorator(d.getName(), path, null) {
public String getInitParameter(String paramName) {
@@ -79,15 +93,15 @@ public class LanguageDecoratorMapper extends AbstractDecoratorMapper {
}
if (result != null) {
- log.debug("Decorator found (\"" + result.getName() + "\", \"" + getFirstNotNull(new Object[] { result.getURIPath(), result.getPage(), "<n/a>"}) + "\").");
+ LOG.debug("Decorator found (\"" + result.getName() + "\", \"" + getFirstNotNull(new Object[] { result.getURIPath(), result.getPage(), "<n/a>"}) + "\").");
return result;
} else {
- log.trace("No decorator found. Delegating to super class.");
+ LOG.trace("No decorator found. Delegating to super class.");
result = super.getDecorator(request, page);
if (result != null) {
- log.debug("Super class returned decorator (\"" + result.getName() + "\", \"" + getFirstNotNull(new Object[] { result.getURIPath(), result.getPage(), "<n/a>"}) + "\").");
+ LOG.debug("Super class returned decorator (\"" + result.getName() + "\", \"" + getFirstNotNull(new Object[] { result.getURIPath(), result.getPage(), "<n/a>"}) + "\").");
} else {
- log.trace("Super class did not return a decorator.");
+ LOG.trace("Super class did not return a decorator.");
}
return result;
}
diff --git a/src/main/java/at/gv/egiz/pdfas/web/i18n/LocaleParamFilter.java b/src/main/java/at/gv/egiz/pdfas/web/i18n/LocaleParamFilter.java
new file mode 100644
index 0000000..598b23b
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/web/i18n/LocaleParamFilter.java
@@ -0,0 +1,96 @@
+package at.gv.egiz.pdfas.web.i18n;
+
+import java.io.IOException;
+import java.util.Locale;
+import java.util.StringTokenizer;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+import org.apache.commons.lang.LocaleUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
+
+public class LocaleParamFilter implements Filter {
+
+ private static final Logger LOG = Logger.getLogger(LocaleParamFilter.class);
+ public static final String LOCALE_SESSION_KEY = "at.gv.egiz.pdfas.web.i18n:currentLocale";
+ public static final String LOCALE_PARAM_KEY = "locale";
+
+ public void destroy() {
+ }
+
+ public static String normalizeLocaleString(String localeString) {
+ if (localeString == null) {
+ return null;
+ }
+ int jsessionIdIndex = localeString.toLowerCase().indexOf(";jsessionid");
+ if (jsessionIdIndex != -1) {
+ localeString = localeString.substring(0, jsessionIdIndex);
+ }
+ StringTokenizer tokenizer = new StringTokenizer(localeString, "_", false);
+ StringBuffer buffer = new StringBuffer();
+ int index = 0;
+ while (tokenizer.hasMoreTokens()) {
+ String token = tokenizer.nextToken();
+ switch (++index) {
+ case 1:
+ buffer.append(token.toLowerCase());
+ break;
+ case 2:
+ buffer.append(token.toUpperCase());
+ break;
+ default:
+ buffer.append(token);
+ break;
+ }
+ if (tokenizer.hasMoreTokens()) {
+ buffer.append("_");
+ }
+ }
+ return buffer.toString();
+ }
+
+ public static Locale getLocale(HttpServletRequest request) {
+ Locale locale = null;
+ HttpSession session = request.getSession();
+
+ LOG.trace("Looking for locale parameter \"" + LOCALE_PARAM_KEY + "\".");
+ String language = request.getParameter(LOCALE_PARAM_KEY);
+ if (!StringUtils.isEmpty(language)) {
+ LOG.debug("Locale parameter \"" + language + "\" found.");
+ String code = normalizeLocaleString(language.trim());
+ LOG.debug("Normalizing locale -> " + code);
+ try {
+ locale = LocaleUtils.toLocale(code);
+ LOG.info("Setting locale flag in session (ID=" + session.getId() + ") to \"" + locale.toString() + "\".");
+ session.setAttribute(LOCALE_SESSION_KEY, locale);
+ } catch (IllegalArgumentException e) {
+ LOG.error("Locale \"" + code + "\" is not valid. Flag will not be set.");
+ }
+ } else {
+ LOG.trace("No locale parameter found.");
+ }
+
+ return locale;
+ }
+
+ public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
+ HttpServletRequest request = (HttpServletRequest) servletRequest;
+
+ LOG.trace("LocaleParamFilter invoked.");
+ getLocale(request);
+
+ filterChain.doFilter(servletRequest, servletResponse);
+ }
+
+ public void init(FilterConfig filterConfig) throws ServletException {
+ }
+
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/web/i18n/SetLanguageServlet.java b/src/main/java/at/gv/egiz/pdfas/web/i18n/SetLanguageServlet.java
deleted file mode 100644
index 582f765..0000000
--- a/src/main/java/at/gv/egiz/pdfas/web/i18n/SetLanguageServlet.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package at.gv.egiz.pdfas.web.i18n;
-
-import java.io.IOException;
-import java.util.Locale;
-
-import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
-
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.commons.lang.StringUtils;
-import org.apache.log4j.Logger;
-
-public class SetLanguageServlet extends HttpServlet {
-
- private static final long serialVersionUID = 1L;
-
- public static final String LANGUAGE_PARAMETER = "code";
- private Logger log = Logger.getLogger(LanguageDecoratorMapper.class);
-
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- this.doPost(request, response);
- }
-
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-
- HttpSession session = request.getSession();
-
- // check manual language override (should be two-letter ISO-639 code)
- Locale currentManualSetLanguage = (Locale) session.getAttribute(LanguageDecoratorMapper.LOCALE_SESSION_KEY);
- String language = request.getParameter(LANGUAGE_PARAMETER);
- if (!StringUtils.isEmpty(language)) {
- String code = language.trim().toLowerCase();
- if (!ArrayUtils.contains(Locale.getISOLanguages(), code)) {
- log.error("Manually set language code \"" + code + "\" is not a valid ISO 639 language. Do not switch language.");
- } else {
- currentManualSetLanguage = new Locale(code);
- log.info("Switching language to " + currentManualSetLanguage.getDisplayLanguage() + ".");
- session.setAttribute(LanguageDecoratorMapper.LOCALE_SESSION_KEY, currentManualSetLanguage);
- }
- }
-
-// if (currentManualSetLanguage != null) {
-// log.info("Forcing language " + currentManualSetLanguage.getDisplayLanguage() + ".");
-// super.getServletContext().setAttribute(LanguageDecoratorMapper.LOCALE_SESSION_KEY, currentManualSetLanguage);
-// }
-
-// response.sendRedirect(response.encodeRedirectURL(request.getContextPath() + "/"));
- RequestDispatcher rd = request.getRequestDispatcher("/");
- rd.forward(request, response);
-
- }
-
-
-
-}