Exemple #1
0
 function java_PageContext($java_session)
 {
     if (java_is_null($java_session)) {
         throw new Exception("session is null");
     }
     $ctx = java_context();
     $this->servlet = $ctx->getAttribute("php.java.servlet.Servlet");
     $this->response = $ctx->getAttribute("php.java.servlet.HttpServletResponse");
     $this->request = $ctx->getAttribute("php.java.servlet.HttpServletRequest");
     $factory = java("javax.servlet.jsp.JspFactory")->getDefaultFactory();
     $this->pc = $factory->getPageContext($this->servlet, $this->request, $this->response, null, true, 8192, false);
     $this->out = $this->pc->out;
 }
 function run()
 {
     $name = java_values(java_context()->getAttribute("name", 100));
     // engine scope
     $out = new Java("java.io.FileOutputStream", "{$name}.out", true);
     $Thread = java("java.lang.Thread");
     $nr = java_values(java_context()->getAttribute("nr", 100));
     echo "started thread: {$nr}\n";
     for ($i = 0; $i < 10; $i++) {
         $out->write(ord("{$nr}"));
         $Thread->yield();
     }
     $out->close();
 }
Exemple #3
0
 public function renderReport($reportName, $options = [], $outputType = self::OUTPUT_TYPE_HTML)
 {
     $reportPath = ArrayHelper::getValue($options, 'reportPath', $this->reportPath);
     if ($reportPath === null) {
         throw new InvalidConfigException('The "reportPath" property must be set.');
     }
     $reportPath = Yii::getAlias($reportPath);
     $context = java_context()->getServletContext();
     $birtReportEngine = java("org.eclipse.birt.php.birtengine.BirtEngine")->getBirtEngine($context);
     java_context()->onShutdown(java("org.eclipse.birt.php.birtengine.BirtEngine")->getShutdownHook());
     $report = $birtReportEngine->openReportDesign("{$reportPath}/{$reportName}");
     //        $parameterArray = $report->getDesignHandle()->getParameters();
     //        $ds = $report->getDesignHandle()->findDataSource("Data Source");
     //        $ds->setProperty('odaURL', 'jdbc:postgresql://localhost:5432/mdmbiz3');
     $task = $birtReportEngine->createRunAndRenderTask($report);
     if (!empty($options['params'])) {
         foreach ($options['params'] as $key => $value) {
             $nval = new Java("java.lang.String", $value);
             $task->setParameterValue($key, $nval);
         }
     }
     if ($outputType == self::OUTPUT_TYPE_PDF) {
         $outputOptions = ['pdfRenderOption.pageOverflow' => 'pdfRenderOption.fitToPage'];
     } else {
         $outputOptions = [];
     }
     if (!empty($options['options'])) {
         $outputOptions = array_merge($outputOptions, $options['options']);
     }
     $optionClass = isset($this->optionClasses[$outputType]) ? $this->optionClasses[$outputType] : $this->optionClasses['default'];
     $taskOptions = new Java($optionClass);
     $outputStream = new Java("java.io.ByteArrayOutputStream");
     $taskOptions->setOutputStream($outputStream);
     foreach ($outputOptions as $key => $value) {
         $taskOptions->setOption($key, $value);
     }
     $taskOptions->setOutputFormat($outputType);
     if ($outputType == self::OUTPUT_TYPE_HTML) {
         $ih = new Java("org.eclipse.birt.report.engine.api.HTMLServerImageHandler");
         $taskOptions->setImageHandler($ih);
         $taskOptions->setEnableAgentStyleEngine(true);
         $taskOptions->setBaseImageURL($this->imagePath);
         $taskOptions->setImageDirectory($this->imagePath);
     }
     $task->setRenderOption($taskOptions);
     $task->run();
     $task->close();
     return java_values($outputStream->toByteArray());
 }
 public function __construct()
 {
     $this->_gateway = java_context()->getServletContext()->getAttribute(PetroQuick_Neo4JGateway_Config::GATEWAY_CONTEXT_PARAM);
     $this->_neo = $this->_gateway->getGraphDb();
     $this->_index = $this->_gateway->factoryIndex();
     $this->_fulltextIndex = $this->_gateway->factoryFulltextIndex();
     $this->DIRECTION = java('org.neo4j.graphdb.Direction');
     if (empty($this->_subrefNodeName)) {
         $parts = explode('_', get_class($this));
         $this->_subrefNodeName = strtoupper($parts[count($parts) - 1]) . 'S';
     }
     if (empty($this->_nodeName)) {
         $parts = explode('_', get_class($this));
         $this->_nodeName = strtoupper($parts[count($parts) - 1]);
     }
 }
<?php

header("Content-type: application/pdf");
header("Content-Disposition: attachment; filename=downloaded.pdf");
define("JAVA_HOSTS", "127.0.0.1:8080");
define("JAVA_SERVLET", "/JavaBridge/JavaBridge.phpjavabridge");
require_once "java/Java.inc";
session_start();
$here = getcwd();
$ctx = java_context()->getServletContext();
$birtReportEngine = java("org.eclipse.birt.php.birtengine.BirtEngine")->getBirtEngine($ctx);
java_context()->onShutdown(java("org.eclipse.birt.php.birtengine.BirtEngine")->getShutdownHook());
try {
    $report = $birtReportEngine->openReportDesign("{$here}/TopNPercent.rptdesign");
    $task = $birtReportEngine->createRunAndRenderTask($report);
    $taskOptions = new java("org.eclipse.birt.report.engine.api.PDFRenderOption");
    $outputStream = new java("java.io.ByteArrayOutputStream");
    $taskOptions->setOutputStream($outputStream);
    $taskOptions->setOption("pdfRenderOption.pageOverflow", "pdfRenderOption.fitToPage");
    $taskOptions->setOutputFormat("pdf");
    $task->setRenderOption($taskOptions);
    $task->run();
    $task->close();
} catch (JavaException $e) {
    echo $e;
    //"Error Calling BIRT";
}
//echo $outputStream;
echo java_values($outputStream->toByteArray());
<html>
<?php 
require_once "java/Java.inc";
$Util = java("php.java.bridge.Util");
$ctx = java_context();
/* get the current instance of the JavaBridge, ServletConfig and Context */
$bridge = $ctx->getAttribute("php.java.bridge.JavaBridge", 100);
$config = $ctx->getAttribute("php.java.servlet.ServletConfig", 100);
$context = $ctx->getAttribute("php.java.servlet.ServletContext", 100);
$servlet = $ctx->getAttribute("php.java.servlet.Servlet", 100);
?>
<head>
   <title>PHP/Java Bridge settings</title>
</head>
<body bgcolor="#FFFFFF">
<H1>PHP/Java Bridge settings</H1>
<p>
The PHP/Java Bridge web application contains two servlets. The <code>PhpJavaServlet</code> handles requests from remote PHP scripts running in Apache/IIS or from the command line. 
The second servlet <code>PhpCGIServlet</code> can handle requests from internet clients directly. 
<p>
The following shows the settings of the <code>PhpJavaServlet</code> and the <code>PhpCGIServlet</code>.
</p>
<H2>PhpJavaServlet</H2>
<p>
The <code>PhpJavaServlet</code> handles requests from PHP clients.
<blockquote>
<code>
Apache/IIS/console::PHP &lt;--&gt; PhpJavaServlet
</code>
</blockquote>
        $this->label = new java("javax.swing.JLabel");
        $button->addActionListener(java_closure($this, null, java("java.awt.event.ActionListener")));
        $this->label->setLabelFor($button);
        $pane = new java("javax.swing.JPanel", new java("java.awt.GridLayout", 0, 1));
        $pane->add($button);
        $pane->add($this->label);
        $BorderFactory = new JavaClass("javax.swing.BorderFactory");
        $pane->setBorder($BorderFactory->createEmptyBorder(30, 30, 10, 30));
        return $pane;
    }
    function init()
    {
        $this->frame = $frame = new java("javax.swing.JFrame", "SwingApplication");
        $frame->setDefaultcloseOperation($frame->EXIT_ON_CLOSE);
        $contents = $this->createComponents();
        $contentPane = $frame->getContentPane();
        $BorderLayout = new JavaClass("java.awt.BorderLayout");
        $contentPane->add($contents, $BorderLayout->CENTER);
        $frame->pack();
    }
    function run()
    {
        $this->frame->setVisible(true);
    }
}
java_context()->call(java_closure(new SwingApplication())) || die("must be called from java");
// The php-invocable engine automatically adds java_context()->call(java_closure())
// to the bottom of each invocable script. Explicitly call exit(0) to avoid calling
// the Java continuation again.
echo "terminating";
exit(0);
function java_call_with_continuation($kontinuation = null)
{
    if (java_getHeader("X_JAVABRIDGE_INCLUDE", $_SERVER) && !java_getHeader("X_JAVABRIDGE_INCLUDE_ONLY", $_SERVER)) {
        if (is_null($kontinuation)) {
            java_context()->call(java_closure());
        } elseif (is_string($kontinuation)) {
            java_context()->call(call_user_func($kontinuation));
        } elseif ($kontinuation instanceof JavaType) {
            java_context()->call($kontinuation);
        } else {
            java_context()->call(java_closure($kontinuation));
        }
    }
}
 protected function setUp()
 {
     $this->_neoGateway = java_context()->getServletContext()->getAttribute(PetroQuick_Neo4JGateway_Config::GATEWAY_CONTEXT_PARAM);
     $this->_cleanupDb();
 }
<?php

include_once "java/Java.inc";
$s = new java("java.lang.String", 12);
$c1 = java_context();
$c2 = java_session();
$c3 = java_session();
$c4 = java_context();
echo "{$c1}\n{$c2}\n{$c3}\n{$c4}\n";
$instance = java_instanceof($s, new java("java.lang.String"));
if (!$c1 || !$c2 || !$c3 || !$c4 || !$instance) {
    echo "ERROR\n";
    exit(1);
}
echo "test okay\n";
exit(0);
Exemple #11
0
function java_get_context()
{
    return java_context();
}
Exemple #12
0
 /**
  * Inicialização básica do Framework.
  * Inicializa "variáveis globais", sessão, log e FrontController.
  */
 public static function initialize()
 {
     if (self::$instance->java = $_SERVER["SERVER_SOFTWARE"] == "JavaBridge") {
         require_once self::$instance->home . "/java/Java.inc";
         self::$instance->javaContext = java_context();
         self::$instance->javaServletContext = java_context()->getServletContext();
     }
     self::$instance->getObject('login');
     self::$instance->session = new MSession();
     self::$instance->session->init(mrequest('sid'));
     self::$msg = new MMessages(self::$instance->getOptions('language'));
     self::$msg->loadMessages();
     self::$instance->mode = self::$instance->getOptions("mode");
     date_default_timezone_set(self::$instance->getOptions("timezone"));
     setlocale(LC_ALL, self::$instance->getOptions("locale"));
     self::$instance->setLog('manager');
     self::$instance->mad = self::$instance->conf['mad']['module'];
     self::$instance->controller = MFrontController::getInstance();
 }