I’d like to pass the commonly used Velocity variable, $sys.item, to my java extension class. From there, I want to extract properties from the “item” like the following:
and handle the work of looking up the needed fields from my class.
A few questions about this:
What is the package and class name for $sys.item?
What jar is it in so that I can reference it in my extension class?
Is the class that is returned by “item.getDefinition()” also in the same jar? What is the class and jar?
I’m assuming that the “String” conversion can be handled by standard java toString() call, as the “.String” in the template contains no parenthases – non-standard.
Assume it’s an object that implements the interface com.percussion.services.contentmgr.IPSNode. This interface extends javax.jcr.Node. If you don’t need any of the special Rhythmyx functions, use the Node interface
What jar is it in so that I can reference it in my extension class?
This interface is defined in rxservices.jar
Is the class that is returned by “item.getDefinition()” also in the same jar? What is the class and jar?
It’s an object that implements IPSNodeDefinition. Again, this extends javax.jcr.NodeDefinition
I’m assuming that the “String” conversion can be handled by standard java toString() call, as the “.String” in the template contains no parenthases – non-standard.
The “.String” is a Jexl / Velocity “convention”, and you cannot do this in Java. You have to call “getString()” in a Java class. In a Velocity template or JEXL expression this can be abbreviated as .String. (In VTL / JEXL, if you have a property name “.foo”, the underlying code will call the “getFoo()” method).
Yes, that helped! We were looking at the javax.jcr.Node, but I was having tourble determining what the Percussion interface or class that was extending it to include the definition.label property. In order to access this, I had to cast the getDefinition() return value to the appropriate internal definition class. I used the internal IPSNode for consistency and self-documentation, but it wasn’t entirely necessary.
// New method
@IPSJexlMethod(description = "Compose the canonical URL", params = { @IPSJexlParam(name = "item", description = "The Percussion-extended version of javax.jcr.Node containing the content item properties and metadata") })
public String getCanonicalUrl(IPSNode item) throws ValueFormatException, RepositoryException {
IPSNodeDefinition definition = (IPSNodeDefinition) item.getDefinition();
String contentType = definition.getLabel();
String prefix = this.getKeywordValue(BC_ARTIFACT_PREFIX, contentType);
String title = item.getProperty("rx:displayTitle").getString();