[sword-svn] r1755 - in trunk/bindings/corba/java/src/org/crosswire: . web web/i18n

dglassey at crosswire.org dglassey at crosswire.org
Fri Mar 25 12:58:04 MST 2005


Author: dglassey
Date: 2005-03-25 12:58:03 -0700 (Fri, 25 Mar 2005)
New Revision: 1755

Added:
   trunk/bindings/corba/java/src/org/crosswire/web/
   trunk/bindings/corba/java/src/org/crosswire/web/i18n/
   trunk/bindings/corba/java/src/org/crosswire/web/i18n/ContextStart.java.notyet
   trunk/bindings/corba/java/src/org/crosswire/web/i18n/TranslateTag.java
Log:


Added: trunk/bindings/corba/java/src/org/crosswire/web/i18n/ContextStart.java.notyet
===================================================================
--- trunk/bindings/corba/java/src/org/crosswire/web/i18n/ContextStart.java.notyet	2005-03-22 16:39:55 UTC (rev 1754)
+++ trunk/bindings/corba/java/src/org/crosswire/web/i18n/ContextStart.java.notyet	2005-03-25 19:58:03 UTC (rev 1755)
@@ -0,0 +1,10 @@
+package org.crosswire.web.i18n;
+
+import javax.servlet.jsp.tagext.*;
+
+public class ContextStart extends TagSupport {
+
+	public ContextStart() {
+	}
+
+}

Added: trunk/bindings/corba/java/src/org/crosswire/web/i18n/TranslateTag.java
===================================================================
--- trunk/bindings/corba/java/src/org/crosswire/web/i18n/TranslateTag.java	2005-03-22 16:39:55 UTC (rev 1754)
+++ trunk/bindings/corba/java/src/org/crosswire/web/i18n/TranslateTag.java	2005-03-25 19:58:03 UTC (rev 1755)
@@ -0,0 +1,87 @@
+package org.crosswire.web.i18n;
+
+import javax.servlet.jsp.tagext.BodyTagSupport;
+import javax.servlet.jsp.tagext.BodyContent;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.JspTagException;
+//import javax.servlet.jsp.JspWriter;
+import javax.servlet.http.HttpSession;
+//import java.util.HashMap;
+//import java.io.StringWriter;
+import java.util.Locale;
+import java.util.ResourceBundle;
+import java.util.MissingResourceException;
+import java.util.Properties;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+
+
+public class TranslateTag extends BodyTagSupport {
+	
+	private String _key=null;
+	private ResourceBundle _bundle=null;
+	private String _lang=null;
+
+	/* Uses code from GNU gettext for translation */
+	/* which is covered by the LGPL */
+	public String doTranslate(ResourceBundle catalog, String msgid) throws JspTagException {
+		String hashkey = "" + msgid.hashCode();
+		try {
+			if (catalog != null) {
+				String result = (String)catalog.getObject(hashkey);
+				if (result != null)
+					return result;
+			}
+		} catch (MissingResourceException e) {
+			// want to add the msgid to the properties file
+			Properties props = new Properties();
+			
+			try {
+				FileInputStream tbtin = new FileInputStream(pageContext.getServletContext().getRealPath("/WEB-INF/classes/tbt.properties"));
+				props.load(tbtin);
+				tbtin.close();
+				
+				props.put(hashkey, msgid);
+
+				FileOutputStream tbtout = new FileOutputStream(pageContext.getServletContext().getRealPath("/WEB-INF/classes/tbt.properties"));
+				props.store(tbtout, null);
+				tbtout.close();
+
+			}
+			catch(java.io.IOException e2)
+			{
+				throw new JspTagException("IO Error: " + e2.getMessage());
+			}
+			
+		}
+		return msgid;
+	}
+
+	public int doAfterBody() throws JspTagException {
+		BodyContent bc = getBodyContent();
+		_key = bc.getString();
+		HttpSession session = pageContext.getSession();
+		Locale locale = (Locale) session.getAttribute("TranslateLocale");
+		
+		if ((_bundle == null) || (_lang != locale.toString())) {
+			_lang = locale.toString();
+			_bundle = ResourceBundle.getBundle("tbt", locale);
+		}
+		
+		return 0;
+	}
+
+	public int doEndTag() throws JspException {
+		try
+		{
+			pageContext.getOut().write(doTranslate(_bundle, _key));
+		}
+		catch(java.io.IOException e)
+		{
+			throw new JspTagException("IO Error: " + e.getMessage());
+		}
+		return EVAL_PAGE;
+	}
+
+
+}



More information about the sword-cvs mailing list