Jump to content
We've recently updated our Privacy Statement, available here ×

identify referenced subreports


pebie

Recommended Posts

Hello all,

 

I want to store my report definitions in a database with access for multiple users.

There will be concurrent access (upload/update, compilation, run, delete) to the report definitions.

To ensure consistency between main- and subreports locking/allocation/copying of reportdefinitions to the beginning of the report generation is neccessary to avoid inconsistencies/locks.

 

So i need to determine, which reports are used by the main report.

I want to put the used JasperReport objects to a hash associated to the current reporting run to avoid them to change.

As i don`t want to write my own parser, i tried to overload JRVerifier/verifySubreport (see 4).

 

Too bad that this method is private.

Is there a deeper reason not to declare it protected ?

Or is there a recommended way to find out my specific subreport references ?

(i have tried to use a manipulated JRXmlWriter. It works, but uses a lot of space and time to get rid of the written xml)

 

Thanx in advance,

pebie

 

PS: i have posted this in 'Discussion/Help'.

Does anyone know how to delete an unintentionally sent item ?

 

--------------

(1)The snippet from the referencing main.jrxml

 

<subreport isUsingCache="true">

<reportElement

x="168"

y="7"

width="350"

height="31"

key="subreport-1"/>

<connectionExpression>

<![CDATA[$P{REPORT_CONNECTION}]]>

</connectionExpression>

<subreportExpression class="net.sf.jasperreports.engine.JasperReport">

<![CDATA[subReportResolver.getReport("subsubsub")]]>

</subreportExpression>

</subreport>

 

-------------

(2)The Subreport Resolver

 

public class SubReportResolver {

// stub implementation for testing with iReport

public static JasperReport getReport(String name) throws JRException{

String basePath="......resourcesjasper";

String ext=".jrxml";

System.out.println("Compiling "+name);

return MyCompileManager.compileReport(basePath+name+ext);

}

 

}

 

--------------

(3)Overloaded Compiler Manager

 

public class MyCompileManager extends JasperCompileManager {

public static JasperReport compileReport(String sourceFileName) throws JRException

{

JasperDesign jasperDesign = JRXmlLoader.load(sourceFileName);

// c should contain accessed JasperReport objects (and maybe errors of cause)

Collection c = MyVerifier.verifyDesign(jasperDesign);

return compileReport(jasperDesign);

}

}

 

--------------

(4)Overloaded Verifier

 

public class MyVerifier extends JRVerifier {

 

protected MyVerifier(JasperDesign jrDesign, JRExpressionCollector expressionCollector)

{

super(jrDesign,expressionCollector);

}

 

public static Collection verifyDesign(JasperDesign jasperDesign, JRExpressionCollector expressionCollector)

{

// copied from base class

MyVerifier verifier = new MyVerifier(jasperDesign, expressionCollector);

return verifier.verifyDesign();

}

 

private void verifySubreport(JRSubreport subreport)

{

// access subreport and put it to a save haven

// subreport.getExpression().getText() matches SubReportResolver

System.out.println("Verifiying "+subreport.toString());

}

}

Link to comment
Share on other sites

  • 2 months later...
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...