protected void handleActionRequest( final HttpServletRequest request, final HttpServletResponse response,
final HttpOutputHandler outputHandler, final HttpServletRequestHandler requestHandler,
IParameterProvider requestParameters, ByteArrayOutputStream outputStream, final IContentItem contentItem )
throws ServletException, IOException {
IRuntimeContext runtime = null;
try {
final org.w3c.dom.Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
final org.w3c.dom.Element root = document.createElement( "action_sequence_info" );
document.appendChild( root );
requestHandler.setCreateFeedbackParameterCallback( new ICreateFeedbackParameterCallback() {
public void createFeedbackParameter( IRuntimeContext runtimeContext, String fieldName, String displayName,
String hint, Object defaultValues, List values, Map dispNames, String displayStyle, boolean optional,
boolean visible ) {
org.w3c.dom.Element parameterElement = document.createElement( "parameter" );
parameterElement.setAttribute( "name", fieldName );
parameterElement.setAttribute( "display-name", displayName );
parameterElement.setAttribute( "display-style", displayStyle );
parameterElement.setAttribute( "hint", "" + hint );
parameterElement.setAttribute( "optional", "" + optional );
parameterElement.setAttribute( "visible", "" + visible );
try {
IActionParameter actionParameter = runtimeContext.getInputParameter( fieldName );
if ( actionParameter != null ) {
List variables = actionParameter.getVariables();
for ( int i = 0; variables != null && i < variables.size(); i++ ) {
Object var = variables.get( i );
if ( var instanceof ActionParameterSource ) {
String sourceName = ( (ActionParameterSource) var ).getSourceName();
String sourceValue = ( (ActionParameterSource) var ).getValue();
parameterElement.setAttribute( "source-name", "" + sourceName );
parameterElement.setAttribute( "source-value", "" + sourceValue );
} else {
System.out.println( var );
}
}
}
} catch ( Exception npe ) {
//ignore
}
root.appendChild( parameterElement );
if ( values != null ) {
org.w3c.dom.Element valuesElement = document.createElement( "values" );
for ( Object value : values ) {
org.w3c.dom.Element valueElement = document.createElement( "value" );
valueElement.setAttribute( "value", "" + value );
if ( dispNames != null && dispNames.containsKey( value ) ) {
valueElement.setAttribute( "display-name", "" + dispNames.get( value ) );
}
valuesElement.appendChild( valueElement );
}
parameterElement.appendChild( valuesElement );
}
if ( defaultValues != null ) {
org.w3c.dom.Element valuesElement = document.createElement( "selected-values" );
if ( defaultValues instanceof List ) {
for ( Object value : (List) defaultValues ) {
org.w3c.dom.Element valueElement = document.createElement( "value" );
valueElement.setAttribute( "value", "" + value );
valuesElement.appendChild( valueElement );
}
} else {
org.w3c.dom.Element valueElement = document.createElement( "value" );
valueElement.setAttribute( "value", "" + defaultValues );
valuesElement.appendChild( valueElement );
}
parameterElement.appendChild( valuesElement );
}
}
} );
runtime = requestHandler.handleActionRequest( 0, 0 );
root.setAttribute( "is-prompt-pending", "" + runtime.isPromptPending() );
DOMSource source = new DOMSource( document );
StreamResult result = new StreamResult( new StringWriter() );
TransformerFactory.newInstance().newTransformer().transform( source, result );
String theXML = result.getWriter().toString();
response.setContentType( "text/xml" );
response.getOutputStream().write( theXML.getBytes() );
response.getOutputStream().close();
} catch ( ParserConfigurationException e ) {
e.printStackTrace();
} catch ( TransformerConfigurationException e ) {
e.printStackTrace();
} catch ( TransformerException e ) {
e.printStackTrace();
} catch ( TransformerFactoryConfigurationError e ) {
e.printStackTrace();
} finally {
if ( runtime != null ) {
runtime.dispose();
}
}
if ( contentItem != null ) {
contentItem.closeOutputStream();
}