Grosse MàJ
This commit is contained in:
Binary file not shown.
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package examples;
|
||||
|
||||
import javax.servlet.jsp.*;
|
||||
import javax.servlet.jsp.tagext.*;
|
||||
|
||||
public abstract class ExampleTagBase extends BodyTagSupport {
|
||||
|
||||
public void setParent(Tag parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void setBodyContent(BodyContent bodyOut) {
|
||||
this.bodyOut = bodyOut;
|
||||
}
|
||||
|
||||
public void setPageContext(PageContext pageContext) {
|
||||
this.pageContext = pageContext;
|
||||
}
|
||||
|
||||
public Tag getParent() {
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
public int doStartTag() throws JspException {
|
||||
return SKIP_BODY;
|
||||
}
|
||||
|
||||
public int doEndTag() throws JspException {
|
||||
return EVAL_PAGE;
|
||||
}
|
||||
|
||||
|
||||
// Default implementations for BodyTag methods as well
|
||||
// just in case a tag decides to implement BodyTag.
|
||||
public void doInitBody() throws JspException {
|
||||
}
|
||||
|
||||
public int doAfterBody() throws JspException {
|
||||
return SKIP_BODY;
|
||||
}
|
||||
|
||||
public void release() {
|
||||
bodyOut = null;
|
||||
pageContext = null;
|
||||
parent = null;
|
||||
}
|
||||
|
||||
protected BodyContent bodyOut;
|
||||
protected PageContext pageContext;
|
||||
protected Tag parent;
|
||||
}
|
Binary file not shown.
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package examples;
|
||||
|
||||
import javax.servlet.jsp.*;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Example1: the simplest tag
|
||||
* Collect attributes and call into some actions
|
||||
*
|
||||
* <foo att1="..." att2="...." att3="...." />
|
||||
*/
|
||||
|
||||
public class FooTag
|
||||
extends ExampleTagBase
|
||||
{
|
||||
private String atts[] = new String[3];
|
||||
int i = 0;
|
||||
|
||||
private final void setAtt(int index, String value) {
|
||||
atts[index] = value;
|
||||
}
|
||||
|
||||
public void setAtt1(String value) {
|
||||
setAtt(0, value);
|
||||
}
|
||||
|
||||
public void setAtt2(String value) {
|
||||
setAtt(1, value);
|
||||
}
|
||||
|
||||
public void setAtt3(String value) {
|
||||
setAtt(2, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process start tag
|
||||
*
|
||||
* @return EVAL_BODY_INCLUDE
|
||||
*/
|
||||
public int doStartTag() throws JspException {
|
||||
i = 0;
|
||||
return EVAL_BODY_BUFFERED;
|
||||
}
|
||||
|
||||
public void doInitBody() throws JspException {
|
||||
pageContext.setAttribute("member", atts[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
public int doAfterBody() throws JspException {
|
||||
try {
|
||||
if (i == 3) {
|
||||
bodyOut.writeOut(bodyOut.getEnclosingWriter());
|
||||
return SKIP_BODY;
|
||||
} else
|
||||
pageContext.setAttribute("member", atts[i]);
|
||||
i++;
|
||||
return EVAL_BODY_BUFFERED;
|
||||
} catch (IOException ex) {
|
||||
throw new JspTagException(ex.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package examples;
|
||||
|
||||
import javax.servlet.jsp.tagext.*;
|
||||
|
||||
public class FooTagExtraInfo extends TagExtraInfo {
|
||||
public VariableInfo[] getVariableInfo(TagData data) {
|
||||
return new VariableInfo[]
|
||||
{
|
||||
new VariableInfo("member",
|
||||
"String",
|
||||
true,
|
||||
VariableInfo.NESTED)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
Binary file not shown.
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package examples;
|
||||
|
||||
|
||||
import javax.servlet.jsp.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Log the contents of the body. Could be used to handle errors etc.
|
||||
*/
|
||||
public class LogTag
|
||||
extends ExampleTagBase
|
||||
{
|
||||
boolean toBrowser = false;
|
||||
|
||||
public void setToBrowser(String value) {
|
||||
if (value == null)
|
||||
toBrowser = false;
|
||||
else if (value.equalsIgnoreCase("true"))
|
||||
toBrowser = true;
|
||||
else
|
||||
toBrowser = false;
|
||||
}
|
||||
|
||||
public int doStartTag() throws JspException {
|
||||
return EVAL_BODY_BUFFERED;
|
||||
}
|
||||
|
||||
public int doAfterBody() throws JspException {
|
||||
try {
|
||||
String s = bodyOut.getString();
|
||||
System.err.println(s);
|
||||
if (toBrowser)
|
||||
bodyOut.writeOut(bodyOut.getEnclosingWriter());
|
||||
return SKIP_BODY;
|
||||
} catch (IOException ex) {
|
||||
throw new JspTagException(ex.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Binary file not shown.
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package examples;
|
||||
|
||||
|
||||
import javax.servlet.jsp.*;
|
||||
import javax.servlet.jsp.tagext.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* Display the sources of the JSP file.
|
||||
*/
|
||||
public class ShowSource
|
||||
extends TagSupport
|
||||
{
|
||||
String jspFile;
|
||||
|
||||
public void setJspFile(String jspFile) {
|
||||
this.jspFile = jspFile;
|
||||
}
|
||||
|
||||
public int doEndTag() throws JspException {
|
||||
if ((jspFile.indexOf( ".." ) >= 0) ||
|
||||
(jspFile.toUpperCase().indexOf("/WEB-INF/") != 0) ||
|
||||
(jspFile.toUpperCase().indexOf("/META-INF/") != 0))
|
||||
throw new JspTagException("Invalid JSP file " + jspFile);
|
||||
|
||||
InputStream in
|
||||
= pageContext.getServletContext().getResourceAsStream(jspFile);
|
||||
|
||||
if (in == null)
|
||||
throw new JspTagException("Unable to find JSP file: "+jspFile);
|
||||
|
||||
JspWriter out = pageContext.getOut();
|
||||
|
||||
|
||||
try {
|
||||
out.println("<body>");
|
||||
out.println("<pre>");
|
||||
for(int ch = in.read(); ch != -1; ch = in.read())
|
||||
if (ch == '<')
|
||||
out.print("<");
|
||||
else
|
||||
out.print((char) ch);
|
||||
out.println("</pre>");
|
||||
out.println("</body>");
|
||||
} catch (IOException ex) {
|
||||
throw new JspTagException("IOException: "+ex.toString());
|
||||
}
|
||||
return super.doEndTag();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user