summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Suhren <suhren.stefan@fh-swf.de>2015-11-02 00:45:07 +0100
committerStefan Suhren <suhren.stefan@fh-swf.de>2015-11-02 00:45:07 +0100
commit311f6b2b33e2f8f32848d1b01e169d0d115080af (patch)
tree35818496190533e43d291598a18d6c7b412de7cf
parent65e29925b16fab7f39973ebd748bc30e9202e487 (diff)
downloadFIT-311f6b2b33e2f8f32848d1b01e169d0d115080af.tar.gz
FIT-311f6b2b33e2f8f32848d1b01e169d0d115080af.zip
Add repeat tag.
-rw-r--r--WebContent/WEB-INF/repeat.tld16
-rw-r--r--src/de/fhswf/in/inf/fit/aufgabe4/Repeat.java75
2 files changed, 91 insertions, 0 deletions
diff --git a/WebContent/WEB-INF/repeat.tld b/WebContent/WEB-INF/repeat.tld
new file mode 100644
index 0000000..f34873b
--- /dev/null
+++ b/WebContent/WEB-INF/repeat.tld
@@ -0,0 +1,16 @@
+<taglib>
+ <tlib-version>1.0</tlib-version>
+ <jsp-version>3.0</jsp-version>
+ <short-name>Custom Repeat Tag</short-name>
+ <tag>
+ <name>Repeat</name>
+ <tag-class>de.fhswf.in.inf.fit.aufgabe4.Repeat</tag-class>
+ <description>Repeats the body multiple times.</description>
+ <body-content>scriptless</body-content>
+ <attribute>
+ <name>times</name>
+ <description>The amount of times the body is printed.</description>
+ <required>true</required>
+ </attribute>
+ </tag>
+</taglib> \ No newline at end of file
diff --git a/src/de/fhswf/in/inf/fit/aufgabe4/Repeat.java b/src/de/fhswf/in/inf/fit/aufgabe4/Repeat.java
new file mode 100644
index 0000000..d644ff9
--- /dev/null
+++ b/src/de/fhswf/in/inf/fit/aufgabe4/Repeat.java
@@ -0,0 +1,75 @@
+/**
+ *
+ */
+package de.fhswf.in.inf.fit.aufgabe4;
+
+import java.io.IOException;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.BodyTagSupport;
+
+/**
+ * Handler for the repeat tag.
+ *
+ * @author Stefan Suhren
+ * @version 1.0
+ */
+public class Repeat extends BodyTagSupport
+{
+ /**
+ * Required attribute for {@link BodyTagSupport}.
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The number of times the Body will be printed.
+ */
+ private int times = 0;
+
+ /**
+ * Getter for property times.
+ *
+ * @return Returns the times.
+ */
+ public int getTimes()
+ {
+ return times;
+ }
+
+ /**
+ * Setter for property times.
+ *
+ * @param times
+ * The times to set.
+ */
+ public void setTimes(int times)
+ {
+ this.times = times;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.jsp.tagext.BodyTagSupport#doEndTag()
+ */
+ @Override
+ public int doEndTag() throws JspException
+ {
+ String bodyText = bodyContent.getString();
+
+ for (int i = 0; i < times; i++)
+ {
+ try
+ {
+ pageContext.getOut().print(bodyText);
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ return EVAL_PAGE;
+ }
+
+}