转译一段PHP代码,转成jsp,急急急!

dwxiao java软件工程师  2012-03-12 11:02:51
<?php
/*
Copyright: Paul Hanlon

Released under the MIT/BSD licence which means you can do anything you want
with it, as long as you keep this copyright notice
*/
class jQTreeTable{
public function init($map,$options,$tbodyid){
$script = <<<EOT

$(function(){//Initialise the treetable
var map1=[0, 0, 2, 3, 4, 4, 6, 4, 2, 9, 10, 0, 0, 13, 0, 0, 0, 17, 17, 0],
map2=[$map];
var options1 = {openImg: "../images/tv-collapsable.gif", shutImg: "../images/tv-expandable.gif", leafImg: "../images/tv-item.gif", lastOpenImg: "../images/tv-collapsable-last.gif", lastShutImg: "../images/tv-expandable-last.gif", lastLeafImg: "../images/tv-item-last.gif", vertLineImg: "../images/vertline.gif", blankImg: "../images/blank.gif", collapse: false, column: 1, striped: true, highlight: true, state:true};
$("#treet1").jqTreeTable(map1, options1);
$("#treet2").jqTreeTable(map2, {$options});
});
EOT;
$style = <<<EOT
.collapsed { display: none; }
.tablemain {background-color:#ccf;border-collapse: collapse; border: solid 1px #447; padding: 0px; text-align: left; }
.tablemain td {margin-left:3px;}
#treet1 {background-color:#ffc}
#treet2 {background-color:#ffc}
#treet1 td { font: normal 10pt Arial; padding: 0px 2px 0px 0px; cursor: pointer;}
#treet2 td { font: normal 10pt Arial; padding: 0px 2px 0px 0px; cursor: pointer;}
.adeimg, .ttimage, .parimg, .preimg { border: none; margin: 0px; padding: 0px; vertical-align: bottom; width: 16px; height: 16px; }
.adeimg, .parimg {cursor: pointer; }
.even { background-color: #ddd; }
.over { background-color: #66f; }
EOT;
return array($script,$style);
}
}
$demo1 = <<<EOT
<table class="tablemain"><thead><tr><th>Row No</th><th>Description</th><th>Path to Row</th><th>Level</th><th>Status</th></tr></thead>
<tbody id="treet1">
<tr><td>1</td><td>Child of 0</td><td>[0, 1]</td><td>1</td><td></td></tr>
<tr><td>2</td><td>Child of 0</td><td>[0, 2] </td><td>1</td><td></td></tr>
<tr><td>3</td><td>Child of 2</td><td>[0, 2, 3] </td><td>2</td><td></td></tr>
<tr><td>4</td><td>Child of 3</td><td>[0, 2, 3, 4] </td><td>3</td><td></td></tr>
<tr><td>5</td><td>Child of 4</td><td>[0, 2, 3, 4, 5] </td><td>4</td><td></td></tr>
<tr><td>6</td><td>Child of 4</td><td>[0, 2, 3, 4, 6] </td><td>4</td><td></td></tr>
<tr><td>7</td><td>Child of 6</td><td>[0, 2, 3, 4, 6, 7] </td><td>5</td><td></td></tr>
<tr><td>8</td><td>Child of 4</td><td>[0, 2, 3, 4, 8] </td><td>4</td><td></td></tr>
<tr><td>9</td><td>Child of 2</td><td>[0, 2, 9] </td><td>2</td><td></td></tr>
<tr><td>10</td><td>Child of 9</td><td>[0, 2, 9, 10] </td><td>3</td><td></td></tr>
<tr><td>11</td><td>Child of 10</td><td>[0, 2, 9, 10, 11] </td><td>4</td><td></td></tr>
<tr><td>12</td><td>Child of 0</td><td>[0, 12] </td><td>1</td><td></td></tr>
<tr><td>13</td><td>Child of 0</td><td>[0, 13] </td><td>1</td><td></td></tr>
<tr><td>14</td><td>Child of 13</td><td>[0, 13, 14] </td><td>2</td><td></td></tr>
<tr><td>15</td><td>Child of 0</td><td>[0, 15] </td><td>1</td><td></td></tr>
<tr><td>16</td><td>Child of 0</td><td>[0, 16] </td><td>1</td><td></td></tr>
<tr><td>17</td><td>Child of 0</td><td>[0, 17] </td><td>1</td><td></td></tr>

<tr><td>18</td><td>Child of 17</td><td>[0, 17, 18] </td><td>2</td><td></td></tr>
<tr><td>19</td><td>Child of 17</td><td>[0, 17, 19] </td><td>2</td><td></td></tr>
<tr><td>20</td><td>Child of 0</td><td>[0, 20] </td><td>1</td><td></td></tr>
</tbody></table>
EOT;
$options = '{openImg: "../images/fopen.gif", shutImg: "../images/fshut.gif", leafImg: "../images/new.gif", lastOpenImg: "../images/fopen.gif", lastShutImg: "../images/fshut.gif", lastLeafImg: "../images/new.gif", vertLineImg: "../images/blank.gif", blankImg: "../images/blank.gif", collapse: false, column: 1, striped: true, highlight: true, state:false}';
$tbodyid = "treet2";
list($str2,$map2) = makeDemo(20,$tbodyid);
$body = $demo1."<br />\n".$str2;
$jq = new jQTreeTable();
$vars = $jq->init($map2,$options,$tbodyid);
echo <<<EOT
<html>
<head>
<title>JQTreeTable</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript">
{$vars[0]}
</script>
<style type="text/css">
{$vars[1]}
</style>
</head>
<body>
$body
</body>
</html>
EOT;
function makeDemo($num,$id){
$head = array("Row No", "Description", "Path to Row", "Level", "Status");
$parents = array(0,1);//Holds the row number of the available parents
$jsmap = array(0);//Holds the eventual map sent to jqTreetable
$parstr = "";
$tabstr = '<tr><td>1</td><td><a href="jQTreeTable.zip" onclick="alert(\'Ive been clicked!\');">Click to download</a></td><td>[0, 1]</td><td>1</td><td></td></tr>'."\n";
for ($i=0; $i<count($head); $i++){
$headrow .= '<th>'.$head[$i].'</th>';
}
$headrow ='<tr>'.$headrow.'</tr>';
for ($x=1; $x<$num;$x++){
$cnt = count($parents)-1;
$rand = rand(0, $cnt);//Rand is basically the level chosen as parent
$par = $parents[$rand];
array_push($jsmap, $par);
if ($rand == $cnt){
array_push($parents, $x+1);
}else{
$parents[$rand+1] = $x+1;
$parents = array_slice($parents, 0, $rand+2);
}
$parstr = "[".implode(", ", $parents)."]";
$tabstr .= '<tr><td>'.($x+1).'</td><td>Child of '.$par.'</td><td>'.$parstr.' </td><td>'.($rand+1).'</td><td></td></tr>'."\n";
}
return array('<table class="tablemain"><thead>'.$headrow."</thead>\n<tfoot>".$headrow."</tfoot>\n".'<tbody id="'.$id.'">'.$tabstr."</tbody><tr><td>Random</td><td>data</td><td>outside</td><td>treetable</td><td>tbody</td></tr>\n</table>\n", implode(", ", $jsmap));
}
?>



这个完全不懂,谁能帮忙转译成jsp代码,谢谢了!很急!
...全文
85 点赞 收藏 3
写回复
3 条回复
dwxiao 2012年03月13日
求助啊,没人帮忙翻译一下么?
回复 点赞
QL0929 2012年03月13日
本人小会一点PHP 用JAVA译过来了 没有测试过 楼主可以看下 ,貌似这段PHP的代码也就是输出动态表格,楼主自己用JAVA也可以实现呀,没必要译这段吧

package com.test;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class JqTreeTable {

public String[] init(String map, String options, String tbodyid) {

String script = "$(function(){//Initialise the treetable"
+ "var map1=[0, 0, 2, 3, 4, 4, 6, 4, 2, 9, 10, 0, 0, 13, 0, 0, 0, 17, 17, 0],"
+ "map2=[$map];"
+ "var options1 = {openImg:'../images/tv-collapsable.gif', shutImg: '../images/tv-expandable.gif', leafImg: '../images/tv-item.gif', lastOpenImg: '../images/tv-collapsable-last.gif', lastShutImg: '../images/tv-expandable-last.gif', lastLeafImg: '../images/tv-item-last.gif', vertLineImg: '../images/vertline.gif', blankImg: '../images/blank.gif', collapse: false, column: 1, striped: true, highlight: true, state:true};"
+ " $('#treet1').jqTreeTable(map1, options1);"
+ " $('#treet2').jqTreeTable(map2, {$options});" + "});";

String style = ".collapsed { display: none; }"
+ ".tablemain {background-color:#ccf;border-collapse: collapse; border: solid 1px #447; padding: 0px; text-align: left; }"
+ ".tablemain td {margin-left:3px;}"
+ "#treet1 {background-color:#ffc}"
+ "#treet2 {background-color:#ffc}"
+ "#treet1 td { font: normal 10pt Arial; padding: 0px 2px 0px 0px; cursor: pointer;}"
+ "#treet2 td { font: normal 10pt Arial; padding: 0px 2px 0px 0px; cursor: pointer;}"
+ ".adeimg, .ttimage, .parimg, .preimg { border: none; margin: 0px; padding: 0px; vertical-align: bottom; width: 16px; height: 16px; }"
+ ".adeimg, .parimg {cursor: pointer; }"
+ "v.even { background-color: #ddd; }"
+ ".over { background-color: #66f; }";

return new String[] { script, style };

}

public String[] makeDemo(int num, String id) {

String parstr = "[";

String[] head = { "Row No", "Description", "Path to Row", "Level",
"Status" };
List parents = new ArrayList();
parents.add(0);
parents.add(1);// Holds the row number of the available parents
List jsmap = new ArrayList();
jsmap.add(0);// Holds the eventual map sent to jqTreetable
// String parstr = "";
String tabstr = "<tr><td>1</td><td><a href='jQTreeTable.zip' onclick='alert(\'Ive been clicked!\');'>Click to download</a></td><td>[0, 1]</td><td>1</td><td></td></tr>\n";
String headrow = "";
for (int i = 0; i < head.length; i++) {
headrow += "<th>" + head[i] + "</th>";
}
headrow = "<tr>" + headrow + "</tr>";
for (int x = 1; x < num; x++) {
int cnt = parents.size() - 1;
Random r = new Random();
int rand = r.nextInt(cnt);
rand = Math.abs(r.nextInt() % 10);

// int rand = rand(0, cnt);// Rand is basically the level chosen as
// parent
String par = parents.get(rand).toString();
jsmap.add(par);
// array_push($jsmap, $par);
if (rand == cnt) {
parents.add(x + 1);
// array_push($parents, $x+1);
} else {
parents.set(rand + 1, x + 1);
// parents.get(rand+1)=x+1;
// $parents[$rand+1] = $x+1;
// parents=parents
List l = new ArrayList();
for (int k = 0; k < rand + 2; k++) {
l.add(parents.get(k));
}
parents = l;
// $parents = array_slice($parents, 0, $rand+2);
}
for (int j = 0; j < parents.size(); j++) {
if (j == parents.size() - 1) {
parstr += "]";
}
parstr += parents.get(j) + ",";
}
// String parstr = "[".implode(", ", $parents)."]";
tabstr += "<tr><td>" + (x + 1) + "</td><td>Child of " + par
+ "</td><td>" + parstr + "' </td><td>" + (rand + 1)
+ "</td><td></td></tr>\n";
}
String strJsMap = "";
for (int j = 0; j < jsmap.size(); j++) {
if (j < jsmap.size() - 1) {
strJsMap += jsmap.get(j) + ",";
}

}

return new String[] {
"<table class='tablemain'><thead>"
+ headrow
+ "</thead>\n<tfoot>"
+ headrow
+ "</tfoot>\n<tbody id=>"
+ tabstr
+ "</tbody><tr><td>Random</td><td>data</td><td>outside</td><td>treetable</td><td>tbody</td></tr>\n</table>\n",
strJsMap };
// return array('<table
// class="tablemain"><thead>'.$headrow."</thead>\n<tfoot>".$headrow."</tfoot>\n".'<tbody
// id="'.$id.'">'.$tabstr."</tbody><tr><td>Random</td><td>data</td><td>outside</td><td>treetable</td><td>tbody</td></tr>\n</table>\n",
// implode(", ", $jsmap));
}

// String [] vars = jq.init(map2,options,tbodyid);

String demo1 = "<table class=''tablemain'><thead><tr><th>Row No</th><th>Description</th><th>Path to Row</th><th>Level</th><th>Status</th></tr></thead>"
+ "<tbody id='treet1'>"
+ "<tr><td>1</td><td>Child of 0</td><td>[0, 1]</td><td>1</td><td></td></tr>"
+ "<tr><td>2</td><td>Child of 0</td><td>[0, 2] </td><td>1</td><td></td></tr>"
+ "<tr><td>3</td><td>Child of 2</td><td>[0, 2, 3] </td><td>2</td><td></td></tr>"
+ "<tr><td>4</td><td>Child of 3</td><td>[0, 2, 3, 4] </td><td>3</td><td></td></tr>"
+ "<tr><td>5</td><td>Child of 4</td><td>[0, 2, 3, 4, 5] </td><td>4</td><td></td></tr>"
+ "<tr><td>6</td><td>Child of 4</td><td>[0, 2, 3, 4, 6] </td><td>4</td><td></td></tr>"
+ "<tr><td>7</td><td>Child of 6</td><td>[0, 2, 3, 4, 6, 7] </td><td>5</td><td></td></tr>"
+ "<tr><td>8</td><td>Child of 4</td><td>[0, 2, 3, 4, 8] </td><td>4</td><td></td></tr>"
+ "<tr><td>9</td><td>Child of 2</td><td>[0, 2, 9] </td><td>2</td><td></td></tr>"
+ "<tr><td>10</td><td>Child of 9</td><td>[0, 2, 9, 10] </td><td>3</td><td></td></tr>"
+ "<tr><td>11</td><td>Child of 10</td><td>[0, 2, 9, 10, 11] </td><td>4</td><td></td></tr>"
+ "<tr><td>12</td><td>Child of 0</td><td>[0, 12] </td><td>1</td><td></td></tr>"
+ "<tr><td>13</td><td>Child of 0</td><td>[0, 13] </td><td>1</td><td></td></tr>"
+ "<tr><td>14</td><td>Child of 13</td><td>[0, 13, 14] </td><td>2</td><td></td></tr>"
+ "<tr><td>15</td><td>Child of 0</td><td>[0, 15] </td><td>1</td><td></td></tr>"
+ "<tr><td>16</td><td>Child of 0</td><td>[0, 16] </td><td>1</td><td></td></tr>"
+ "<tr><td>17</td><td>Child of 0</td><td>[0, 17] </td><td>1</td><td></td></tr>"
+ "<tr><td>18</td><td>Child of 17</td><td>[0, 17, 18] </td><td>2</td><td></td></tr>"
+ "<tr><td>19</td><td>Child of 17</td><td>[0, 17, 19] </td><td>2</td><td></td></tr>"
+ "<tr><td>20</td><td>Child of 0</td><td>[0, 20] </td><td>1</td><td></td></tr>"
+ "</tbody></table>";

String options = "{openImg: '../images/fopen.gif', shutImg: '../images/fshut.gif', leafImg: '../images/new.gif', lastOpenImg:'../images/fopen.gif', lastShutImg: '../images/fshut.gif', lastLeafImg: '../images/new.gif', vertLineImg: '../images/blank.gif', blankImg: '../images/blank.gif', collapse: false, column: 1, striped: true, highlight: true, state:false}";
String tbodyid = "treet2";
// list($str2,$map2) = makeDemo(20,$tbodyid);
String[] str = makeDemo(20, tbodyid);
String str2 = str[0];
String map2 = str[1];
String body = demo1 + "<br />\n" + str2;

public void print() {
JqTreeTable jq = new JqTreeTable();
jq.init(map2, options, tbodyid);

String html = "<html>"
+ "<head>"
+ "<title>JQTreeTable</title>"
+ " <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js'></script>"
+ "<script type=''text/javascript'>" + " {$vars[0]}"
+ " </script>" + "<style type='text/css'>" + "{$vars[1]}"
+ "</style>" + "</head>" + "<body>" + "$body" + "</body>"
+ "</html>";

System.out.print(html);
}

}



回复 点赞
dwxiao 2012年03月12日
没有人来帮下忙么?
回复 点赞
发动态
发帖子
Web 开发
创建于2007-09-28

5.2w+

社区成员

34.1w+

社区内容

Java Web 开发
社区公告
暂无公告