CODE STYLE class.javaBridgePM.php

This commit is contained in:
Fernando Ontiveros
2012-10-09 12:52:35 -04:00
parent ace3ab8006
commit f2ec274099

View File

@@ -1,6 +1,7 @@
<?php <?php
/** /**
* class.javaBridgePM.php * class.javaBridgePM.php
*
* @package workflow.engine.classes * @package workflow.engine.classes
* *
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
@@ -13,166 +14,160 @@
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
* For more information, contact Colosa Inc, 2566 Le Jeune Rd., * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
*/ */
if ( ! defined ( 'JAVA_BRIDGE_PATH') ) define ( 'JAVA_BRIDGE_PATH', 'JavaBridgePM' );
if ( ! defined ( 'JAVA_BRIDGE_PORT') ) define ( 'JAVA_BRIDGE_PORT', '8080' );
if ( ! defined ( 'JAVA_BRIDGE_HOST') ) define ( 'JAVA_BRIDGE_HOST', '127.0.0.1' );
/** if (! defined( 'JAVA_BRIDGE_PATH' ))
* @package workflow.engine.classes define( 'JAVA_BRIDGE_PATH', 'JavaBridgePM' );
*/ if (! defined( 'JAVA_BRIDGE_PORT' ))
class JavaBridgePM define( 'JAVA_BRIDGE_PORT', '8080' );
{ if (! defined( 'JAVA_BRIDGE_HOST' ))
var $JavaBridgeDir = JAVA_BRIDGE_PATH; define( 'JAVA_BRIDGE_HOST', '127.0.0.1' );
/**
*
* @package workflow.engine.classes
*/
class JavaBridgePM
{
var $JavaBridgeDir = JAVA_BRIDGE_PATH;
var $JavaBridgePort = JAVA_BRIDGE_PORT; var $JavaBridgePort = JAVA_BRIDGE_PORT;
var $JavaBridgeHost = JAVA_BRIDGE_HOST; var $JavaBridgeHost = JAVA_BRIDGE_HOST;
/** /**
* checkJavaExtension * checkJavaExtension
* check if the java extension was loaded. * check if the java extension was loaded.
* *
* @return true or false *
*/ * @return true or false
function checkJavaExtension() */
function checkJavaExtension ()
{ {
try { try {
if (!extension_loaded('java')) { if (! extension_loaded( 'java' )) {
if (!(@include_once("java/Java.inc"))) { if (! (@include_once ("java/Java.inc"))) {
$urlJavaInc = "http://$this->JavaBridgeHost:$this->JavaBridgePort/$this->JavaBridgeDir/java/Java.inc"; $urlJavaInc = "http://$this->JavaBridgeHost:$this->JavaBridgePort/$this->JavaBridgeDir/java/Java.inc";
@include_once( $urlJavaInc); @include_once ($urlJavaInc);
$includedFiles = get_included_files(); $includedFiles = get_included_files();
$found = false; $found = false;
foreach ($includedFiles as $filename) { foreach ($includedFiles as $filename) {
if ( $urlJavaInc == $filename ) $found = true; if ($urlJavaInc == $filename)
$found = true;
}
if (! $found) {
throw new Exception( 'The PHP/Java Bridge is not defined' );
}
}
return true;
} }
if ( !$found ) {
throw new Exception ('The PHP/Java Bridge is not defined' ) ; if (! function_exists( "java_get_server_name" )) {
throw new Exception( 'The loaded java extension is not the PHP/Java Bridge' );
} }
} return true;
return true; } catch (Exception $e) {
throw new Exception( 'Error in checkJavaExtension: ' . $e->getMessage() );
} }
if ( !function_exists("java_get_server_name")) {
throw new Exception ('The loaded java extension is not the PHP/Java Bridge' );
}
return true;
}
catch ( Exception $e ) {
throw new Exception ( 'Error in checkJavaExtension: ' . $e->getMessage() );
}
} }
/**
* convert a php value to a java one...
* @param string $value
* @param string $className
* @returns boolean success
*/
function convertValue($value, $className)
{
// if we are a string, just use the normal conversion
// methods from the java extension...
try {
if ($className == 'java.lang.String') {
$temp = new Java('java.lang.String', $value);
return $temp;
}
else if ($className == 'java.lang.Boolean' ||
$className == 'java.lang.Integer' ||
$className == 'java.lang.Long' ||
$className == 'java.lang.Short' ||
$className == 'java.lang.Double' ||
$className == 'java.math.BigDecimal') {
$temp = new Java($className, $value);
return $temp;
}
else if ($className == 'java.sql.Timestamp' ||
$className == 'java.sql.Time') {
$temp = new Java($className);
$javaObject = $temp->valueOf($value);
return $javaObject;
}
}
catch (Exception $err) {
echo ( 'unable to convert value, ' . $value .
' could not be converted to ' . $className);
return false;
}
echo ( 'unable to convert value, class name '.$className.
' not recognised');
return false;
}
/** /**
* generateJrxmlFromDynaform * convert a php value to a java one...
* @param string $outDocUid *
* @param string $dynaformUid * @param string $value
* @param object $template * @param string $className
* @return void * @return s boolean success
*/ */
function generateJrxmlFromDynaform ( $outDocUid, $dynaformUid, $template ) { function convertValue ($value, $className)
require_once 'classes/model/Dynaform.php'; {
$dyn = new Dynaform(); // if we are a string, just use the normal conversion
$aFields = $dyn->load( $dynaformUid); // methods from the java extension...
$xmlFields = $dyn->getDynaformFields( $dynaformUid); try {
if ($className == 'java.lang.String') {
$reportTpl = PATH_TPL . 'javaBridgePM/classic.xml'; $temp = new Java( 'java.lang.String', $value );
$reportFilename = PATH_DYNAFORM . $aFields['PRO_UID'] . PATH_SEP . $outDocUid .'.jrxml'; return $temp;
foreach ( $xmlFields as $key => $val ) { } else if ($className == 'java.lang.Boolean' || $className == 'java.lang.Integer' || $className == 'java.lang.Long' || $className == 'java.lang.Short' || $className == 'java.lang.Double' || $className == 'java.math.BigDecimal') {
if ( $val->type == 'submit' || $val->type == 'button' || $val->type == 'title' || $val->type == 'subtitle' ) $temp = new Java( $className, $value );
unset ( $xmlFields[$key] ); return $temp;
} } else if ($className == 'java.sql.Timestamp' || $className == 'java.sql.Time') {
$temp = new Java( $className );
//$sqlSentence = 'SELECT * from ' . $tableName; $javaObject = $temp->valueOf( $value );
$sqlSentence = 'dynaform/'; return $javaObject;
}
$template = new TemplatePower( $reportTpl ); } catch (Exception $err) {
$template->prepare(); echo ('unable to convert value, ' . $value . ' could not be converted to ' . $className);
$template->assign ( 'sqlSentence', $sqlSentence ); return false;
$template->assign ( 'tableName', $aFields['DYN_TITLE'] ); }
$template->assign ( 'heightDetail', count ($xmlFields)*15 + 20 );
$template->assign ( 'PAGE_NUMBER' , '{PAGE_NUMBER}' );
$logoReporte = 'http://' .$_SERVER['SERVER_NAME'] . ':' .$_SERVER['SERVER_PORT'] . echo ('unable to convert value, class name ' . $className . ' not recognised');
'/images/processmaker.logo.jpg'; return false;
$template->assign ( 'logoReporte', $logoReporte );
foreach ( $xmlFields as $key => $val ) {
$template->newBlock( 'fields');
$template->assign ( 'fieldName' , $key );
}
$posX = 140;
$posLabelX = 5;
$posY = 10;
foreach ( $xmlFields as $key => $val ) {
$template->newBlock( 'detailFields');
$template->assign ( 'fieldName' , '{' . $key . '}' );
$template->assign ( 'fieldLabel' , $key );
$template->assign ( 'labelPosX' , $posLabelX );
$template->assign ( 'fieldPosX' , $posX );
$template->assign ( 'fieldPosY' , $posY );
$posY += 15;
}
$content = $template->getOutputContent();
$iSize = file_put_contents ( $reportFilename, $content );
printf("saved %s bytes in file %s \n", $iSize, $reportFilename );
} }
} /**
* generateJrxmlFromDynaform
*
* @param string $outDocUid
* @param string $dynaformUid
* @param object $template
* @return void
*/
function generateJrxmlFromDynaform ($outDocUid, $dynaformUid, $template)
{
require_once 'classes/model/Dynaform.php';
$dyn = new Dynaform();
$aFields = $dyn->load( $dynaformUid );
$xmlFields = $dyn->getDynaformFields( $dynaformUid );
$reportTpl = PATH_TPL . 'javaBridgePM/classic.xml';
$reportFilename = PATH_DYNAFORM . $aFields['PRO_UID'] . PATH_SEP . $outDocUid . '.jrxml';
foreach ($xmlFields as $key => $val) {
if ($val->type == 'submit' || $val->type == 'button' || $val->type == 'title' || $val->type == 'subtitle')
unset( $xmlFields[$key] );
}
//$sqlSentence = 'SELECT * from ' . $tableName;
$sqlSentence = 'dynaform/';
$template = new TemplatePower( $reportTpl );
$template->prepare();
$template->assign( 'sqlSentence', $sqlSentence );
$template->assign( 'tableName', $aFields['DYN_TITLE'] );
$template->assign( 'heightDetail', count( $xmlFields ) * 15 + 20 );
$template->assign( 'PAGE_NUMBER', '{PAGE_NUMBER}' );
$logoReporte = 'http://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . '/images/processmaker.logo.jpg';
$template->assign( 'logoReporte', $logoReporte );
foreach ($xmlFields as $key => $val) {
$template->newBlock( 'fields' );
$template->assign( 'fieldName', $key );
}
$posX = 140;
$posLabelX = 5;
$posY = 10;
foreach ($xmlFields as $key => $val) {
$template->newBlock( 'detailFields' );
$template->assign( 'fieldName', '{' . $key . '}' );
$template->assign( 'fieldLabel', $key );
$template->assign( 'labelPosX', $posLabelX );
$template->assign( 'fieldPosX', $posX );
$template->assign( 'fieldPosY', $posY );
$posY += 15;
}
$content = $template->getOutputContent();
$iSize = file_put_contents( $reportFilename, $content );
printf( "saved %s bytes in file %s \n", $iSize, $reportFilename );
}
}