* Weitere Verbesserungen an den sprachunabhängigen Content Items

* Selectboxen zur Auswahl der Sprache und die Anzeige der Sprachen im Tab Sprachen ist nun lokalisiert mittels java.util.Locale

git-svn-id: https://svn.libreccm.org/ccm/trunk@1200 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2011-10-26 11:28:22 +00:00
parent c1aeb0f822
commit eabd0ec620
6 changed files with 113 additions and 79 deletions

View File

@ -34,7 +34,6 @@ import com.arsdigita.kernel.permissions.PermissionService;
import com.arsdigita.persistence.DataAssociation;
import com.arsdigita.persistence.DataAssociationCursor;
import com.arsdigita.persistence.DataObject;
import com.arsdigita.persistence.Filter;
import com.arsdigita.persistence.FilterFactory;
import com.arsdigita.persistence.OID;
import com.arsdigita.persistence.metadata.Property;
@ -66,6 +65,7 @@ public class ContentBundle extends ContentItem {
private static DomainObjectObserver s_instancesObserver =
new AbstractDomainObjectObserver() {
@Override
public void add(DomainObject dom, String name,
DataObject dobj) {
if (INSTANCES.equals(name)) {
@ -97,6 +97,7 @@ public class ContentBundle extends ContentItem {
/**
* Returns the data object type for this bundle.
*/
@Override
public String getBaseDataObjectType() {
return BASE_DATA_OBJECT_TYPE;
}
@ -159,6 +160,7 @@ public class ContentBundle extends ContentItem {
super(type);
}
@Override
protected ContentItem makeCopy() {
final ContentBundle newItem = (ContentBundle) super.makeCopy();
@ -328,7 +330,7 @@ public class ContentBundle extends ContentItem {
instances.addEqualsFilter(LANGUAGE, language);
if (instances.next()) {
contentItem = (ContentItem) DomainObjectFactory.newInstance(instances.getDataObject());
contentItem = (ContentItem) DomainObjectFactory.newInstance(instances.getDataObject());
}
instances.close();
@ -378,8 +380,6 @@ public class ContentBundle extends ContentItem {
language + " is not an ISO639 language code");
}
boolean retVal = false;
final DataAssociationCursor instances = instances();
// If allowLanguageIndependent == false (default case), only search
@ -586,6 +586,7 @@ public class ContentBundle extends ContentItem {
}
// Methods from item that bundle overrides
@Override
protected void beforeSave() {
super.beforeSave();
@ -598,25 +599,30 @@ public class ContentBundle extends ContentItem {
}
}
@Override
protected boolean canPublishToFS() {
return false;
}
@Override
protected void publishToFS() {
throw new UnsupportedOperationException();
}
@Override
public ContentItem publish(final LifecycleDefinition definition,
final Date start) {
throw new UnsupportedOperationException();
}
@Override
public Lifecycle getLifecycle() {
// Bundles do not have lifecycles.
return null;
}
@Override
public void setLifecycle(final Lifecycle lifecycle) {
// I'd like to do the following, but VersionCopier calls
// setLifecycle.
@ -635,6 +641,7 @@ public class ContentBundle extends ContentItem {
* that regular metadata-driven methods should be used
* to copy the property.
*/
@Override
public boolean copyProperty(final CustomCopy source,
final Property property,
final ItemCopier copier) {
@ -649,6 +656,7 @@ public class ContentBundle extends ContentItem {
return super.copyProperty(source, property, copier);
}
@Override
public boolean copyServices(final ContentItem source) {
if (s_log.isDebugEnabled()) {
s_log.debug("Copying services on bundle " + getName() + " "
@ -667,6 +675,7 @@ public class ContentBundle extends ContentItem {
return true;
}
@Override
protected void initialize() {
super.initialize();
addObserver(s_instancesObserver);
@ -674,6 +683,7 @@ public class ContentBundle extends ContentItem {
m_wasNew = isNew();
}
@Override
protected void afterSave() {
if (m_wasNew) {
getPrimaryInstance().setContentSection(getContentSection());

View File

@ -46,7 +46,6 @@ import com.arsdigita.util.LockableImpl;
import java.math.BigDecimal;
import org.apache.log4j.Logger;
/**
* Displays a list of all language instances of an item.
*
@ -76,17 +75,17 @@ public class ItemLanguagesTable extends DataTable {
* Builds the query for all the language instances in the current Bundle
*/
private static class LanguagesBuilder extends LockableImpl
implements DataQueryBuilder {
implements DataQueryBuilder {
ItemSelectionModel m_model;
public LanguagesBuilder(ItemSelectionModel model) {
super();
m_model = model;
}
public DataQuery makeDataQuery(DataTable t, PageState s) {
ContentPage multiLingual = (ContentPage)m_model.getSelectedObject(s);
ContentPage multiLingual = (ContentPage) m_model.getSelectedObject(s);
DataQuery q = SessionManager.getSession().retrieveQuery("com.arsdigita.cms.getBundledItems");
q.setParameter("bundleID", multiLingual.getContentBundle().getID());
return q;
@ -101,14 +100,13 @@ public class ItemLanguagesTable extends DataTable {
* Renders the full language name.
*/
private static class LanguageRenderer implements TableCellRenderer {
public Component getComponent(Table table, PageState state, Object value,
boolean isSelected, Object key,
int row, int column) {
boolean isSelected, Object key,
int row, int column) {
BigDecimal id = (BigDecimal) key;
String target = ContentItemPage.getRelativeItemURL
(id, ContentItemPage.AUTHORING_TAB);
GlobalizedMessage fullName = LanguageUtil.globalize((String)value);
return new Link(new Label(fullName), target);
String target = ContentItemPage.getRelativeItemURL(id, ContentItemPage.AUTHORING_TAB);
return new Link(new Label(LanguageUtil.getLangFull((String) value)), target);
}
}
@ -116,6 +114,7 @@ public class ItemLanguagesTable extends DataTable {
* Delete language instance action link.
*/
private static class ActionCellRenderer implements TableCellRenderer {
private static final Logger logger = Logger.getLogger(ActionCellRenderer.class);
private static Label s_noAction;
private static Label s_primary;
@ -131,15 +130,15 @@ public class ItemLanguagesTable extends DataTable {
s_link.setConfirmation("Permanently delete this item?"); // XXX G11N ?
logger.debug("Static initalizer finished.");
}
private ItemSelectionModel m_model;
public ActionCellRenderer(ItemSelectionModel model) {
m_model = model;
}
public Component getComponent(Table table, PageState state, Object value,
boolean isSelected, Object key,
int row, int column) {
boolean isSelected, Object key,
int row, int column) {
if (m_model.getSelectedKey(state).equals(key)) {
return s_noAction;
} else {
@ -148,8 +147,8 @@ public class ItemLanguagesTable extends DataTable {
OID oid = new OID(ContentPage.BASE_DATA_OBJECT_TYPE, id);
try {
ContentPage item = (ContentPage) DomainObjectFactory.newInstance(oid);
if ( item.getLanguage().equals(
item.getContentBundle().getDefaultLanguage())) {
if (item.getLanguage().equals(
item.getContentBundle().getDefaultLanguage())) {
return s_primary;
}
} catch (com.arsdigita.domain.DataObjectNotFoundException ex) {
@ -162,10 +161,11 @@ public class ItemLanguagesTable extends DataTable {
// delete one language instance
private class InstanceDeleter extends TableActionAdapter {
public void cellSelected(TableActionEvent e) {
int col = e.getColumn().intValue();
if ( m_deleteColumn != getColumn(col) ) {
if (m_deleteColumn != getColumn(col)) {
return;
}
@ -184,5 +184,4 @@ public class ItemLanguagesTable extends DataTable {
((Table) e.getSource()).clearSelection(s);
}
}
}

View File

@ -29,11 +29,11 @@ import com.arsdigita.util.Pair;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
/**
* Utility methods for dealing with the multilingual items.
*
@ -41,88 +41,86 @@ import java.util.StringTokenizer;
* @author Sören Bernstein
*/
public class LanguageUtil {
private static org.apache.log4j.Logger s_log =
org.apache.log4j.Logger.getLogger(LanguageUtil.class);
org.apache.log4j.Logger.getLogger(LanguageUtil.class);
private static String s_languages = null;
private static String[] s_languagesArray = null;
/** Mapping from the ISO639-1 2-letter codes to the ISO639-2 3-letter codes */
private static final String ISO639_2LA_3LA = "com.arsdigita.cms.util.iso639rev";
private static ResourceBundle s_lang3LA = ResourceBundle.getBundle(ISO639_2LA_3LA);
/** Mapping from the ISO639-1 2-letter codes to the full descriptive name */
private static final String ISO639_2LA_FULL = "com.arsdigita.cms.util.iso639full";
private static ResourceBundle s_langFull = ResourceBundle.getBundle(ISO639_2LA_FULL);
public static GlobalizedMessage globalize(String key) {
return new GlobalizedMessage(key, ISO639_2LA_FULL);
return new LanguageGlobalizedMessage(key);
}
/**
* Sets the supported languages, eliminates all spaces and trims
*
* @param comma separated list of langages initialized from initializer
* at the server startup
*/
public static void setSupportedLanguages(String languages) {
if(Kernel.getConfig().languageIndependentItems()) {
s_languages = languages + "," + GlobalizationHelper.LANG_INDEPENDENT;
if (Kernel.getConfig().languageIndependentItems() && !languages.contains(GlobalizationHelper.LANG_INDEPENDENT)) {
s_languages = languages.replace(" ", "").trim() + "," + GlobalizationHelper.LANG_INDEPENDENT;
} else {
s_languages = languages;
s_languages = languages.replace(" ", "").trim();
}
}
/** Get the comma separated list of all supported languages */
public static String getSupportedLanguages() {
Assert.exists(s_languages , "supported languages not set");
Assert.exists(s_languages, "supported languages not set");
return s_languages;
}
/** Returns the collection of all supported languages.
* @return all supported languages
*/
public static Collection getSupportedLanguages2LA() {
String allLanguages = getSupportedLanguages();
StringTokenizer tokenizer = new StringTokenizer(allLanguages , ",");
StringTokenizer tokenizer = new StringTokenizer(allLanguages, ",");
Collection langList = new LinkedList();
while (tokenizer.hasMoreElements()) {
String language = tokenizer.nextToken().trim();
String language = tokenizer.nextToken();
langList.add(language);
}
return langList;
}
/** Returns the collection of all supported languages.
* Each entry is a pair of 2 letter code as key and three letter code as value.
* @return all supported languages
*/
public static Collection getSupportedLanguages3LA() {
String allLanguages = getSupportedLanguages();
StringTokenizer tokenizer = new StringTokenizer(allLanguages , ",");
StringTokenizer tokenizer = new StringTokenizer(allLanguages, ",");
Collection langList = new LinkedList();
while (tokenizer.hasMoreElements()) {
String language = tokenizer.nextToken().trim();
langList.add(new Pair(language , getLang3LA(language)));
String language = tokenizer.nextToken();
langList.add(new Pair(language, getLang3LA(language)));
}
return langList;
}
/** Returns the collection of all supported languages.
* Each entry is a pair of 2 letter code as key and full language name as a value.
* @return all supported languages
*/
public static Collection getSupportedLanguagesFull() {
String allLanguages = getSupportedLanguages();
StringTokenizer tokenizer = new StringTokenizer(allLanguages , ",");
StringTokenizer tokenizer = new StringTokenizer(allLanguages, ",");
Collection langList = new LinkedList();
while (tokenizer.hasMoreElements()) {
String language = tokenizer.nextToken().trim();
langList.add(new Pair(language , getLangFull(language)));
String language = tokenizer.nextToken();
langList.add(new Pair(language, getLangFull(language)));
}
return langList;
}
/**
* Get the List of languages in which this item can be created.
* Usefull on UI where we need to display the list of languages in which this Item can
@ -134,7 +132,7 @@ public class LanguageUtil {
allList.removeAll(bundle.getLanguages());
return allList;
}
/**
* Returns three letter acronym for language code
* mapped from two letter code.
@ -142,13 +140,21 @@ public class LanguageUtil {
* @return three letter code for the two letter code.
* If the resource is not found then the key itself is returned.
*/
public static String getLang3LA( String lang ) {
public static String getLang3LA(String lang) {
String threeLA;
try {
threeLA = s_lang3LA.getString(lang);
} catch (MissingResourceException mexc) {
s_log.warn("Three letter language code for key '"+lang+"' not found: "+mexc);
threeLA = lang.trim();
// Lookup 3-letter language code via java.util.Locale
threeLA = (new Locale(lang)).getISO3Language();
} catch (MissingResourceException mre) {
// If there is none
try {
// Lookup 3-letter code via ressource bundle
threeLA = s_lang3LA.getString(lang);
} catch (MissingResourceException mexc) {
// if there is still no match, log a warning and return the 2-letter code
s_log.warn("Three letter language code for key '" + lang + "' not found: " + mexc);
threeLA = lang;
}
}
return threeLA;
}
@ -160,45 +166,64 @@ public class LanguageUtil {
* @return full language name for the given two letter code
* If the resource is not found then the key itself is returned.
*/
public static String getLangFull( String lang ) {
String fullName;
try{
fullName = s_langFull.getString(lang);
} catch (MissingResourceException mexc) {
s_log.warn( "Full language name for key '"+lang+"' not found "+mexc);
fullName = lang;
public static String getLangFull(String lang) {
// Lookup language name via java.util.Locale
String fullName = (new Locale(lang)).getDisplayLanguage(GlobalizationHelper.getNegotiatedLocale());
if(lang.equals(fullName)) {
// If that fails
try {
// Lookup language name vie ressource bundle
fullName = s_langFull.getString(lang);
} catch (MissingResourceException mexc) {
// If there is still nomatch, log a warning and return 2-letter code
s_log.warn("Full language name for key '" + lang + "' not found " + mexc);
fullName = lang;
}
}
return fullName;
}
/** Takes in a list of 2 letter codes and converts into 3 letter codes.
* Each entry is pair of 2 letter code as key and 3 letter code as value.
*/
public static Collection convertTo3LA(Collection list) {
Collection conList = new LinkedList();
for (Iterator iter=list.iterator(); iter.hasNext(); ) {
for (Iterator iter = list.iterator(); iter.hasNext();) {
String lang2Code = (String) iter.next();
conList.add( new Pair( lang2Code , getLang3LA(lang2Code) ) );
conList.add(new Pair(lang2Code, getLang3LA(lang2Code)));
}
return conList;
}
public static Collection convertToFull(Collection list) {
Collection conList = new LinkedList();
for (Iterator iter=list.iterator(); iter.hasNext(); ) {
for (Iterator iter = list.iterator(); iter.hasNext();) {
String lang2Code = (String) iter.next();
conList.add( new Pair( lang2Code , getLangFull(lang2Code) ) );
conList.add(new Pair(lang2Code, getLangFull(lang2Code)));
}
return conList;
}
public static Collection convertToG11N(Collection list) {
Collection conList = new LinkedList();
for (Iterator iter=list.iterator(); iter.hasNext(); ) {
for (Iterator iter = list.iterator(); iter.hasNext();) {
String lang2Code = (String) iter.next();
conList.add( new Pair( lang2Code , globalize(lang2Code) ) );
conList.add(new Pair(lang2Code, globalize(lang2Code)));
}
return conList;
}
// Special GlobalizedMessage for use with the LanguageUtil#globalize method
private static class LanguageGlobalizedMessage extends GlobalizedMessage {
public LanguageGlobalizedMessage(String key) {
super(key);
}
@Override
public Object localize(Locale locale) {
return LanguageUtil.getLangFull(this.getKey());
}
}
}

View File

@ -371,10 +371,12 @@ public class MultipartHttpServletRequest implements HttpServletRequest {
}
private String convertToString( Object value ) throws IOException {
if( value instanceof String ) return (String) value;
if( value instanceof String ) {
return (String) value;
}
if( value instanceof ByteArrayInputStream ) {
StringBuffer output = new StringBuffer();
StringBuilder output = new StringBuilder();
InputStreamReader reader;
try {
@ -391,7 +393,9 @@ public class MultipartHttpServletRequest implements HttpServletRequest {
int read = bufSize;
while( bufSize == read ) {
read = reader.read( buffer, 0, bufSize );
if( read > 0 ) output.append( buffer, 0, read );
if( read > 0 ) {
output.append( buffer, 0, read );
}
}
return output.toString();

View File

@ -18,7 +18,6 @@
*/
package com.arsdigita.globalization;
import com.arsdigita.kernel.Kernel;
import java.text.MessageFormat;
import java.util.Locale;
import java.util.MissingResourceException;
@ -178,7 +177,6 @@ public class GlobalizedMessage {
* GlobalizedObject?
*/
public Object localize() {
// return localize(Kernel.getContext().getLocale());
return localize(com.arsdigita.globalization.GlobalizationHelper.getNegotiatedLocale());
}
@ -204,7 +202,6 @@ public class GlobalizedMessage {
* GlobalizedObject?
*/
public Object localize(HttpServletRequest request) {
// return localize(Kernel.getContext().getLocale());
return localize(com.arsdigita.globalization.GlobalizationHelper.getNegotiatedLocale());
}

View File

@ -18,7 +18,6 @@
package com.arsdigita.london.navigation.ui;
import com.arsdigita.bebop.PageState;
import java.util.logging.Level;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;