@Override
public String renderTag(TagSupport tag, PageContext pageContext, String body) throws Exception {
StringWriter strWriter = new StringWriter();
HttpServletResponse response = mock(HttpServletResponse.class);
when(response.getWriter()).thenReturn(new PrintWriter(strWriter, true));
if (!mockingDetails(pageContext).isSpy()) {
pageContext = spy(pageContext);
}
JspWriter jspWriter = new JspWriterImpl(response);
doReturn(jspWriter).when(pageContext).getOut();
tag.setPageContext(pageContext);
if (Tag.EVAL_BODY_INCLUDE == tag.doStartTag()) {
jspWriter.flush();
strWriter.write(body);
}
jspWriter.flush();
tag.doEndTag();
jspWriter.flush();
tag.release();
return strWriter.toString();
}
java类javax.servlet.jsp.tagext.TagSupport的实例源码
Tags.java 文件源码
项目:aem-testing
阅读 40
收藏 0
点赞 0
评论 0
TestTag.java 文件源码
项目:opengse
阅读 38
收藏 0
点赞 0
评论 0
public void doInitBody() throws JspException {
//Test for doInitBody method.
if ( "doInitBody".equalsIgnoreCase ( this.getAtt1() ) ) {
TestString += this.getAtt1();
}
// Test for getParent method in TagSupport
if ( "getParent".equalsIgnoreCase ( this.getAtt2() ) ) {
TagSupport ts = new TagSupport();
setParent( this );
Tag tt = getParent();
if ( tt == this ) {
TestString = TestString + "Pass";
} else {
TestString = TestString + "Fails";
}
}
}
AbstractBusinessObjectPropertyTag.java 文件源码
项目:Telepathology
阅读 35
收藏 0
点赞 0
评论 0
@SuppressWarnings("unchecked")
private P getParentTag()
throws JspException
{
try
{
AbstractBusinessObjectTag<T> parentTag = null;
for(
parentTag = (AbstractBusinessObjectTag)TagSupport.findAncestorWithClass(this, AbstractBusinessObjectTag.class);
parentTag != null && ! businessObjectType.equals(parentTag.getBusinessObjectType());
parentTag = (AbstractBusinessObjectTag)TagSupport.findAncestorWithClass(parentTag, AbstractBusinessObjectTag.class) );
return (P)parentTag;
}
catch (ClassCastException e)
{
throw new JspException("Parent tag of this '" + this.getClass().getName() + "' must present business object of type '" + getBusinessObjectType().getName() + "'.");
}
}
SectionContainerTag.java 文件源码
项目:nyla
阅读 38
收藏 0
点赞 0
评论 0
/**
*
* @see javax.servlet.jsp.tagext.TagSupport#doEndTag()
*/
public int doEndTag() throws JspException
{
try
{
section = null;
pageContext.removeAttribute("counter");
pageContext.removeAttribute("sectionCounter");
pageContext.getOut().write("</table>");
return TagSupport.EVAL_PAGE;
}
catch(Exception e)
{
throw new JspException(Debugger.stackTrace(e));
}
}
ShowControlTag.java 文件源码
项目:webcurator
阅读 32
收藏 0
点赞 0
评论 0
@Override
public int doStartTag() throws JspException {
StringTokenizer tokenizer = new StringTokenizer(privileges, ";");
String[] privs = new String[tokenizer.countTokens()];
for(int i=0; tokenizer.hasMoreTokens(); i++) {
privs[i] = tokenizer.nextToken();
}
if(ownedObject instanceof UserOwnable) {
showControl = editMode && authorityManager.hasAtLeastOnePrivilege( (UserOwnable) ownedObject, privs);
}
else if(ownedObject instanceof AgencyOwnable) {
showControl = editMode && authorityManager.hasAtLeastOnePrivilege( (AgencyOwnable) ownedObject, privs);
}
else {
showControl = false;
}
// release the object (usually its a ti) from the tag to prevent a memory leak (Tags are pooled)
ownedObject = null;
return TagSupport.EVAL_BODY_INCLUDE;
}
GrpNameTag.java 文件源码
项目:webcurator
阅读 34
收藏 0
点赞 0
评论 0
@Override
public int doStartTag() throws JspException {
try {
if (name.contains(subGroupSeparator)) {
int sepIndex = name.lastIndexOf(subGroupSeparator);
String parentName = name.substring(0, sepIndex);
String subGroupName = name.substring(sepIndex + subGroupSeparator.length());
pageContext.getOut().print("<div class=\"subGroupParent\">");
pageContext.getOut().print(parentName);
pageContext.getOut().print("</div>");
pageContext.getOut().print(subGroupSeparator);
pageContext.getOut().print("<div class=\"subGroupChild\">");
pageContext.getOut().print(subGroupName);
pageContext.getOut().print("</div>");
} else {
pageContext.getOut().print(name);
}
} catch (IOException ex) {
throw new JspException(ex);
}
return TagSupport.SKIP_BODY;
}
TreeTag.java 文件源码
项目:webcurator
阅读 32
收藏 0
点赞 0
评论 0
@SuppressWarnings("unchecked")
public int doStartTag() throws JspException {
rowAlt = 0;
try {
//NodeTree theTree = (NodeTree) ExpressionUtil.evalNotNull("tree", "tree", tree, NodeTree.class, this, pageContext);
NodeTree theTree = getTree();
Iterator<Node> rootIterator = theTree.getRootNodes().iterator();
pageContext.getOut().println("<table cellspacing=\"0\" cellpadding=\"0\">");
displayHeader(pageContext.getOut());
while (rootIterator.hasNext()) {
display(pageContext.getOut(), rootIterator.next(), 0);
}
pageContext.getOut().println("</table>");
}
catch (IOException ex) {
throw new JspException(ex.getMessage(), ex);
}
// Never process the body.
return TagSupport.SKIP_BODY;
}
RenderInitializationScriptTagTest.java 文件源码
项目:rave
阅读 49
收藏 0
点赞 0
评论 0
@Test
public void doStartTag_beforeRave_existingAttribute() throws Exception {
tag.setLocation(ScriptLocation.BEFORE_RAVE);
expect(pageContext.getRequest()).andReturn(request);
expect(request.getAttribute(ModelKeys.BEFORE_RAVE_INIT_SCRIPT)).andReturn(VALID_SCRIPT);
expect(pageContext.getOut()).andReturn(writer);
writer.print(VALID_SCRIPT.toString());
expectLastCall();
replay(pageContext, request, writer);
int returnValue = tag.doStartTag();
assertThat(returnValue, is(TagSupport.EVAL_BODY_INCLUDE));
verify(pageContext, request, writer);
}
RenderInitializationScriptTagTest.java 文件源码
项目:rave
阅读 52
收藏 0
点赞 0
评论 0
@Test
public void doStartTag_afterRave_existingAttribute() throws Exception {
tag.setLocation(ScriptLocation.AFTER_RAVE);
expect(pageContext.getRequest()).andReturn(request);
expect(request.getAttribute(ModelKeys.AFTER_RAVE_INIT_SCRIPT)).andReturn(VALID_SCRIPT);
expect(pageContext.getOut()).andReturn(writer);
writer.print(VALID_SCRIPT.toString());
expectLastCall();
replay(pageContext, request, writer);
int returnValue = tag.doStartTag();
assertThat(returnValue, is(TagSupport.EVAL_BODY_INCLUDE));
verify(pageContext, request, writer);
}
ScriptTagTest.java 文件源码
项目:rave
阅读 51
收藏 0
点赞 0
评论 0
@Test
public void doStartTag_skip() throws IOException, JspException {
List<String> strings = new ArrayList<String>();
strings.add(SCRIPT);
strings.add(SCRIPT_2);
expect(service.getScriptBlocks(ScriptLocation.BEFORE_RAVE, context)).andReturn(null);
replay(service);
JspWriter writer = createNiceMock(JspWriter.class);
replay(writer);
expect(pageContext.getOut()).andReturn(writer).anyTimes();
replay(pageContext);
tag.setLocation(ScriptLocation.BEFORE_RAVE);
int result = tag.doStartTag();
assertThat(result, is(equalTo(TagSupport.SKIP_BODY)));
verify(writer);
}
DialogButtonTag.java 文件源码
项目:winlet
阅读 39
收藏 0
点赞 0
评论 0
public int doAfterBody() {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(baos, "UTF-8");
bodyContent.writeOut(writer);
writer.flush();
button.put("label", baos.toString("UTF-8"));
} catch (IOException e) {
e.printStackTrace();
}
DialogTag dialog = (DialogTag) TagSupport.findAncestorWithClass(this,
DialogTag.class);
dialog.addButton(button);
button = new HashMap<String, String>();
bodyContent.clearBody();
return SKIP_BODY;
}
OnlyIfClientModeTag.java 文件源码
项目:webgenome
阅读 35
收藏 0
点赞 0
评论 0
/**
* Do after start tag parsed.
* @throws JspException if anything goes wrong.
* @return Return value
*/
@Override
public final int doStartTag() throws JspException {
int rVal = TagSupport.SKIP_BODY;
try {
SessionMode mode =
org.rti.webgenome.webui.util.PageContext.getSessionMode(
(HttpServletRequest) pageContext.getRequest());
if (mode == SessionMode.CLIENT) {
rVal = TagSupport.EVAL_BODY_INCLUDE;
}
} catch (SessionTimeoutException e) {
rVal = TagSupport.SKIP_BODY;
}
return rVal;
}
QuantitationTypeOptionsTag.java 文件源码
项目:webgenome
阅读 34
收藏 0
点赞 0
评论 0
/**
* Do after start tag parsed.
* @throws JspException if anything goes wrong.
* @return Return value
*/
@Override
public final int doStartTag() throws JspException {
Map<String, QuantitationType> index =
QuantitationType.getQuantitationTypeIndex();
Writer out = pageContext.getOut();
for (String id : index.keySet()) {
String name = index.get(id).getName();
try {
out.write("<option value=\"" + id + "\">" + name + "</option>");
} catch (IOException e) {
throw new JspException("Error writing to page.");
}
}
return TagSupport.SKIP_BODY;
}
OnlyIfParameteredDerivedExperimentTag.java 文件源码
项目:webgenome
阅读 42
收藏 0
点赞 0
评论 0
/**
* {@inheritDoc}
*/
@Override
public int doStartTag() throws JspException {
int rval = TagSupport.SKIP_BODY;
if (name != null && name.length() > 0) {
Object obj = pageContext.findAttribute(name);
if (obj != null) {
if (!(obj instanceof Experiment)) {
throw new JspException("Bean named '"
+ this.name + "' not of type Experiment");
}
Experiment exp = (Experiment) obj;
if (exp.isDerived()) {
AnalysisDataSourceProperties props =
(AnalysisDataSourceProperties)
exp.getDataSourceProperties();
Collection<UserConfigurableProperty> userProps =
props.getUserConfigurableProperties();
if (userProps != null && userProps.size() > 0) {
rval = TagSupport.EVAL_BODY_INCLUDE;
}
}
}
}
return rval;
}
OnlyIfAdminTag.java 文件源码
项目:webgenome
阅读 40
收藏 0
点赞 0
评论 0
/**
* Do after start tag parsed.
* @throws JspException if anything goes wrong.
* @return Return value
*/
@Override
public final int doStartTag() throws JspException {
int rVal = TagSupport.SKIP_BODY;
try {
Principal principal =
org.rti.webgenome.webui.util.PageContext.getPrincipal(
(HttpServletRequest) pageContext.getRequest());
if (principal.isAdmin()) {
rVal = TagSupport.EVAL_BODY_INCLUDE;
}
} catch (SessionTimeoutException e) {
rVal = TagSupport.SKIP_BODY;
}
return rVal;
}
OnlyIfLoggedInAndStandAloneModeTag.java 文件源码
项目:webgenome
阅读 37
收藏 0
点赞 0
评论 0
/**
* Do after start tag parsed.
* @throws JspException if anything goes wrong.
* @return Return value
*/
@Override
public final int doStartTag() throws JspException {
int rVal = TagSupport.SKIP_BODY;
try {
SessionMode mode =
org.rti.webgenome.webui.util.PageContext.getSessionMode(
(HttpServletRequest) pageContext.getRequest());
Principal principal =
org.rti.webgenome.webui.util.PageContext.getPrincipal(
(HttpServletRequest) pageContext.getRequest());
if (mode == SessionMode.STAND_ALONE && principal != null) {
rVal = TagSupport.EVAL_BODY_INCLUDE;
}
} catch (SessionTimeoutException e) {
rVal = TagSupport.SKIP_BODY;
}
return rVal;
}
OnlyIfClientModeTag.java 文件源码
项目:webgenome
阅读 36
收藏 0
点赞 0
评论 0
/**
* Do after start tag parsed.
* @throws JspException if anything goes wrong.
* @return Return value
*/
@Override
public final int doStartTag() throws JspException {
int rVal = TagSupport.SKIP_BODY;
try {
SessionMode mode =
org.rti.webgenome.webui.util.PageContext.getSessionMode(
(HttpServletRequest) pageContext.getRequest());
if (mode == SessionMode.CLIENT) {
rVal = TagSupport.EVAL_BODY_INCLUDE;
}
} catch (SessionTimeoutException e) {
rVal = TagSupport.SKIP_BODY;
}
return rVal;
}
QuantitationTypeOptionsTag.java 文件源码
项目:webgenome
阅读 35
收藏 0
点赞 0
评论 0
/**
* Do after start tag parsed.
* @throws JspException if anything goes wrong.
* @return Return value
*/
@Override
public final int doStartTag() throws JspException {
Map<String, QuantitationType> index =
QuantitationType.getQuantitationTypeIndex();
Writer out = pageContext.getOut();
for (String id : index.keySet()) {
String name = index.get(id).getName();
try {
out.write("<option value=\"" + id + "\">" + name + "</option>");
} catch (IOException e) {
throw new JspException("Error writing to page.");
}
}
return TagSupport.SKIP_BODY;
}
OnlyIfParameteredDerivedExperimentTag.java 文件源码
项目:webgenome
阅读 36
收藏 0
点赞 0
评论 0
/**
* {@inheritDoc}
*/
@Override
public int doStartTag() throws JspException {
int rval = TagSupport.SKIP_BODY;
if (name != null && name.length() > 0) {
Object obj = pageContext.findAttribute(name);
if (obj != null) {
if (!(obj instanceof Experiment)) {
throw new JspException("Bean named '"
+ this.name + "' not of type Experiment");
}
Experiment exp = (Experiment) obj;
if (exp.isDerived()) {
AnalysisDataSourceProperties props =
(AnalysisDataSourceProperties)
exp.getDataSourceProperties();
Collection<UserConfigurableProperty> userProps =
props.getUserConfigurableProperties();
if (userProps != null && userProps.size() > 0) {
rval = TagSupport.EVAL_BODY_INCLUDE;
}
}
}
}
return rval;
}
OnlyIfAdminTag.java 文件源码
项目:webgenome
阅读 39
收藏 0
点赞 0
评论 0
/**
* Do after start tag parsed.
* @throws JspException if anything goes wrong.
* @return Return value
*/
@Override
public final int doStartTag() throws JspException {
int rVal = TagSupport.SKIP_BODY;
try {
Principal principal =
org.rti.webgenome.webui.util.PageContext.getPrincipal(
(HttpServletRequest) pageContext.getRequest());
if (principal.isAdmin()) {
rVal = TagSupport.EVAL_BODY_INCLUDE;
}
} catch (SessionTimeoutException e) {
rVal = TagSupport.SKIP_BODY;
}
return rVal;
}
OnlyIfLoggedInAndStandAloneModeTag.java 文件源码
项目:webgenome
阅读 51
收藏 0
点赞 0
评论 0
/**
* Do after start tag parsed.
* @throws JspException if anything goes wrong.
* @return Return value
*/
@Override
public final int doStartTag() throws JspException {
int rVal = TagSupport.SKIP_BODY;
try {
SessionMode mode =
org.rti.webgenome.webui.util.PageContext.getSessionMode(
(HttpServletRequest) pageContext.getRequest());
Principal principal =
org.rti.webgenome.webui.util.PageContext.getPrincipal(
(HttpServletRequest) pageContext.getRequest());
if (mode == SessionMode.STAND_ALONE && principal != null) {
rVal = TagSupport.EVAL_BODY_INCLUDE;
}
} catch (SessionTimeoutException e) {
rVal = TagSupport.SKIP_BODY;
}
return rVal;
}
UIXComponentTag.java 文件源码
项目:myfaces-trinidad
阅读 37
收藏 0
点赞 0
评论 0
@Override
public int doStartTag() throws JspException
{
_parentELContext = (ELContextTag)
TagSupport.findAncestorWithClass(this, ELContextTag.class);
// Transform "rendered" on behalf of the UIComponentTag
String rendered = _rendered;
if (rendered != null)
{
if ((_parentELContext != null) && isValueReference(rendered))
rendered = _parentELContext.transformExpression(rendered);
super.setRendered(rendered);
}
String id = _id;
if (id != null)
{
if (_parentELContext != null)
id = _parentELContext.transformId(id);
super.setId(id);
}
int retVal = super.doStartTag();
//pu: There could have been some validation error during property setting
// on the bean, this is the closest opportunity to burst out.
if (_validationError != null)
throw new JspException(_validationError);
return retVal;
}
TransformTag.java 文件源码
项目:spring4-understanding
阅读 33
收藏 0
点赞 0
评论 0
@Override
protected final int doStartTagInternal() throws JspException {
if (this.value != null) {
// Find the containing EditorAwareTag (e.g. BindTag), if applicable.
EditorAwareTag tag = (EditorAwareTag) TagSupport.findAncestorWithClass(this, EditorAwareTag.class);
if (tag == null) {
throw new JspException("TransformTag can only be used within EditorAwareTag (e.g. BindTag)");
}
// OK, let's obtain the editor...
String result = null;
PropertyEditor editor = tag.getEditor();
if (editor != null) {
// If an editor was found, edit the value.
editor.setValue(this.value);
result = editor.getAsText();
}
else {
// Else, just do a toString.
result = this.value.toString();
}
result = htmlEscape(result);
if (this.var != null) {
pageContext.setAttribute(this.var, result, TagUtils.getScope(this.scope));
}
else {
try {
// Else, just print it out.
pageContext.getOut().print(result);
}
catch (IOException ex) {
throw new JspException(ex);
}
}
}
return SKIP_BODY;
}
Flashback.java 文件源码
项目:spring-abc
阅读 35
收藏 0
点赞 0
评论 0
@Override
public int doStartTag() throws JspException {
JspWriter out = this.pageContext.getOut();
try {
out.print(FlashbackSupport.format(time));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return TagSupport.SKIP_BODY;
}
NotAuthenticatedTag.java 文件源码
项目:rabbitframework
阅读 39
收藏 0
点赞 0
评论 0
public int onDoStartTag() throws JspException {
if (getSubject() == null || !getSubject().isAuthenticated()) {
if (log.isTraceEnabled()) {
log.trace("Subject does not exist or is not authenticated. Tag body will be evaluated.");
}
return TagSupport.EVAL_BODY_INCLUDE;
} else {
if (log.isTraceEnabled()) {
log.trace("Subject exists and is authenticated. Tag body will not be evaluated.");
}
return TagSupport.SKIP_BODY;
}
}
GuestTag.java 文件源码
项目:rabbitframework
阅读 51
收藏 0
点赞 0
评论 0
public int onDoStartTag() throws JspException {
if (getSubject() == null || getSubject().getPrincipal() == null) {
if (log.isTraceEnabled()) {
log.trace("Subject does not exist or does not have a known identity (aka 'principal'). " +
"Tag body will be evaluated.");
}
return TagSupport.EVAL_BODY_INCLUDE;
} else {
if (log.isTraceEnabled()) {
log.trace("Subject exists or has a known identity (aka 'principal'). " +
"Tag body will not be evaluated.");
}
return TagSupport.SKIP_BODY;
}
}
AuthenticatedTag.java 文件源码
项目:rabbitframework
阅读 31
收藏 0
点赞 0
评论 0
public int onDoStartTag() throws JspException {
if (getSubject() != null && getSubject().isAuthenticated()) {
if (log.isTraceEnabled()) {
log.trace("Subject exists and is authenticated. Tag body will be evaluated.");
}
return TagSupport.EVAL_BODY_INCLUDE;
} else {
if (log.isTraceEnabled()) {
log.trace("Subject does not exist or is not authenticated. Tag body will not be evaluated.");
}
return TagSupport.SKIP_BODY;
}
}
RoleTag.java 文件源码
项目:rabbitframework
阅读 39
收藏 0
点赞 0
评论 0
public int onDoStartTag() throws JspException {
boolean show = showTagBody(getName());
if (show) {
return TagSupport.EVAL_BODY_INCLUDE;
} else {
return TagSupport.SKIP_BODY;
}
}
PermissionTag.java 文件源码
项目:rabbitframework
阅读 39
收藏 0
点赞 0
评论 0
public int onDoStartTag() throws JspException {
String p = getName();
boolean show = showTagBody(p);
if (show) {
return TagSupport.EVAL_BODY_INCLUDE;
} else {
return TagSupport.SKIP_BODY;
}
}
IterateTag.java 文件源码
项目:personal
阅读 40
收藏 0
点赞 0
评论 0
@Override
public int doStartTag() throws JspException {
Object object = this.pageContext.getAttribute(items);
if (object != null && object instanceof List) {
this.iterator = ((List) object).iterator();
if (iterator.hasNext()) {
this.pageContext.setAttribute(value, iterator.next());
return TagSupport.EVAL_BODY_INCLUDE; // 执行标签体
}
}
return SKIP_BODY;
}