下面列出了怎么用javax.servlet.jsp.tagext.BodyTagSupport的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* {@inheritDoc}
*/
public int doEndTag() throws JspException {
StringBuilder result = new StringBuilder();
if (nolink || id == null) {
result.append(writeIcon());
result.append(name);
}
else {
result.append("<a href=\"" +
ConfigChannelTag.makeConfigChannelUrl(id) + "\">");
result.append(writeIcon());
result.append(StringEscapeUtils.escapeXml(name) + "</a>");
}
JspWriter writer = pageContext.getOut();
try {
writer.write(result.toString());
}
catch (IOException e) {
throw new JspException(e);
}
return BodyTagSupport.SKIP_BODY;
}
/**
* ${@inheritDoc}
*/
public int doEndTag() throws JspException {
if (sortable && attributeName == null && sortAttribute == null) {
throw new JspException("Sortable columns must use either attr or sortAttr");
}
checkForBoundsAndAttrs();
ListCommand command = ListTagUtil.getCurrentCommand(this, pageContext);
if (command.equals(ListCommand.RENDER)) {
ListTagUtil.write(pageContext, "</td>");
}
else if (command.equals(ListCommand.ENUMERATE) &&
!StringUtils.isBlank(filterAttr)) {
setupColumnFilter();
}
return BodyTagSupport.EVAL_PAGE;
}
/**
* {@inheritDoc}
*/
@Override
public int doStartTag() throws JspException {
ListCommand command = ListTagUtil.getCurrentCommand(this, pageContext);
ListTag parent = (ListTag) BodyTagSupport.findAncestorWithClass(this,
ListTag.class);
listName = parent.getUniqueName();
int retval = BodyTagSupport.SKIP_BODY;
setupRhnSet();
if (command.equals(ListCommand.ENUMERATE)) {
parent.addColumn();
retval = BodyTagSupport.EVAL_PAGE;
}
else if (command.equals(ListCommand.COL_HEADER)) {
renderHeader(parent);
retval = BodyTagSupport.EVAL_PAGE;
}
else if (command.equals(ListCommand.RENDER)) {
renderCheckbox();
}
return retval;
}
private void renderHiddenItem(String listId, String value) throws JspException {
ListTagUtil.write(pageContext, "<input type=\"hidden\" ");
ListTagUtil.write(pageContext, "id=\"");
ListTagUtil.write(pageContext, "list_items_" + listName + "_" + listId);
String pageItems = ListTagUtil.makePageItemsName(listName);
ListTag parent = (ListTag)
BodyTagSupport.findAncestorWithClass(this, ListTag.class);
if (!parent.isParentAnElement() &&
RhnListTagFunctions.isExpandable(getCurrent())) {
pageItems = "parent_" + pageItems;
}
ListTagUtil.write(pageContext, "\" name=\"" + pageItems + "\" ");
ListTagUtil.write(pageContext, "value=\"");
ListTagUtil.write(pageContext, value);
ListTagUtil.write(pageContext, "\" />\n");
}
private String getIgnorableParentIds() {
ListTag parent = (ListTag)
BodyTagSupport.findAncestorWithClass(this, ListTag.class);
if (!parent.isParentAnElement()) {
StringBuilder buf = new StringBuilder();
for (Object current : parent.getPageData()) {
if (RhnListTagFunctions.isExpandable(current)) {
if (buf.length() > 0) {
buf.append(",");
}
buf.append("'");
buf.append(makeCheckboxId(listName,
ListTagHelper.getObjectId(current)));
buf.append("'");
}
}
buf.insert(0, "[");
buf.append("]");
return buf.toString();
}
return "[]";
}
private ListDecorator getDecorator(String decName) throws JspException {
if (decName != null) {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
try {
if (decName.indexOf('.') == -1) {
decName = "com.redhat.rhn.frontend.taglibs.list.decorators." +
decName;
}
ListDecorator dec = (ListDecorator) cl.loadClass(decName)
.newInstance();
ListSetTag parent = (ListSetTag) BodyTagSupport
.findAncestorWithClass(this, ListSetTag.class);
dec.setEnvironment(pageContext, parent, getUniqueName());
return dec;
}
catch (Exception e) {
String msg = "Exception while adding Decorator [" + decName + "]";
throw new JspException(msg, e);
}
}
return null;
}
/**
* ${@inheritDoc}
*/
@Override
public int doEndTag() throws JspException {
// print the hidden fields after the list widget is printed
// but before the form of the listset is closed.
ListTagUtil.write(pageContext, String.format(HIDDEN_TEXT,
ListTagUtil.makeParentIsAnElementLabel(getUniqueName()),
parentIsElement));
// here decorators should insert other e.g hidden input fields
for (ListDecorator dec : getDecorators()) {
dec.afterList();
}
ListTagUtil.write(pageContext, "<!-- END " + getUniqueName() + " -->");
release();
return BodyTagSupport.EVAL_PAGE;
}
private int doAfterBodyRenderBeforeData() throws JspException {
ListTagUtil.write(pageContext, "</tr>");
ListTagUtil.write(pageContext, "</thead>");
ListTagUtil.setCurrentCommand(pageContext, getUniqueName(),
ListCommand.BEFORE_RENDER);
if (manip.isListEmpty()) {
renderEmptyList();
ListTagUtil.write(pageContext, "</table>");
// close panel
ListTagUtil.write(pageContext, "</div>");
// close list
ListTagUtil.write(pageContext, "</div>");
return BodyTagSupport.SKIP_BODY;
}
ListTagUtil.write(pageContext, "<tbody>");
// render first row. The rest will be rendered in subsequent
// calls to doAfterBody
return doAfterBodyRenderData();
}
/**
* ${@inheritDoc}
*/
@Override
public int doAfterBody() throws JspException {
int retval = BodyTagSupport.EVAL_BODY_AGAIN;
ListCommand nextCmd = getNextCommand();
switch (nextCmd) {
case TBL_HEADING: doAfterBodyRenderListBegin(); break;
case TBL_ADDONS: doAfterBodyRenderTopAddons(); break;
case COL_HEADER: doAfterBodyRenderColHeaders(); break;
case BEFORE_RENDER: retval = doAfterBodyRenderBeforeData(); break;
case RENDER: retval = doAfterBodyRenderData(); break;
case AFTER_RENDER: retval = doAfterBodyRenderAfterData(); break;
case TBL_FOOTER: retval = doAfterBodyRenderFooterAddons(); break;
default: break;
}
return retval;
}
/**
* {@inheritDoc}
*/
@Override
public int doStartTag() throws JspException {
ListCommand command = ListTagUtil.getCurrentCommand(this, pageContext);
ListTag parent = (ListTag) BodyTagSupport.findAncestorWithClass(this,
ListTag.class);
listName = parent.getUniqueName();
int retval = BodyTagSupport.SKIP_BODY;
if (command.equals(ListCommand.ENUMERATE)) {
parent.addColumn();
renderHiddenField();
retval = BodyTagSupport.EVAL_PAGE;
}
else if (command.equals(ListCommand.COL_HEADER)) {
renderHeader(parent);
retval = BodyTagSupport.EVAL_PAGE;
}
else if (command.equals(ListCommand.RENDER)) {
render(valueExpr);
}
return retval;
}
@Override
public int doStartTag() throws JspException {
try {
NaviMap nav = NaviMap.getInstance(this.cnf);
this.ebb = (this.act == null || nav.chkAuth(this.act))
&& (this.rol == null || nav.chkRole(this.rol))
&& (this.men == null || nav.chkRole(this.men));
} catch ( HongsException ex) {
throw new JspException(ex);
}
if (this.not) {
this.ebb = !this.ebb;
}
if (this.ebb) {
return BodyTagSupport.EVAL_BODY_BUFFERED;
} else {
return BodyTagSupport.SKIP_BODY;
}
}
@Override
public int doStartTag() throws JspException {
// 在标签开始处出发该方法
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
SSOToken token = SSOHelper.getSSOToken(request);
// 如果 token 或者 name 为空
if (token != null && this.getName() != null && !"".equals(this.getName().trim())) {
boolean result = SSOConfig.getInstance().getAuthorization().isPermitted(token, this.getName());
if (result) {
// 权限验证通过
// 返回此则执行标签body中内容,SKIP_BODY则不执行
return BodyTagSupport.EVAL_BODY_INCLUDE;
}
}
return BodyTagSupport.SKIP_BODY;
}
/**
* {@inheritDoc}
*/
public int doEndTag() throws JspException {
StringBuilder result = new StringBuilder();
if (nolink || id == null) {
result.append(writeIcon());
result.append(name);
}
else {
result.append("<a href=\"" +
ConfigChannelTag.makeConfigChannelUrl(id) + "\">");
result.append(writeIcon());
result.append(StringEscapeUtils.escapeXml(name) + "</a>");
}
JspWriter writer = pageContext.getOut();
try {
writer.write(result.toString());
}
catch (IOException e) {
throw new JspException(e);
}
return BodyTagSupport.SKIP_BODY;
}
/**
* ${@inheritDoc}
*/
public int doEndTag() throws JspException {
if (sortable && attributeName == null && sortAttribute == null) {
throw new JspException("Sortable columns must use either attr or sortAttr");
}
checkForBoundsAndAttrs();
ListCommand command = ListTagUtil.getCurrentCommand(this, pageContext);
if (command.equals(ListCommand.RENDER)) {
ListTagUtil.write(pageContext, "</td>");
}
else if (command.equals(ListCommand.ENUMERATE) &&
!StringUtils.isBlank(filterAttr)) {
setupColumnFilter();
}
return BodyTagSupport.EVAL_PAGE;
}
/**
* {@inheritDoc}
*/
@Override
public int doStartTag() throws JspException {
ListCommand command = ListTagUtil.getCurrentCommand(this, pageContext);
ListTag parent = (ListTag) BodyTagSupport.findAncestorWithClass(this,
ListTag.class);
listName = parent.getUniqueName();
int retval = BodyTagSupport.SKIP_BODY;
setupRhnSet();
if (command.equals(ListCommand.ENUMERATE)) {
parent.addColumn();
retval = BodyTagSupport.EVAL_PAGE;
}
else if (command.equals(ListCommand.COL_HEADER)) {
renderHeader(parent);
retval = BodyTagSupport.EVAL_PAGE;
}
else if (command.equals(ListCommand.RENDER)) {
renderCheckbox();
}
return retval;
}
/**
* renders
* //onclick="checkbox_clicked(this, '$rhnSet')"
*
*/
private String getOnClickScript(String funcName, String boxName) {
Object current = getCurrent();
Object parent = getParentObject();
String childIds = "[]";
String memberIds = "[]";
String parentId = "";
ListTag parentTag = (ListTag)
BodyTagSupport.findAncestorWithClass(this, ListTag.class);
if (RhnListTagFunctions.isExpandable(current)) {
childIds = getChildIds(current);
}
else {
parentId = getParentId(current, parent);
memberIds = getMemberIds(current, parent);
}
return String.format(CHECKBOX_CLICKED_SCRIPT, funcName, boxName,
rhnSet, makeSelectAllCheckboxId(listName),
childIds, memberIds, parentId,
parentTag.isParentAnElement());
}
private void renderHiddenItem(String listId, String value) throws JspException {
ListTagUtil.write(pageContext, "<input type=\"hidden\" ");
ListTagUtil.write(pageContext, "id=\"");
ListTagUtil.write(pageContext, "list_items_" + listName + "_" + listId);
String pageItems = ListTagUtil.makePageItemsName(listName);
ListTag parent = (ListTag)
BodyTagSupport.findAncestorWithClass(this, ListTag.class);
if (!parent.isParentAnElement() &&
RhnListTagFunctions.isExpandable(getCurrent())) {
pageItems = "parent_" + pageItems;
}
ListTagUtil.write(pageContext, "\" name=\"" + pageItems + "\" ");
ListTagUtil.write(pageContext, "value=\"");
ListTagUtil.write(pageContext, value);
ListTagUtil.write(pageContext, "\" />\n");
}
private String getIgnorableParentIds() {
ListTag parent = (ListTag)
BodyTagSupport.findAncestorWithClass(this, ListTag.class);
if (!parent.isParentAnElement()) {
StringBuilder buf = new StringBuilder();
for (Object current : parent.getPageData()) {
if (RhnListTagFunctions.isExpandable(current)) {
if (buf.length() > 0) {
buf.append(",");
}
buf.append("'");
buf.append(makeCheckboxId(listName,
ListTagHelper.getObjectId(current)));
buf.append("'");
}
}
buf.insert(0, "[");
buf.append("]");
return buf.toString();
}
return "[]";
}
private ListDecorator getDecorator(String decName) throws JspException {
if (decName != null) {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
try {
if (decName.indexOf('.') == -1) {
decName = "com.redhat.rhn.frontend.taglibs.list.decorators." +
decName;
}
ListDecorator dec = (ListDecorator) cl.loadClass(decName)
.newInstance();
ListSetTag parent = (ListSetTag) BodyTagSupport
.findAncestorWithClass(this, ListSetTag.class);
dec.setEnvironment(pageContext, parent, getUniqueName());
return dec;
}
catch (Exception e) {
String msg = "Exception while adding Decorator [" + decName + "]";
throw new JspException(msg, e);
}
}
return null;
}
/**
* ${@inheritDoc}
*/
@Override
public int doEndTag() throws JspException {
// print the hidden fields after the list widget is printed
// but before the form of the listset is closed.
ListTagUtil.write(pageContext, String.format(HIDDEN_TEXT,
ListTagUtil.makeParentIsAnElementLabel(getUniqueName()),
parentIsElement));
// here decorators should insert other e.g hidden input fields
for (ListDecorator dec : getDecorators()) {
dec.afterList();
}
ListTagUtil.write(pageContext, "<!-- END " + getUniqueName() + " -->");
release();
return BodyTagSupport.EVAL_PAGE;
}
private int doAfterBodyRenderBeforeData() throws JspException {
ListTagUtil.write(pageContext, "</tr>");
ListTagUtil.write(pageContext, "</thead>");
ListTagUtil.setCurrentCommand(pageContext, getUniqueName(),
ListCommand.BEFORE_RENDER);
if (manip.isListEmpty()) {
renderEmptyList();
ListTagUtil.write(pageContext, "</table>");
// close panel
ListTagUtil.write(pageContext, "</div>");
// close list
ListTagUtil.write(pageContext, "</div>");
return BodyTagSupport.SKIP_BODY;
}
ListTagUtil.write(pageContext, "<tbody>");
// render first row. The rest will be rendered in subsequent
// calls to doAfterBody
return doAfterBodyRenderData();
}
/**
* ${@inheritDoc}
*/
@Override
public int doAfterBody() throws JspException {
int retval = BodyTagSupport.EVAL_BODY_AGAIN;
ListCommand nextCmd = getNextCommand();
switch (nextCmd) {
case TBL_HEADING: doAfterBodyRenderListBegin(); break;
case TBL_ADDONS: doAfterBodyRenderTopAddons(); break;
case COL_HEADER: doAfterBodyRenderColHeaders(); break;
case BEFORE_RENDER: retval = doAfterBodyRenderBeforeData(); break;
case RENDER: retval = doAfterBodyRenderData(); break;
case AFTER_RENDER: retval = doAfterBodyRenderAfterData(); break;
case TBL_FOOTER: retval = doAfterBodyRenderFooterAddons(); break;
default: break;
}
return retval;
}
/**
* {@inheritDoc}
*/
@Override
public int doStartTag() throws JspException {
ListCommand command = ListTagUtil.getCurrentCommand(this, pageContext);
ListTag parent = (ListTag) BodyTagSupport.findAncestorWithClass(this,
ListTag.class);
listName = parent.getUniqueName();
int retval = BodyTagSupport.SKIP_BODY;
if (command.equals(ListCommand.ENUMERATE)) {
parent.addColumn();
renderHiddenField();
retval = BodyTagSupport.EVAL_PAGE;
}
else if (command.equals(ListCommand.COL_HEADER)) {
renderHeader(parent);
retval = BodyTagSupport.EVAL_PAGE;
}
else if (command.equals(ListCommand.RENDER)) {
render(valueExpr);
}
return retval;
}
/**
* {@inheritDoc}
*/
@Override
public int doEndTag() throws JspException {
StringBuilder result = new StringBuilder();
if (nolink || id == null) {
result.append(writeIcon());
result.append(StringEscapeUtils.escapeXml(path));
}
else {
String url;
if (revisionId != null) {
url = makeConfigFileRevisionUrl(id, revisionId);
}
else {
url = makeConfigFileUrl(id);
}
result.append("<a href=\"" + url + "\">");
result.append(writeIcon());
result.append(StringEscapeUtils.escapeXml(path) + "</a>");
}
JspWriter writer = pageContext.getOut();
try {
writer.write(result.toString());
}
catch (IOException e) {
throw new JspException(e);
}
return BodyTagSupport.SKIP_BODY;
}
/**
* ${@inheritDoc}
*/
public int doStartTag() throws JspException {
ListCommand command = ListTagUtil.getCurrentCommand(this, pageContext);
ListTag parent = (ListTag) BodyTagSupport.findAncestorWithClass(this,
ListTag.class);
int retval = BodyTagSupport.SKIP_BODY;
if (command.equals(ListCommand.ENUMERATE)) {
parent.addColumn();
retval = BodyTagSupport.EVAL_PAGE;
if (isSortable()) {
parent.setSortable(true);
}
}
else if (command.equals(ListCommand.COL_HEADER)) {
renderHeader();
retval = BodyTagSupport.EVAL_PAGE;
}
else if (command.equals(ListCommand.RENDER)) {
if (isBound) {
renderBound();
retval = BodyTagSupport.SKIP_BODY;
}
else {
renderUnbound();
retval = BodyTagSupport.EVAL_BODY_INCLUDE;
}
}
return retval;
}
protected void renderUnbound() throws JspException {
ListTag parent = (ListTag)
BodyTagSupport.findAncestorWithClass(this, ListTag.class);
if (attributeName != null) {
Object bean = parent.getCurrentObject();
String value = ListTagUtil.getBeanValue(bean, attributeName);
pageContext.setAttribute("beanValue", value, PageContext.PAGE_SCOPE);
}
writeStartingTd();
}
protected void renderBound() throws JspException {
ListTag parent = (ListTag)
BodyTagSupport.findAncestorWithClass(this, ListTag.class);
Object bean = parent.getCurrentObject();
writeStartingTd();
ListTagUtil.write(pageContext, ListTagUtil.
getBeanValue(bean, attributeName));
}
/**
* Gets current sort direction for this column, or empty string if the list is not
* currently sorted on this column
*
* @return Current sort direction for the column
*/
private String getCurrentSortDir() {
ListTag parent = (ListTag) BodyTagSupport.findAncestorWithClass(this,
ListTag.class);
String currSortAttr = parent.getCurrentSortAttr();
String currSortDir = parent.getCurrentSortDir();
return currSortAttr.equals(getSortName()) ? currSortDir : "";
}
private void setupColumnFilter() throws JspException {
ListTag parent = (ListTag)
BodyTagSupport.findAncestorWithClass(this, ListTag.class);
String key = headerKey;
if (!StringUtils.isBlank(filterMessage)) {
key = filterMessage;
}
ColumnFilter f = new ColumnFilter(key, filterAttr);
parent.setColumnFilter(f);
}
/**
* {@inheritDoc}
*/
public int doStartTag() throws JspException {
//if legend was set, process legends
if (legend != null) {
setLegends(legend);
}
verifyEnvironment();
startForm();
return BodyTagSupport.EVAL_BODY_INCLUDE;
}