@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(); }
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"; } } }
@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() + "'."); } }
/** * * @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)); } }
@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; }
@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; }
@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; }
@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); }
@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); }
@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); }
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; }
/** * 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; }
/** * 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; }
/** * {@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; }
/** * 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; }
/** * 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; }
@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; }
@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; }
@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; }
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; } }
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; } }
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; } }
public int onDoStartTag() throws JspException { boolean show = showTagBody(getName()); if (show) { return TagSupport.EVAL_BODY_INCLUDE; } else { return TagSupport.SKIP_BODY; } }
public int onDoStartTag() throws JspException { String p = getName(); boolean show = showTagBody(p); if (show) { return TagSupport.EVAL_BODY_INCLUDE; } else { return TagSupport.SKIP_BODY; } }
@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; }
@Override public int doStartTag() throws JspException { JspWriter jspWriter = this.pageContext.getOut(); try { jspWriter.println("自定义标签"+ name + "你好"); } catch (IOException e) { e.printStackTrace(); } return TagSupport.SKIP_BODY; // 跳过body, 直接结束标签 }
private void checkDoEndTagEvaluationOfVar(String varName, int scope, String expectedOutput) throws Exception { final int tagReturnValue = openmrsMessageTag.doEndTag(); final String output = (String) mockPageContext.getAttribute(varName, scope); Assert.assertEquals("Tag should return 'EVAL_PAGE'", TagSupport.EVAL_PAGE, tagReturnValue); Assert.assertEquals(String.format("Variable '%s' should be '%s'", varName, expectedOutput), output, expectedOutput); }
/** * Convenient method that checks results of evaluation of {@link OpenmrsMessageTag#doEndTag()} * method * * @param expectedOutput the expected output of tag evaluation * @throws Exception if any evaluation error occurs */ private void checkDoEndTagEvaluation(String expectedOutput) throws Exception { int tagReturnValue = openmrsMessageTag.doEndTag(); String output = ((MockHttpServletResponse) mockPageContext.getResponse()).getContentAsString(); Assert.assertEquals("Tag should return 'EVAL_PAGE'", TagSupport.EVAL_PAGE, tagReturnValue); Assert.assertEquals(String.format("Output should be '%s'", expectedOutput), expectedOutput, output); }
/** * * @return * @throws JspException */ protected EnumIteratorTag getParentEnumIteratorTag() throws JspException { try { return (EnumIteratorTag)TagSupport.findAncestorWithClass(this, EnumIteratorTag.class); } catch (ClassCastException e) { throw new JspException("Parent tag of any derivation of AbstractEnumIteratorElementTag must be of type EnumIteratorTag"); } }
/** * * @return * @throws JspException */ protected WellKnownOIDIteratorTag getParentEnumIteratorTag() throws JspException { try { return (WellKnownOIDIteratorTag)TagSupport.findAncestorWithClass(this, WellKnownOIDIteratorTag.class); } catch (ClassCastException e) { throw new JspException("Parent tag of any derivation of AbstractEnumIteratorElementTag must be of type EnumIteratorTag"); } }
private AbstractPatientListTag getParentListTag() throws JspException { try { return (AbstractPatientListTag)TagSupport.findAncestorWithClass(this, AbstractPatientListTag.class); } catch (ClassCastException e) { throw new JspException("Parent tag of StudyListElementTag must be of type AbstractStudyListTag"); } }
private AbstractPatientTag getParentPatientTag() throws JspException { try { return (AbstractPatientTag)TagSupport.findAncestorWithClass(this, AbstractPatientTag.class); } catch (ClassCastException e) { throw new JspException("Parent tag of AbstractStudyPropertyTag must be of type AbstractStudyTag"); } }
private StringArrayList getParentTag() throws JspException { try { return (StringArrayList)TagSupport.findAncestorWithClass(this, StringArrayList.class); } catch (ClassCastException e) { throw new JspException("Parent tag of ObjectOriginListElement must be of type StringArrayList"); } }
private AbstractSeriesTag getParentSeriesTag() throws JspException { try { return (AbstractSeriesTag)TagSupport.findAncestorWithClass(this, AbstractSeriesTag.class); } catch (ClassCastException e) { throw new JspException("Parent tag of AbstractSeriesPropertyTag must be of type AbstractSeriesTag"); } }