[MMBASE CVS] src/org/mmbase/util LocalizedString.java

2009-04-30 Thread Michiel Meeuwissen
Update of /var/cvs/src/org/mmbase/util
In directory james.mmbase.org:/tmp/cvs-serv17809

Modified Files:
LocalizedString.java 
Log Message:
Removed some hacking with default locale which made stuff hard to undertnad and 
fails testcase


See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase/util


Index: LocalizedString.java
===
RCS file: /var/cvs/src/org/mmbase/util/LocalizedString.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -b -r1.39 -r1.40
--- LocalizedString.java29 Apr 2009 07:39:08 -  1.39
+++ LocalizedString.java30 Apr 2009 19:53:46 -  1.40
@@ -32,7 +32,7 @@
  *
  *
  * @author Michiel Meeuwissen
- * @version $Id: LocalizedString.java,v 1.39 2009/04/29 07:39:08 michiel Exp $
+ * @version $Id: LocalizedString.java,v 1.40 2009/04/30 19:53:46 michiel Exp $
  * @since MMBase-1.8
  */
 public class LocalizedString implements java.io.Serializable, 
PublicCloneable {
@@ -47,16 +47,13 @@
  * Sets a default locale for this JVM or web-app. When not using it, the 
locale is the system
  * default. Several web-apps do run in one JVM however and it is very 
imaginable that you want a
  * different default for the Locale.
- *
- * So, this function can be called only once. Calling it the second time 
will not do
- * anything. It returns the already set default locale then, which should 
probably prompt you to log an error
- * or throw an exception or so. Otherwise it returns null 
indicating that the
- * default locale is now what you just set.
+ * @return The previously set default locale. Should normally be 
null since it is
+ * odd to call this more than once.
  */
 public static Locale setDefault(Locale locale) {
-if (defaultLocale != null) return defaultLocale;
+Locale prev = defaultLocale;
 defaultLocale = locale;
-return null;
+return prev;
 }
 /**
  * Returns the default locale if set, or otherwise the system default 
({...@link java.util.Locale#getDefault}).
@@ -83,10 +80,6 @@
 private Map values = null;
 private String bundle = null;
 
-// just for the contract of Serializable
-protected LocalizedString() {
-}
-
 /**
  * @param k The key of this String, if k == null then the 
first set will define it.
  */
@@ -113,7 +106,7 @@
  */
 public String get(Locale locale) {
 if (locale == null) {
-locale = defaultLocale == null ? Locale.getDefault() : 
defaultLocale;
+locale = getDefault();
 }
 if (values != null) {
 String result = values.get(locale);
@@ -140,12 +133,14 @@
 // This code 'fixes' that reference.
 // It's not nice, but as a proper fix likely requires a total 
rewrite of Module.java and
 // MMBase.java, this will have to do for the moment.
-if (locale.equals(defaultLocale)) {
+Locale def = getDefault();
+if (locale.equals(def)) {
 result = values.get(null);
 if (result != null) {
 values.put(locale, result);
 return result;
 }
+
 }
 }
 
@@ -175,11 +170,12 @@
 }
 
 if (locale == null) {
-locale = defaultLocale;
+locale = getDefault();
 }
 
 values.put(locale, value);
 
+
 if (locale != null) {
 String variant  = locale.getVariant();
 String country  = locale.getCountry();
@@ -237,7 +233,7 @@
 }
 
 public String getDebugString() {
-return "k: " + getKey() + " values: " + getValues() + " b:" + 
getBundle();
+return "k: " + getKey() + " values: " + getValues() + " b:" + 
getBundle() + " dl: " + defaultLocale;
 }
 
 /**
___
Cvs mailing list
Cvs@lists.mmbase.org
http://lists.mmbase.org/mailman/listinfo/cvs


[MMBASE CVS] src/org/mmbase/util LocalizedString.java ReplacingLocalizedString.java WrappedLocalizedString.java

2009-04-27 Thread Michiel Meeuwissen
Update of /var/cvs/src/org/mmbase/util
In directory james.mmbase.org:/tmp/cvs-serv1812

Modified Files:
LocalizedString.java ReplacingLocalizedString.java 
WrappedLocalizedString.java 
Log Message:
Added some @Override's


See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase/util


Index: LocalizedString.java
===
RCS file: /var/cvs/src/org/mmbase/util/LocalizedString.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -b -r1.37 -r1.38
--- LocalizedString.java27 Apr 2009 17:14:00 -  1.37
+++ LocalizedString.java28 Apr 2009 06:31:22 -  1.38
@@ -32,7 +32,7 @@
  *
  *
  * @author Michiel Meeuwissen
- * @version $Id: LocalizedString.java,v 1.37 2009/04/27 17:14:00 michiel Exp $
+ * @version $Id: LocalizedString.java,v 1.38 2009/04/28 06:31:22 michiel Exp $
  * @since MMBase-1.8
  */
 public class LocalizedString implements java.io.Serializable, 
PublicCloneable {
@@ -426,6 +426,7 @@
 }
 }
 
+@Overrde
 public boolean equals(Object o) {
 if (o instanceof LocalizedString) {
 LocalizedString os = (LocalizedString) o;
@@ -438,7 +439,7 @@
 return false;
 }
 }
-
+@Override
 public int hashCode() {
 int result = 0;
 result = HashCodeUtil.hashCode(result, key);


Index: ReplacingLocalizedString.java
===
RCS file: /var/cvs/src/org/mmbase/util/ReplacingLocalizedString.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- ReplacingLocalizedString.java   27 Apr 2009 17:47:24 -  1.9
+++ ReplacingLocalizedString.java   28 Apr 2009 06:31:22 -  1.10
@@ -22,7 +22,7 @@
  *
  *
  * @author Michiel Meeuwissen
- * @version $Id: ReplacingLocalizedString.java,v 1.9 2009/04/27 17:47:24 
michiel Exp $
+ * @version $Id: ReplacingLocalizedString.java,v 1.10 2009/04/28 06:31:22 
michiel Exp $
  * @since MMBase-1.8
  */
 public class ReplacingLocalizedString extends WrappedLocalizedString {
@@ -31,6 +31,7 @@
 
 private List> replacements = new 
ArrayList>();
 
+
 /**
  * @param s The wrapped LocalizedString.
  */
@@ -38,6 +39,7 @@
 super(s);
 }
 
+
 public void replaceAll(String regexp, String replacement) {
 replacements.add(new Entry(regexp, replacement));
 }
@@ -54,7 +56,7 @@
 return output;
 }
 
-// javadoc inherited
+@Override
 public String get(Locale locale) {
 return replace(super.get(locale));
 }
@@ -64,6 +66,7 @@
  *
  * Also takes into account the replacements in the values (but only 
'lazily', when actually requested).
  */
+@Override
 public Map asMap() {
 final Map map = super.asMap();
 return new AbstractMap() {
@@ -104,6 +107,7 @@
 
 
 @SuppressWarnings("unchecked")
+@Override
 public ReplacingLocalizedString clone() {
 ReplacingLocalizedString clone = (ReplacingLocalizedString) 
super.clone();
 clone.replacements = (List)((ArrayList)replacements).clone();


Index: WrappedLocalizedString.java
===
RCS file: /var/cvs/src/org/mmbase/util/WrappedLocalizedString.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- WrappedLocalizedString.java 27 Apr 2009 17:14:00 -  1.3
+++ WrappedLocalizedString.java 28 Apr 2009 06:31:22 -  1.4
@@ -16,17 +16,17 @@
  * Extends and wraps LocalizedString.
  *
  * @author Michiel Meeuwissen
- * @version $Id: WrappedLocalizedString.java,v 1.3 2009/04/27 17:14:00 michiel 
Exp $
+ * @version $Id: WrappedLocalizedString.java,v 1.4 2009/04/28 06:31:22 michiel 
Exp $
  * @since MMBase-1.9
  */
 public class WrappedLocalizedString extends LocalizedString {
 
 private static final Logger log = 
Logging.getLoggerInstance(WrappedLocalizedString.class);
 
-
-protected LocalizedString wrapped;
+protected final LocalizedString wrapped;
 private Locale defaultLocale = null;
 
+
 /**
  * @param s The wrapped LocalizedString.
  */
@@ -35,6 +35,7 @@
 wrapped = s;
 }
 
+
 public Locale setLocale(Locale loc) {
 Locale prev = defaultLocale;
 defaultLocale = loc;
@@ -81,6 +82,10 @@
 protected MapgetValues() {
 return wrapped.getValues();
 }
+@Override
+public boolean equals(Object o) {
+return wrapped.equals(o);
+}
 
 
 
___
Cvs mailing list
Cvs@lists.mmbase.org
http://lists.mmbase.org/mailman/listinfo/cvs


[MMBASE CVS] src/org/mmbase/util LocalizedString.java

2009-04-27 Thread Michiel Meeuwissen
Update of /var/cvs/src/org/mmbase/util
In directory james.mmbase.org:/tmp/cvs-serv10117

Modified Files:
LocalizedString.java 
Log Message:
oops, should not be transient, serializability would be broken


See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase/util


Index: LocalizedString.java
===
RCS file: /var/cvs/src/org/mmbase/util/LocalizedString.java,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -b -r1.35 -r1.36
--- LocalizedString.java27 Apr 2009 14:43:35 -  1.35
+++ LocalizedString.java27 Apr 2009 16:41:24 -  1.36
@@ -32,7 +32,7 @@
  *
  *
  * @author Michiel Meeuwissen
- * @version $Id: LocalizedString.java,v 1.35 2009/04/27 14:43:35 michiel Exp $
+ * @version $Id: LocalizedString.java,v 1.36 2009/04/27 16:41:24 michiel Exp $
  * @since MMBase-1.8
  */
 public class LocalizedString implements java.io.Serializable, 
PublicCloneable {
@@ -80,7 +80,7 @@
 
 private String key;
 
-private transient Map values = null;
+private Map values = null;
 private String bundle = null;
 
 // just for the contract of Serializable
___
Cvs mailing list
Cvs@lists.mmbase.org
http://lists.mmbase.org/mailman/listinfo/cvs


[MMBASE CVS] src/org/mmbase/util LocalizedString.java

2009-04-27 Thread Michiel Meeuwissen
Update of /var/cvs/src/org/mmbase/util
In directory james.mmbase.org:/tmp/cvs-serv7102

Modified Files:
LocalizedString.java 
Log Message:
a bit silly to let super clone the map at all


See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase/util


Index: LocalizedString.java
===
RCS file: /var/cvs/src/org/mmbase/util/LocalizedString.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -b -r1.34 -r1.35
--- LocalizedString.java27 Aug 2008 17:07:34 -  1.34
+++ LocalizedString.java27 Apr 2009 14:43:35 -  1.35
@@ -32,7 +32,7 @@
  *
  *
  * @author Michiel Meeuwissen
- * @version $Id: LocalizedString.java,v 1.34 2008/08/27 17:07:34 michiel Exp $
+ * @version $Id: LocalizedString.java,v 1.35 2009/04/27 14:43:35 michiel Exp $
  * @since MMBase-1.8
  */
 public class LocalizedString implements java.io.Serializable, 
PublicCloneable {
@@ -80,7 +80,7 @@
 
 private String key;
 
-private Map values = null;
+private transient Map values = null;
 private String bundle = null;
 
 // just for the contract of Serializable
@@ -414,7 +414,6 @@
 return clone;
 } catch (CloneNotSupportedException cnse) {
 // should not happen
-log.error("Cannot clone this LocalizedString");
 throw new RuntimeException("Cannot clone this LocalizedString", 
cnse);
 }
 }
___
Cvs mailing list
Cvs@lists.mmbase.org
http://lists.mmbase.org/mailman/listinfo/cvs


[MMBASE CVS] src/org/mmbase/util LocalizedString.java

2008-07-11 Thread Michiel Meeuwissen
Update of /var/cvs/src/org/mmbase/util
In directory james.mmbase.org:/tmp/cvs-serv30416

Modified Files:
LocalizedString.java 
Log Message:
StringBuffer -> StringBuilder


See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase/util


Index: LocalizedString.java
===
RCS file: /var/cvs/src/org/mmbase/util/LocalizedString.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- LocalizedString.java23 May 2007 13:19:59 -  1.31
+++ LocalizedString.java11 Jul 2008 14:47:58 -  1.32
@@ -32,7 +32,7 @@
  *
  *
  * @author Michiel Meeuwissen
- * @version $Id: LocalizedString.java,v 1.31 2007/05/23 13:19:59 michiel Exp $
+ * @version $Id: LocalizedString.java,v 1.32 2008/07/11 14:47:58 michiel Exp $
  * @since MMBase-1.8
  */
 public class LocalizedString implements java.io.Serializable, Cloneable {
@@ -312,7 +312,7 @@
  */
 public static String getXmlLang(Locale locale) {
 if (locale == null) return null;
-StringBuffer lang = new StringBuffer(locale.getLanguage());
+StringBuilder lang = new StringBuilder(locale.getLanguage());
 String country = locale.getCountry();
 if (country.length() > 0) {
 lang.append("-").append(country);
@@ -378,11 +378,12 @@
 Locale loc   = entry.getKey();
 String value = entry.getValue();
 String xmlLang = getXmlLang(loc);
-// look if such an element is available
+// look if such an element is already available
 Element child = null;
 for (int j = 0; j < nl.getLength(); j++) {
 Element cand = (Element) nl.item(j);
-if (cand.getAttribute("xml:lang").equals(xmlLang)) {
+String l = cand.getAttribute("xml:lang");
+if (l.equals(xmlLang) || (l.equals("") && xmlLang == 
null)) {
 child = cand;
 break;
 }
@@ -393,7 +394,9 @@
 } else {
 child = 
element.getOwnerDocument().createElement(tagName);
 }
+if (loc != null || value.length() > 0) {
 DocumentReader.appendChild(element, child, path);
+}
 setXmlLang(child, loc);
 }
 DocumentReader.setNodeTextValue(child, value);
@@ -401,6 +404,7 @@
 }
 }
 
+
 public Object clone() {
 try {
 LocalizedString clone = (LocalizedString)super.clone();
___
Cvs mailing list
Cvs@lists.mmbase.org
http://lists.mmbase.org/mailman/listinfo/cvs