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.DataAssociation;
|
||||||
import com.arsdigita.persistence.DataAssociationCursor;
|
import com.arsdigita.persistence.DataAssociationCursor;
|
||||||
import com.arsdigita.persistence.DataObject;
|
import com.arsdigita.persistence.DataObject;
|
||||||
|
import com.arsdigita.persistence.Filter;
|
||||||
|
import com.arsdigita.persistence.FilterFactory;
|
||||||
import com.arsdigita.persistence.OID;
|
import com.arsdigita.persistence.OID;
|
||||||
import com.arsdigita.persistence.metadata.Property;
|
import com.arsdigita.persistence.metadata.Property;
|
||||||
import com.arsdigita.util.Assert;
|
import com.arsdigita.util.Assert;
|
||||||
|
|
@ -59,9 +61,9 @@ import org.apache.log4j.Logger;
|
||||||
public class ContentBundle extends ContentItem {
|
public class ContentBundle extends ContentItem {
|
||||||
|
|
||||||
private static final Logger s_log = Logger.getLogger(ContentBundle.class);
|
private static final Logger s_log = Logger.getLogger(ContentBundle.class);
|
||||||
|
|
||||||
private static DomainObjectObserver s_instancesObserver =
|
private static DomainObjectObserver s_instancesObserver =
|
||||||
new AbstractDomainObjectObserver() {
|
new AbstractDomainObjectObserver() {
|
||||||
|
|
||||||
public void add(DomainObject dom, String name,
|
public void add(DomainObject dom, String name,
|
||||||
DataObject dobj) {
|
DataObject dobj) {
|
||||||
if (INSTANCES.equals(name)) {
|
if (INSTANCES.equals(name)) {
|
||||||
|
|
@ -71,28 +73,23 @@ public class ContentBundle extends ContentItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base data object type of a bundle
|
* The base data object type of a bundle
|
||||||
*/
|
*/
|
||||||
public static final String BASE_DATA_OBJECT_TYPE =
|
public static final String BASE_DATA_OBJECT_TYPE =
|
||||||
"com.arsdigita.cms.ContentBundle";
|
"com.arsdigita.cms.ContentBundle";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The primary instances association
|
* The primary instances association
|
||||||
*/
|
*/
|
||||||
public static final String INSTANCES = "instances";
|
public static final String INSTANCES = "instances";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The association to AtoZ aliases
|
* The association to AtoZ aliases
|
||||||
*/
|
*/
|
||||||
public static final String ATOZ_ALIASING_PROVIDERS = "atozAliasingProviders";
|
public static final String ATOZ_ALIASING_PROVIDERS = "atozAliasingProviders";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default language property
|
* The default language property
|
||||||
*/
|
*/
|
||||||
public static final String DEFAULT_LANGUAGE = "defaultLanguage";
|
public static final String DEFAULT_LANGUAGE = "defaultLanguage";
|
||||||
|
|
||||||
private boolean m_wasNew = false;
|
private boolean m_wasNew = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -160,13 +157,11 @@ public class ContentBundle extends ContentItem {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected ContentItem makeCopy() {
|
protected ContentItem makeCopy() {
|
||||||
final ContentBundle newItem = (ContentBundle) super.makeCopy();
|
final ContentBundle newItem = (ContentBundle) super.makeCopy();
|
||||||
|
|
||||||
final WorkflowTemplate template =
|
final WorkflowTemplate template =
|
||||||
ContentTypeWorkflowTemplate.getWorkflowTemplate
|
ContentTypeWorkflowTemplate.getWorkflowTemplate(newItem.getContentSection(), newItem.getContentType());
|
||||||
(newItem.getContentSection(), newItem.getContentType());
|
|
||||||
|
|
||||||
if (template != null) {
|
if (template != null) {
|
||||||
s_log.debug("Setting up new workflow template");
|
s_log.debug("Setting up new workflow template");
|
||||||
|
|
@ -226,8 +221,8 @@ public class ContentBundle extends ContentItem {
|
||||||
if (Assert.isEnabled()) {
|
if (Assert.isEnabled()) {
|
||||||
Assert.exists(instance, ContentItem.class);
|
Assert.exists(instance, ContentItem.class);
|
||||||
Assert.isFalse(hasInstance(instance.getLanguage()),
|
Assert.isFalse(hasInstance(instance.getLanguage()),
|
||||||
"The bundle already contains an instance " +
|
"The bundle already contains an instance "
|
||||||
"for the language " + instance.getLanguage());
|
+ "for the language " + instance.getLanguage());
|
||||||
}
|
}
|
||||||
|
|
||||||
instance.setParent(this);
|
instance.setParent(this);
|
||||||
|
|
@ -303,11 +298,11 @@ public class ContentBundle extends ContentItem {
|
||||||
if (Assert.isEnabled()) {
|
if (Assert.isEnabled()) {
|
||||||
Assert.exists(language, String.class);
|
Assert.exists(language, String.class);
|
||||||
Assert.isTrue(language.length() == 2,
|
Assert.isTrue(language.length() == 2,
|
||||||
language + " does not look like a valid language " +
|
language + " does not look like a valid language "
|
||||||
"code");
|
+ "code");
|
||||||
}
|
}
|
||||||
|
|
||||||
final DataAssociationCursor instances = instances();
|
DataAssociationCursor instances = instances();
|
||||||
instances.addEqualsFilter(LANGUAGE, language);
|
instances.addEqualsFilter(LANGUAGE, language);
|
||||||
|
|
||||||
DataObject dataObject = null;
|
DataObject dataObject = null;
|
||||||
|
|
@ -325,8 +320,23 @@ public class ContentBundle extends ContentItem {
|
||||||
|
|
||||||
return (ContentItem) DomainObjectFactory.newInstance(data);
|
return (ContentItem) DomainObjectFactory.newInstance(data);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
instances.close();
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -363,8 +373,12 @@ public class ContentBundle extends ContentItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
final DataAssociationCursor instances = instances();
|
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();
|
return !instances.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -407,7 +421,6 @@ public class ContentBundle extends ContentItem {
|
||||||
* <code>locales</code>
|
* <code>locales</code>
|
||||||
* @pre locales != null
|
* @pre locales != null
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Quasimodo:
|
// Quasimodo:
|
||||||
// Is this method ever used? Netbeans couldn't find anything.
|
// Is this method ever used? Netbeans couldn't find anything.
|
||||||
public ContentItem negotiate(Locale[] locales) {
|
public ContentItem negotiate(Locale[] locales) {
|
||||||
|
|
@ -423,7 +436,7 @@ public class ContentBundle extends ContentItem {
|
||||||
language = (String) dataObject.get(LANGUAGE);
|
language = (String) dataObject.get(LANGUAGE);
|
||||||
|
|
||||||
// If language is not one of the supported languages, skip this entry
|
// If language is not one of the supported languages, skip this entry
|
||||||
if(!supportedLanguages.contains(language)) {
|
if (!supportedLanguages.contains(language)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -432,7 +445,14 @@ public class ContentBundle extends ContentItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (language != null) {
|
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 (language.equals(locales[i].getLanguage())) {
|
||||||
if (i < bestMatch || matchingInstance == null) {
|
if (i < bestMatch || matchingInstance == null) {
|
||||||
bestMatch = i;
|
bestMatch = i;
|
||||||
|
|
@ -445,6 +465,7 @@ public class ContentBundle extends ContentItem {
|
||||||
} // else other match with less preferred language found
|
} // else other match with less preferred language found
|
||||||
}
|
}
|
||||||
} // end for
|
} // end for
|
||||||
|
}
|
||||||
} // end if
|
} // end if
|
||||||
if (bestMatch == 0 && matchingInstance != null) {
|
if (bestMatch == 0 && matchingInstance != null) {
|
||||||
s_log.debug("negotiate: best possible match found, exiting");
|
s_log.debug("negotiate: best possible match found, exiting");
|
||||||
|
|
@ -453,8 +474,7 @@ public class ContentBundle extends ContentItem {
|
||||||
}
|
}
|
||||||
instancesCursor.close();
|
instancesCursor.close();
|
||||||
if (matchingInstance != null) {
|
if (matchingInstance != null) {
|
||||||
return (ContentItem) DomainObjectFactory.newInstance
|
return (ContentItem) DomainObjectFactory.newInstance(matchingInstance);
|
||||||
(matchingInstance);
|
|
||||||
} else {
|
} else {
|
||||||
s_log.info("negotiate: no match found!");
|
s_log.info("negotiate: no match found!");
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -481,18 +501,24 @@ public class ContentBundle extends ContentItem {
|
||||||
Locale loc = null;
|
Locale loc = null;
|
||||||
List languageCodes = new ArrayList();
|
List languageCodes = new ArrayList();
|
||||||
for (int i = 0; locales.hasMoreElements(); i++) {
|
for (int i = 0; locales.hasMoreElements(); i++) {
|
||||||
loc = (Locale)locales.nextElement();
|
loc = (Locale) locales.nextElement();
|
||||||
|
|
||||||
// Quasimodo:
|
// Quasimodo:
|
||||||
// Only add languages to the List which are supported by cms
|
// Only add languages to the List which are supported by cms
|
||||||
if(supportedLanguages.contains(loc.getLanguage())) {
|
if (supportedLanguages.contains(loc.getLanguage())) {
|
||||||
languageCodes.add( loc.getLanguage());
|
languageCodes.add(loc.getLanguage());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s_log.isDebugEnabled()) {
|
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();
|
final DataAssociationCursor instances = instances();
|
||||||
|
|
||||||
DataObject dataObject = null;
|
DataObject dataObject = null;
|
||||||
|
|
@ -509,8 +535,8 @@ public class ContentBundle extends ContentItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (language != null) {
|
if (language != null) {
|
||||||
for (int i=0; i < languageCodes.size(); i++) {
|
for (int i = 0; i < languageCodes.size(); i++) {
|
||||||
if (language.equals( (String)languageCodes.get(i) )) {
|
if (language.equals((String) languageCodes.get(i))) {
|
||||||
if (i < bestMatch || match == null) {
|
if (i < bestMatch || match == null) {
|
||||||
bestMatch = i;
|
bestMatch = i;
|
||||||
match = dataObject;
|
match = dataObject;
|
||||||
|
|
@ -536,7 +562,6 @@ public class ContentBundle extends ContentItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Methods from item that bundle overrides
|
// Methods from item that bundle overrides
|
||||||
|
|
||||||
protected void beforeSave() {
|
protected void beforeSave() {
|
||||||
super.beforeSave();
|
super.beforeSave();
|
||||||
|
|
||||||
|
|
@ -574,7 +599,6 @@ public class ContentBundle extends ContentItem {
|
||||||
//throw new UnsupportedOperationException();
|
//throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ignore the <code>INSTANCES</code> property for
|
* Ignore the <code>INSTANCES</code> property for
|
||||||
* <code>ItemCopier.VERSION_COPY</code>.
|
* <code>ItemCopier.VERSION_COPY</code>.
|
||||||
|
|
@ -603,13 +627,13 @@ public class ContentBundle extends ContentItem {
|
||||||
|
|
||||||
public boolean copyServices(final ContentItem source) {
|
public boolean copyServices(final ContentItem source) {
|
||||||
if (s_log.isDebugEnabled()) {
|
if (s_log.isDebugEnabled()) {
|
||||||
s_log.debug("Copying services on bundle " + getName() + " " +
|
s_log.debug("Copying services on bundle " + getName() + " "
|
||||||
getID() + " using source " + source.getID());
|
+ getID() + " using source " + source.getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy categories
|
// Copy categories
|
||||||
CategoryCollection categories = source.getCategoryCollection();
|
CategoryCollection categories = source.getCategoryCollection();
|
||||||
while (categories.next() ) {
|
while (categories.next()) {
|
||||||
final Category category = categories.getCategory();
|
final Category category = categories.getCategory();
|
||||||
category.addChild(this);
|
category.addChild(this);
|
||||||
category.save(); // XXX remove me
|
category.save(); // XXX remove me
|
||||||
|
|
@ -635,7 +659,6 @@ public class ContentBundle extends ContentItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Utility methods
|
// Utility methods
|
||||||
|
|
||||||
private DataAssociationCursor instances() {
|
private DataAssociationCursor instances() {
|
||||||
final DataAssociationCursor cursor =
|
final DataAssociationCursor cursor =
|
||||||
((DataAssociation) super.get(INSTANCES)).cursor();
|
((DataAssociation) super.get(INSTANCES)).cursor();
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ public class LanguageUtil {
|
||||||
* at the server startup
|
* at the server startup
|
||||||
*/
|
*/
|
||||||
public static void setSupportedLanguages(String languages) {
|
public static void setSupportedLanguages(String languages) {
|
||||||
s_languages = languages;
|
s_languages = languages + ",--";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the comma separated list of all supported languages */
|
/** Get the comma separated list of all supported languages */
|
||||||
|
|
@ -80,7 +80,7 @@ public class LanguageUtil {
|
||||||
StringTokenizer tokenizer = new StringTokenizer(allLanguages , ",");
|
StringTokenizer tokenizer = new StringTokenizer(allLanguages , ",");
|
||||||
Collection langList = new LinkedList();
|
Collection langList = new LinkedList();
|
||||||
while (tokenizer.hasMoreElements()) {
|
while (tokenizer.hasMoreElements()) {
|
||||||
String language = tokenizer.nextToken();
|
String language = tokenizer.nextToken().trim();
|
||||||
langList.add(language);
|
langList.add(language);
|
||||||
}
|
}
|
||||||
return langList;
|
return langList;
|
||||||
|
|
@ -95,7 +95,7 @@ public class LanguageUtil {
|
||||||
StringTokenizer tokenizer = new StringTokenizer(allLanguages , ",");
|
StringTokenizer tokenizer = new StringTokenizer(allLanguages , ",");
|
||||||
Collection langList = new LinkedList();
|
Collection langList = new LinkedList();
|
||||||
while (tokenizer.hasMoreElements()) {
|
while (tokenizer.hasMoreElements()) {
|
||||||
String language = tokenizer.nextToken();
|
String language = tokenizer.nextToken().trim();
|
||||||
langList.add(new Pair(language , getLang3LA(language)));
|
langList.add(new Pair(language , getLang3LA(language)));
|
||||||
}
|
}
|
||||||
return langList;
|
return langList;
|
||||||
|
|
@ -110,7 +110,7 @@ public class LanguageUtil {
|
||||||
StringTokenizer tokenizer = new StringTokenizer(allLanguages , ",");
|
StringTokenizer tokenizer = new StringTokenizer(allLanguages , ",");
|
||||||
Collection langList = new LinkedList();
|
Collection langList = new LinkedList();
|
||||||
while (tokenizer.hasMoreElements()) {
|
while (tokenizer.hasMoreElements()) {
|
||||||
String language = tokenizer.nextToken();
|
String language = tokenizer.nextToken().trim();
|
||||||
langList.add(new Pair(language , getLangFull(language)));
|
langList.add(new Pair(language , getLangFull(language)));
|
||||||
}
|
}
|
||||||
return langList;
|
return langList;
|
||||||
|
|
|
||||||
|
|
@ -138,3 +138,4 @@ yo=Yoruba
|
||||||
za=Zhuang
|
za=Zhuang
|
||||||
zh=Chinese
|
zh=Chinese
|
||||||
zu=Zulu
|
zu=Zulu
|
||||||
|
--=Undefined
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ import com.arsdigita.london.navigation.DataCollectionRenderer;
|
||||||
|
|
||||||
import com.arsdigita.persistence.DataCollection;
|
import com.arsdigita.persistence.DataCollection;
|
||||||
|
|
||||||
|
import com.arsdigita.persistence.Filter;
|
||||||
|
import com.arsdigita.persistence.FilterFactory;
|
||||||
import com.arsdigita.util.Assert;
|
import com.arsdigita.util.Assert;
|
||||||
import com.arsdigita.util.UncheckedWrapperException;
|
import com.arsdigita.util.UncheckedWrapperException;
|
||||||
|
|
||||||
|
|
@ -94,9 +96,14 @@ public abstract class AbstractObjectList
|
||||||
DataCollection objects = getObjects(request, response);
|
DataCollection objects = getObjects(request, response);
|
||||||
|
|
||||||
// Quasimodo: Begin
|
// 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) {
|
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
|
// Quasimodo: End
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,8 @@
|
||||||
|
|
||||||
<!-- ZeS extension -->
|
<!-- 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-types-organization"/>
|
||||||
<ccm:application name="ccm-sci-publications"/>
|
<ccm:application name="ccm-sci-publications"/>
|
||||||
<ccm:application name="ccm-zes-aplaws"/>
|
<ccm:application name="ccm-zes-aplaws"/>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue