~ubuntu-branches/ubuntu/saucy/ruby-erubis/saucy

« back to all changes in this revision

Viewing changes to test/data/users-guide/Example.ejava

  • Committer: Package Import Robot
  • Author(s): Laurent Bigonville
  • Date: 2012-01-26 15:15:58 UTC
  • Revision ID: package-import@ubuntu.com-20120126151558-9u7mnf9ooqnw3bwz
Tags: upstream-2.7.0
ImportĀ upstreamĀ versionĀ 2.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<%
 
2
import java.util.*;
 
3
 
 
4
public class Example {
 
5
  private String user;
 
6
  private String[] list;
 
7
  public example(String user, String[] list) {
 
8
    this.user = user;
 
9
    this.list = list;
 
10
  }
 
11
 
 
12
  public String view() {
 
13
    StringBuffer _buf = new StringBuffer();
 
14
%>
 
15
<html>
 
16
 <body>
 
17
  <p>Hello <%= user %>!</p>
 
18
  <table>
 
19
   <tbody>
 
20
    <% for (int i = 0; i < list.length; i++) { %>
 
21
    <tr bgcolor="<%= i % 2 == 0 ? "#FFCCCC" : "#CCCCFF" %>">
 
22
     <td><%= i + 1 %></td>
 
23
     <td><%== list[i] %></td>
 
24
    </tr>
 
25
    <% } %>
 
26
   </tbody>
 
27
  </table>
 
28
 <body>
 
29
</html>
 
30
<%
 
31
    return _buf.toString();
 
32
  }
 
33
 
 
34
  public static void main(String[] args) {
 
35
    String[] list = { "<aaa>", "b&b", "\"ccc\"" };
 
36
    Example ex = Example.new("Erubis", list);
 
37
    System.out.print(ex.view());
 
38
  }
 
39
 
 
40
  public static String escape(String s) {
 
41
    StringBuffer sb = new StringBuffer();
 
42
    for (int i = 0; i < s.length(); i++) {
 
43
      char ch = s.charAt(i);
 
44
      switch (ch) {
 
45
      case '<':   sb.append("&lt;"); break;
 
46
      case '>':   sb.append("&gt;"); break;
 
47
      case '&':   sb.append("&amp;"); break;
 
48
      case '"':   sb.append("&quot;"); break;
 
49
      default:    sb.append(ch);
 
50
      }
 
51
    }
 
52
    return sb.toString();
 
53
  }
 
54
}
 
55
%>