Redirect to URL with language extension for content item view
git-svn-id: https://svn.libreccm.org/ccm/trunk@4919 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
11ba1d550f
commit
e9da0a7fce
|
|
@ -69,7 +69,8 @@ import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NOTE:
|
* NOTE:
|
||||||
|
|
@ -79,7 +80,7 @@ import org.apache.log4j.Logger;
|
||||||
* is CACHE_KEY_DELIMITER.
|
* is CACHE_KEY_DELIMITER.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NOTE 2:
|
* NOTE 2:
|
||||||
* In a process of refactoring from legacy compatible to legacy free applications.
|
* In a process of refactoring from legacy compatible to legacy free applications.
|
||||||
* TODO:
|
* TODO:
|
||||||
|
|
@ -88,11 +89,11 @@ import org.apache.log4j.Logger;
|
||||||
* - Refactor content item UI bebop ApplicationPage or PageFactory instead of
|
* - Refactor content item UI bebop ApplicationPage or PageFactory instead of
|
||||||
* legacy infected sitenode / package dispatchers.
|
* legacy infected sitenode / package dispatchers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Content Section's Application Servlet according CCM core web application
|
* Content Section's Application Servlet according CCM core web application
|
||||||
* structure {@see com.arsdigita.web.Application} implements the content
|
* structure {
|
||||||
* section UI.
|
*
|
||||||
|
* @see com.arsdigita.web.Application} implements the content section UI.
|
||||||
*
|
*
|
||||||
* It handles the UI for content items and delegates the UI for sections and
|
* It handles the UI for content items and delegates the UI for sections and
|
||||||
* folders to jsp templates.
|
* folders to jsp templates.
|
||||||
|
|
@ -103,60 +104,77 @@ import org.apache.log4j.Logger;
|
||||||
*/
|
*/
|
||||||
public class ContentSectionServlet extends BaseApplicationServlet {
|
public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
|
|
||||||
/** Internal logger instance to faciliate debugging. Enable logging output
|
/**
|
||||||
* by editing /WEB-INF/conf/log4j.properties int hte runtime environment
|
* Internal logger instance to faciliate debugging. Enable logging output by
|
||||||
* and set com.arsdigita.cms.ContentSectionServlet=DEBUG
|
* editing /WEB-INF/conf/log4j.properties int hte runtime environment and
|
||||||
* by uncommenting or adding the line. */
|
* set com.arsdigita.cms.ContentSectionServlet=DEBUG by uncommenting or
|
||||||
private static final Logger s_log =
|
* adding the line.
|
||||||
Logger.getLogger(ContentSectionServlet.class);
|
*/
|
||||||
/** Stringarray of file name patterns for index files. */
|
private static final Logger s_log = LogManager.getLogger(
|
||||||
|
ContentSectionServlet.class);
|
||||||
|
/**
|
||||||
|
* Stringarray of file name patterns for index files.
|
||||||
|
*/
|
||||||
// private static final String[] WELCOME_FILES = new String[]{
|
// private static final String[] WELCOME_FILES = new String[]{
|
||||||
// "index.jsp", "index.html"
|
// "index.jsp", "index.html"
|
||||||
// };
|
// };
|
||||||
|
|
||||||
// Some literals
|
// Some literals
|
||||||
|
/**
|
||||||
/** Literal for the prefix (in url) for previewing items */
|
* Literal for the prefix (in url) for previewing items
|
||||||
|
*/
|
||||||
public static final String PREVIEW = "/preview";
|
public static final String PREVIEW = "/preview";
|
||||||
/** Literal Template files suffix */
|
/**
|
||||||
|
* Literal Template files suffix
|
||||||
|
*/
|
||||||
public static final String FILE_SUFFIX = ".jsp";
|
public static final String FILE_SUFFIX = ".jsp";
|
||||||
/** Literal of URL Stub for index file name (includes leading slash) */
|
/**
|
||||||
|
* Literal of URL Stub for index file name (includes leading slash)
|
||||||
|
*/
|
||||||
public static final String INDEX_FILE = "/index";
|
public static final String INDEX_FILE = "/index";
|
||||||
public static final String XML_SUFFIX = ".xml";
|
public static final String XML_SUFFIX = ".xml";
|
||||||
public static final String XML_MODE = "xmlMode";
|
public static final String XML_MODE = "xmlMode";
|
||||||
public static final String MEDIA_TYPE = "templateContext";
|
public static final String MEDIA_TYPE = "templateContext";
|
||||||
private static final String CACHE_KEY_DELIMITER = "%";
|
private static final String CACHE_KEY_DELIMITER = "%";
|
||||||
|
|
||||||
public static final String CONTENT_ITEM =
|
public static final String CONTENT_ITEM
|
||||||
"com.arsdigita.cms.dispatcher.item";
|
= "com.arsdigita.cms.dispatcher.item";
|
||||||
public static final String CONTENT_SECTION =
|
public static final String CONTENT_SECTION
|
||||||
"com.arsdigita.cms.dispatcher.section";
|
= "com.arsdigita.cms.dispatcher.section";
|
||||||
|
|
||||||
private final ContentItemDispatcher m_disp = new ContentItemDispatcher();
|
private final ContentItemDispatcher m_disp = new ContentItemDispatcher();
|
||||||
public static Map s_itemResolverCache = Collections
|
public static Map s_itemResolverCache = Collections
|
||||||
.synchronizedMap(new HashMap());
|
.synchronizedMap(new HashMap());
|
||||||
private static Map s_itemURLCacheMap = null;
|
private static Map s_itemURLCacheMap = null;
|
||||||
/** Whether to cache the content items */
|
/**
|
||||||
|
* Whether to cache the content items
|
||||||
|
*/
|
||||||
private static final boolean s_cacheItems = true;
|
private static final boolean s_cacheItems = true;
|
||||||
// NEW STUFF here used to process the pages in this servlet
|
// NEW STUFF here used to process the pages in this servlet
|
||||||
/** URL (pathinfo) -> Page object mapping. Based on it (and the http
|
/**
|
||||||
* request url) the doService method selects a page to display */
|
* URL (pathinfo) -> Page object mapping. Based on it (and the http request
|
||||||
|
* url) the doService method selects a page to display
|
||||||
|
*/
|
||||||
private final Map m_pages = new HashMap();
|
private final Map m_pages = new HashMap();
|
||||||
/** Path to directory containg ccm-cms template (jsp) files */
|
/**
|
||||||
|
* Path to directory containg ccm-cms template (jsp) files
|
||||||
|
*/
|
||||||
private String m_templatePath;
|
private String m_templatePath;
|
||||||
|
|
||||||
/** Resolver to actually use to find templates (JSP). JSP may be stored in
|
/**
|
||||||
* file system or otherwise, depends on resolver. Resolver is retrieved
|
* Resolver to actually use to find templates (JSP). JSP may be stored in
|
||||||
* from configuration.
|
* file system or otherwise, depends on resolver. Resolver is retrieved from
|
||||||
* (probably used for other stuff as JSP's as well) */
|
* configuration. (probably used for other stuff as JSP's as well)
|
||||||
|
*/
|
||||||
private ApplicationFileResolver m_resolver;
|
private ApplicationFileResolver m_resolver;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init method overwrites parents init to pass in optional parameters
|
* Init method overwrites parents init to pass in optional parameters
|
||||||
* {@link com.arsdigita.web.BaseServlet}. If not specified system wide
|
* {@link com.arsdigita.web.BaseServlet}. If not specified system wide
|
||||||
* defaults are used.
|
* defaults are used.
|
||||||
|
*
|
||||||
* @param config
|
* @param config
|
||||||
|
*
|
||||||
* @throws javax.servlet.ServletException
|
* @throws javax.servlet.ServletException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -179,17 +197,17 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
Assert.isTrue(!m_templatePath.endsWith("/"),
|
Assert.isTrue(!m_templatePath.endsWith("/"),
|
||||||
"template-path must not end with '/'");
|
"template-path must not end with '/'");
|
||||||
|
|
||||||
|
|
||||||
// optional init-param named file-resolver from ~/WEB-INF/web.xml
|
// optional init-param named file-resolver from ~/WEB-INF/web.xml
|
||||||
String resolverName = config.getInitParameter("file-resolver");
|
String resolverName = config.getInitParameter("file-resolver");
|
||||||
if (resolverName == null) {
|
if (resolverName == null) {
|
||||||
m_resolver = Web.getConfig().getApplicationFileResolver();
|
m_resolver = Web.getConfig().getApplicationFileResolver();
|
||||||
} else {
|
} else {
|
||||||
m_resolver = (ApplicationFileResolver) Classes.newInstance(resolverName);
|
m_resolver = (ApplicationFileResolver) Classes.newInstance(
|
||||||
|
resolverName);
|
||||||
}
|
}
|
||||||
if (s_log.isDebugEnabled()) {
|
if (s_log.isDebugEnabled()) {
|
||||||
s_log.debug("Template path is " + m_templatePath +
|
s_log.debug("Template path is " + m_templatePath + " with resolver "
|
||||||
" with resolver " + m_resolver.
|
+ m_resolver.
|
||||||
getClass().getName());
|
getClass().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -198,15 +216,14 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
// addPage("/admin", new MainPage()); // index page at address ~/cs
|
// addPage("/admin", new MainPage()); // index page at address ~/cs
|
||||||
// addPage("/admin/index.jsp", new MainPage());
|
// addPage("/admin/index.jsp", new MainPage());
|
||||||
// addPage("/admin/item.jsp", new MainPage());
|
// addPage("/admin/item.jsp", new MainPage());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal service method, adds one pair of Url - Page to the internal
|
* Internal service method, adds one pair of Url - Page to the internal hash
|
||||||
* hash map, used as a cache.
|
* map, used as a cache.
|
||||||
*
|
*
|
||||||
* @param pathInfo url stub for a page to display
|
* @param pathInfo url stub for a page to display
|
||||||
* @param page Page object to display
|
* @param page Page object to display
|
||||||
*/
|
*/
|
||||||
private void addPage(final String pathInfo, final Page page) {
|
private void addPage(final String pathInfo, final Page page) {
|
||||||
|
|
||||||
|
|
@ -220,17 +237,18 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
m_pages.put(pathInfo, page);
|
m_pages.put(pathInfo, page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of parent's (abstract) doService method checks HTTP request
|
* Implementation of parent's (abstract) doService method checks HTTP
|
||||||
* to determine whether to handle a content item or other stuff which is
|
* request to determine whether to handle a content item or other stuff
|
||||||
* delegated to jsp templates.
|
* which is delegated to jsp templates. {
|
||||||
* {@see com.arsdigita.web.BaseApplicationServlet#doService
|
*
|
||||||
* (HttpServletRequest, HttpServletResponse, Application)}
|
* @see com.arsdigita.web.BaseApplicationServlet#doService
|
||||||
|
* (HttpServletRequest, HttpServletResponse, Application)}
|
||||||
*
|
*
|
||||||
* @param sreq
|
* @param sreq
|
||||||
* @param sresp
|
* @param sresp
|
||||||
* @param app
|
* @param app
|
||||||
|
*
|
||||||
* @throws javax.servlet.ServletException
|
* @throws javax.servlet.ServletException
|
||||||
* @throws java.io.IOException
|
* @throws java.io.IOException
|
||||||
*/
|
*/
|
||||||
|
|
@ -238,7 +256,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
protected void doService(HttpServletRequest sreq,
|
protected void doService(HttpServletRequest sreq,
|
||||||
HttpServletResponse sresp,
|
HttpServletResponse sresp,
|
||||||
Application app)
|
Application app)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
|
|
||||||
ContentSection section = (ContentSection) app;
|
ContentSection section = (ContentSection) app;
|
||||||
|
|
||||||
|
|
@ -265,10 +283,71 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
String pathInfo = sreq.getPathInfo();
|
String pathInfo = sreq.getPathInfo();
|
||||||
s_log.debug("Path info is: " + pathInfo);
|
s_log.debug("Path info is: " + pathInfo);
|
||||||
|
|
||||||
final ContentItem item = getItem(section, pathInfo, itemResolver);
|
if (CMSConfig.getInstanceOf().getUseLanguageExtension()
|
||||||
|
&& (!pathInfo.endsWith(".jsp")
|
||||||
|
|| !pathInfo.endsWith(".xml"))) {
|
||||||
|
|
||||||
Assert.exists(pathInfo, "String pathInfo");
|
if (pathInfo.lastIndexOf(".") == -1) {
|
||||||
if (pathInfo.length() > 1 && pathInfo.endsWith("/")) {
|
final String lang;
|
||||||
|
if (GlobalizationHelper.getSelectedLocale(sreq) == null) {
|
||||||
|
lang = GlobalizationHelper
|
||||||
|
.getNegotiatedLocale()
|
||||||
|
.getLanguage();
|
||||||
|
} else {
|
||||||
|
lang = GlobalizationHelper
|
||||||
|
.getSelectedLocale(sreq)
|
||||||
|
.getLanguage();
|
||||||
|
}
|
||||||
|
// try {
|
||||||
|
final StringBuffer redirectTo = new StringBuffer();
|
||||||
|
if (DispatcherHelper.getWebappContext() != null
|
||||||
|
&& !DispatcherHelper.getWebappContext().trim()
|
||||||
|
.isEmpty()) {
|
||||||
|
|
||||||
|
redirectTo
|
||||||
|
.append("/")
|
||||||
|
.append(DispatcherHelper.getWebappContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
redirectTo
|
||||||
|
.append("/ccm")
|
||||||
|
.append(section.getPath());
|
||||||
|
if (pathInfo.endsWith("/")) {
|
||||||
|
redirectTo
|
||||||
|
// .append("/")
|
||||||
|
.append(pathInfo.substring(0,
|
||||||
|
pathInfo.length() - 1));
|
||||||
|
} else {
|
||||||
|
redirectTo
|
||||||
|
// .append("/")
|
||||||
|
.append(pathInfo);
|
||||||
|
}
|
||||||
|
redirectTo
|
||||||
|
.append(".").append(lang);
|
||||||
|
|
||||||
|
sresp.setHeader("Location", redirectTo.toString());
|
||||||
|
sresp.sendError(HttpServletResponse.SC_MOVED_PERMANENTLY);
|
||||||
|
// sreq
|
||||||
|
// .getRequestDispatcher(redirectTo.toString())
|
||||||
|
// .forward(sreq, sresp);
|
||||||
|
return;
|
||||||
|
// } catch (ServletException | IOException ex) {
|
||||||
|
// throw new RuntimeException(ex);
|
||||||
|
// }
|
||||||
|
|
||||||
|
} else {
|
||||||
|
final String lang = url.substring(url.lastIndexOf("."));
|
||||||
|
GlobalizationHelper.setSelectedLocale(lang);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final ContentItem item = getItem(section, pathInfo, sreq, sresp,
|
||||||
|
itemResolver);
|
||||||
|
|
||||||
|
Assert.exists(pathInfo,
|
||||||
|
"String pathInfo");
|
||||||
|
if (pathInfo.length()
|
||||||
|
> 1 && pathInfo.endsWith("/")) {
|
||||||
/* NOTE: ServletAPI specifies, pathInfo may be empty or will
|
/* NOTE: ServletAPI specifies, pathInfo may be empty or will
|
||||||
* start with a '/' character. It currently carries a
|
* start with a '/' character. It currently carries a
|
||||||
* trailing '/' if a "virtual" page, i.e. not a real jsp, but
|
* trailing '/' if a "virtual" page, i.e. not a real jsp, but
|
||||||
|
|
@ -276,18 +355,18 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
* NOT to end with a trailing '/' for legacy free applications. */
|
* NOT to end with a trailing '/' for legacy free applications. */
|
||||||
pathInfo = pathInfo.substring(0, pathInfo.length() - 1);
|
pathInfo = pathInfo.substring(0, pathInfo.length() - 1);
|
||||||
}
|
}
|
||||||
final Page page = (Page) m_pages.get(pathInfo);
|
|
||||||
|
|
||||||
|
final Page page = (Page) m_pages.get(pathInfo);
|
||||||
|
|
||||||
// ////////////////////////////////////////////////////////////////////
|
// ////////////////////////////////////////////////////////////////////
|
||||||
// Serve the page
|
// Serve the page
|
||||||
// ////////////////////////////////////////////////////////////////////
|
// ////////////////////////////////////////////////////////////////////
|
||||||
/* FIRST try new style servlet based service */
|
/* FIRST try new style servlet based service */
|
||||||
if (page != null) {
|
if (page
|
||||||
|
!= null) {
|
||||||
|
|
||||||
// Check user access.
|
// Check user access.
|
||||||
// checkUserAccess(sreq, sresp); // done in individual pages ??
|
// checkUserAccess(sreq, sresp); // done in individual pages ??
|
||||||
|
|
||||||
if (page instanceof CMSPage) {
|
if (page instanceof CMSPage) {
|
||||||
// backwards compatibility fix until migration completed
|
// backwards compatibility fix until migration completed
|
||||||
final CMSPage cmsPage = (CMSPage) page;
|
final CMSPage cmsPage = (CMSPage) page;
|
||||||
|
|
@ -304,8 +383,9 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
pm.servePage(doc, sreq, sresp);
|
pm.servePage(doc, sreq, sresp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* SECONDLY try if we have to serve an item (old style dispatcher based */
|
/* SECONDLY try if we have to serve an item (old style dispatcher based */
|
||||||
} else if (item != null) {
|
} else if (item
|
||||||
|
!= null) {
|
||||||
|
|
||||||
/* We have to serve an item here */
|
/* We have to serve an item here */
|
||||||
String param = sreq.getParameter("transID");
|
String param = sreq.getParameter("transID");
|
||||||
|
|
@ -314,6 +394,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
Session ssn = SessionManager.getSession();
|
Session ssn = SessionManager.getSession();
|
||||||
TransactionContext txn = ssn.getTransactionContext();
|
TransactionContext txn = ssn.getTransactionContext();
|
||||||
txn.addTransactionListener(new AbstractTransactionListener() {
|
txn.addTransactionListener(new AbstractTransactionListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeCommit(TransactionContext txn) {
|
public void beforeCommit(TransactionContext txn) {
|
||||||
Assert.fail("uncommittable transaction");
|
Assert.fail("uncommittable transaction");
|
||||||
|
|
@ -329,7 +410,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
|
|
||||||
serveItem(sreq, sresp, section, item);
|
serveItem(sreq, sresp, section, item);
|
||||||
|
|
||||||
/* OTHERWISE delegate to a JSP in file system */
|
/* OTHERWISE delegate to a JSP in file system */
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* We have to deal with a content-section, folder or another bit */
|
/* We have to deal with a content-section, folder or another bit */
|
||||||
|
|
@ -357,8 +438,8 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
sresp.sendError(404, requestUri + " not found on this server.");
|
sresp.sendError(404, requestUri + " not found on this server.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // END doService
|
|
||||||
|
|
||||||
|
} // END doService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -366,6 +447,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
* @param sresp
|
* @param sresp
|
||||||
* @param section
|
* @param section
|
||||||
* @param item
|
* @param item
|
||||||
|
*
|
||||||
* @throws ServletException
|
* @throws ServletException
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
|
|
@ -373,7 +455,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
HttpServletResponse sresp,
|
HttpServletResponse sresp,
|
||||||
ContentSection section,
|
ContentSection section,
|
||||||
ContentItem item)
|
ContentItem item)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
|
|
||||||
if (s_log.isInfoEnabled()) {
|
if (s_log.isInfoEnabled()) {
|
||||||
s_log.info("serving content item");
|
s_log.info("serving content item");
|
||||||
|
|
@ -389,8 +471,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
sreq.setAttribute(CONTENT_ITEM, item);
|
sreq.setAttribute(CONTENT_ITEM, item);
|
||||||
|
|
||||||
//set the template context
|
//set the template context
|
||||||
TemplateResolver templateResolver =
|
TemplateResolver templateResolver = m_disp.getTemplateResolver(section);
|
||||||
m_disp.getTemplateResolver(section);
|
|
||||||
|
|
||||||
String templateURL = url;
|
String templateURL = url;
|
||||||
if (!templateURL.startsWith("/")) {
|
if (!templateURL.startsWith("/")) {
|
||||||
|
|
@ -414,7 +495,8 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
Date endDate = cycle.getEndDate();
|
Date endDate = cycle.getEndDate();
|
||||||
|
|
||||||
if (endDate != null) {
|
if (endDate != null) {
|
||||||
int maxAge = (int) ((endDate.getTime() - System.currentTimeMillis()) / 1000l);
|
int maxAge = (int) ((endDate.getTime() - System
|
||||||
|
.currentTimeMillis()) / 1000l);
|
||||||
if (maxAge < expires) {
|
if (maxAge < expires) {
|
||||||
expires = maxAge;
|
expires = maxAge;
|
||||||
}
|
}
|
||||||
|
|
@ -443,7 +525,9 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
* Fetches the content section from the request attributes.
|
* Fetches the content section from the request attributes.
|
||||||
*
|
*
|
||||||
* @param request The HTTP request
|
* @param request The HTTP request
|
||||||
|
*
|
||||||
* @return The content section
|
* @return The content section
|
||||||
|
*
|
||||||
* @pre ( request != null )
|
* @pre ( request != null )
|
||||||
*/
|
*/
|
||||||
public static ContentSection getContentSection(HttpServletRequest request) {
|
public static ContentSection getContentSection(HttpServletRequest request) {
|
||||||
|
|
@ -454,6 +538,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
* Fetches the ItemResolver for a content section. Checks cache first.
|
* Fetches the ItemResolver for a content section. Checks cache first.
|
||||||
*
|
*
|
||||||
* @param section The content section
|
* @param section The content section
|
||||||
|
*
|
||||||
* @return The ItemResolver associated with the content section
|
* @return The ItemResolver associated with the content section
|
||||||
*/
|
*/
|
||||||
public ItemResolver getItemResolver(ContentSection section) {
|
public ItemResolver getItemResolver(ContentSection section) {
|
||||||
|
|
@ -473,20 +558,16 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
return ir;
|
return ir;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public ContentItem getItem(ContentSection section,
|
||||||
*
|
String url,
|
||||||
* @param section
|
HttpServletRequest request,
|
||||||
* @param url
|
HttpServletResponse response,
|
||||||
* @param itemResolver
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public ContentItem getItem(ContentSection section, String url,
|
|
||||||
ItemResolver itemResolver) {
|
ItemResolver itemResolver) {
|
||||||
|
|
||||||
if (s_log.isDebugEnabled()) {
|
if (s_log.isDebugEnabled()) {
|
||||||
s_log.debug("getting item at url " + url);
|
s_log.debug("getting item at url " + url);
|
||||||
}
|
}
|
||||||
HttpServletRequest request = Web.getRequest();
|
// HttpServletRequest request = Web.getRequest();
|
||||||
|
|
||||||
//first sanitize the url
|
//first sanitize the url
|
||||||
if (url.endsWith(XML_SUFFIX)) {
|
if (url.endsWith(XML_SUFFIX)) {
|
||||||
|
|
@ -495,8 +576,10 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
url = "/" + url.substring(0, url.length() - XML_SUFFIX.length());
|
url = "/" + url.substring(0, url.length() - XML_SUFFIX.length());
|
||||||
} else {
|
} else {
|
||||||
request.setAttribute(XML_MODE, Boolean.FALSE);
|
request.setAttribute(XML_MODE, Boolean.FALSE);
|
||||||
|
|
||||||
if (url.endsWith(FILE_SUFFIX)) {
|
if (url.endsWith(FILE_SUFFIX)) {
|
||||||
url = "/" + url.substring(0, url.length() - FILE_SUFFIX.length());
|
url = "/" + url
|
||||||
|
.substring(0, url.length() - FILE_SUFFIX.length());
|
||||||
} else if (url.endsWith("/")) {
|
} else if (url.endsWith("/")) {
|
||||||
url = "/" + url.substring(0, url.length() - 1);
|
url = "/" + url.substring(0, url.length() - 1);
|
||||||
}
|
}
|
||||||
|
|
@ -526,7 +609,8 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
|
|
||||||
item = itemResolver.getItem(section, url, CMSDispatcher.PREVIEW);
|
item = itemResolver.getItem(section, url, CMSDispatcher.PREVIEW);
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
hasPermission = sm.canAccess(request, SecurityManager.PREVIEW_PAGES, item);
|
hasPermission = sm.canAccess(request,
|
||||||
|
SecurityManager.PREVIEW_PAGES, item);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (s_log.isInfoEnabled()) {
|
if (s_log.isInfoEnabled()) {
|
||||||
|
|
@ -536,11 +620,13 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
//check if this item is in the cache
|
//check if this item is in the cache
|
||||||
//we only cache live items
|
//we only cache live items
|
||||||
if (s_log.isDebugEnabled()) {
|
if (s_log.isDebugEnabled()) {
|
||||||
s_log.debug("Trying to get content item for URL " + url + " from cache");
|
s_log.debug("Trying to get content item for URL " + url
|
||||||
|
+ " from cache");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the negotiated locale
|
// Get the negotiated locale
|
||||||
String lang = GlobalizationHelper.getNegotiatedLocale().getLanguage();
|
String lang = GlobalizationHelper.getNegotiatedLocale()
|
||||||
|
.getLanguage();
|
||||||
|
|
||||||
// XXX why assign a value and afterwards null??
|
// XXX why assign a value and afterwards null??
|
||||||
// Effectively it just ignores the cache and forces a fallback to
|
// Effectively it just ignores the cache and forces a fallback to
|
||||||
|
|
@ -552,7 +638,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
if (s_log.isDebugEnabled()) {
|
if (s_log.isDebugEnabled()) {
|
||||||
s_log.debug("Did not find content item in cache, so trying "
|
s_log.debug("Did not find content item in cache, so trying "
|
||||||
+ "to retrieve and cache...");
|
+ "to retrieve and cache...");
|
||||||
}
|
}
|
||||||
//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);
|
||||||
|
|
@ -615,10 +701,12 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContentItem getItem(ContentSection section, String url) {
|
public ContentItem getItem(ContentSection section, String url,
|
||||||
|
HttpServletRequest request,
|
||||||
|
HttpServletResponse response) {
|
||||||
ItemResolver itemResolver = getItemResolver(section);
|
ItemResolver itemResolver = getItemResolver(section);
|
||||||
|
|
||||||
return getItem(section, url, itemResolver);
|
return getItem(section, url, request, response, itemResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
// synchronize access to the item-url cache
|
// synchronize access to the item-url cache
|
||||||
|
|
@ -632,10 +720,11 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps the content item to the URL in a cache
|
* Maps the content item to the URL in a cache
|
||||||
|
*
|
||||||
* @param section the content section in which the content item is published
|
* @param section the content section in which the content item is published
|
||||||
* @param sURL the URL at which the content item s published
|
* @param sURL the URL at which the content item s published
|
||||||
* @param lang
|
* @param lang
|
||||||
* @param item the content item at the URL
|
* @param item the content item at the URL
|
||||||
*/
|
*/
|
||||||
public static synchronized void itemURLCachePut(ContentSection section,
|
public static synchronized void itemURLCachePut(ContentSection section,
|
||||||
String sURL,
|
String sURL,
|
||||||
|
|
@ -645,8 +734,8 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
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 "
|
||||||
" and language " + lang);
|
+ lang);
|
||||||
}
|
}
|
||||||
|
|
||||||
itemURLCachePut(section, sURL, lang, item.getID());
|
itemURLCachePut(section, sURL, lang, item.getID());
|
||||||
|
|
@ -654,16 +743,17 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the cache entry for the URL, sURL
|
* Removes the cache entry for the URL, sURL
|
||||||
|
*
|
||||||
* @param section the content section in which to remove the key
|
* @param section the content section in which to remove the key
|
||||||
* @param sURL the cache entry key to remove
|
* @param sURL the cache entry key to remove
|
||||||
* @param lang
|
* @param lang
|
||||||
*/
|
*/
|
||||||
public static synchronized void itemURLCacheRemove(ContentSection section,
|
public static synchronized void itemURLCacheRemove(ContentSection section,
|
||||||
String sURL,
|
String sURL,
|
||||||
String lang) {
|
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);
|
+ "and language " + lang);
|
||||||
}
|
}
|
||||||
getItemURLCache(section).remove(sURL + CACHE_KEY_DELIMITER + lang);
|
getItemURLCache(section).remove(sURL + CACHE_KEY_DELIMITER + lang);
|
||||||
}
|
}
|
||||||
|
|
@ -672,37 +762,41 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
* Fetches the ContentItem published at that URL from the cache.
|
* Fetches the ContentItem published at that URL from the cache.
|
||||||
*
|
*
|
||||||
* @param section the content section in which the content item is published
|
* @param section the content section in which the content item is published
|
||||||
* @param sURL the URL for the item to fetch
|
* @param sURL the URL for the item to fetch
|
||||||
* @param lang
|
* @param lang
|
||||||
|
*
|
||||||
* @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 String lang) {
|
final String lang) {
|
||||||
final BigDecimal itemID = (BigDecimal) getItemURLCache(section).get(
|
final BigDecimal itemID = (BigDecimal) getItemURLCache(section).get(
|
||||||
sURL + CACHE_KEY_DELIMITER + lang);
|
sURL + CACHE_KEY_DELIMITER + lang);
|
||||||
|
|
||||||
if (itemID == null) {
|
if (itemID == null) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
return (ContentItem) DomainObjectFactory.newInstance(new OID(
|
return (ContentItem) DomainObjectFactory.newInstance(new OID(
|
||||||
ContentItem.BASE_DATA_OBJECT_TYPE, itemID));
|
ContentItem.BASE_DATA_OBJECT_TYPE, itemID));
|
||||||
} catch (DataObjectNotFoundException donfe) {
|
} catch (DataObjectNotFoundException donfe) {
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static synchronized CacheTable getItemURLCache(ContentSection section) {
|
private static synchronized CacheTable getItemURLCache(
|
||||||
Assert.exists(section, ContentSection.class);
|
ContentSection section) {
|
||||||
|
Assert.exists(section, ContentSection.class
|
||||||
|
);
|
||||||
if (s_itemURLCacheMap == null) {
|
if (s_itemURLCacheMap == null) {
|
||||||
initializeItemURLCache();
|
initializeItemURLCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s_itemURLCacheMap.get(section.getPath()) == null) {
|
if (s_itemURLCacheMap.get(section.getPath()) == null) {
|
||||||
final CacheTable cache = new CacheTable("ContentSectionServletItemURLCache" +
|
final CacheTable cache = new CacheTable(
|
||||||
section.getID().toString());
|
"ContentSectionServletItemURLCache" + section.getID().toString());
|
||||||
s_itemURLCacheMap.put(section.getPath(), cache);
|
s_itemURLCacheMap.put(section.getPath(), cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -716,8 +810,8 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
ContentSection section = sections.getContentSection();
|
ContentSection section = sections.getContentSection();
|
||||||
String idStr = section.getID().toString();
|
String idStr = section.getID().toString();
|
||||||
String path = section.getPath();
|
String path = section.getPath();
|
||||||
CacheTable itemURLCache =
|
CacheTable itemURLCache = new CacheTable(
|
||||||
new CacheTable("ContentSectionServletItemURLCache" + idStr);
|
"ContentSectionServletItemURLCache" + idStr);
|
||||||
s_itemURLCacheMap.put(path, itemURLCache);
|
s_itemURLCacheMap.put(path, itemURLCache);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -725,10 +819,13 @@ public class ContentSectionServlet extends BaseApplicationServlet {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks that the current user has permission to access the admin pages.
|
* Checks that the current user has permission to access the admin pages.
|
||||||
|
*
|
||||||
* @param request
|
* @param request
|
||||||
* @param section
|
* @param section
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
**/
|
*
|
||||||
|
*/
|
||||||
public static boolean checkAdminAccess(HttpServletRequest request,
|
public static boolean checkAdminAccess(HttpServletRequest request,
|
||||||
ContentSection section) {
|
ContentSection section) {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -258,7 +258,7 @@ public class PublicationList extends AbstractComponent {
|
||||||
final ResultSet mainQueryResult = publicationsQueryStatement
|
final ResultSet mainQueryResult = publicationsQueryStatement
|
||||||
.executeQuery();
|
.executeQuery();
|
||||||
|
|
||||||
final Element listElem = Navigation.newElement("publication-list");
|
final Element listElem = Navigation.newElement("sci-publication-list");
|
||||||
|
|
||||||
final Element paginatorElem = listElem.newChildElement("paginator");
|
final Element paginatorElem = listElem.newChildElement("paginator");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue