Discussion:
[opencms-dev] injecting Publish Date/Timestamp into page
Christoph Kukulies
2014-08-07 09:58:09 UTC
Permalink
An HTML attachment was scrubbed...
URL: <http://lists.opencms.org/pipermail/opencms-dev/attachments/20140807/5adececd/attachment.html>
] Code Create [
2014-08-07 10:43:30 UTC
Permalink
Hi Chris,

why don't you simply use "getDateLastModified".
Because, if it is not published it doesn't matter.
If it is published the date last modified should be fine if there is not
a too great time span in between. If there is you could just refresh the
resource prior to publishing it.

Me, I use an extra schema field/property to set a real publication date
(date issued).
Because I don't want to have this "issued date" changed, just because I
republish a resource for technical reasons, like orthography errors, or
if you have to republish the whole site for some other reason ... all
publish dates would be the same ...; i assume, that's not what you want.

For the same reason I have an extra field/property for the last edit
date too :D

All the best, Bernd
I'm seeking for a means to insert the date/time a page was published
last time so that one can read e.g. at the bottom of a
page something like "last edit Aug, 7th, 2014".
I found some suggestion in a stackoverflow thread
|public static Date getLastPublishedDate(CmsJspActionElement cms, CmsResource resource) throws Exception {
CmsObject cmso = cms.getCmsObject();
String sitePath = cmso.getSitePath(resource);
if (cmso.readAllAvailableVersions(sitePath).size() > 0) {
I_CmsHistoryResource histRes = cmso.readAllAvailableVersions(sitePath).get(0);
int publishTag = histRes.getPublishTag();
CmsHistoryProject project = cmso.readHistoryProject(publishTag);
return new Date(project.getPublishingDate());
} else {
return null;
}
}
I'm wondering whether it could be accomplished in another way.
--
Chris Christoph P. U. Kukulies kukulies (at) rwth-aachen.de
|
_______________________________________________
This mail is sent to you from the opencms-dev mailing list
To change your list options, or to unsubscribe from the list, please visit
http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
Christoph Kukulies
2014-08-07 10:56:30 UTC
Permalink
Hi Bernd,

nice idea. Do you happen to know which element to access to obtain the
GetDateLastModified().
It looks like it's in CmsCntPageData.
Post by ] Code Create [
Hi Chris,
why don't you simply use "getDateLastModified".
Because, if it is not published it doesn't matter.
If it is published the date last modified should be fine if there is not
a too great time span in between. If there is you could just refresh the
resource prior to publishing it.
Me, I use an extra schema field/property to set a real publication date
(date issued).
Because I don't want to have this "issued date" changed, just because I
republish a resource for technical reasons, like orthography errors, or
if you have to republish the whole site for some other reason ... all
publish dates would be the same ...; i assume, that's not what you want.
For the same reason I have an extra field/property for the last edit
date too :D
All the best, Bernd
I'm seeking for a means to insert the date/time a page was published
last time so that one can read e.g. at the bottom of a
page something like "last edit Aug, 7th, 2014".
I found some suggestion in a stackoverflow thread
|public static Date getLastPublishedDate(CmsJspActionElement cms, CmsResource resource) throws Exception {
CmsObject cmso = cms.getCmsObject();
String sitePath = cmso.getSitePath(resource);
if (cmso.readAllAvailableVersions(sitePath).size() > 0) {
I_CmsHistoryResource histRes = cmso.readAllAvailableVersions(sitePath).get(0);
int publishTag = histRes.getPublishTag();
CmsHistoryProject project = cmso.readHistoryProject(publishTag);
return new Date(project.getPublishingDate());
} else {
return null;
}
}
I'm wondering whether it could be accomplished in another way.
--
Chris Christoph P. U. Kukulies kukulies (at) rwth-aachen.de
|
--
Chris Christoph P. U. Kukulies kukulies (at) rwth-aachen.de
Schliemann, Kai
2014-08-07 14:00:18 UTC
Permalink
Hi Chris,
you can find a lot of help in the pdf ship with OpenCms since version 8.
Find attached a screenshot with some useful resource related functions.

HTH

BR
Kai

-----Urspr?ngliche Nachricht-----
Von: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] Im Auftrag von Christoph Kukulies
Gesendet: Donnerstag, 7. August 2014 12:57
An: ocms at code-create.de; The OpenCms mailing list
Betreff: Re: [opencms-dev] injecting Publish Date/Timestamp into page

Hi Bernd,

nice idea. Do you happen to know which element to access to obtain the GetDateLastModified().
It looks like it's in CmsCntPageData.
Post by ] Code Create [
Hi Chris,
why don't you simply use "getDateLastModified".
Because, if it is not published it doesn't matter.
If it is published the date last modified should be fine if there is not
a too great time span in between. If there is you could just refresh the
resource prior to publishing it.
Me, I use an extra schema field/property to set a real publication date
(date issued).
Because I don't want to have this "issued date" changed, just because I
republish a resource for technical reasons, like orthography errors, or
if you have to republish the whole site for some other reason ... all
publish dates would be the same ...; i assume, that's not what you want.
For the same reason I have an extra field/property for the last edit
date too :D
All the best, Bernd
I'm seeking for a means to insert the date/time a page was published
last time so that one can read e.g. at the bottom of a
page something like "last edit Aug, 7th, 2014".
I found some suggestion in a stackoverflow thread
|public static Date getLastPublishedDate(CmsJspActionElement cms, CmsResource resource) throws Exception {
CmsObject cmso = cms.getCmsObject();
String sitePath = cmso.getSitePath(resource);
if (cmso.readAllAvailableVersions(sitePath).size() > 0) {
I_CmsHistoryResource histRes = cmso.readAllAvailableVersions(sitePath).get(0);
int publishTag = histRes.getPublishTag();
CmsHistoryProject project = cmso.readHistoryProject(publishTag);
return new Date(project.getPublishingDate());
} else {
return null;
}
}
I'm wondering whether it could be accomplished in another way.
--
Chris Christoph P. U. Kukulies kukulies (at) rwth-aachen.de
|
--
Chris Christoph P. U. Kukulies kukulies (at) rwth-aachen.de

_______________________________________________
This mail is sent to you from the opencms-dev mailing list
To change your list options, or to unsubscribe from the list, please visit
http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev



-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenCms-9.0.1-Documentation_v2.1-8.2.6-the-resource-bean.gif
Type: image/gif
Size: 63990 bytes
Desc: OpenCms-9.0.1-Documentation_v2.1-8.2.6-the-resource-bean.gif
URL: <Loading Image...>
Paul-Inge Flakstad
2014-08-11 08:46:29 UTC
Permalink
Hi Chris,

Like Bernd says, you probably want to avoid using "published" or "last-modified". ("Published" will never renew, and "last-modified" will renew too often - even after fixing typos).

For added control over the timestamp, *without* using an extra field/property, consider using the "date released" attribute. (Should be safe as long as you're not using it for any other customization.) We have chosen this approach, and it seems to work OK so far. Additionally, an unexpected benefit is that it allows us to do bulk updates on the timestamp (by updating it on a parent folder).

Here's a code suggestion:


CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response);
CmsObject cmso = cms.getCmsObject();
String resourceUri = cms.getRequestContext().getUri();

Date dr = null;
String drStr = null;
try {
long drLong = cmso.readResource(resourceUri).getDateReleased();
dr = drLong > 0 ? new Date(drLong) : null;
drStr = new SimpleDateFormat("d MMM yyyy", locale).format(dr);
} catch (Exception e) {
// No "date released" attribute set
}

if (drStr != null) {
// Print the timestamp
}


HTH.

Cheers,
Paul

-----Original Message-----
From: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Schliemann, Kai
Sent: 7. august 2014 16:00
To: kuku at physik.rwth-aachen.de; The OpenCms mailing list
Subject: Re: [opencms-dev] injecting Publish Date/Timestamp into page

Hi Chris,
you can find a lot of help in the pdf ship with OpenCms since version 8.
Find attached a screenshot with some useful resource related functions.

HTH

BR
Kai

-----Urspr?ngliche Nachricht-----
Von: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] Im Auftrag von Christoph Kukulies
Gesendet: Donnerstag, 7. August 2014 12:57
An: ocms at code-create.de; The OpenCms mailing list
Betreff: Re: [opencms-dev] injecting Publish Date/Timestamp into page

Hi Bernd,

nice idea. Do you happen to know which element to access to obtain the GetDateLastModified().
It looks like it's in CmsCntPageData.
Post by ] Code Create [
Hi Chris,
why don't you simply use "getDateLastModified".
Because, if it is not published it doesn't matter.
If it is published the date last modified should be fine if there is
not a too great time span in between. If there is you could just
refresh the resource prior to publishing it.
Me, I use an extra schema field/property to set a real publication
date (date issued).
Because I don't want to have this "issued date" changed, just because
I republish a resource for technical reasons, like orthography errors,
or if you have to republish the whole site for some other reason ...
all publish dates would be the same ...; i assume, that's not what you want.
For the same reason I have an extra field/property for the last edit
date too :D
All the best, Bernd
I'm seeking for a means to insert the date/time a page was published
last time so that one can read e.g. at the bottom of a page something
like "last edit Aug, 7th, 2014".
I found some suggestion in a stackoverflow thread
|public static Date getLastPublishedDate(CmsJspActionElement cms,
|CmsResource resource) throws Exception {
CmsObject cmso = cms.getCmsObject();
String sitePath = cmso.getSitePath(resource);
if (cmso.readAllAvailableVersions(sitePath).size() > 0) {
I_CmsHistoryResource histRes = cmso.readAllAvailableVersions(sitePath).get(0);
int publishTag = histRes.getPublishTag();
CmsHistoryProject project = cmso.readHistoryProject(publishTag);
return new Date(project.getPublishingDate());
} else {
return null;
}
}
I'm wondering whether it could be accomplished in another way.
--
Chris Christoph P. U. Kukulies kukulies (at) rwth-aachen.de
|
Loading...