Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

many refractors

moved files

add report and container elements
  • Loading branch information...
commit 097834df26123ee8e4acd8027c69a31ec6af996b 1 parent 4dce50e
@adrianj98 adrianj98 authored
View
4 .gitignore
@@ -2,4 +2,6 @@ tmp/*
config/database.php
app/tmp/*
app/config/database.php
-!empty
+!empty
+/class/nbproject/private/
+/nbproject/private/
View
13 class/JasperExp.php → class/eval/JasperExp.php
@@ -53,4 +53,17 @@ function replaceVars($code)
function _setVar($name,$codename,$value) { }
+}
+
+
+function loadData($report)
+{
+ foreach ($report->table[$data->global_pointer] as $name => $value)
+ $this->addVar('$F{' . $name . '}', $value);
+ foreach ($report->variable as $name => $value)
+ $this->addVar('$V{' . $name . '}', $value);
+ foreach ($report->parameters as $name => $value)
+ $this->addVar('$P{' . $name . '}', $value);
+
+
}
View
1  class/JasperGroovy.php → class/eval/JasperGroovy.php
@@ -1,5 +1,6 @@
<?php
+require_once(dirname(__FILE__).'/JasperExp.php');
/**
* Description of JasperGroovy
View
4 class/JasperJS.php → class/eval/JasperJS.php
@@ -1,6 +1,6 @@
<?php
-
-require_once(dirname(__FILE__) . '/j4p5/js.php');
+require_once(dirname(__FILE__).'/JasperExp.php');
+require_once(dirname(__FILE__) . '/../j4p5/js.php');
class jasperJavascript extends JasperExp {
View
34 class/parser/JasperBand.php
@@ -4,9 +4,9 @@
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
-include dirname(__FILE__).'/JasperObject.php';
-include dirname(__FILE__).'/JasperElement.php';
-include dirname(__FILE__).'/JasperElements.php';
+require_once dirname(__FILE__).'/JasperObject.php';
+require_once dirname(__FILE__).'/JasperElement.php';
+require_once dirname(__FILE__).'/JasperElements.php';
/**
* Description of JasperBand
@@ -18,19 +18,30 @@
class Jasper_band extends JasperObject {
- protected $_height;
- protected $_isSplitAllowed;
- protected $_splitType;
+ protected $_height = 0; // Height of the band.
+ protected $_isSplitAllowed = ''; // Deprecated. Replaced by attribute splitType. Flag that indicates if the band is allowed to split when it stretches.
+
+ /**
+ * Specifies the band split behavior.
+ *
+ * Stretch The band is allowed to split, but never within its declared height. This means the band splits only when its content stretches.
+ * Prevent Prevents the band from splitting on first break attempt. On subsequent pages/columns, the band is allowed to split, to avoid infinite loops.
+ * Immediate The band is allowed to split anywhere, as early as needed, but not before at least one element being printed on the current page/column.
+ * @var string
+ */
+ protected $_splitType;
function addElement($element) {
$this->elements[] = $element;
}
- function parse($xm_path)
+ function parse($band)
{
- $band = $xm_path->band[0];
- $this->height = (integer) $band['height'];
- $this->isSplitAllowed = (string) $band['isSplitAllowed'];
- $this->splitType = (string) $band['splitType'];
+
+ // $this->height = $this-> $band['height'];
+ // $this->isSplitAllowed = (string) $band['isSplitAllowed'];
+ // $this->splitType = (string) $band['splitType'];
+
+ $this->loadValues($band);
$this->parseElements($band);
//array("type" => "band", "height" => $object["height"], "splitType" => $object["splitType"], "y_axis" => $this->y_axis);
@@ -45,7 +56,6 @@ public function parseElements($xml_path) {
$element = new $elementName($this);
else
$element = new Jasper_reportElement($this);
- $element->type = $k;
$element->parse($out);
$this->addElement($element);
// case "stackedBarChart":
View
32 class/parser/JasperContainer.php
@@ -0,0 +1,32 @@
+<?php
+
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/**
+ * Description of JasperContainer
+ *
+ * @author adrianjones
+ */
+class JasperContainer extends JasperObject {
+ protected $_band = null;
+
+ function parse($xm_path)
+ {
+ $this->_band = new Jasper_band($this);
+
+ $this->loadValues($xm_path);
+ $this->_band->parse($xm_path->band);
+
+ }
+}
+
+
+
+class Jasper_pageHeader extends JasperContainer {
+
+
+
+}
View
53 class/parser/JasperElement.php
@@ -27,10 +27,7 @@ function getString($value,$def='')
}
- function __construct($parent) {
- $this->parent = $parent;
- parent::__construct();
- }
+
function getBool($value,$def=false)
{
if (!isset($value))
@@ -89,31 +86,53 @@ function layout()
}
}
-
+class Jasper_pen extends JasperObject{
+ protected $_lineColor = '';
+ protected $_lineStyle = '';
+ protected $_lineWidth = -1;
+}
class Jasper_box extends Jasper_reportElement
{
//box
- protected $_border = 0;
- protected $_drawcolor = array("r" => 0, "g" => 0, "b" => 0);
+protected $_pen;
+protected $_topPen;
+protected $_leftPen;
+protected $_bottomPen;
+protected $_rightPen;
+
+protected $_padding = 0;
+protected $_topPadding = 0;
+protected $_leftPadding = 0;
+protected $_rightPadding = 0;
+protected $_bottomPadding = 0;
+
function layout()
- {
+ {
parent::layout();
}
function parse($data)
{
- parent::parse($data) ;
+ parent::parse($data);
+ $this->loadValues($data);
+
+ $data = $data->box;
+ if ($data->getName() == 'box')
+ {
// box dom there is a lot more needed for this dom
- if ((isset($data->box)) && ($data->box->pen["lineWidth"] > 0)) {
- $this->border = 1;
- if (isset($data->box->pen["lineColor"])) {
- $this->drawcolor = array("r" => hexdec(substr($data->box->pen["lineColor"], 1, 2)), "g" => hexdec(substr($data->box->pen["lineColor"], 3, 2)), "b" => hexdec(substr($data->box->pen["lineColor"], 5, 2)));
+ foreach (array('pen', 'topPen', 'leftPen', 'bottomPen', 'rightPen') as $pen) {
+ $p = $data->$pen;
+ $penname = $p->getName();
+ if (!empty($penname)) {
+ $penname = '_' . $penname;
+ $this->$penname = new Jasper_pen($this);
+ $this->$penname->loadValues($p);
}
- }
- }
+ }
+ }}
}
-class Jasper_textElement extends Jasper_box
+abstract class Jasper_textElement extends Jasper_box
{
//textElement
@@ -123,7 +142,7 @@ class Jasper_textElement extends Jasper_box
protected $_fontsize = 10;
protected $_font = "helvetica";
protected $_fontstyle = '';
-
+ abstract function getText();
function getTextSize($text)
{
View
16 class/parser/JasperElements.php
@@ -14,6 +14,10 @@ class Jasper_staticText extends Jasper_textElement {
protected $_text = "";
+ function getText()
+ {
+ return $this->_text;
+ }
public function parse($data) {
parent::parse($data);
@@ -54,16 +58,22 @@ function layout()
class Jasper_textField extends Jasper_textElement {
protected $_textFieldExpression = "";
-
+ protected $_curData ;
public function parse($data) {
+
+
parent::parse($data);
-
+
$this->textFieldExpression = (string) $data->textFieldExpression;
}
+ function getText() {
+ return '';
+ }
function layout()
- {
+ {
+
parent::layout();
$text = ''; //need get text expression
$this->getTextSize($text);
View
30 class/parser/JasperObject.php
@@ -15,11 +15,15 @@ class JasperObject implements Iterator {
protected $elements = array();
protected $elements_position = 0;
-
- public function __construct() {
+ protected $parent = null;
+ public $report = null;
+ public function __construct($parent) {
$this->elements_position = 0;
+ $this->parent = $parent;
+ if (isset($parent))
+ $this->report = $this->parent->report;
+
}
-
function rewind() {
$this->elements_position = 0;
}
@@ -58,6 +62,26 @@ function __set($name,$value)
}
+ function loadValues($values)
+ {
+ foreach($values->attributes() as $name => $value)
+ {
+ $name = '_'.$name;
+ if (property_exists($this, $name)){
+ $type = gettype($this->$name ) ;
+ if ($type== 'string' )
+ $this->$name = (string) $value;
+ elseif ($type== 'integer' )
+ $this->$name = (integer) $value;
+ elseif ($type == 'double' )
+ $this->$name = (float) $value;
+ else
+ $this->$name = $value;
+ }
+
+ }
+ }
+
}
View
62 class/parser/JasperReport.php
@@ -0,0 +1,62 @@
+<?php
+
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+require_once dirname(__FILE__).'/JasperContainer.php';
+require_once dirname(__FILE__).'/JasperBand.php';
+
+/**
+ * Description of jasperReport
+ *
+ * @author adrianjones
+ */
+class JasperReport extends JasperObject {
+
+ protected $_name = '';
+ protected $_language = 'java';
+ protected $_pageWidth = 595;
+ protected $_pageHeight = 842;
+ protected $_orientation = 'Portrait';
+ protected $_leftMargin = 20;
+ protected $_rightMargin = 20;
+ protected $_topMargin = 30;
+ protected $_bottomMargin = 30;
+
+
+
+ protected $_pageHeader = null;
+
+ public function parse($xml_path) {
+
+
+
+ // parent::parse($xml_path);
+
+
+ $this->loadValues($xml_path);
+
+ foreach ($xml_path as $k => $out) {
+
+ $elementName = 'Jasper_' . $k;
+ if (class_exists($elementName)) {
+ $element = new $elementName($this);
+
+ $element->parse($out);
+ $propertyName = '_' . $k;
+ if (property_exists($this, $propertyName))
+ $this->$propertyName = $element;
+ }
+ if ($k == 'parameter')
+ {
+ $name = $out['name'];
+ $value = (string)$out->defaultValueExpression;
+ if (isset($name))
+ $this->parameters[$name] = $value;
+ }
+ }
+ }
+
+}
+
View
3  tests/class/parser/JasperBandTest.php
@@ -71,6 +71,9 @@ public function testParseElements() {
public $testBand = '<pageHeader>
<band height="177" splitType="Stretch">
<textField>
+ <box>
+ <leftPen lineStyle="Solid" />
+ </box>
<reportElement style="Column header" x="492" y="14" width="66" height="26" forecolor="#000000">
<printWhenExpression><![CDATA[$P{printType} == ( "quote" )]]></printWhenExpression>
</reportElement>
View
26 tests/class/parser/JasperReportTest.php
@@ -0,0 +1,26 @@
+<?php
+require_once dirname(__FILE__) . '/../../../class/parser/JasperBand.php';
+require_once dirname(__FILE__) . '/../../../class/parser/JasperReport.php';
+
+
+
+/**
+ * Description of JasperReportTest
+ *
+ * @author adrianjones
+ */
+class JasperReportTest extends PHPUnit_Framework_TestCase {
+
+ function testParse()
+ {
+ $report = new JasperReport();
+
+
+ $xml = simplexml_load_file(dirname(__FILE__) . '/reportTest.jrxml');
+
+ $report->parse($xml);
+
+
+
+ }
+}
View
216 tests/class/parser/reportTest.jrxml
@@ -0,0 +1,216 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report7" language="javascript" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="12" bottomMargin="20">
+ <property name="ireport.zoom" value="1.0"/>
+ <property name="ireport.x" value="0"/>
+ <property name="ireport.y" value="0"/>
+ <style name="Title" forecolor="#FFFFFF" fontName="times" fontSize="50" isBold="false" pdfFontName="times"/>
+ <style name="SubTitle" forecolor="#CCCCCC" fontName="times" fontSize="18" isBold="false" pdfFontName="times"/>
+ <style name="Column header" forecolor="#666666" fontName="times" fontSize="14" isBold="true" pdfFontName="times"/>
+ <style name="Detail" mode="Transparent" fontName="times" pdfFontName="times"/>
+ <style name="Row" mode="Transparent" fontName="times" pdfFontName="times">
+ <conditionalStyle>
+ <conditionExpression><![CDATA[$V{REPORT_COUNT}%2 == 0]]></conditionExpression>
+ <style mode="Opaque" backcolor="#F0EFEF"/>
+ </conditionalStyle>
+ </style>
+ <parameter name="printType" class="java.lang.String">
+ <defaultValueExpression><![CDATA[quote]]></defaultValueExpression>
+ </parameter>
+ <queryString>
+ <![CDATA[]]>
+ </queryString>
+ <field name="Article" class="java.lang.String"/>
+ <field name="Category" class="java.lang.String"/>
+ <field name="Description" class="java.lang.String"/>
+ <field name="Quantity" class="java.lang.String"/>
+ <field name="Value" class="java.lang.String"/>
+ <filterExpression><![CDATA[$F{Article}.toString().length > 1]]></filterExpression>
+ <group name="Category" isReprintHeaderOnEachPage="true" minHeightToStartNewPage="60">
+ <groupExpression><![CDATA[$F{Category}]]></groupExpression>
+ <groupHeader>
+ <band height="43">
+ <textField isStretchWithOverflow="true">
+ <reportElement style="SubTitle" x="1" y="13" width="431" height="15" forecolor="#000000"/>
+ <textElement verticalAlignment="Middle">
+ <font fontName="Palatino Linotype" size="11" isBold="false" isItalic="true"/>
+ </textElement>
+ <textFieldExpression><![CDATA[$F{Category}]]></textFieldExpression>
+ </textField>
+ <line>
+ <reportElement x="0" y="41" width="555" height="2" forecolor="#000000"/>
+ </line>
+ <staticText>
+ <reportElement style="Column header" x="0" y="27" width="99" height="13" forecolor="#000000"/>
+ <textElement verticalAlignment="Bottom">
+ <font fontName="cid0jp" size="9" />
+ </textElement>
+ <text><![CDATA[你好]]></text>
+ </staticText>
+ <staticText>
+ <reportElement style="Column header" x="125" y="18" width="307" height="22" forecolor="#000000"/>
+ <textElement textAlignment="Center" verticalAlignment="Bottom">
+ <font fontName="times" size="9" isBold="true"/>
+ </textElement>
+ <text><![CDATA[Description]]></text>
+ </staticText>
+ <staticText>
+ <reportElement style="Column header" x="492" y="14" width="66" height="26" forecolor="#000000">
+ <printWhenExpression><![CDATA[$P{printType} == ( "quote" )]]></printWhenExpression>
+ </reportElement>
+ <textElement textAlignment="Center" verticalAlignment="Bottom">
+ <font fontName="times" size="9" isBold="true"/>
+ </textElement>
+ <text><![CDATA[Quotation Per Unit (US$)]]></text>
+ </staticText>
+ <staticText>
+ <reportElement style="Column header" x="442" y="14" width="47" height="26" forecolor="#000000"/>
+ <textElement textAlignment="Center" verticalAlignment="Bottom">
+ <font fontName="times" size="9" isBold="true"/>
+ </textElement>
+ <text><![CDATA[Quantity Per Unit]]></text>
+ </staticText>
+ <staticText>
+ <reportElement style="Column header" x="502" y="14" width="50" height="26" forecolor="#000000">
+ <printWhenExpression><![CDATA[$P{printType} == ( "pricelist" )]]></printWhenExpression>
+ </reportElement>
+ <textElement textAlignment="Center" verticalAlignment="Bottom">
+ <font fontName="times" size="9" isBold="true"/>
+ </textElement>
+ <text><![CDATA[Price Per Unit(US$)]]></text>
+ </staticText>
+ <staticText>
+ <reportElement style="Column header" x="500" y="14" width="50" height="26" forecolor="#000000">
+ <printWhenExpression><![CDATA[$P{printType} == ( "ordersheet" )]]></printWhenExpression>
+ </reportElement>
+ <textElement textAlignment="Center" verticalAlignment="Bottom">
+ <font fontName="times" size="9" isBold="true"/>
+ </textElement>
+ <text><![CDATA[Units Ordered]]></text>
+ </staticText>
+ </band>
+ </groupHeader>
+ <groupFooter>
+ <band/>
+ </groupFooter>
+ </group>
+ <background>
+ <band splitType="Stretch"/>
+ </background>
+ <pageHeader>
+ <band height="70">
+ <image>
+ <reportElement x="0" y="-1" width="206" height="66"/>
+ <imageExpression><![CDATA["images/logo.jpg"]]></imageExpression>
+ </image>
+ <staticText>
+ <reportElement x="440" y="11" width="115" height="27">
+ <printWhenExpression><![CDATA[$P{printType} == "quote"]]></printWhenExpression>
+ </reportElement>
+ <textElement textAlignment="Right">
+ <font fontName="cid0jp" size="16" isPdfEmbedded="true"/>
+ </textElement>
+ <text><![CDATA[你好]]></text>
+ </staticText>
+ <staticText>
+ <reportElement x="440" y="12" width="115" height="27">
+ <printWhenExpression><![CDATA[$P{printType} == "pricelist"]]></printWhenExpression>
+ </reportElement>
+ <textElement textAlignment="Right">
+ <font fontName="times" size="16" isBold="true" isPdfEmbedded="true"/>
+ </textElement>
+ <text><![CDATA[Price List]]></text>
+ </staticText>
+ <textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true">
+ <reportElement style="Detail" positionType="Float" x="490" y="38" width="65" height="24"/>
+ <textElement textAlignment="Right" verticalAlignment="Middle">
+ <font fontName="times" size="8"/>
+ </textElement>
+ <textFieldExpression><![CDATA[""]]></textFieldExpression>
+ </textField>
+ </band>
+ </pageHeader>
+ <columnHeader>
+ <band splitType="Stretch"/>
+ </columnHeader>
+ <detail>
+ <band height="26" splitType="Stretch">
+ <textField isStretchWithOverflow="true">
+ <reportElement style="Detail" positionType="Float" x="0" y="0" width="65" height="24"/>
+ <textElement verticalAlignment="Middle">
+ <font fontName="times" size="8"/>
+ </textElement>
+ <textFieldExpression><![CDATA[$F{Article}]]></textFieldExpression>
+ </textField>
+ <textField isStretchWithOverflow="true">
+ <reportElement style="Detail" positionType="Float" x="123" y="0" width="307" height="24"/>
+ <textElement textAlignment="Center" verticalAlignment="Middle">
+ <font fontName="times" size="8" isPdfEmbedded="true"/>
+ </textElement>
+ <textFieldExpression><![CDATA[$F{Description}]]></textFieldExpression>
+ </textField>
+ <textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true">
+ <reportElement style="Detail" positionType="Float" x="500" y="0" width="37" height="24">
+ <printWhenExpression><![CDATA[$P{printType} != "ordersheet"]]></printWhenExpression>
+ </reportElement>
+ <textElement textAlignment="Right" verticalAlignment="Middle">
+ <font fontName="times" size="8"/>
+ </textElement>
+ <textFieldExpression><![CDATA[$F{Value}]]></textFieldExpression>
+ </textField>
+ <image hAlign="Center" vAlign="Middle" isUsingCache="false" onErrorType="Blank">
+ <reportElement stretchType="RelativeToBandHeight" x="65" y="1" width="53" height="22" forecolor="#FFFFFF"/>
+ <imageExpression><![CDATA["images/"+ $F{Image} +".jpg"]]></imageExpression>
+ </image>
+ <textField isStretchWithOverflow="true">
+ <reportElement style="Detail" positionType="Float" x="431" y="0" width="65" height="24"/>
+ <textElement textAlignment="Center" verticalAlignment="Middle">
+ <font fontName="times" size="8"/>
+ </textElement>
+ <textFieldExpression><![CDATA[$F{Quantity}]]></textFieldExpression>
+ </textField>
+ <line>
+ <reportElement positionType="FixRelativeToBottom" x="0" y="25" width="555" height="1"/>
+ <graphicElement>
+ <pen lineWidth="0.5" lineColor="#999999"/>
+ </graphicElement>
+ </line>
+ </band>
+ </detail>
+ <columnFooter>
+ <band splitType="Stretch"/>
+ </columnFooter>
+ <pageFooter>
+ <band height="49" splitType="Stretch">
+ <image onErrorType="Blank">
+ <reportElement x="0" y="17" width="557" height="32">
+ <printWhenExpression><![CDATA[$P{printType}.equals( "none" )]]></printWhenExpression>
+ </reportElement>
+ <imageExpression><![CDATA["images/footer.gif"]]></imageExpression>
+ </image>
+ <line>
+ <reportElement x="1" y="12" width="555" height="1" forecolor="#D92127"/>
+ </line>
+ <image onErrorType="Blank">
+ <reportElement x="0" y="17" width="557" height="32"/>
+ <imageExpression><![CDATA["images/footer.gif"]]></imageExpression>
+ </image>
+ <staticText>
+ <reportElement x="475" y="0" width="132" height="20"/>
+ <textElement>
+ <font fontName="times" size="8" isItalic="true" isPdfEmbedded="true"/>
+ </textElement>
+ <text><![CDATA[*All prices are ex-works]]></text>
+ </staticText>
+ <textField pattern="#,##0">
+ <reportElement x="547" y="38" width="9" height="11"/>
+ <textElement textAlignment="Right">
+ <font fontName="times" size="8"/>
+ </textElement>
+ <textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
+ </textField>
+ </band>
+ </pageFooter>
+ <summary>
+ <band splitType="Stretch"/>
+ </summary>
+</jasperReport>

0 comments on commit 097834d

Please sign in to comment.
Something went wrong with that request. Please try again.