Sprachinvariate ContentItems
LangUtil:
- supportedLanguage wird immer um "--" für die invarianten CIs erweitert, d.h. Invariante CIs werden immer unterstützt
- trim() für alle LanguageStrings eingeführt, da sonst ein versehentliches Leerzeichen in der Config für die supportedLanguages das System in einen Fehler laufen läßt.
iso639full.properties:
- Eigentlich ist diese Datei überflüssig, aber in diesem Fall noch hilfreich, da ich den String für sprachinvariante CIs ("--") einfach eintragen konnte
ContentBundle:
- getInstance(String language), negotiate(...) und hasInstance(String language) so angepaßt, daß sie mit sprachunabhängigen CIs umgehen können
AbstrctObjectList:
- Filter in generateObjectListXML() geändert, so daß er auch auf sprachinvariante CI matched
git-svn-id: https://svn.libreccm.org/ccm/trunk@1161 8810af33-2d31-482b-a856-94f89814c4df
master
parent
66a189a304
commit
ad84f95434
|
|
@ -32,6 +32,8 @@ 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;
|
||||
import com.arsdigita.util.Assert;
|
||||
|
|
@ -59,9 +61,9 @@ import org.apache.log4j.Logger;
|
|||
public class ContentBundle extends ContentItem {
|
||||
|
||||
private static final Logger s_log = Logger.getLogger(ContentBundle.class);
|
||||
|
||||
private static DomainObjectObserver s_instancesObserver =
|
||||
new AbstractDomainObjectObserver() {
|
||||
|
||||
public void add(DomainObject dom, String name,
|
||||
DataObject dobj) {
|
||||
if (INSTANCES.equals(name)) {
|
||||
|
|
@ -71,28 +73,23 @@ public class ContentBundle extends ContentItem {
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The base data object type of a bundle
|
||||
*/
|
||||
public static final String BASE_DATA_OBJECT_TYPE =
|
||||
"com.arsdigita.cms.ContentBundle";
|
||||
|
||||
/**
|
||||
* The primary instances association
|
||||
*/
|
||||
public static final String INSTANCES = "instances";
|
||||
|
||||
/**
|
||||
* The association to AtoZ aliases
|
||||
*/
|
||||
public static final String ATOZ_ALIASING_PROVIDERS = "atozAliasingProviders";
|
||||
|
||||
/**
|
||||
* The default language property
|
||||
*/
|
||||
public static final String DEFAULT_LANGUAGE = "defaultLanguage";
|
||||
|
||||
private boolean m_wasNew = false;
|
||||
|
||||
/**
|
||||
|
|
@ -160,13 +157,11 @@ public class ContentBundle extends ContentItem {
|
|||
super(type);
|
||||
}
|
||||
|
||||
|
||||
protected ContentItem makeCopy() {
|
||||
final ContentBundle newItem = (ContentBundle) super.makeCopy();
|
||||
|
||||
final WorkflowTemplate template =
|
||||
ContentTypeWorkflowTemplate.getWorkflowTemplate
|
||||
(newItem.getContentSection(), newItem.getContentType());
|
||||
ContentTypeWorkflowTemplate.getWorkflowTemplate(newItem.getContentSection(), newItem.getContentType());
|
||||
|
||||
if (template != null) {
|
||||
s_log.debug("Setting up new workflow template");
|
||||
|
|
@ -226,8 +221,8 @@ public class ContentBundle extends ContentItem {
|
|||
if (Assert.isEnabled()) {
|
||||
Assert.exists(instance, ContentItem.class);
|
||||
Assert.isFalse(hasInstance(instance.getLanguage()),
|
||||
"The bundle already contains an instance " +
|
||||
"for the language " + instance.getLanguage());
|
||||
"The bundle already contains an instance "
|
||||
+ "for the language " + instance.getLanguage());
|
||||
}
|
||||
|
||||
instance.setParent(this);
|
||||
|
|
@ -303,11 +298,11 @@ public class ContentBundle extends ContentItem {
|
|||
if (Assert.isEnabled()) {
|
||||
Assert.exists(language, String.class);
|
||||
Assert.isTrue(language.length() == 2,
|
||||
language + " does not look like a valid language " +
|
||||
"code");
|
||||
language + " does not look like a valid language "
|
||||
+ "code");
|
||||
}
|
||||
|
||||
final DataAssociationCursor instances = instances();
|
||||
DataAssociationCursor instances = instances();
|
||||
instances.addEqualsFilter(LANGUAGE, language);
|
||||
|
||||
DataObject dataObject = null;
|
||||
|
|
@ -325,8 +320,23 @@ public class ContentBundle extends ContentItem {
|
|||
|
||||
return (ContentItem) DomainObjectFactory.newInstance(data);
|
||||
} else {
|
||||
|
||||
instances.close();
|
||||
|
||||
// Look for language invariant version
|
||||
instances = instances();
|
||||
instances.addEqualsFilter(LANGUAGE, "--");
|
||||
|
||||
if (instances.next()) {
|
||||
final DataObject data = instances.getDataObject();
|
||||
|
||||
instances.close();
|
||||
|
||||
return (ContentItem) DomainObjectFactory.newInstance(data);
|
||||
} else {
|
||||
instances.close();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -363,8 +373,12 @@ public class ContentBundle extends ContentItem {
|
|||
}
|
||||
|
||||
final DataAssociationCursor instances = instances();
|
||||
instances.addEqualsFilter(LANGUAGE, language);
|
||||
|
||||
// instances.addEqualsFilter(LANGUAGE, language);
|
||||
FilterFactory ff = instances.getFilterFactory();
|
||||
Filter filter = ff.or().
|
||||
addFilter(ff.equals("language", language)).
|
||||
addFilter(ff.equals("language", "--"));
|
||||
instances.addFilter(filter);
|
||||
return !instances.isEmpty();
|
||||
}
|
||||
|
||||
|
|
@ -407,7 +421,6 @@ public class ContentBundle extends ContentItem {
|
|||
* <code>locales</code>
|
||||
* @pre locales != null
|
||||
*/
|
||||
|
||||
// Quasimodo:
|
||||
// Is this method ever used? Netbeans couldn't find anything.
|
||||
public ContentItem negotiate(Locale[] locales) {
|
||||
|
|
@ -423,7 +436,7 @@ public class ContentBundle extends ContentItem {
|
|||
language = (String) dataObject.get(LANGUAGE);
|
||||
|
||||
// If language is not one of the supported languages, skip this entry
|
||||
if(!supportedLanguages.contains(language)) {
|
||||
if (!supportedLanguages.contains(language)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -432,7 +445,14 @@ public class ContentBundle extends ContentItem {
|
|||
}
|
||||
|
||||
if (language != null) {
|
||||
for (int i=0; i < locales.length; i++) {
|
||||
// If the current object is languange invariant and no better
|
||||
// match is already found, match it with the lowest priority
|
||||
if (language.equals("--") && matchingInstance == null) {
|
||||
bestMatch = locales.length;
|
||||
matchingInstance = dataObject;
|
||||
} else {
|
||||
// In any other case
|
||||
for (int i = 0; i < locales.length; i++) {
|
||||
if (language.equals(locales[i].getLanguage())) {
|
||||
if (i < bestMatch || matchingInstance == null) {
|
||||
bestMatch = i;
|
||||
|
|
@ -445,6 +465,7 @@ public class ContentBundle extends ContentItem {
|
|||
} // else other match with less preferred language found
|
||||
}
|
||||
} // end for
|
||||
}
|
||||
} // end if
|
||||
if (bestMatch == 0 && matchingInstance != null) {
|
||||
s_log.debug("negotiate: best possible match found, exiting");
|
||||
|
|
@ -453,8 +474,7 @@ public class ContentBundle extends ContentItem {
|
|||
}
|
||||
instancesCursor.close();
|
||||
if (matchingInstance != null) {
|
||||
return (ContentItem) DomainObjectFactory.newInstance
|
||||
(matchingInstance);
|
||||
return (ContentItem) DomainObjectFactory.newInstance(matchingInstance);
|
||||
} else {
|
||||
s_log.info("negotiate: no match found!");
|
||||
return null;
|
||||
|
|
@ -481,18 +501,24 @@ public class ContentBundle extends ContentItem {
|
|||
Locale loc = null;
|
||||
List languageCodes = new ArrayList();
|
||||
for (int i = 0; locales.hasMoreElements(); i++) {
|
||||
loc = (Locale)locales.nextElement();
|
||||
loc = (Locale) locales.nextElement();
|
||||
|
||||
// Quasimodo:
|
||||
// Only add languages to the List which are supported by cms
|
||||
if(supportedLanguages.contains(loc.getLanguage())) {
|
||||
languageCodes.add( loc.getLanguage());
|
||||
if (supportedLanguages.contains(loc.getLanguage())) {
|
||||
languageCodes.add(loc.getLanguage());
|
||||
}
|
||||
|
||||
if (s_log.isDebugEnabled()) {
|
||||
s_log.debug("negotiate: pref " + i + ": "+ loc.getLanguage());
|
||||
s_log.debug("negotiate: pref " + i + ": " + loc.getLanguage());
|
||||
}
|
||||
}
|
||||
|
||||
// Add unspecified language for language invariant objects
|
||||
if (supportedLanguages.contains("--")) {
|
||||
languageCodes.add("--");
|
||||
}
|
||||
|
||||
final DataAssociationCursor instances = instances();
|
||||
|
||||
DataObject dataObject = null;
|
||||
|
|
@ -509,8 +535,8 @@ public class ContentBundle extends ContentItem {
|
|||
}
|
||||
|
||||
if (language != null) {
|
||||
for (int i=0; i < languageCodes.size(); i++) {
|
||||
if (language.equals( (String)languageCodes.get(i) )) {
|
||||
for (int i = 0; i < languageCodes.size(); i++) {
|
||||
if (language.equals((String) languageCodes.get(i))) {
|
||||
if (i < bestMatch || match == null) {
|
||||
bestMatch = i;
|
||||
match = dataObject;
|
||||
|
|
@ -536,7 +562,6 @@ public class ContentBundle extends ContentItem {
|
|||
}
|
||||
|
||||
// Methods from item that bundle overrides
|
||||
|
||||
protected void beforeSave() {
|
||||
super.beforeSave();
|
||||
|
||||
|
|
@ -574,7 +599,6 @@ public class ContentBundle extends ContentItem {
|
|||
//throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ignore the <code>INSTANCES</code> property for
|
||||
* <code>ItemCopier.VERSION_COPY</code>.
|
||||
|
|
@ -603,13 +627,13 @@ public class ContentBundle extends ContentItem {
|
|||
|
||||
public boolean copyServices(final ContentItem source) {
|
||||
if (s_log.isDebugEnabled()) {
|
||||
s_log.debug("Copying services on bundle " + getName() + " " +
|
||||
getID() + " using source " + source.getID());
|
||||
s_log.debug("Copying services on bundle " + getName() + " "
|
||||
+ getID() + " using source " + source.getID());
|
||||
}
|
||||
|
||||
// Copy categories
|
||||
CategoryCollection categories = source.getCategoryCollection();
|
||||
while (categories.next() ) {
|
||||
while (categories.next()) {
|
||||
final Category category = categories.getCategory();
|
||||
category.addChild(this);
|
||||
category.save(); // XXX remove me
|
||||
|
|
@ -635,7 +659,6 @@ public class ContentBundle extends ContentItem {
|
|||
}
|
||||
|
||||
// Utility methods
|
||||
|
||||
private DataAssociationCursor instances() {
|
||||
final DataAssociationCursor cursor =
|
||||
((DataAssociation) super.get(INSTANCES)).cursor();
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public class LanguageUtil {
|
|||
* at the server startup
|
||||
*/
|
||||
public static void setSupportedLanguages(String languages) {
|
||||
s_languages = languages;
|
||||
s_languages = languages + ",--";
|
||||
}
|
||||
|
||||
/** Get the comma separated list of all supported languages */
|
||||
|
|
@ -80,7 +80,7 @@ public class LanguageUtil {
|
|||
StringTokenizer tokenizer = new StringTokenizer(allLanguages , ",");
|
||||
Collection langList = new LinkedList();
|
||||
while (tokenizer.hasMoreElements()) {
|
||||
String language = tokenizer.nextToken();
|
||||
String language = tokenizer.nextToken().trim();
|
||||
langList.add(language);
|
||||
}
|
||||
return langList;
|
||||
|
|
@ -95,7 +95,7 @@ public class LanguageUtil {
|
|||
StringTokenizer tokenizer = new StringTokenizer(allLanguages , ",");
|
||||
Collection langList = new LinkedList();
|
||||
while (tokenizer.hasMoreElements()) {
|
||||
String language = tokenizer.nextToken();
|
||||
String language = tokenizer.nextToken().trim();
|
||||
langList.add(new Pair(language , getLang3LA(language)));
|
||||
}
|
||||
return langList;
|
||||
|
|
@ -110,7 +110,7 @@ public class LanguageUtil {
|
|||
StringTokenizer tokenizer = new StringTokenizer(allLanguages , ",");
|
||||
Collection langList = new LinkedList();
|
||||
while (tokenizer.hasMoreElements()) {
|
||||
String language = tokenizer.nextToken();
|
||||
String language = tokenizer.nextToken().trim();
|
||||
langList.add(new Pair(language , getLangFull(language)));
|
||||
}
|
||||
return langList;
|
||||
|
|
|
|||
|
|
@ -138,3 +138,4 @@ yo=Yoruba
|
|||
za=Zhuang
|
||||
zh=Chinese
|
||||
zu=Zulu
|
||||
--=Undefined
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ import com.arsdigita.london.navigation.DataCollectionRenderer;
|
|||
|
||||
import com.arsdigita.persistence.DataCollection;
|
||||
|
||||
import com.arsdigita.persistence.Filter;
|
||||
import com.arsdigita.persistence.FilterFactory;
|
||||
import com.arsdigita.util.Assert;
|
||||
import com.arsdigita.util.UncheckedWrapperException;
|
||||
|
||||
|
|
@ -94,9 +96,14 @@ public abstract class AbstractObjectList
|
|||
DataCollection objects = getObjects(request, response);
|
||||
|
||||
// Quasimodo: Begin
|
||||
// Limit list to objects in the negotiated language
|
||||
// Limit list to objects in the negotiated language and language invariant items
|
||||
if (objects != null && objects.size() > 0) {
|
||||
objects.addEqualsFilter("language", com.arsdigita.globalization.GlobalizationHelper.getNegotiatedLocale().getLanguage());
|
||||
FilterFactory ff = objects.getFilterFactory();
|
||||
Filter filter = ff.or().
|
||||
addFilter(ff.equals("language", com.arsdigita.globalization.GlobalizationHelper.getNegotiatedLocale().getLanguage())).
|
||||
addFilter(ff.equals("language", "--"));
|
||||
objects.addFilter(filter);
|
||||
// objects.addEqualsFilter("language", com.arsdigita.globalization.GlobalizationHelper.getNegotiatedLocale().getLanguage());
|
||||
}
|
||||
// Quasimodo: End
|
||||
|
||||
|
|
|
|||
|
|
@ -94,7 +94,8 @@
|
|||
|
||||
<!-- ZeS extension -->
|
||||
<!-- - - - - - - - -->
|
||||
<ccm:application name="ccm-cms-dabinimporter" />
|
||||
<ccm:application name="ccm-cms-dabinimporter"/>
|
||||
<!-- <ccm:application name="ccm-cms-publicpersonalprofile"/> -->
|
||||
<ccm:application name="ccm-sci-types-organization"/>
|
||||
<ccm:application name="ccm-sci-publications"/>
|
||||
<ccm:application name="ccm-zes-aplaws"/>
|
||||
|
|
|
|||
Loading…
Reference in New Issue