Redirect to URL with language extension for ccm-navigation
git-svn-id: https://svn.libreccm.org/ccm/trunk@4920 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
e9da0a7fce
commit
9b80ee7a9e
|
|
@ -145,6 +145,7 @@ public class ApplicationFileServlet extends BaseApplicationServlet {
|
||||||
* @throws ServletException
|
* @throws ServletException
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected void doService(HttpServletRequest sreq,
|
protected void doService(HttpServletRequest sreq,
|
||||||
HttpServletResponse sresp,
|
HttpServletResponse sresp,
|
||||||
Application app)
|
Application app)
|
||||||
|
|
@ -153,6 +154,10 @@ public class ApplicationFileServlet extends BaseApplicationServlet {
|
||||||
RequestDispatcher rd = m_resolver.resolve(m_templatePath,
|
RequestDispatcher rd = m_resolver.resolve(m_templatePath,
|
||||||
sreq, sresp, app);
|
sreq, sresp, app);
|
||||||
|
|
||||||
|
if (sresp.isCommitted()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (rd == null) {
|
if (rd == null) {
|
||||||
if (s_log.isDebugEnabled()) {
|
if (s_log.isDebugEnabled()) {
|
||||||
s_log.debug("No template found, sending 404");
|
s_log.debug("No template found, sending 404");
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,6 @@ public final class NavigationConfig extends AbstractConfig {
|
||||||
// Quasimodo: End
|
// Quasimodo: End
|
||||||
private final Parameter m_dateOrderCategories;
|
private final Parameter m_dateOrderCategories;
|
||||||
private final Parameter m_topLevelDateOrderCategories;
|
private final Parameter m_topLevelDateOrderCategories;
|
||||||
private final Parameter m_useLanguageExtension;
|
|
||||||
/**
|
/**
|
||||||
* Class that provides categories included in menu for any categories that
|
* Class that provides categories included in menu for any categories that
|
||||||
* do not have an alternative provider registered
|
* do not have an alternative provider registered
|
||||||
|
|
@ -176,11 +175,6 @@ public final class NavigationConfig extends AbstractConfig {
|
||||||
"com.arsdigita.navigation.default_menu_cat_provider",
|
"com.arsdigita.navigation.default_menu_cat_provider",
|
||||||
Parameter.OPTIONAL, null);
|
Parameter.OPTIONAL, null);
|
||||||
|
|
||||||
m_useLanguageExtension = new BooleanParameter(
|
|
||||||
"com.arsdigita.navigation.use_language_extension",
|
|
||||||
Parameter.OPTIONAL,
|
|
||||||
false);
|
|
||||||
|
|
||||||
register(m_indexPageCacheLifetime);
|
register(m_indexPageCacheLifetime);
|
||||||
register(m_generateItemURL);
|
register(m_generateItemURL);
|
||||||
register(m_defaultTemplate);
|
register(m_defaultTemplate);
|
||||||
|
|
@ -203,7 +197,6 @@ public final class NavigationConfig extends AbstractConfig {
|
||||||
register(m_dateOrderCategories);
|
register(m_dateOrderCategories);
|
||||||
register(m_topLevelDateOrderCategories);
|
register(m_topLevelDateOrderCategories);
|
||||||
register(m_defaultMenuCatProvider);
|
register(m_defaultMenuCatProvider);
|
||||||
register(m_useLanguageExtension);
|
|
||||||
loadInfo();
|
loadInfo();
|
||||||
|
|
||||||
// Quasimodo: Begin
|
// Quasimodo: Begin
|
||||||
|
|
@ -432,8 +425,4 @@ public final class NavigationConfig extends AbstractConfig {
|
||||||
return m_treeCatProvider;
|
return m_treeCatProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getUseLanguageExtension() {
|
|
||||||
return (Boolean) get(m_useLanguageExtension);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,3 @@ com.arsdigita.navigation.default_menu_cat_provider.purpose=Class that provides c
|
||||||
com.arsdigita.navigation.default_menu_cat_provider.example=com.arsdigita.navigation.ui.category.TreeCatProviderImpl
|
com.arsdigita.navigation.default_menu_cat_provider.example=com.arsdigita.navigation.ui.category.TreeCatProviderImpl
|
||||||
com.arsdigita.navigation.default_menu_cat_provider.format=[class]
|
com.arsdigita.navigation.default_menu_cat_provider.format=[class]
|
||||||
|
|
||||||
com.arsdigita.navigation.use_language_extension.title=Use language extension
|
|
||||||
com.arsdigita.navigation.use_language_extension.purpose=Use language extension to distiguish language version.
|
|
||||||
com.arsdigita.navigation.use_language_extension.example=true
|
|
||||||
com.arsdigita.navigation.use_language_extension.format=[Boolean]
|
|
||||||
|
|
@ -31,7 +31,9 @@ import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.arsdigita.categorization.Category;
|
import com.arsdigita.categorization.Category;
|
||||||
import com.arsdigita.categorization.CategoryCollection;
|
import com.arsdigita.categorization.CategoryCollection;
|
||||||
|
import com.arsdigita.cms.CMSConfig;
|
||||||
import com.arsdigita.cms.TemplateContext;
|
import com.arsdigita.cms.TemplateContext;
|
||||||
|
import com.arsdigita.dispatcher.DispatcherHelper;
|
||||||
import com.arsdigita.domain.DomainCollection;
|
import com.arsdigita.domain.DomainCollection;
|
||||||
import com.arsdigita.london.terms.Domain;
|
import com.arsdigita.london.terms.Domain;
|
||||||
import com.arsdigita.persistence.DataCollection;
|
import com.arsdigita.persistence.DataCollection;
|
||||||
|
|
@ -45,6 +47,8 @@ import com.arsdigita.web.Web;
|
||||||
|
|
||||||
import com.arsdigita.globalization.GlobalizationHelper;
|
import com.arsdigita.globalization.GlobalizationHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages the processing of URLs in the Navigation application.
|
* Manages the processing of URLs in the Navigation application.
|
||||||
*
|
*
|
||||||
|
|
@ -54,7 +58,8 @@ public class NavigationFileResolver extends DefaultApplicationFileResolver {
|
||||||
private static final Logger s_log = Logger.getLogger(
|
private static final Logger s_log = Logger.getLogger(
|
||||||
NavigationFileResolver.class);
|
NavigationFileResolver.class);
|
||||||
private static final String CATEGORY_PATH_ATTR
|
private static final String CATEGORY_PATH_ATTR
|
||||||
= NavigationFileResolver.class + ".categoryPath";
|
= NavigationFileResolver.class
|
||||||
|
+ ".categoryPath";
|
||||||
// path is set in a cookie, which navigation models may use if they wish
|
// path is set in a cookie, which navigation models may use if they wish
|
||||||
public static final String PATH_COOKIE_NAME = "ad_path";
|
public static final String PATH_COOKIE_NAME = "ad_path";
|
||||||
public static final char PATH_COOKIE_SEPARATOR = '|';
|
public static final char PATH_COOKIE_SEPARATOR = '|';
|
||||||
|
|
@ -73,12 +78,42 @@ public class NavigationFileResolver extends DefaultApplicationFileResolver {
|
||||||
s_log.debug("Resolving " + path);
|
s_log.debug("Resolving " + path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Navigation.getConfig().getUseLanguageExtension()
|
if (CMSConfig.getInstanceOf().getUseLanguageExtension()
|
||||||
&& path.matches("(.*)/index\\.[a-zA-Z]{2}")) {
|
&& path.matches("(.*)/index\\.[a-zA-Z]{2}")) {
|
||||||
|
|
||||||
final String lang = path.substring(path.length() - 2);
|
final String lang = path.substring(path.length() - 2);
|
||||||
path = path.substring(0, path.length() - "index.$$".length());
|
path = path.substring(0, path.length() - "index.$$".length());
|
||||||
GlobalizationHelper.setSelectedLocale(lang);
|
GlobalizationHelper.setSelectedLocale(lang);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
final String lang;
|
||||||
|
if (GlobalizationHelper.getSelectedLocale(sreq) == null) {
|
||||||
|
lang = GlobalizationHelper.getNegotiatedLocale().getLanguage();
|
||||||
|
} else {
|
||||||
|
lang = GlobalizationHelper.getSelectedLocale(sreq).getLanguage();
|
||||||
|
}
|
||||||
|
|
||||||
|
final StringBuffer redirectTo = new StringBuffer();
|
||||||
|
if (DispatcherHelper.getWebappContext() != null
|
||||||
|
&& !DispatcherHelper.getWebappContext().trim().isEmpty()) {
|
||||||
|
redirectTo.append(DispatcherHelper.getWebappContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
redirectTo
|
||||||
|
.append("/ccm")
|
||||||
|
.append(app.getPath())
|
||||||
|
.append(path)
|
||||||
|
.append("index.")
|
||||||
|
.append(lang);
|
||||||
|
|
||||||
|
|
||||||
|
sresp.setHeader("Location", redirectTo.toString());
|
||||||
|
try {
|
||||||
|
sresp.sendError(HttpServletResponse.SC_MOVED_PERMANENTLY);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path.equals("/category.jsp")) {
|
if (path.equals("/category.jsp")) {
|
||||||
|
|
@ -271,7 +306,7 @@ public class NavigationFileResolver extends DefaultApplicationFileResolver {
|
||||||
// If there's an explicit use context which doesn't exist, give a 404
|
// If there's an explicit use context which doesn't exist, give a 404
|
||||||
if (!Template.DEFAULT_USE_CONTEXT.equals(useContext) && null == template) {
|
if (!Template.DEFAULT_USE_CONTEXT.equals(useContext) && null == template) {
|
||||||
s_log.debug("No template found in context " + getTemplateContext()
|
s_log.debug("No template found in context " + getTemplateContext()
|
||||||
+ " for category " + cat.getID()
|
+ " for category " + cat.getID()
|
||||||
+ " with use context " + useContext);
|
+ " with use context " + useContext);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue