Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Passing Parameters Using JAVA, XSL, XML

Posted on 2005-03-02
11
Medium Priority
?
409 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:jmc430
  • 5
  • 4
  • 2
11 Comments
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 13441923
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
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 13441958


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
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 13442044
>>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
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:jmc430
ID: 13442050
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..

0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 13442235
Ok can you post the compilation errors

Regards
Sudhakar Chavali
0
 

Author Comment

by:jmc430
ID: 13442323
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
0
 
LVL 14

Assisted Solution

by:sudhakar_koundinya
sudhakar_koundinya earned 1000 total points
ID: 13442483
Generally I code like this -> Directly uses Sun's JDK API
public Transformer getTransformer(String xslFileName)
{
    try
   {
      System.err.println(xslFileName);
      Transformer transformer = null;
      StreamSource source=new StreamSource(xslFileName);
      transformer = transformerfactory.newTransformer(source);
      return transformer;
    }
    catch (Exception ex)
   {
      ex.printStackTrace();
      return null;
    }
}


Uses xlst.jar


 public Transformer getTransformer(String xslFileName) {
    try {
      System.err.println(xslFileName);
      Transformer transformer = null;
      Templates templates = null;
      StreamSource source=new StreamSource(xslFileName);
      templates = transformerfactory.newTemplates(source);
      transformer = templates.newTransformer();
      return transformer;
    }
    catch (Exception ex) {
      ex.printStackTrace();
      return null;
    }
0
 

Author Comment

by:jmc430
ID: 13442527
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..
0
 
LVL 92

Accepted Solution

by:
objects earned 1000 total points
ID: 13444502
> javax.xml.transform.TransformerException:java.net.MalformedURLException

looks more like a runtime error rather than a compile error
and the problem is more likely in your xml/xsl files.
0
 

Author Comment

by:jmc430
ID: 13450127
thanks for pointing me in the right direction.

:)
0
 
LVL 92

Expert Comment

by:objects
ID: 13453221
no worries :)
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month15 days, 7 hours left to enroll

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question