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

x
?
Solved

XMl And parsing Document

Posted on 2009-05-19
20
Medium Priority
?
263 Views
Last Modified: 2012-08-14
This line is not executed of GenerateReportAction

 JRXmlDataSource xmlDataSource = new JRXmlDataSource(doc.getDocumentURI(),"/userData M55_USERS_NEW");
 
         
Please help me

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
package net.ensode.jasperbook.struts;
 
import java.io.*;
    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    import org.xml.sax.*;
 
    public class BasicDom {
 
        // Parses an XML file and returns a DOM document.
        // If validating is true, the contents is validated against the DTD
        // specified in the file.
       
         public Document parseFile(String fileName) {
        System.out.println("Parsing XML file... " + fileName);
         DocumentBuilder docBuilder;
         Document doc = null;
         DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
         docBuilderFactory.setIgnoringElementContentWhitespace(true);
         try {
             docBuilder = docBuilderFactory.newDocumentBuilder();
         }
         catch (ParserConfigurationException e) {
             System.out.println("Wrong parser configuration: " + e.getMessage());
             return null;
        }
         File sourceFile = new File(fileName);
         try {
             doc = docBuilder.parse(sourceFile);
         }
         catch (SAXException e) {
             System.out.println("Wrong XML file structure: " + e.getMessage());
             return null;
         }
         catch (IOException e) {
             System.out.println("Could not read source file: " + e.getMessage());
         }
         System.out.println("XML file parsed");
         return doc;
     }
    }
 
__________________________________________________________________________
 
 
package net.ensode.jasperbook.struts;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import javax.servlet.ServletContext;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import net.sf.jasperreports.engine.JRResultSetDataSource;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperRunManager;
 
import net.sf.jasperreports.engine.data.JRXmlDataSource;
import org.apache.struts.Globals;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.w3c.dom.Document;
public class GenerateReportAction extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
 
     ServletContext application=servlet.getServletContext();
     ServletOutputStream servletOutputStream =response.getOutputStream();
 
     try{
 
/*         File file = new File("C:/Documents and Settings/ashish/My Documents/NetBeansProjects/StrutsJasperXml/build/web/reports/ashish.txt");
         file.createNewFile(); */
         System.out.println("Compiling report...");
 
         JasperCompileManager.compileReportToFile("C:/Documents and Settings/ashish/My Documents/NetBeansProjects/StrutsJasperXml/build/web/reports/RemoteReport.jrxml");
         System.out.println("Compilation Succesfully----------------------->");
       
         BasicDom basicDom=new BasicDom();
      
         Document doc =basicDom.parseFile(application.getRealPath("/reports/userxml.xml"));
//        Document doc =basicDom.parseXmlFile("reports/userxml.xml", false);
         System.out.println("After Parse method_______________->++++++ "+doc.getDocumentURI());
         JRXmlDataSource xmlDataSource = new JRXmlDataSource(doc.getDocumentURI(),"/userData/M55_USERS_NEW");
 
         System.out.println("Filling report...");
         InputStream reportStream=new FileInputStream("C:/Documents and Settings/ashish/My Documents/NetBeansProjects/StrutsJasperCompleteApplication/reports/RemoteReport.jasper");
         System.out.println("ReportStream---------->>>>>>>>>>>>>>>>"+reportStream.toString());
         System.out.println("Done!");
         JasperRunManager.runReportToPdfStream(reportStream,servletOutputStream, new HashMap(),xmlDataSource);
         response.setContentType("application/pdf");
        }catch(Exception e){
            e.printStackTrace();
        }
     finally{
       
        servletOutputStream.flush();
        servletOutputStream.close();
     }
     return mapping.getInputForward();
    }
}

Open in new window

0
Comment
Question by:Adwait Chitaley
  • 10
  • 9
19 Comments
 
LVL 92

Expert Comment

by:objects
ID: 24420841
>  JRXmlDataSource xmlDataSource = new JRXmlDataSource(doc.getDocumentURI(),"/userData M55_USERS_NEW");

that can just be:

 JRXmlDataSource xmlDataSource = new JRXmlDataSource(doc ,"/userData M55_USERS_NEW");

0
 

Author Comment

by:Adwait Chitaley
ID: 24420882
not taking this line for executing
0
 
LVL 92

Expert Comment

by:objects
ID: 24420895
you can avoid parsing the xml yourself though and just pass the file path directly to the data source

0
Technology Partners: 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!

 
LVL 92

Expert Comment

by:objects
ID: 24420900
what console output are you getting?

0
 

Author Comment

by:Adwait Chitaley
ID: 24420910
This is my console outpu

Compiling report...
Compilation Succesfully----------------------->
Parsing XML file... C:\Documents and Settings\ashish\My Documents\NetBeansProjects\StrutsJasperXml\build\web\reports\userxml.xml
XML file parsed
After Parse method_______________->++++++ file:C:/Documents%20and%20Settings/ashish/My%20Documents/NetBeansProjects/StrutsJasperXml/build/web/reports/userxml.xml
0
 
LVL 92

Accepted Solution

by:
objects earned 1500 total points
ID: 24420932
did you make the change I suggested above?

or alternatively

 JRXmlDataSource xmlDataSource = new JRXmlDataSource(application.getRealPath("/reports/userxml.xml") ,"/userData M55_USERS_NEW");

0
 

Author Comment

by:Adwait Chitaley
ID: 24420962
ya i did the changes. after that also its taking the line
0
 

Author Comment

by:Adwait Chitaley
ID: 24420998
sorry sorry

its not taking the line
0
 
LVL 92

Expert Comment

by:objects
ID: 24421036
that select expression doesn't look right. that should be a valid path

0
 

Author Comment

by:Adwait Chitaley
ID: 24421038
hello expert i did not working plz..............
0
 

Author Comment

by:Adwait Chitaley
ID: 24421056
select expression means i didnt get

i change the path in every manner but not working..
0
 
LVL 92

Expert Comment

by:objects
ID: 24421095
why don't you know what it should be?
It specifies the data to include

0
 

Author Comment

by:Adwait Chitaley
ID: 24421152
Actually i read the this from jasper report pdf that
JRXmlDataSource contains other constructors that allow us to send the XML document as an org.w3c.dom document, as a java.io file, or as a String containing a Uniform Resource Identifier (URI)


JRXmlDataSource xmlDataSource = new JRXmlDataSource(doc ,"/userData M55_USERS_NEW");


that why i gave as document as in construtor  so this is not taking
and i want to used for jasper report so that i did the parsing of xml...

if u have any code then please give me its urgent
0
 
LVL 92

Expert Comment

by:objects
ID: 24421162
sorry your right, it would be:

 JRXmlDataSource xmlDataSource = new JRXmlDataSource(new File(application.getRealPath("/reports/userxml.xml")) ,"/userData M55_USERS_NEW");

but you still need to work out what select expression you need

0
 

Author Comment

by:Adwait Chitaley
ID: 24421234
i dont get it did not executing the line
JRXmlDataSource xmlDataSource = new JRXmlDataSource(new File(application.getRealPath("/reports/userxml.xml")) ,"/userData M55_USERS_NEW");

i printed the one line after this by using system.out.println but its not shows..the output

if u hava any other solution please give me
0
 
LVL 92

Expert Comment

by:objects
ID: 24421263
I do understand that. From what you have said it is inside that method attempting to load the data source
I can't tell you what the select expression is as it is related to your data

0
 

Author Comment

by:Adwait Chitaley
ID: 24570686
i tried as u told but the program is not working
0
 
LVL 92

Expert Comment

by:objects
ID: 24577737
I pointed out what the problem was, there is no way I can tell you what the select expression should be. Only you can determine that.
0
 

Author Closing Comment

by:Adwait Chitaley
ID: 31582944
not a proper solution but some clue  i got from this Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month13 days, 7 hours left to enroll

581 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