package com.cv.jsp.simple.tag;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.JspTag;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import org.apache.log4j.Logger;
public class SimpleTagSupportImpl extends SimpleTagSupport {
private static final Logger LOGGER = Logger.getLogger(SimpleTagSupportImpl.class);
private String item;
public String getItem() {
return item;
}
public void setItem(String item) {
this.item = item;
}
public void doTag() throws JspException, IOException {
JspTag handler = getParent();
boolean flag = false;
if (handler instanceof TagSupportImpl) {
flag = true;
LOGGER.info(" LOGGER : Parent tag available and it is TagSupportImpl ");
TagSupportImpl classicTagHandler = (TagSupportImpl) handler;
String item2 = classicTagHandler.getItem();
LOGGER.info(" LOGGER : TagSupportImpl item is : " + item2);
try {
getJspContext().getOut().print("<br>TagSupportImpl item is : " + item2+"<br>");
} catch (IOException e1) {
e1.printStackTrace();
}
} else if (handler instanceof SimpleTagSupportImpl) {
LOGGER.info(" LOGGER : Parent tag available and it is SimpleTagSupportImpl ");
SimpleTagSupportImpl mySimpleTagHandler = (SimpleTagSupportImpl) handler;
String item2 = mySimpleTagHandler.getItem();
LOGGER.info(" LOGGER : SimpleTagSupportImpl item is : " + item2);
try {
getJspContext().getOut().print("<br>SimpleTagSupportImpl item is : " + item2+"<br>");
} catch (IOException e1) {
e1.printStackTrace();
}
} /*else {
LOGGER.info(" LOGGER : It is not a Parent tag and it is SimpleTagSupportImpl ");
String item2 = getItem();
if (item2 != null) {
flag = true;
LOGGER.info(" LOGGER : SimpleTagSupportImpl item is : " + item2);
getJspContext().getOut().print("<br>SimpleTagSupportImpl item is : " + item2+"<br>");
int levels = findNumberOfParents();
if(levels >= 1) {
LOGGER.info(" LOGGER : SimpleTagSupportImpl levels available is : " + levels);
getJspContext().getOut().print("<br>SimpleTagSupportImpllevels available is : " + levels+"<br>");
}
}
}*/
/*if (!flag) {
StringWriter sw = new StringWriter();
JspFragment jspBody2 = getJspBody();
if(jspBody2 != null) {
jspBody2.invoke(sw);
}
getJspContext().getOut().println("<br>"+sw.toString()+"<br>");
}*/
}
private int findNumberOfParents() {
int level = 0;
JspTag parent = getParent();
while (parent != null) {
parent = getParent();
++level;
}
return level;
}
} |
No comments:
Post a Comment