This repository was archived by the owner on Jan 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathJspTag.php
More file actions
113 lines (102 loc) · 3.12 KB
/
JspTag.php
File metadata and controls
113 lines (102 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
* These classes allow one to call JSP tags from PHP.
* Example:
* <code>
* $tag = new java_Tag($ctx=new java_PageContext(), "FooTag, null);<br>
* if($tag->start()) do { ... } while($tag->repeat()); <br>
* $tag->end();<br>
* </code>
*/
if(!class_exists("java_Tag")) {
class java_PageContext {
var $servlet = null;
var $response = null;
var $request = null;
var $out = null;
var $pc = null;
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 getPageContext () {
return $this->pc;
}
}
class java_Tag {
var $clazz = null;
var $pc = null;
var $noend = false;
var $evalTag = null;
/**
* Create a java tag proxy.
* @param $pageContext, the java_PageContext object
* @param $tagname The name of the tag
* @param $params The parameters
*/
function java_Tag($pageContext, $tagname, $params = null) {
$this->pc = $pageContext;
$this->clazz = new Java($tagname);
$this->clazz->setPageContext($pageContext->pc);
if(null != $params) {
foreach($params as $k => $v) {
$method = "set";
$s = substr($k, 0, 1);
$method .= $s.substr($k, 1);
$this->clazz->$method($v);
}
}
}
/**
* Must be called to open the tag.
* @return true, if the body should be evaluated.
*/
function start() {
$this->evalTag = java_values($this->clazz->doStartTag());
if($this->evalTag != java_values(Java("javax.servlet.jsp.tagext.Tag")->SKIP_BODY)) {
$this->noend=true;
if($this->evalTag == java_values(Java("javax.servlet.jsp.tagext.Tag")->EVAL_BODY_INCLUDE)) {
$out = $this->pc->pc->pushBody();
$this->clazz->setBodyContent($out);
$this->clazz->doInitBody();
}
return true;
}
return false;
}
/**
* Must be called at the end of the body.
* @return true if the body should be evaluated again.
*/
function repeat() {
$evalDoAfterBody = java_values($this->clazz->doAfterBody());
if ($evalDoAfterBody != java_values(Java("javax.servlet.jsp.tagext.BodyTag")->EVAL_BODY_AGAIN)) {
return false;
}
return true;
}
/**
* Must be called at the end.
*/
function end($autoflush = true) {
if(!$this->noend) {
if ($this->evalTag != java_values(Java("javax.servlet.jsp.tagext.Tag")->EVAL_BODY_INCLUDE)) {
$this->pc->pc->popBody();
}
}
$this->clazz->doEndTag();
if($autoflush ) {
$this->pc->out->flush();
echo java_values($this->pc->response->getBufferContents());
}
return true;
}
}
}
?>