1

I'm unable to get the last published date of a resource. There is no way to do that with OpenCms API. http://files.opencms.org/javadoc/core/org/opencms/file/CmsResource.html

That's very weird, it has to be stored in some place because OpenCms Workplace shows this information in the History option.

History of a resource in OpenCms Workplace

The method getDateReleased() from CmsResource class always returns DATE_RELEASED_DEFAULT until you set the availability of the resource.

Any thoughts? Thanks!

spekdrum
  • 1,559
  • 2
  • 11
  • 15

1 Answers1

2

Finally I achieve this by digging in the source code from OpenCms. I found the solution here, in the getListItems method:

https://github.com/alkacon/opencms-core/blob/branch_8_5_x/src/org/opencms/workplace/commons/CmsHistoryList.java

So I built this method to get the last published date from any resource:

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;
    }   
}

If NULL is returned then the resource has not been published yet.

spekdrum
  • 1,559
  • 2
  • 11
  • 15