javax.servlet.jsp.tagext.TagSupport Java Examples

The following examples show how to use javax.servlet.jsp.tagext.TagSupport. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScriptTagTest.java    From attic-rave with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: ShowByPermissionTag.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
    * permission control
    */
   @Override
public int doStartTag() throws JspException {
   	ComAdmin aAdmin = AgnUtils.getAdmin(pageContext);
	if (aAdmin != null) {
           try {
               if (aAdmin.permissionAllowed(Permission.getPermissionsByToken(token))) {
                   return TagSupport.EVAL_BODY_INCLUDE;
               }
           } catch (Exception e) {
               releaseException(e, token);
           }
       }

	return SKIP_BODY;
}
 
Example #3
Source File: ShowControlTag.java    From webcurator with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #4
Source File: GrpNameTag.java    From webcurator with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #5
Source File: RenderInitializationScriptTagTest.java    From attic-rave with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #6
Source File: RenderInitializationScriptTagTest.java    From attic-rave with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #7
Source File: TreeTag.java    From webcurator with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #8
Source File: AbstractFunction.java    From ontopia with Apache License 2.0 5 votes vote down vote up
@Override
public Collection execute(PageContext pageContext, TagSupport callingTag)
  throws IOException, JspException {
  // Delegate to deprecated call method.
  call(pageContext, callingTag);
  // Return value
  String retvar = getReturnVariableName();
  if (retvar != null) {
    // Note: may throw VariableNotSetException if variable not set.
    return ContextUtils.getValue(retvar, pageContext);
  }
  return null;
}
 
Example #9
Source File: DateTag.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@Override
public int doStartTag() throws JspException  {
	try {
		if("fullDateTime".equals(type)) {
			pageContext.getOut().print(DateUtils.get().formatFullDateTime(value));
		}
		else if("shortDateTime".equals(type)) { 
			pageContext.getOut().print(DateUtils.get().formatShortDateTime(value));
		}
		else if("shortDate".equals(type)) { 
			pageContext.getOut().print(DateUtils.get().formatShortDate(value));
		}
		else if("longDateTime".equals(type)) {
			pageContext.getOut().print(DateUtils.get().formatLongDateTime(value));
		}
		else if("fullDate".equals(type)) {
			pageContext.getOut().print(DateUtils.get().formatFullDate(value));
		}
		else if("fullTime".equals(type)) {
			pageContext.getOut().print(DateUtils.get().formatFullTime(value));
		}			
		else {
			throw new IllegalArgumentException("Illegal Type provided");
		}
	}
	catch(IOException ex) { 
		throw new JspException(ex);
	}
	
	return TagSupport.SKIP_BODY;
}
 
Example #10
Source File: JSPPageExecuter.java    From ontopia with Apache License 2.0 5 votes vote down vote up
private void loopTag(TagSupport tag, JSPTreeNodeIF curNode)
  throws JspException, IOException {
  // loop as long as tag says so
  int token;
  do {
    runTag(tag, curNode);
    token = tag.doAfterBody();
  } while (token == BodyTagSupport.EVAL_BODY_AGAIN);
  if (token != BodyTagSupport.SKIP_BODY)
    throw new OntopiaRuntimeException("Internal error: unknown doAfterBody token: " + token);
}
 
Example #11
Source File: QaIndicatorUnitTag.java    From webcurator with Apache License 2.0 5 votes vote down vote up
/**
    *	Output a value and the measurement unit with appropriate scaling 
    */
	@Override
public int doStartTag() throws JspException  {
			
	String output = null;
	
	if (unit.equals("integer")) {
		output = new Integer((new Float(value)).intValue()).toString();
	} else if (unit.equals("millisecond")) {
		output = getElapsedTime();
	} else if (unit.equals("byte")) {
		Long bytes;
		// scale the number of bytes as appropriate
		String[] decimal = value.split("\\.");
		if (decimal.length > 1) {
			bytes = Long.parseLong(decimal[0]);
		} else {
			bytes = Long.parseLong(value);
		}
		output = ConverterUtil.formatBytes(bytes);
	}
	
	try {
		pageContext.getOut().print(output);
	} catch (IOException e) {
		throw new JspException(e);
	}
	
	return TagSupport.SKIP_BODY;
}
 
Example #12
Source File: HarvestResultChain.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@Override
public int doStartTag() throws JspException {
	try {
		doIt(0);
		return TagSupport.SKIP_BODY;
	}
	catch(IOException ex) { 
		throw new JspException(ex);
	}
}
 
Example #13
Source File: ParamValueTag.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * When reach the end tag, fire this operation
 * 
 * @see javax.servlet.jsp.tagext.BodyTagSupport#doEndTag()
 */
public int doEndTag( ) throws JspException
{
	// included in viewer tag
	ParamTag paramTag = (ParamTag) TagSupport
			.findAncestorWithClass( this, ParamTag.class );
	if ( paramTag != null )
	{
		if ( bodyContent != null )
		{
			String bodyString = bodyContent.getString( );
			if ( bodyString != null )
			{
				bodyString = bodyString.trim( );
				if ( !"".equals(bodyString) )
				{
					// replace the value attribute with the content, if empty
					if ( param.getValue() == null || "".equals(param.getValue()) )
					{
						param.setValue( bodyString );
					}
				}
			}
		}
		paramTag.addValue( param );
	}
	return super.doEndTag( );
}
 
Example #14
Source File: TransformTag.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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) {
			this.pageContext.setAttribute(this.var, result, TagUtils.getScope(this.scope));
		}
		else {
			try {
				// Else, just print it out.
				this.pageContext.getOut().print(result);
			}
			catch (IOException ex) {
				throw new JspException(ex);
			}
		}
	}

	return SKIP_BODY;
}
 
Example #15
Source File: ParamTag.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * When reach the end tag, fire this operation
 * 
 * @see javax.servlet.jsp.tagext.BodyTagSupport#doEndTag()
 */
public int doEndTag( ) throws JspException
{
	if ( param.validate( ) )
	{
		// included in viewer tag
		AbstractViewerTag viewerTag = (AbstractViewerTag) TagSupport
				.findAncestorWithClass( this, AbstractViewerTag.class );
		if ( viewerTag != null )
			viewerTag.addParameter( param );
	}
	return super.doEndTag( );
}
 
Example #16
Source File: TransformTag.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #17
Source File: TransformTag.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example #18
Source File: SpanTag.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ${@inheritDoc}
 */
public int doEndTag() throws JspException {
    ListCommand cmd = ListTagUtil.getCurrentCommand(this, pageContext);
    ListTag parent = (ListTag) TagSupport.findAncestorWithClass(this, ListTag.class);
    if (cmd.equals(ListCommand.TBL_ADDONS) && role.equals("header")) {
        renderHeader(parent);
    }
    else if (cmd.equals(ListCommand.BEFORE_RENDER) && role.equals("footer")) {
        renderFooter(parent);
    }
    return TagSupport.EVAL_PAGE;
}
 
Example #19
Source File: CustomListTypeTag.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@Override
  public int doStartTag() throws JspException {
JspWriter writer = pageContext.getOut();
try {
	
	
	WCTTreeSet entries = list.getCopy();
	entries.add(currentValue);
	
	if(onChangeFunction != null && !onChangeFunction.isEmpty())
	{
		writer.println("<select id=\"" + paramName + "\" name=\"" + paramName + "\" onchange=\""+onChangeFunction+"\">");
	}
	else
	{
		writer.println("<select id=\"" + paramName + "\" name=\"" + paramName + "\">");
	}
	
	for (String entry : entries) {
		if (entry.equals(currentValue)) {
			writer.println("<option value=\"" + entry +"\" selected>" + entry +"</option>");
		}
		else {
			writer.println("<option value=\"" + entry +"\">" + entry +"</option>");
		}
	}
	writer.println("</select>");
} 
catch (IOException e) {
	throw new JspException(e.getMessage(), e);
}

return TagSupport.SKIP_BODY;
  }
 
Example #20
Source File: Function.java    From ontopia with Apache License 2.0 5 votes vote down vote up
@Override
public void call(PageContext pageContext, TagSupport callingTag)
  throws IOException, JspException {

  JSPPageExecuter exec = new JSPPageExecuter();
  exec.run(pageContext, callingTag, rootNode);
}
 
Example #21
Source File: HasPermissionTag.java    From jeecg with Apache License 2.0 5 votes vote down vote up
public int doStartTag() throws JspException {
       boolean show = showTagBody(code);
       if (show) {
           return TagSupport.SKIP_BODY;
       } else {
           return TagSupport.EVAL_BODY_INCLUDE;
       }
}
 
Example #22
Source File: TransformTag.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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) {
			this.pageContext.setAttribute(this.var, result, TagUtils.getScope(this.scope));
		}
		else {
			try {
				// Else, just print it out.
				this.pageContext.getOut().print(result);
			}
			catch (IOException ex) {
				throw new JspException(ex);
			}
		}
	}

	return SKIP_BODY;
}
 
Example #23
Source File: ShowControlTrueTag.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@Override
public int doStartTag() throws JspException {  
	if(getParent() instanceof ShowControlTag) {
		if(((ShowControlTag)getParent()).isShowControl()) {
			return TagSupport.EVAL_BODY_INCLUDE;
		}
		else {
			return TagSupport.SKIP_BODY;
		}
	}
	else {
		throw new JspTagException("True outside ShowControl");
	}
}
 
Example #24
Source File: HasUserOwnedPrivTag.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@Override
public int doStartTag() throws JspException {
    if (ownedObject instanceof UserOwnable) {
        if (authorityManager.hasPrivilege(ownedObject, privilege)) {
            return TagSupport.EVAL_BODY_INCLUDE;
        } 
    	// release the object (usually its a target which references tis) from the tag to prevent a memory leak (Tags are pooled)
        ownedObject = null;
        return TagSupport.SKIP_BODY;
    }
    throw new JspException("authority:hasUserOwnedPriv tag called but ownedObject was not of type UserOwnable");
}
 
Example #25
Source File: HasUserOwnedPrivTag.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@Override
public int doEndTag() throws JspException {
	// release the object (usually its a target which references tis) from the tag to prevent a memory leak (Tags are pooled)
    if (ownedObject != null)
    	ownedObject = null;

    return TagSupport.EVAL_PAGE;
}
 
Example #26
Source File: NoPrivilegeTag.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@Override
public int doStartTag() throws JspException {
    User user = AuthUtil.getRemoteUserObject();
    HashMap privs = authorityManager.getPrivilegesForUser(user);
    if (privs.containsKey(getPrivilege())) {
        RolePrivilege rp = (RolePrivilege)privs.get(getPrivilege());
        int usersPrivScope = rp.getPrivilegeScope();
        if (usersPrivScope <= getScope()) {
            return TagSupport.SKIP_BODY;
        }
    }
    return TagSupport.EVAL_BODY_INCLUDE;
}
 
Example #27
Source File: HasPrivilegeTag.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@Override
public int doStartTag() throws JspException {
    if (hasPrivilege(getPrivilege(),getScope()) == true) {
        return TagSupport.EVAL_BODY_INCLUDE;
    } else {
        return TagSupport.SKIP_BODY;
    }
}
 
Example #28
Source File: HasAtLeastOnePrivTag.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@Override
public int doStartTag() throws JspException {  
    String[] privArray = getPrivilegeKeys();
    if (authorityManager.hasAtLeastOnePrivilege(privArray)) {
        return TagSupport.EVAL_BODY_INCLUDE;
    }
   	return TagSupport.SKIP_BODY;
}
 
Example #29
Source File: ShowControlFalseTag.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@Override
public int doStartTag() throws JspException {  
	if(getParent() instanceof ShowControlTag) {
		if(((ShowControlTag)getParent()).isShowControl()) {
			return TagSupport.SKIP_BODY;
		}
		else {
			return TagSupport.EVAL_BODY_INCLUDE;
		}
	}
	else {
		throw new JspTagException("True outside ShowControl");
	}
}
 
Example #30
Source File: HasAgencyOwnedPrivTag.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@Override
public int doStartTag() throws JspException {
    if (ownedObject instanceof AgencyOwnable) {
        if (authorityManager.hasPrivilege(ownedObject, privilege)) {
            return TagSupport.EVAL_BODY_INCLUDE;
        } 
        return TagSupport.SKIP_BODY;
    }
    throw new JspException("authority:hasAgencyOwnedPriv tag called but ownedObject was not of type AgencyOwnable");
}