?
Solved

Passing Parameters Using JAVA, XSL, XML

Posted on 2005-03-02
11
Medium Priority
?
394 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses
Course of the Month12 days, 13 hours left to enroll

777 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