View Javadoc
1   /*
2    * REPOWEB, repository manager.
3    *
4    * Terms of license - http://opensource.org/licenses/apachepl.php
5    */
6   package org.repoweb.tag;
7   import java.io.IOException;
8   import javax.servlet.jsp.JspException;
9   import javax.servlet.jsp.tagext.TagSupport;
10  import org.repoweb.model.Artifact;
11  /***
12   * Tag to display the size of an artifact.
13   */
14  public class SizeTag extends TagSupport {
15      public int doStartTag() throws JspException {
16          try {
17              Artifact artifact = (Artifact)pageContext.getAttribute(getId());
18              final long length = artifact.getLength();
19              if (length < 1024) {
20                  pageContext.getOut().write(String.valueOf(length));
21                  pageContext.getOut().write(" octets");
22              }
23              else {
24                  pageContext.getOut().write(String.valueOf(length / 1024));
25                  pageContext.getOut().write(" Ko");
26              }
27          }
28          catch (IOException error) {
29              throw new JspException(error);
30          }
31          return SKIP_BODY;
32      }
33  }