LanguageSelector

Fixed: Beim Umschalten eines ContentItems, dessen URL keine Sprachvariante enthält, funktioniert das nicht, wenn man sich bereits in der Applikation ContentItem befindet. Das funktioniert allerdings auch nicht mit dem QuickLocaleSwitcher.

Das war ein Caching-Problem: Der ContentSectionServletItemURLCache war nicht in der Lage, die gecachten Objekte nach Sprache zu differenzieren, falls diese Sprache nicht bereits in der URL kodiert war. Das ist nun behoben. Der Cache-Key beinhaltet nun zusätzlich die Sprache.

git-svn-id: https://svn.libreccm.org/ccm/trunk@1096 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2011-09-05 11:54:14 +00:00
parent e417f60c2a
commit 7b7760a88e
1 changed files with 34 additions and 10 deletions

View File

@ -30,6 +30,7 @@ import com.arsdigita.dispatcher.DispatcherHelper;
import com.arsdigita.dispatcher.RequestContext; import com.arsdigita.dispatcher.RequestContext;
import com.arsdigita.domain.DataObjectNotFoundException; import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.domain.DomainObjectFactory; import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.globalization.GlobalizationHelper;
import com.arsdigita.kernel.ACSObjectCache; import com.arsdigita.kernel.ACSObjectCache;
import com.arsdigita.kernel.Kernel; import com.arsdigita.kernel.Kernel;
import com.arsdigita.kernel.Party; import com.arsdigita.kernel.Party;
@ -60,6 +61,17 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
/**
*
* Repaired ItemURLCache to save multilingual items with automatic
* language negotiation. The cahce now uses the remaining url part
* and the language concatinated as a hash table key. The delimiter
* is CACHE_KEY_DELIMITER.
*
* @author unknown
* @author Sören Bernstein <sbernstein@quasiweb.de>
*/
public class ContentSectionServlet extends BaseApplicationServlet { public class ContentSectionServlet extends BaseApplicationServlet {
private static final String[] WELCOME_FILES = new String[] { private static final String[] WELCOME_FILES = new String[] {
@ -92,6 +104,8 @@ public class ContentSectionServlet extends BaseApplicationServlet {
private static boolean s_cacheItems = true; private static boolean s_cacheItems = true;
private static final String CACHE_KEY_DELIMITER = "%";
/** /**
* @see com.arsdigita.web.BaseApplicationServlet#doService * @see com.arsdigita.web.BaseApplicationServlet#doService
* (HttpServletRequest, HttpServletResponse, Application) * (HttpServletRequest, HttpServletResponse, Application)
@ -335,7 +349,12 @@ public class ContentSectionServlet extends BaseApplicationServlet {
s_log.debug("Trying to get content item for URL " + url + s_log.debug("Trying to get content item for URL " + url +
" from cache"); " from cache");
} }
item = itemURLCacheGet(section, url);
// Get the negotiated locale
String lang = GlobalizationHelper.getNegotiatedLocale().getLanguage();
item = itemURLCacheGet(section, url, lang);
item = null;
if (item == null) { if (item == null) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
@ -345,7 +364,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
} }
//item not cached, so retreive it and cache it //item not cached, so retreive it and cache it
item = itemResolver.getItem(section, url, ContentItem.LIVE); item = itemResolver.getItem(section, url, ContentItem.LIVE);
itemURLCachePut(section, url, item); itemURLCachePut(section, url, lang, item);
} else if (s_log.isDebugEnabled()) { } else if (s_log.isDebugEnabled()) {
s_log.debug("Found content item in cache"); s_log.debug("Found content item in cache");
} }
@ -417,9 +436,10 @@ public class ContentSectionServlet extends BaseApplicationServlet {
private static synchronized void itemURLCachePut(ContentSection section, private static synchronized void itemURLCachePut(ContentSection section,
String sURL, String sURL,
String lang,
BigDecimal itemID) { BigDecimal itemID) {
getItemURLCache(section).put(sURL, itemID); getItemURLCache(section).put(sURL + CACHE_KEY_DELIMITER + lang, itemID);
} }
/** /**
@ -430,15 +450,16 @@ public class ContentSectionServlet extends BaseApplicationServlet {
*/ */
public static synchronized void itemURLCachePut(ContentSection section, public static synchronized void itemURLCachePut(ContentSection section,
String sURL, String sURL,
String lang,
ContentItem item) { ContentItem item) {
if (sURL == null || item == null) { if (sURL == null || item == null) {
return; return;
} }
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("adding cached entry for url " + sURL); s_log.debug("adding cached entry for url " + sURL + " and language " + lang);
} }
itemURLCachePut(section, sURL, item.getID()); itemURLCachePut(section, sURL, lang, item.getID());
} }
/** /**
@ -447,11 +468,12 @@ public class ContentSectionServlet extends BaseApplicationServlet {
* @param sURL the cache entry key to remove * @param sURL the cache entry key to remove
*/ */
public static synchronized void itemURLCacheRemove(ContentSection section, public static synchronized void itemURLCacheRemove(ContentSection section,
String sURL) { String sURL,
String lang) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("removing cached entry for url " + sURL); s_log.debug("removing cached entry for url " + sURL + "and language " + lang);
} }
getItemURLCache(section).remove(sURL); getItemURLCache(section).remove(sURL + CACHE_KEY_DELIMITER + lang);
} }
/** /**
@ -461,8 +483,10 @@ public class ContentSectionServlet extends BaseApplicationServlet {
* @return the ContentItem in the cache, or null * @return the ContentItem in the cache, or null
*/ */
public static ContentItem itemURLCacheGet(ContentSection section, public static ContentItem itemURLCacheGet(ContentSection section,
final String sURL) { final String sURL,
final BigDecimal itemID = (BigDecimal) getItemURLCache(section).get(sURL); final String lang) {
final BigDecimal itemID = (BigDecimal) getItemURLCache(section)
.get(sURL + CACHE_KEY_DELIMITER + lang);
if (itemID == null) { if (itemID == null) {
return null; return null;