001/* 002 * flattr4j - A Java library for Flattr 003 * 004 * Copyright (C) 2011 Richard "Shred" Körber 005 * http://flattr4j.shredzone.org 006 * 007 * This program is free software: you can redistribute it and/or modify 008 * it under the terms of the GNU General Public License / GNU Lesser 009 * General Public License as published by the Free Software Foundation, 010 * either version 3 of the License, or (at your option) any later version. 011 * 012 * Licensed under the Apache License, Version 2.0 (the "License"); 013 * you may not use this file except in compliance with the License. 014 * 015 * This program is distributed in the hope that it will be useful, 016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 018 */ 019package org.shredzone.flattr4j.web.tag; 020 021import java.util.Collection; 022 023import javax.servlet.jsp.JspException; 024import javax.servlet.jsp.tagext.BodyTagSupport; 025 026/** 027 * An optional tag for the parent button tag. 028 * 029 * @author Richard "Shred" Körber 030 */ 031public class TagTag extends BodyTagSupport { 032 private static final long serialVersionUID = -2512754082305270317L; 033 034 private Collection<String> list; 035 private String value; 036 037 public void setList(Collection<String> list) { 038 this.list = list; 039 } 040 041 public void setValue(String value) { 042 this.value = value; 043 } 044 045 @Override 046 public int doStartTag() throws JspException { 047 if (value != null) { 048 return SKIP_BODY; 049 } else { 050 return EVAL_BODY_BUFFERED; 051 } 052 } 053 054 @Override 055 public int doEndTag() throws JspException { 056 ButtonTag parent = TagUtils.findAncestorWithType(this, ButtonTag.class); 057 if (parent != null) { 058 if (value != null) { 059 parent.addTag(value); 060 } else { 061 parent.addTag(getBodyContent().getString()); 062 } 063 if (list != null) { 064 parent.addTags(list); 065 } 066 } 067 return EVAL_PAGE; 068 } 069 070}