Skip to content

Commit

Permalink
Fixing issue alkacon#217 where expired resource in container pages ca…
Browse files Browse the repository at this point in the history
…used error

messages in the opencms.log.
  • Loading branch information
tHerrmann committed Jan 17, 2014
1 parent 23e7911 commit d0f30e6
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 72 deletions.
12 changes: 6 additions & 6 deletions src/org/opencms/jsp/CmsJspTagContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -960,15 +960,15 @@ private boolean renderContainerElement(
if (isOnline && !showInContext) {
return false;
}
element.initResource(cms);
if (isOnline && !element.isReleasedAndNotExpired()) {
// do not render expired resources for the online project
return false;
}
ServletRequest req = pageContext.getRequest();
ServletResponse res = pageContext.getResponse();
String containerType = getType();
int containerWidth = getContainerWidth();
element.initResource(cms);
if (cms.getRequestContext().getCurrentProject().isOnlineProject()
&& !element.getResource().isReleasedAndNotExpired(System.currentTimeMillis())) {
return false;
}
CmsADEConfigData adeConfig = OpenCms.getADEManager().lookupConfiguration(
cms,
cms.getRequestContext().getRootUri());
Expand Down Expand Up @@ -1002,7 +1002,7 @@ private boolean renderContainerElement(
try {
subelement.initResource(cms);
boolean shouldShowSubElementInContext = shouldShowInContext(subelement, context);
if (isOnline && !shouldShowSubElementInContext) {
if (isOnline && (!shouldShowSubElementInContext || !subelement.isReleasedAndNotExpired())) {
continue;
}
I_CmsFormatterBean subElementFormatterConfig = null;
Expand Down
5 changes: 5 additions & 0 deletions src/org/opencms/jsp/CmsJspTagFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ protected void init() throws JspException {
// get the resource name from the selected container
m_element = OpenCms.getADEManager().getCurrentElement(pageContext.getRequest());
m_element.initResource(m_cms);
if (m_cms.getRequestContext().getCurrentProject().isOnlineProject() && !m_element.isReleasedAndNotExpired()) {
throw new CmsException(Messages.get().container(
Messages.ERR_RESOURCE_IS_NOT_RELEASE_OR_EXPIRED_1,
m_element.getResource().getRootPath()));
}
if (m_locale == null) {
// no locale set, use locale from users request context
m_locale = m_cms.getRequestContext().getLocale();
Expand Down
118 changes: 69 additions & 49 deletions src/org/opencms/jsp/CmsJspTagHeadIncludes.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,21 +334,41 @@ public void tagCssAction(CmsObject cms, ServletRequest req) throws CmsException,
for (CmsContainerElementBean element : container.getElements()) {
try {
element.initResource(cms);
if (element.isGroupContainer(cms) || element.isInheritedContainer(cms)) {
List<CmsContainerElementBean> subElements;
if (element.isGroupContainer(cms)) {
subElements = CmsJspTagContainer.getGroupContainerElements(
cms,
element,
req,
container.getType());
if (!standardContext.isOnline()
|| element.getResource().isReleasedAndNotExpired(cms.getRequestContext().getRequestTime())) {
if (element.isGroupContainer(cms) || element.isInheritedContainer(cms)) {
List<CmsContainerElementBean> subElements;
if (element.isGroupContainer(cms)) {
subElements = CmsJspTagContainer.getGroupContainerElements(
cms,
element,
req,
container.getType());
} else {
subElements = CmsJspTagContainer.getInheritedContainerElements(cms, element);
}
for (CmsContainerElementBean subElement : subElements) {
subElement.initResource(cms);
if (!standardContext.isOnline()
|| subElement.getResource().isReleasedAndNotExpired(
cms.getRequestContext().getRequestTime())) {
I_CmsFormatterBean formatter = getFormatterBeanForElement(
subElement,
container,
formatters);
if (formatter != null) {
cssIncludes.addAll(formatter.getCssHeadIncludes());
if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(formatter.getInlineCss())) {
inlineCss.put(formatter.getId(), formatter.getInlineCss());
}
} else {
cssIncludes.addAll(getCSSHeadIncludes(cms, subElement.getResource()));
}
}
}
} else {
subElements = CmsJspTagContainer.getInheritedContainerElements(cms, element);
}
for (CmsContainerElementBean subElement : subElements) {
subElement.initResource(cms);
I_CmsFormatterBean formatter = getFormatterBeanForElement(
subElement,
element,
container,
formatters);
if (formatter != null) {
Expand All @@ -357,19 +377,9 @@ public void tagCssAction(CmsObject cms, ServletRequest req) throws CmsException,
inlineCss.put(formatter.getId(), formatter.getInlineCss());
}
} else {
cssIncludes.addAll(getCSSHeadIncludes(cms, subElement.getResource()));
cssIncludes.addAll(getCSSHeadIncludes(cms, element.getResource()));
}
}
} else {
I_CmsFormatterBean formatter = getFormatterBeanForElement(element, container, formatters);
if (formatter != null) {
cssIncludes.addAll(formatter.getCssHeadIncludes());
if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(formatter.getInlineCss())) {
inlineCss.put(formatter.getId(), formatter.getInlineCss());
}
} else {
cssIncludes.addAll(getCSSHeadIncludes(cms, element.getResource()));
}
}
} catch (CmsException e) {
LOG.error(
Expand Down Expand Up @@ -477,21 +487,42 @@ public void tagJSAction(CmsObject cms, ServletRequest req) throws CmsException,
for (CmsContainerElementBean element : container.getElements()) {
try {
element.initResource(cms);
if (element.isGroupContainer(cms) || element.isInheritedContainer(cms)) {
List<CmsContainerElementBean> subElements;
if (element.isGroupContainer(cms)) {
subElements = CmsJspTagContainer.getGroupContainerElements(
cms,
element,
req,
container.getType());
if (!standardContext.isOnline()
|| element.getResource().isReleasedAndNotExpired(cms.getRequestContext().getRequestTime())) {
if (element.isGroupContainer(cms) || element.isInheritedContainer(cms)) {
List<CmsContainerElementBean> subElements;
if (element.isGroupContainer(cms)) {
subElements = CmsJspTagContainer.getGroupContainerElements(
cms,
element,
req,
container.getType());
} else {
subElements = CmsJspTagContainer.getInheritedContainerElements(cms, element);
}
for (CmsContainerElementBean subElement : subElements) {
subElement.initResource(cms);
if (!standardContext.isOnline()
|| subElement.getResource().isReleasedAndNotExpired(
cms.getRequestContext().getRequestTime())) {
I_CmsFormatterBean formatter = getFormatterBeanForElement(
subElement,
container,
formatters);
if (formatter != null) {
jsIncludes.addAll(formatter.getJavascriptHeadIncludes());
if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(formatter.getInlineJavascript())) {
inlineJS.put(formatter.getId(), formatter.getInlineJavascript());
}
} else {

jsIncludes.addAll(getJSHeadIncludes(cms, subElement.getResource()));
}
}
}
} else {
subElements = CmsJspTagContainer.getInheritedContainerElements(cms, element);
}
for (CmsContainerElementBean subElement : subElements) {
subElement.initResource(cms);
I_CmsFormatterBean formatter = getFormatterBeanForElement(
subElement,
element,
container,
formatters);
if (formatter != null) {
Expand All @@ -501,19 +532,8 @@ public void tagJSAction(CmsObject cms, ServletRequest req) throws CmsException,
}
} else {

jsIncludes.addAll(getJSHeadIncludes(cms, subElement.getResource()));
}
}
} else {
I_CmsFormatterBean formatter = getFormatterBeanForElement(element, container, formatters);
if (formatter != null) {
jsIncludes.addAll(formatter.getJavascriptHeadIncludes());
if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(formatter.getInlineJavascript())) {
inlineJS.put(formatter.getId(), formatter.getInlineJavascript());
jsIncludes.addAll(getJSHeadIncludes(cms, element.getResource()));
}
} else {

jsIncludes.addAll(getJSHeadIncludes(cms, element.getResource()));
}
}
} catch (CmsException e) {
Expand Down
3 changes: 3 additions & 0 deletions src/org/opencms/jsp/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ public final class Messages extends A_CmsMessageBundle {
/** Message constant for key in the resource bundle. */
public static final String ERR_READING_REQUIRED_RESOURCE_1 = "ERR_READING_REQUIRED_RESOURCE_1";

/** Message constant for key in the resource bundle. */
public static final String ERR_RESOURCE_IS_NOT_RELEASE_OR_EXPIRED_1 = "ERR_RESOURCE_IS_NOT_RELEASE_OR_EXPIRED_1";

/** Message constant for key in the resource bundle. */
public static final String ERR_RUNTIME_1 = "ERR_RUNTIME_1";

Expand Down
3 changes: 2 additions & 1 deletion src/org/opencms/jsp/messages.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ERR_BAD_REQUEST_RESPONSE_0 =ServletRequest or ServletResponse is not of required "Http" type.
ERR_COLLECTOR_NOT_FOUND_1 =Collector "{0}" was not found.
ERR_DIRECT_EDIT_PROVIDER_1 =Unable to create a new instance of direct edit provider "{0}".
ERR_IMAGE_TAG_VFS_ACCESS_1 =Error acessing image resource "{0}".
ERR_IMAGE_TAG_VFS_ACCESS_1 =Error accessing image resource "{0}".
ERR_MISSING_CMS_CONTROLLER_1 ="{0}" is usable only on a OpenCms controlled JSP page.
ERR_PARENTLESS_TAG_1 =Tag "{0}" without required parent tag found.
ERR_PROCESS_TAG_1 =Error processing "{0}" tag in Jsp.
Expand All @@ -19,6 +19,7 @@ ERR_CONTAINER_PAGE_NO_TYPE_3 =Container page "{1}" used as template for resour
ERR_XSD_NO_TEMPLATE_FORMATTER_3 =Schema of type "{1}" for resource "{0}" defines no "{2}" formatter.
ERR_CONTAINER_PAGE_NOT_FOUND_3 =Resource "{0}" is no container page or its "{1}" property with value "{2}" does not point to a container page.
ERR_CONTAINER_PAGE_ELEMENT_RENDER_ERROR_2=Container-page element "{0}" could not be rendered with formatter "{1}".
ERR_RESOURCE_IS_NOT_RELEASE_OR_EXPIRED_1=The requested resource "{0}" is either not released or expired.

GUI_ERR_ACTIONELEM_NOT_INIT_0 =+++ CmsJspActionElement not initialized. +++
GUI_ERR_FILE_PROP_MISSING_2 =+++ File property "{0}" on "{1}" not found. +++
Expand Down
20 changes: 4 additions & 16 deletions src/org/opencms/xml/containerpage/CmsContainerElementBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -408,28 +408,16 @@ public int hashCode() {
public void initResource(CmsObject cms) throws CmsException {

if (m_resource == null) {
if (cms.getRequestContext().getCurrentProject().isOnlineProject()) {
m_resource = cms.readResource(getId());
m_releasedAndNotExpired = true;
} else {
m_resource = cms.readResource(getId(), CmsResourceFilter.IGNORE_EXPIRATION);
m_releasedAndNotExpired = m_resource.isReleasedAndNotExpired(cms.getRequestContext().getRequestTime());
}
m_resource = cms.readResource(getId(), CmsResourceFilter.IGNORE_EXPIRATION);
m_releasedAndNotExpired = m_resource.isReleasedAndNotExpired(cms.getRequestContext().getRequestTime());
} else if (!isInMemoryOnly()) {
CmsUUID id = m_resource.getStructureId();
if (id == null) {
id = getId();
}
// the resource object may have a wrong root path, e.g. if it was created before the resource was moved
if (cms.getRequestContext().getCurrentProject().isOnlineProject()) {
m_resource = cms.readResource(getId());
m_releasedAndNotExpired = true;
} else {
if (!isTemporaryContent()) {
m_resource = cms.readResource(getId(), CmsResourceFilter.IGNORE_EXPIRATION);
}
m_releasedAndNotExpired = m_resource.isReleasedAndNotExpired(cms.getRequestContext().getRequestTime());
}
m_resource = cms.readResource(id, CmsResourceFilter.IGNORE_EXPIRATION);
m_releasedAndNotExpired = m_resource.isReleasedAndNotExpired(cms.getRequestContext().getRequestTime());
}
if (m_settings == null) {
m_settings = CmsXmlContentPropertyHelper.mergeDefaults(cms, m_resource, m_individualSettings);
Expand Down

0 comments on commit d0f30e6

Please sign in to comment.