net.sf.jasperreports.engine.data
Class JsonDataSource

java.lang.Object
  extended by net.sf.jasperreports.engine.data.JRAbstractTextDataSource
      extended by net.sf.jasperreports.engine.data.JsonDataSource
All Implemented Interfaces:
JRDataSource, JRRewindableDataSource

public class JsonDataSource
extends JRAbstractTextDataSource
implements JRRewindableDataSource

JSON data source implementation

Version:
$Id: JsonDataSource.java 5346 2012-05-08 12:08:01Z teodord $
Author:
Narcis Marcu (narcism@users.sourceforge.net)

Constructor Summary
JsonDataSource(java.io.File file)
           
JsonDataSource(java.io.File file, java.lang.String selectExpression)
           
JsonDataSource(java.io.InputStream stream)
           
JsonDataSource(java.io.InputStream jsonStream, java.lang.String selectExpression)
           
JsonDataSource(JasperReportsContext jasperReportsContext, java.lang.String location, java.lang.String selectExpression)
          Creates a data source instance that reads JSON data from a given location
JsonDataSource(java.lang.String location, java.lang.String selectExpression)
           
 
Method Summary
 void close()
           
 java.lang.Object getFieldValue(JRField jrField)
          Gets the field value for the current position.
protected  org.codehaus.jackson.JsonNode getJsonData(org.codehaus.jackson.JsonNode rootNode, java.lang.String jsonExpression)
          Extracts the JSON nodes based on the query expression
protected  org.codehaus.jackson.JsonNode goDownPath(org.codehaus.jackson.JsonNode rootNode, java.lang.String simplePath)
          Extracts the JSON nodes under the simple path
protected  org.codehaus.jackson.JsonNode goDownPathWithAttribute(org.codehaus.jackson.JsonNode rootNode, java.lang.String pathWithAttributeExpression)
          Extracts the JSON nodes that match the attribute expression
protected  boolean isValidExpression(org.codehaus.jackson.JsonNode operand, java.lang.String attributeExpression)
          Validates an attribute expression on a JsonNode
static void main(java.lang.String[] args)
           
 void moveFirst()
          Moves back to the first element in the data source.
 boolean next()
          Tries to position the cursor on the next element in the data source.
 
Methods inherited from class net.sf.jasperreports.engine.data.JRAbstractTextDataSource
convertNumber, convertStringValue, getConvertBean, getDatePattern, getFormattedDate, getFormattedNumber, getLocale, getNumberPattern, getTimeZone, setDatePattern, setLocale, setLocale, setNumberPattern, setTextAttributes, setTimeZone, setTimeZone
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsonDataSource

public JsonDataSource(java.io.InputStream stream)
               throws JRException
Throws:
JRException

JsonDataSource

public JsonDataSource(java.io.InputStream jsonStream,
                      java.lang.String selectExpression)
               throws JRException
Throws:
JRException

JsonDataSource

public JsonDataSource(java.io.File file)
               throws java.io.FileNotFoundException,
                      JRException
Throws:
java.io.FileNotFoundException
JRException

JsonDataSource

public JsonDataSource(java.io.File file,
                      java.lang.String selectExpression)
               throws java.io.FileNotFoundException,
                      JRException
Throws:
java.io.FileNotFoundException
JRException

JsonDataSource

public JsonDataSource(JasperReportsContext jasperReportsContext,
                      java.lang.String location,
                      java.lang.String selectExpression)
               throws JRException
Creates a data source instance that reads JSON data from a given location

Parameters:
jasperReportsContext - the JasperReportsContext
location - a String representing JSON data source
selectExpression - a String representing the select expression
Throws:
JRException

JsonDataSource

public JsonDataSource(java.lang.String location,
                      java.lang.String selectExpression)
               throws JRException
Throws:
JRException
See Also:
JsonDataSource(JasperReportsContext, String, String)
Method Detail

moveFirst

public void moveFirst()
               throws JRException
Description copied from interface: JRRewindableDataSource
Moves back to the first element in the data source.

Specified by:
moveFirst in interface JRRewindableDataSource
Throws:
JRException

next

public boolean next()
Description copied from interface: JRDataSource
Tries to position the cursor on the next element in the data source.

Specified by:
next in interface JRDataSource
Returns:
true if there is a next record, false otherwise

getFieldValue

public java.lang.Object getFieldValue(JRField jrField)
                               throws JRException
Description copied from interface: JRDataSource
Gets the field value for the current position.

Specified by:
getFieldValue in interface JRDataSource
Returns:
an object containing the field value. The object type must be the field object type.
Throws:
JRException

getJsonData

protected org.codehaus.jackson.JsonNode getJsonData(org.codehaus.jackson.JsonNode rootNode,
                                                    java.lang.String jsonExpression)
                                             throws JRException
Extracts the JSON nodes based on the query expression

Parameters:
rootNode -
jsonExpression -
Throws:
JRException

goDownPathWithAttribute

protected org.codehaus.jackson.JsonNode goDownPathWithAttribute(org.codehaus.jackson.JsonNode rootNode,
                                                                java.lang.String pathWithAttributeExpression)
                                                         throws JRException
Extracts the JSON nodes that match the attribute expression

Parameters:
rootNode -
pathWithAttributeExpression - : e.g. Orders(CustomerId == HILAA)
Throws:
JRException

goDownPath

protected org.codehaus.jackson.JsonNode goDownPath(org.codehaus.jackson.JsonNode rootNode,
                                                   java.lang.String simplePath)
Extracts the JSON nodes under the simple path

Parameters:
rootNode -
simplePath - - a simple field name, with no selection by attribute

isValidExpression

protected boolean isValidExpression(org.codehaus.jackson.JsonNode operand,
                                    java.lang.String attributeExpression)
                             throws JRException
Validates an attribute expression on a JsonNode

Parameters:
operand -
attributeExpression -
Throws:
JRException

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception

close

public void close()


© 2001-2010 Jaspersoft Corporation www.jaspersoft.com