1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.html;
17
18 import org.apache.commons.lang3.StringUtils;
19 import org.kuali.common.util.Counter;
20
21
22
23
24 public class HtmlUtils {
25
26 public static String getIndentedContent(String content, Counter indent) {
27 return getIndent(indent) + content;
28 }
29
30 public static String getIndent(Counter indent) {
31 return StringUtils.repeat(" ", indent.getValue());
32 }
33
34
35
36
37 public static String getHref(String dest, String show, Counter indent) {
38 return getIndent(indent) + "<a href=\"" + dest + "\">" + show + "</a>";
39 }
40
41
42
43
44 public static String getImage(String image, Counter indent) {
45 return getIndent(indent) + "<img src=\"" + image + "\">";
46 }
47
48 public static String openTag(Tag tag, Counter indent) {
49 StringBuffer sb = new StringBuffer();
50 sb.append(getIndent(indent));
51 indent.increment();
52 sb.append("<" + tag.getName());
53 if (tag.getId() != null) {
54 sb.append(" id=\"" + tag.getId() + '"');
55 }
56 if (tag.getClazz() != null) {
57 sb.append(" class=\"" + tag.getClazz() + '"');
58 }
59 sb.append(">\n");
60 return sb.toString();
61 }
62
63 public static String closeTag(Tag tag, Counter indent) {
64 indent.decrement();
65 return getIndent(indent) + "</" + tag.getName() + ">\n";
66 }
67
68 public static String getTag(Tag tag, String content, Counter indent) {
69 StringBuffer sb = new StringBuffer();
70 sb.append(openTag(tag, indent));
71 sb.append(getIndent(indent));
72 sb.append(content);
73 sb.append("\n");
74 sb.append(closeTag(tag, indent));
75 return sb.toString();
76 }
77 }