IPSItemValidator interface

Hello,

I’m looking for examples of how the IPSItemValidator interface is used, and I notice two things I don’t understand:

  1. Some files in Extensions.xml have interface=“PSItemValidator”, but if you look in the Java file, they are not implementing this interface. Why is that?
  2. I’m not finding any java classes under exits/ that are using the PSItemValidator interface. Are there any extensions that use it that I could look at for an example of how it works?

Thanks,
April

April,

The PSItemValidator interface is a “sub interface” of the post processing extension interface. Basically, the “input document” is the XML representation of the content editor item (like what you see when you change .htm to .txt).

Your validation must “walk” through this XML to determine if the fields contained in it are valid.

One easy way to do this is use the base classes in the PSOToolkit (PSOAbstractItemValidation and PSOItemXMLSupport). Calling PSOItemXMLSupport.getFieldValue() (or getFieldValues()) is an easy way for you to determine the current value of any field in this XML representation.

I added these to the toolkit precisely because the underlying validation interface is so difficult to deal with.

Dave

Thanks. That’s helpful to know.

I have an extension that doesn’t really do anything yet. But it does manage to stop Rhythmyx from starting up successfully. The log shows this error:

13:10:35,004 INFO [ActionSets] An action set could not be loaded because of an
error and will be skipped. com.percussion.extension.PSExtensionException: The Ex
tensionHandler handler could not initialize the Java extension: java.lang.ArrayI
ndexOutOfBoundsException: 2.

There’s no stack trace from this exception that I can find in the logs.

Attached is my extensions file. I copied the xml for this extension from the xml for the PSORequiredFieldsItemValidation extension. In my class, you can see that I wrapped the init in a try statement, because I thought maybe the error was happening there, and that I could output a stack trace. But that didn’t make any difference.


/**
 * 
 */
package com.percussion.tutorial.jexl;

import org.apache.log4j.Logger;

import java.io.File;

import org.w3c.dom.Document;

import com.percussion.extension.IPSExtensionDef;
import com.percussion.extension.IPSItemValidator;
import com.percussion.extension.PSExtensionException;
import com.percussion.extension.PSExtensionProcessingException;
import com.percussion.extension.PSParameterMismatchException;
import com.percussion.pso.validation.PSORequiredFieldsItemValidation;
import com.percussion.server.IPSRequestContext;

/**
 * @author apapajoh
 *
 */
public class MWValidateOnTransition extends PSORequiredFieldsItemValidation implements IPSItemValidator {

	/* (non-Javadoc)
	 * @see com.percussion.extension.IPSResultDocumentProcessor#canModifyStyleSheet()
	 */
	public boolean canModifyStyleSheet() {
		// TODO Auto-generated method stub
		return false;
	}

	/* (non-Javadoc)
	 * @see com.percussion.extension.IPSResultDocumentProcessor#processResultDocument(java.lang.Object[], com.percussion.server.IPSRequestContext, org.w3c.dom.Document)
	 */
	public Document processResultDocument(Object[] arg0,
			IPSRequestContext arg1, Document arg2)
			throws PSParameterMismatchException, PSExtensionProcessingException {
		Document doc = super.processResultDocument(arg0, arg1, arg2);
		return doc;
	}

	public void init(IPSExtensionDef def,
	          File codeRoot)
	          throws PSExtensionException {
		try {
			super.init(def,codeRoot);
		} catch (Exception e){
			 ms_log.debug(e.getStackTrace());
		}
	}
	public MWValidateOnTransition (){
		
	}
	
	private static Logger ms_log = Logger.getLogger(MWValidateOnTransition.class);
}

To get rid of the offending extension, I restored my Rhythmyx root (not sure how else to get rid of an extension), and I got Rhythmyx to start up successfully. then I tried adding another extension, identical to the tutorial extension, just to see what would happen. I got the same ArrayIndexOutOfBounds error.

Here’s what my extensions.xml file looks like this time:


<?xml version="1.0" encoding="utf-8"?>
<PSXExtensionHandlerConfiguration handlerName="Java">
<!-- Add your extensions here -->
<Extension categorystring="jexl" context="global/percussion/user/" deprecated="no" handler="Java" name="tutorialSlotContents" restoreRequestParamsOnError="no">
		<initParam name="com.percussion.user.description">Slot Utility Functions</initParam>
		<initParam name="com.percussion.extension.version">1</initParam>
		<initParam name="com.percussion.extension.reentrant">yes</initParam>
		<initParam name="className">com.percussion.tutorial.jexl.SlotContents</initParam>
		<interface name="com.percussion.extension.IPSJexlExpression"/>
		<suppliedResources/>
	</Extension>
	
	<Extension categorystring="jexl" context="global/percussion/user/" deprecated="no" handler="Java" name="tutorialSlotContentsCopy" restoreRequestParamsOnError="no">
		<initParam name="com.percussion.user.description">Slot Utility Functions</initParam>
		<initParam name="com.percussion.extension.version">1</initParam>
		<initParam name="com.percussion.extension.reentrant">yes</initParam>
		<initParam name="className">com.percussion.tutorial.jexl.CopyOfSlotContents</initParam>
		<interface name="com.percussion.extension.IPSJexlExpression"/>
		<suppliedResources/>
	</Extension>
	

April,

Did you actually add the new extension to any content types or templates? or is just defining it in the Extensions.xml enough to cause the problem?

Also, how did you register the extension? Did you use the Workbench or edit an XML file?

Dave

I haven’t added it to any content types. Actually, I can’t, since I can’t start Rhythmyx with the extension in there.

I used PSExtensionInstallTool.

What I recommend then is that you back out the changes to the extensions.xml in the Handlers/Java/1 folder (that’s all you need to change),
add the JAR to the lib directory and then start the server.

You should then be able to register the extension with the Workbench. Let us know if you cannot.

Dave

OK. I have to put this on the back burner for a while. But when I get back to it, I will try that.

I figured out why I was getting the ArrayIndexOutofBounds error. I had a method that was missing an @IPSJexlParam annotation. The error was occurring even when I didn’t add the class to the extensions. All it took was for the class to be in the jar.

Do we need to add @IPSJexlParam annotations for preprocessor and post processor extensions as well?

No, the annotations are only used by JEXL, not by the server itself.