java class for $sys.item

Hello,

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:

$sys.item.getProperty(“rx:myPropertyName”).String
$sys.item.getDefinition().getLabel())

With the item at my disposal, I’d be able to simplify my method call from this:

#set($url = $user.bcurlutils.getCanonicalUrl(“BC_Artifact_Prefix”,$contentType,$sys.item.getProperty(“displayTitle”).String, $legacyId, “BC_Url_Suffix”, $sys.item.getProperty(“parentCenter”)))

to this:

#set($url = $user.bcurlutils.getCanonicalUrl($sys.item))

and handle the work of looking up the needed fields from my class.

A few questions about this:

  1. What is the package and class name for $sys.item?
  2. What jar is it in so that I can reference it in my extension class?
  3. Is the class that is returned by “item.getDefinition()” also in the same jar? What is the class and jar?
  4. 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.

Some answers, I hope

  1. What is the package and class name for $sys.item?

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

  1. What jar is it in so that I can reference it in my extension class?

This interface is defined in rxservices.jar

  1. 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

  1. 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).

I hope this helps

Dave

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();



}