diff --git a/applications/content/data/ContentHttpErrorData.xml b/applications/content/data/ContentHttpErrorData.xml new file mode 100644 index 0000000000..599e0dc1b7 --- /dev/null +++ b/applications/content/data/ContentHttpErrorData.xml @@ -0,0 +1,48 @@ + + + + + + + + Access Forbidden${statusCode?if_exists} Forbidden]]> + + + + + Page not found${statusCode?if_exists} Not Found]]> + + + + + + + Page inconnue${statusCode?if_exists} Page Inconnue]]> + + + + + + + Page is gone${statusCode?if_exists} Page is gone]]> + + + + diff --git a/applications/content/data/ContentTypeData.xml b/applications/content/data/ContentTypeData.xml index 79d52defb0..4bedb5fd50 100644 --- a/applications/content/data/ContentTypeData.xml +++ b/applications/content/data/ContentTypeData.xml @@ -190,6 +190,7 @@ under the License. + diff --git a/applications/content/ofbiz-component.xml b/applications/content/ofbiz-component.xml index 0c3aae93ec..c48842d67d 100644 --- a/applications/content/ofbiz-component.xml +++ b/applications/content/ofbiz-component.xml @@ -38,6 +38,7 @@ under the License. + diff --git a/applications/content/src/org/ofbiz/content/cms/CmsEvents.java b/applications/content/src/org/ofbiz/content/cms/CmsEvents.java index bedd0a3cf1..2f18dbf26f 100644 --- a/applications/content/src/org/ofbiz/content/cms/CmsEvents.java +++ b/applications/content/src/org/ofbiz/content/cms/CmsEvents.java @@ -31,6 +31,7 @@ import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpServletResponseWrapper; import javax.servlet.http.HttpSession; import org.ofbiz.base.util.Debug; @@ -183,25 +184,81 @@ public class CmsEvents { } // verify the request content is associated with the current website - boolean websiteOk; + int statusCode=-1; + boolean hasErrorPage=false; + try { - websiteOk = verifyContentToWebSite(delegator, webSiteId, contentId); + statusCode = verifyContentToWebSite(delegator, webSiteId, contentId); } catch (GeneralException e) { Debug.logError(e, module); throw new GeneralRuntimeException(e.getMessage(), e); } + + // We try to find a specific Error page for this website concerning the status code + if (statusCode!=HttpServletResponseWrapper.SC_OK) { + List errorContainers = null; + try { + errorContainers = delegator.findByAndCache("WebSiteContent", + UtilMisc.toMap("webSiteId", webSiteId, "webSiteContentTypeId", "ERROR_ROOT"), + UtilMisc.toList("-fromDate")); + } catch (GenericEntityException e) { + Debug.logError(e, module); + } - if (websiteOk) { + errorContainers = EntityUtil.filterByDate(errorContainers); + if (UtilValidate.isNotEmpty(errorContainers)) { + if (Debug.verboseOn()) Debug.logVerbose("Found error containers: " + errorContainers, module); + GenericValue errorContainer = EntityUtil.getFirst(errorContainers); + + List errorPages = null; + try { + errorPages = delegator.findByAnd("ContentAssocViewTo", UtilMisc.toMap("contentIdStart", errorContainer.getString("contentId"), "caContentAssocTypeId", "TREE_CHILD", "contentTypeId", "DOCUMENT", "caMapKey",""+statusCode)); + } catch (GenericEntityException e) { + Debug.logError(e, module); + } + errorPages = EntityUtil.filterByDate(errorPages); + if (UtilValidate.isNotEmpty(errorPages)) { + if (Debug.verboseOn()) Debug.logVerbose("Found error pages "+ statusCode + " : " + errorPages, module); + contentId=EntityUtil.getFirst(errorPages).getString("contentId"); + } + else { + if (Debug.verboseOn()) Debug.logVerbose("No specific error page, falling back to the Error Container for "+ statusCode, module); + contentId=errorContainer.getString("contentId"); + } + mapKey = null; + hasErrorPage=true; + } + // We try to find a generic content Error page concerning the status code + if (!hasErrorPage) { + try { + GenericValue errorPage = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", "CONTENT_ERROR_"+statusCode)); + if (errorPage!=null) { + Debug.logVerbose("Found generic page " + statusCode, module); + contentId=errorPage.getString("contentId"); + mapKey = null; + hasErrorPage=true; + } + } catch (GenericEntityException e) { + Debug.logError(e, module); + } + } + + } + + if (statusCode==HttpServletResponseWrapper.SC_OK || hasErrorPage) { // create the template map MapStack templateMap = MapStack.create(); ScreenRenderer.populateContextForRequest(templateMap, null, request, response, servletContext); templateMap.put("formStringRenderer", new HtmlFormRenderer(request, response)); + templateMap.put("statusCode", statusCode); // make the link prefix ServletContext ctx = (ServletContext) request.getAttribute("servletContext"); RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_"); templateMap.put("_REQUEST_HANDLER_", rh); + response.setStatus(statusCode); + // NOTE DEJ20080817: this is done in the ContentMapFacade class now to avoid problems with the jsessionid being in the middle of the URL and such //String contextLinkPrefix = rh.makeLink(request, response, "", true, false, true); //templateMap.put("_CONTEXT_LINK_PREFIX_", contextLinkPrefix); @@ -239,9 +296,13 @@ public class CmsEvents { String siteName = null; try { GenericValue content = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", contentId)); - if (UtilValidate.isNotEmpty(content)) { + if (content !=null && UtilValidate.isNotEmpty(content)) { contentName = content.getString("contentName"); } + else { + request.setAttribute("_ERROR_MESSAGE_", "Content: " + contentName + " [" + contentId + "] is not a publish point for the current website: [" + webSiteId + "]"); + return "error"; + } siteName = delegator.findByPrimaryKeyCache("WebSite", UtilMisc.toMap("webSiteId", webSiteId)).getString("siteName"); } catch (GenericEntityException e) { Debug.logError(e, module); @@ -262,9 +323,10 @@ public class CmsEvents { //throw new GeneralRuntimeException("Unknown request; this request does not exist or cannot be called directly."); } - protected static boolean verifyContentToWebSite(Delegator delegator, String webSiteId, String contentId) throws GeneralException { + protected static int verifyContentToWebSite(Delegator delegator, String webSiteId, String contentId) throws GeneralException { // first check if the passed in contentId is a publish point for the web site List publishPoints = null; + boolean hasContent=false; try { publishPoints = delegator.findByAndCache("WebSiteContent", UtilMisc.toMap("webSiteId", webSiteId, "contentId", contentId, "webSiteContentTypeId", "PUBLISH_POINT"), @@ -272,47 +334,60 @@ public class CmsEvents { } catch (GenericEntityException e) { throw e; } - + if (UtilValidate.isNotEmpty(publishPoints)) { + hasContent=true; + } publishPoints = EntityUtil.filterByDate(publishPoints); if (UtilValidate.isNotEmpty(publishPoints)) { if (Debug.verboseOn()) Debug.logVerbose("Found publish points: " + publishPoints, module); - return true; + return HttpServletResponseWrapper.SC_OK; } else { // the passed in contentId is not a publish point for the web site; // however we will publish its content if it is a node of one of the trees that have a publish point as the root List topLevelContentValues = delegator.findByAndCache("WebSiteContent", UtilMisc.toMap("webSiteId", webSiteId, "webSiteContentTypeId", "PUBLISH_POINT"), UtilMisc.toList("-fromDate")); topLevelContentValues = EntityUtil.filterByDate(topLevelContentValues); + if (topLevelContentValues != null) { for (GenericValue point: topLevelContentValues) { - if (verifySubContent(delegator, contentId, point.getString("contentId"))) { - return true; + int subContentStatusCode=verifySubContent(delegator, contentId, point.getString("contentId")); + if (subContentStatusCode== HttpServletResponseWrapper.SC_OK) { + return HttpServletResponseWrapper.SC_OK; + } else if (subContentStatusCode== HttpServletResponseWrapper.SC_GONE) { + hasContent=true; } } } } - - return false; + if (hasContent) return HttpServletResponseWrapper.SC_GONE; + return HttpServletResponseWrapper.SC_NOT_FOUND; } - protected static boolean verifySubContent(Delegator delegator, String contentId, String contentIdFrom) throws GeneralException { + protected static int verifySubContent(Delegator delegator, String contentId, String contentIdFrom) throws GeneralException { List contentAssoc = delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentId", contentIdFrom, "contentIdTo", contentId, "contentAssocTypeId", "SUB_CONTENT")); + boolean hasContent=false; + if (UtilValidate.isNotEmpty(contentAssoc)) { + hasContent=true; + } contentAssoc = EntityUtil.filterByDate(contentAssoc); if (contentAssoc == null || contentAssoc.size() == 0) { List assocs = delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentId", contentIdFrom)); assocs = EntityUtil.filterByDate(assocs); if (assocs != null) { for (GenericValue assoc: assocs) { - if (verifySubContent(delegator, contentId, assoc.getString("contentIdTo"))) { - return true; + int subContentStatusCode=verifySubContent(delegator, contentId, assoc.getString("contentIdTo")); + if (subContentStatusCode== HttpServletResponseWrapper.SC_OK) { + return HttpServletResponseWrapper.SC_OK; + } else if (subContentStatusCode== HttpServletResponseWrapper.SC_GONE) { + hasContent=true; } } } } else { if (Debug.verboseOn()) Debug.logVerbose("Found assocs: " + contentAssoc, module); - return true; + return HttpServletResponseWrapper.SC_OK; } - - return false; + if (hasContent) return HttpServletResponseWrapper.SC_GONE; + return HttpServletResponseWrapper.SC_NOT_FOUND; } } diff --git a/applications/content/webapp/content/WEB-INF/actions/website/WebSitePublishPoint.groovy b/applications/content/webapp/content/WEB-INF/actions/website/WebSitePublishPoint.groovy index 977323fa07..a0edf5c774 100644 --- a/applications/content/webapp/content/WEB-INF/actions/website/WebSitePublishPoint.groovy +++ b/applications/content/webapp/content/WEB-INF/actions/website/WebSitePublishPoint.groovy @@ -44,7 +44,21 @@ if (webSiteMenu) { context.menu = menu; context.menuRoot = menuRoot; - // get all sub content for the publish point + // get all sub content for the menu root menus = delegator.findList("ContentAssoc", EntityCondition.makeCondition([contentId : menuRoot]), null, null, null, false); context.menus = menus; +} + +erlookupMap = [webSiteId : webSiteId, webSiteContentTypeId : 'ERROR_ROOT']; +webSiteErrors = delegator.findList("WebSiteContent", EntityCondition.makeCondition(erlookupMap), null, ['-fromDate'], null, false); +webSiteError = EntityUtil.getFirst(webSiteErrors); +if (webSiteError) { + error = webSiteError.getRelatedOne("Content"); + errorRoot = error.contentId; + context.error = error; + context.errorRoot = errorRoot; + + // get all sub content for the error root + errors = delegator.findList("ContentAssoc", EntityCondition.makeCondition([contentId : errorRoot]), null, null, null, false); + context.errors = errors; } \ No newline at end of file diff --git a/applications/content/webapp/content/website/WebSiteCMSNav.ftl b/applications/content/webapp/content/website/WebSiteCMSNav.ftl index 4da6cbd656..06f295cbb3 100644 --- a/applications/content/webapp/content/website/WebSiteCMSNav.ftl +++ b/applications/content/webapp/content/website/WebSiteCMSNav.ftl @@ -410,4 +410,30 @@ <#if (!menus?has_content)> ${uiLabelMap.ContentWebSiteAddMenu} + + +
 
+
 
+ +
+
+
+ +
+ ${uiLabelMap.ContentWebSiteErrors} +
+
+ ${uiLabelMap.ContentWebSiteAddNewErrors} +
+
 
+ + +
+ <#if (errors?has_content)> + ${errors} + <@fillTree assocList = errors/> + +
+<#if (!errors?has_content)> + ${uiLabelMap.ContentWebSiteAddError} \ No newline at end of file diff --git a/specialpurpose/cmssite/data/CmsSiteDemoData.xml b/specialpurpose/cmssite/data/CmsSiteDemoData.xml index 51f46acbbd..0ee90d2bfa 100644 --- a/specialpurpose/cmssite/data/CmsSiteDemoData.xml +++ b/specialpurpose/cmssite/data/CmsSiteDemoData.xml @@ -161,8 +161,21 @@ under the License.

]]> - - + + + + + Status Code : ${statusCode?if_exists}Error ${statusCode?if_exists}]]> + + + + + + cmsSite : Page not foundcmsSite : ${statusCode?if_exists} Not Found]]> + + +