Changes in the OpenCms API (CmsObject)
Because of the massive internal code changes in OpenCms 6
compared to OpenCms 5, some methods of the API had to be changed, deleted or added.
For some methods, the method signature had to be modified.
What to do?
It is possible that your JSPs will still not compile after you have done steps
1-3 of the migration process. This will happen, if your JSP contains scriplet
code that uses those parts of the OpenCms API which have been modified in
OpenCms 6, especially the CmsObject and the CmsRequestContext.
If your JSP uses old method calls which are not supported by the API anymore,
its highly recommended to take a look OpenCms JavaDocs to see which methotds are
available in the API now.
Below, some examples for API changes are shown.
CmsObject
Several API changes had to be done in the CmsObject, which is the main API to
access OpenCms core functions. In most cases, those changes are related to the
method signature, i.e. the method parameters have been changed. In addition,
several methods have either been deleted (because they are not required anymore)
or have been marked as depricated (e.g. the often used readFileHeader()
method):
Example for reading the file header in OpenCms 5:
CmsResource res = cms.readFileHeader(filename);
New code in OpenCms 6:
CmsResource res = cms.readResource(filename);
Other methods of the API have been replaced by new ones, because of the
introduction of a cleaner object model in OpenCms 6 (e.g. readPropertyObject()
instead of readProperty()). The old methods were either deleted or marked as
depricated.
Reading a property value in OpenCms 5:
String property = cms.readProperty(resourcename, propertyname);
Reading a property value in OpenCms 6:
CmsProperty propertyObject = cms.readPropertyObject(resourcename, propertyname, false);
String property = propertyObject.getValue();
RequestContext
As part of the core modifications, the CmsRequestContext does not contain the
reference to the original servlet request in it anymore. One common usage of the
CmsRequestContext was to access the original request and get some data from it
like this
CmsObject cmsObject = cms.getCmsObject();
cmsObject.getRequestContext().getRequest().getOriginalRequest().someMethodHere()
This is not possible anymore, instead access the request Object in your JSP
directly.
|