1 package net.sourceforge.blogentis.utils.tools;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28 import org.apache.turbine.util.RunData;
29 import org.apache.turbine.util.template.HtmlPageAttributes;
30
31 /***
32 * @author abas
33 *
34 */
35 public class PageAttributes extends HtmlPageAttributes {
36 public static class Link {
37 protected String relation;
38
39 protected String type;
40
41 protected String title;
42
43 protected String href;
44
45 public Link(String relation, String type, String href, String title) {
46 this.relation = relation;
47 this.type = type;
48 this.href = href;
49 this.title = title;
50 }
51
52 private static void addAttribute(String name, String value,
53 StringBuffer sb) {
54 if (value == null)
55 return;
56 sb.append(name);
57 sb.append("=\"");
58 sb.append(value);
59 sb.append("\" ");
60 }
61
62 public String toString() {
63 StringBuffer sb = new StringBuffer("<link ");
64 addAttribute("rel", relation, sb);
65 addAttribute("type", type, sb);
66 addAttribute("href", href, sb);
67 addAttribute("title", title, sb);
68 sb.append("/>");
69 return sb.toString();
70 }
71 }
72
73 protected List list = new ArrayList();
74
75 public PageAttributes() {
76 super();
77 }
78
79 public PageAttributes(RunData data) {
80 super(data);
81 }
82
83 public String addLink(String rel, String href) {
84 list.add(new Link(rel, null, href, null));
85 return "";
86 }
87
88 public String addLink(String rel, String type, String href) {
89 list.add(new Link(rel, type, href, null));
90 return "";
91 }
92
93 public String addLink(String rel, String type, String href, String title) {
94 list.add(new Link(rel, type, href, title));
95 return "";
96 }
97
98 public void init(Object data) {
99 super.init(data);
100 list.clear();
101 }
102
103 public List getLinks() {
104 return list;
105 }
106 }