Link to home
Start Free TrialLog in
Avatar of jmc430
jmc430

asked on

Passing Parameters Using JAVA, XSL, XML

Greetings!

I have a question concerning passing parameters using Java.  I have a function that takes the XSL parameters, and is supposed to set them for processing.  However, I continue to receive various befuddling errors upon compilation.

Here is the Java function that does the Transformer actions:

        public void appendToResponse(WOResponse response, WOContext context) {
                response.setContentEncoding("UTF8");
                super.appendToResponse(response, context);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();

                try {
     
                TransformerFactory tFactory = TransformerFactory.newInstance();
                StreamSource xslSource = new StreamSource("http://here.is.my.fullpath.to/File.xsl");
     
                Transformer transformer = tFactory.newTransformer(xslSource);

                StreamSource inXML = new StreamSource(getXmlSource());
                StreamResult outXML = new StreamResult(baos);
                transformer.setParameter("BatchIndex", BatchIndex);                < =====   why doesn't this work?
                transformer.setParameter("SessionID", SessionID);                       < =====   why doesn't this work?
                transformer.setParameter("Criteria", Criteria);                                 < =====   why doesn't this work?
                transformer.setParameter("BatchCount", BatchCount);                            < =====   why doesn't this work?
                transformer.transform(inXML, outXML);
                } catch (TransformerException e) {
                        System.err.println(e);
                }
                response.setContent(new NSData(baos.toByteArray()));
                response.setHeader("text/html; charset=UTF-8 encoding=UTF-8", "content_type");
     }

I also have an additional  function in another class, that is supposed to take the formValueForKey values.

     public WOComponent renderXMLAction(){

     WORequest request = request();
     String xmlFile=(String)request().formValueForKey("BatchIndex");                < =====   why doesn't this work?
     String xmlFile=(String)request().formValueForKey("BatchCount");                   < =====   why doesn't this work?
     String xmlFile=(String)request().formValueForKey("Criteria");                           < =====   why doesn't this work?
     String xmlFile=(String)request().formValueForKey("SessionId");                           < =====   why doesn't this work?
 
     SearchResults nextPage=(SearchResults)pageWithName("SearchResults");
     nextPage.setXmlSource(xmlFile);  
     return nextPage;

    }

Any advice or guidance is greatly appreciated!

Best regards,
Jamie
Avatar of sudhakar_koundinya
sudhakar_koundinya

For your second issue

I see same variable name for all the requests
>>String xmlFile=(String)request().formValueForKey("BatchIndex");          
>>String xmlFile=(String)request().formValueForKey("BatchCount");              

And also check the instance that you are getting from request.
As an example include this debugging statement.
System.err.println(request().formValueForKey("BatchIndex").getClass());

If the result is not java.lang.String you need to recheck your code

Best Regards
Sudhakar


If your requests are conditional, you should put them in conditions

String xmlFile=(String)request().formValueForKey("BatchIndex");          
if(xmlFile==null||xmlFile.length()==0)
{
xmlFile=(String)request().formValueForKey("BatchCount");            
}

Is that what you are expecting??

Regards
Sudhakar
>>transformer.setParameter("BatchIndex", BatchIndex);
>>transformer.setParameter("SessionID", SessionID);

Check if BatchIndex,SessionID are null or valid objects. Similarly you should check other objects also

Best Regards
Sudhakar Chavali
Avatar of jmc430

ASKER

I'm trying to append all those values, (BatchCount, BatchIndex, SessionID, Criteria), into the XSLT transform.

These parameters will not be null in any instances..

Ok can you post the compilation errors

Regards
Sudhakar Chavali
Avatar of jmc430

ASKER

Hi Sudhakar,

I'm only getting one error:

javax.xml.transform.TransformerException:java.net.MalformedURLException

I found online that this means the "text of a stylesheet to an interface that was expecting a URI." but I don't know what this means.

Thanks for helping me ...

Best regards,
Jamie
SOLUTION
Avatar of sudhakar_koundinya
sudhakar_koundinya

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jmc430

ASKER

I don't think the transformation itself is giving me issues ..

Basically my transformation works on the first transform (when I first submit parameters to be processed by the XSL).  However, on the second transform, when I want to take all the parameters (plus the newly inputted parameters) I want to pass the new parameters to the same transform.

I want to be able to have a request.setParameter() and a request.getParameter() somewhere (as in JSP) but I do not know how to achieve this.

I'm getting this error as well:

javax.xml.transform.Transformer.Exception: The declaration for the entity "HTML.Version" must end with '>'.

Thanks for helping me..
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jmc430

ASKER

thanks for pointing me in the right direction.

:)
no worries :)