[opencms-dev] injecting Publish Date/Timestamp into page
Paul-Inge Flakstad
flakstad at npolar.no
Mon Aug 11 10:46:29 CEST 2014
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.
Am 07.08.2014 12:43, schrieb ] 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
>
> Am 07.08.2014 11:58, schrieb Christoph Kukulies:
>> 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
>> <http://stackoverflow.com/questions/14338306/how-to-get-last-published-date-from-a-cmsresource-in-opencms>:
>>
>> |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
More information about the opencms-dev
mailing list