function createComponents()
 {
     $button = new java("javax.swing.JButton", "I'm a Swing button!");
     $button->addActionListener(java_closure($this, new JavaClass("java.awt.event.ActionListener")));
     $label->setLabelFor($button);
     $pane = new java("javax.swing.Jpanel", new java("javax.swing.GridLayout", 0, 1));
     $pane->add(button);
     $pane->add(label);
     $BorderFactory = new JavaClass("javax.swing.BorderFactory");
     $pane->setBorder($BorderFactory->createEmptyBorder(30, 30, 10, 30));
     return $pane;
 }
Exemplo n.º 2
0
#!/usr/bin/php

<?php 
include_once "java/Java.inc";
$ar = array(1, 2, 3, 5, 7, 11, -13, -17.01, 19);
unset($ar[1]);
$v = new java("java.util.Vector", $ar);
$Arrays = new java_class("java.util.Arrays");
$l = $Arrays->asList($ar);
$v->add(1, null);
$l2 = $v->sublist(0, $v->size());
echo java_cast($l, "S") . "\n" . java_cast($l2, "S") . "\n";
$res1 = java_values($l);
$res2 = java_values($l2);
$res3 = array();
$res4 = array();
$i = 0;
foreach ($v as $key => $val) {
    $res3[$i++] = java_values($val);
}
for ($i = 0; $i < java_values($l2->size()); $i++) {
    $res4[$i] = java_values($l2[$i]);
}
if (!$l->equals($l2)) {
    echo "ERROR\n";
    exit(1);
}
if (java_values($l[1]) != null || (string) $res3 != (string) $res1 || (string) $res4 != (string) $res1) {
    echo "ERROR\n";
    exit(2);
}
Exemplo n.º 3
0
#!/usr/bin/php

<?php 
include_once "java/Java.inc";
$ListClass = new java_class("java.util.ArrayList");
$list = new java("java.util.ArrayList");
$list->add(0);
$list->add("one");
$list->add(null);
$list->add(new java("java.lang.Object"));
$list->add(new java("java.lang.Long", 4));
$list->add($list);
// the list now contains itself
$list->add(new java("java.lang.String", "last entry"));
foreach ($list as $key => $value) {
    echo "{$key} => ";
    if ($value instanceof java) {
        if (java_instanceof($value, $ListClass)) {
            // second argument may also be an instance of a class
            if (!java_instanceof($value, $list)) {
                exit(1);
            }
            echo "[I have found myself!] \n";
        } else {
            echo "[found java object: " . java_cast($value, "S") . "] \n";
        }
    } else {
        echo "{$value}\n";
    }
}
Exemplo n.º 4
0
#!/usr/bin/php

<?php 
include_once "java/Java.inc";
$v = new java("java.util.Vector");
$ar = array("one" => 1, "two" => 2, "three" => 3, array("a", array(1, 2, 3, array("a", "b"), 5, "c", "d"), "five" => 5, "six" => 6));
$v->add($ar);
$result = array_diff_assoc(java_values($v), $ar);
if (sizeof($result) == 0) {
    echo "test okay\n";
    exit(0);
} else {
    echo "ERROR\n";
    exit(1);
}
Exemplo n.º 5
0
$t1 = java_values($Sys->currentTimeMillis());
$v = new java("java.util.HashMap", $a1);
$t2 = java_values($Sys->currentTimeMillis());
$T2 = $t2 - $t1;
$Arrays = new JavaClass("java.util.Arrays");
$Sys->gc();
$t1 = java_values($Sys->currentTimeMillis());
$v = $Arrays->asList($a1);
$t2 = java_values($Sys->currentTimeMillis());
$T3 = $t2 - $t1;
$Sys->gc();
$t1 = java_values($Sys->currentTimeMillis());
java_begin_document();
$v = new java("java.util.LinkedList");
for ($i = 0; $i < $n; $i++) {
    $v->add($i, $i);
}
java_end_document();
$t2 = java_values($Sys->currentTimeMillis());
$T4 = $t2 - $t1;
$Sys->gc();
$t1 = java_values($Sys->currentTimeMillis());
java_begin_document();
$v = new java("java.util.HashMap");
for ($i = 0; $i < $n; $i++) {
    $v->put($i, $i);
}
java_end_document();
$t2 = java_values($Sys->currentTimeMillis());
$T5 = $t2 - $t1;
$Sys->gc();
        }
        $path = JPATH_PLUGINS . DS . $plugin->type . DS . $plugin->name . '.php';
        $className = 'plg' . $plugin->type . $plugin->name;
        require_once $path;
        $instance = new $className($dispatcher, $plugin);
        $pluginindex = $indexpath . DS . $plugin->name;
        $index = new java("java.io.File", $pluginindex);
        if (!$index->exists()) {
            continue;
        }
        $searcher = new java("org.apache.lucene.search.IndexSearcher", $index);
        $phrase = new java("org.apache.lucene.search.MatchAllDocsQuery");
        $hits = $searcher->search($phrase);
        //$hits = $searcher->search($_qobj);
        $n = java_values($hits->length());
        echo $n . " results for " . $plugin->name . "\n";
        if ($n > 0) {
            $iter = $hits->iterator();
            java_begin_document();
            while ($n--) {
                $next = $iter->next();
                $title = $next->get("title");
                $content = $next->get("summary");
                $resultList->add($title . "\n" . $content);
            }
            java_end_document();
        }
    }
    $result = java_values($resultList);
}
print_r($result);
Exemplo n.º 7
0
 static function ArrayList($ar_data)
 {
     $arrayList = new \java('java.util.ArrayList');
     foreach ($ar_data as $value) {
         $arrayList->add($value);
     }
     return $arrayList;
 }
function indexData($writer, $fields, $data)
{
    if (is_array($data) && !isset($data['content'])) {
        return;
    }
    if (is_object($data) && !isset($data->content)) {
        return;
    }
    $doc = new java("org.apache.lucene.document.Document");
    foreach ($fields as $field) {
        $type = $field['type'];
        $store = $type == 'unStored' ? java('org.apache.lucene.document.Field$Store')->NO : java('org.apache.lucene.document.Field$Store')->YES;
        $index = $type == 'text' || $type == 'unStored' ? java('org.apache.lucene.document.Field$Index')->TOKENIZED : java('org.apache.lucene.document.Field$Index')->NO;
        $content = is_array($data) ? $data[$field['name']] : $data->{$field['name']};
        if ($content == null) {
            $content = "";
            echo 'id:' . (is_array($data) ? $data['id'] : $data->id) . ' :: ' . $field['name'];
        }
        $doc->add(new java("org.apache.lucene.document.Field", $field['name'], $content, $store, $index));
        unset($index);
        unset($store);
    }
    //Reindex
    $writer->addDocument($doc);
    //index this document.
    unset($doc);
}
    $iter = $hits->iterator();
    $n = java_values($hits->length());
    echo "done\n";
    echo "Hits: {$n}\n";
    /* Instead of retrieving the values one-by-one, we store them into a
     * LinkedList on the server side and then retrieve the list in one
     * query using java_values():
     */
    $resultList = new java("java.util.LinkedList");
    // create an XML document from the
    // following PHP code, ...
    java_begin_document();
    while ($n--) {
        $next = $iter->next();
        $name = $next->get("name");
        $resultList->add($name);
    }
    //  ... execute the XML document on
    //  the server side, ...
    java_end_document();
    // .. retrieve the result, ...
    $result = java_values($resultList);
    // ... print the result array
    print_r($result);
    delete_index_dir();
} catch (JavaException $e) {
    echo "Exception occured: ";
    echo $e;
    echo "<br>\n";
}
/** helper functions */