ContentData

- The default locale if one is not specified
 - Client code must still handle null locales for backwards compatibility
NodeService
 - Moved support methods for instrinsic properties
Locale
 - The Alfresco String representation of a Locale is x_y_z, even if x, y or z are ""
 - This makes the SQL like function more accurate for searches against locale properties


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4618 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2006-12-15 14:27:17 +00:00
parent d9a20c4e55
commit 026f9203a8
9 changed files with 200 additions and 63 deletions

View File

@@ -21,6 +21,7 @@ import java.util.Locale;
import java.util.StringTokenizer;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.util.EqualsHelper;
/**
@@ -126,7 +127,7 @@ public class ContentData implements Serializable
}
/**
* Create a content data without a locale.
* Create a content data using the {@link I18NUtil#getLocale() default locale}.
*
* @see #ContentData(String, String, long, String, Locale)
*/
@@ -146,7 +147,8 @@ public class ContentData implements Serializable
* @param mimetype the content mimetype. This is mandatory if the <b>contentUrl</b> is specified.
* @param size the content size.
* @param encoding the content encoding (may be <tt>null</tt>).
* @param locale the locale of the content (may be <tt>null</tt>).
* @param locale the locale of the content (may be <tt>null</tt>). If <tt>null</tt>, the
* {@link I18NUtil#getLocale() default locale} will be used.
*/
public ContentData(String contentUrl, String mimetype, long size, String encoding, Locale locale)
{
@@ -155,6 +157,10 @@ public class ContentData implements Serializable
this.mimetype = mimetype;
this.size = size;
this.encoding = encoding;
if (locale == null)
{
locale = I18NUtil.getLocale();
}
this.locale = locale;
}
@@ -184,7 +190,7 @@ public class ContentData implements Serializable
.append("|mimetype=").append(mimetype == null ? "" : mimetype)
.append("|size=").append(size)
.append("|encoding=").append(encoding == null ? "" : encoding)
.append("|locale=").append(locale == null ? "" : locale);
.append("|locale=").append(locale == null ? "" : DefaultTypeConverter.INSTANCE.convert(String.class, locale));
return sb.toString();
}

View File

@@ -16,10 +16,13 @@
*/
package org.alfresco.service.cmr.repository;
import org.alfresco.i18n.I18NUtil;
import java.util.Locale;
import junit.framework.TestCase;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
/**
* @see org.alfresco.service.cmr.repository.ContentData
*
@@ -35,18 +38,20 @@ public class ContentDataTest extends TestCase
public void testToAndFromString() throws Exception
{
ContentData property = new ContentData(null, null, 0L, null);
Locale locale = I18NUtil.getLocale();
String localeStr = DefaultTypeConverter.INSTANCE.convert(String.class, locale);
ContentData property = new ContentData(null, null, 0L, null, null);
// check null string
String propertyStr = property.toString();
assertEquals("Null values not converted correctly",
"contentUrl=|mimetype=|size=0|encoding=|locale=", propertyStr);
"contentUrl=|mimetype=|size=0|encoding=|locale=" + localeStr,
propertyStr);
// convert back
ContentData checkProperty = ContentData.createContentProperty(propertyStr);
assertEquals("Conversion from string failed", property, checkProperty);
String localeStr = I18NUtil.getLocale().toString();
property = new ContentData("uuu", "mmm", 123L, "eee", I18NUtil.getLocale());
// convert to a string

View File

@@ -287,7 +287,12 @@ public class DefaultTypeConverter
{
public String convert(Locale source)
{
return source.toString();
String localeStr = source.toString();
if (localeStr.length() < 6)
{
localeStr += "_";
}
return localeStr;
}
});

View File

@@ -90,9 +90,12 @@ public class DefaultTypeConverterTest extends TestCase
assertEquals(ISO8601DateFormat.format(date), DefaultTypeConverter.INSTANCE.convert(String.class, date));
assertEquals("P0Y25D", DefaultTypeConverter.INSTANCE.convert(String.class, new Duration("P0Y25D")));
assertEquals("woof", DefaultTypeConverter.INSTANCE.convert(String.class, "woof"));
// MLText
MLText mlText = new MLText("woof");
mlText.addValue(Locale.SIMPLIFIED_CHINESE, "");
assertEquals("woof", DefaultTypeConverter.INSTANCE.convert(String.class, mlText));
// Locale
assertEquals("fr_FR_", DefaultTypeConverter.INSTANCE.convert(String.class, Locale.FRANCE));
}
public void testFromString()
@@ -114,6 +117,9 @@ public class DefaultTypeConverterTest extends TestCase
MLText converted = DefaultTypeConverter.INSTANCE.convert(MLText.class, "woof");
assertEquals("woof", converted.getValue(Locale.getDefault()));
assertEquals(Locale.FRANCE, DefaultTypeConverter.INSTANCE.convert(Locale.class, "fr_FR"));
assertEquals(Locale.FRANCE, DefaultTypeConverter.INSTANCE.convert(Locale.class, "fr_FR_"));
}
public void testPrimativeAccessors()