Author: rdonkin
Date: Fri May 15 14:30:36 2009
New Revision: 775152
URL: http://svn.apache.org/viewvc?rev=775152&view=rev
Log:
IMAP-89 Introduce Localizer interface. Allow HumanReadableText to store
parameters. https://issues.apache.org/jira/browse/IMAP-89
Added:
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/Locales.java
(with props)
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/Localizer.java
(with props)
Modified:
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/HumanReadableText.java
Modified:
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/HumanReadableText.java
URL:
http://svn.apache.org/viewvc/james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/HumanReadableText.java?rev=775152&r1=775151&r2=775152&view=diff
==============================================================================
---
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/HumanReadableText.java
(original)
+++
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/HumanReadableText.java
Fri May 15 14:30:36 2009
@@ -19,6 +19,8 @@
package org.apache.james.imap.api.display;
+import java.util.Arrays;
+
import org.apache.james.imap.api.ImapConstants;
/**
@@ -186,11 +188,19 @@
private final String defaultValue;
private final String key;
+
+ private final Object[] parameters;
+
public HumanReadableText(final String key, final String defaultValue) {
+ this(key, defaultValue, (Object[])null);
+ }
+
+ public HumanReadableText(final String key, final String defaultValue,
final Object... parameters) {
super();
this.defaultValue = defaultValue;
this.key = key;
+ this.parameters = parameters;
}
/**
@@ -212,13 +222,25 @@
return key;
}
+ /**
+ * Gets parameters that may be substituted into the text.
+ * @return substitution paramters, possibly null
+ */
+ public Object[] getParameters() {
+ return parameters;
+ }
+
+ @Override
public int hashCode() {
final int PRIME = 31;
int result = 1;
+ result = PRIME * result + ((defaultValue == null) ? 0 :
defaultValue.hashCode());
result = PRIME * result + ((key == null) ? 0 : key.hashCode());
+ result = PRIME * result + Arrays.hashCode(parameters);
return result;
}
+ @Override
public boolean equals(Object obj) {
if (this == obj)
return true;
@@ -227,11 +249,18 @@
if (getClass() != obj.getClass())
return false;
final HumanReadableText other = (HumanReadableText) obj;
+ if (defaultValue == null) {
+ if (other.defaultValue != null)
+ return false;
+ } else if (!defaultValue.equals(other.defaultValue))
+ return false;
if (key == null) {
if (other.key != null)
return false;
} else if (!key.equals(other.key))
return false;
+ if (!Arrays.equals(parameters, other.parameters))
+ return false;
return true;
}
Added:
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/Locales.java
URL:
http://svn.apache.org/viewvc/james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/Locales.java?rev=775152&view=auto
==============================================================================
---
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/Locales.java
(added)
+++
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/Locales.java
Fri May 15 14:30:36 2009
@@ -0,0 +1,63 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.imap.api.display;
+
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * <p>Immutable bean describing localisation preferences.</p>
+ * <p>Two separate sources of information about localisation are available:</p>
+ * <ul>
+ * <li>A client may ask for a locale (see {...@link
#getClientPreference()})</li>
+ * <li>Localisation preferences may be available from user data(see @link
{...@link #getUserPreferences()})</li>
+ * </ul>
+ */
+public class Locales {
+
+
+ private final List<Locale> userPreferences;
+ private final Locale clientPreference;
+
+ public Locales(final List<Locale> userPreferences, final Locale
clientPreference) {
+ super();
+ this.userPreferences = userPreferences;
+ this.clientPreference = clientPreference;
+ }
+
+ /**
+ * Gets the locale preferred by the client.
+ * @return when set, the locale currently preferred by the client
+ * or null when no preference has been set by the client
+ * @see #getUserPreferences()
+ */
+ public Locale getClientPreference() {
+ return clientPreference;
+ }
+
+ /**
+ * Gets the list of locales preferred by the user.
+ * @return preferred first not null, possibly empty
+ * @see #getUserPreferences()
+ */
+ public List<Locale> getUserPreferences() {
+ return userPreferences;
+ }
+}
Propchange:
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/Locales.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/Localizer.java
URL:
http://svn.apache.org/viewvc/james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/Localizer.java?rev=775152&view=auto
==============================================================================
---
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/Localizer.java
(added)
+++
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/Localizer.java
Fri May 15 14:30:36 2009
@@ -0,0 +1,52 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.imap.api.display;
+
+/**
+ * Localizes text for display.
+ */
+public interface Localizer {
+
+ /**
+ * <p>Localizes the given text for display.</p>
+ * <p>
+ * It is recommended that {...@link HumanReadableText#getKey()} is
+ * used as key. {...@link HumanReadableText#getParameters()} may
(optionally)
+ * be used for substitution into a parameterised text.
+ * </p>
+ * <p>
+ * Implementators are free to use any appropriate algorithm
+ * to determine which locale should be used. A client application
+ * may request a particular Locale based on it's local settings.
+ * This preference SHOULD be made available (by the caller)
+ * through {...@link Locales#getClientPreference()}.
+ * In addition, user data may contain localization preferences. These
+ * SHOULD be made available (by the caller) through {...@link
Locales#getUserPreferences()}.
+ * </p><p>
+ * {...@link HumanReadableText#getDefaultValue()} provides a simple,
standard english phrase.
+ * It is recommended that implementors use this value when a suitable
localisation
+ * cannot be discovered.
+ * </p>
+ * @param text describes the text requiring localisation, not null
+ * @param locales describes preferences, not null
+ * @return localized message not null
+ */
+ public String localize(HumanReadableText text, Locales locales);
+}
Propchange:
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/Localizer.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]