1 package org.argeo.connect.ui;
2
3 import java.text.DateFormat;
4 import java.text.SimpleDateFormat;
5
6 import javax.jcr.Node;
7 import javax.jcr.Property;
8 import javax.jcr.RepositoryException;
9 import javax.jcr.nodetype.NodeType;
10
11 import org.argeo.connect.ConnectConstants;
12 import org.argeo.connect.util.ConnectUtils;
13
14
15 public class ConnectUiSnippets {
16
17
18
19
20
21
22
23 public static String getRWTLink(String href, String value) {
24
25
26 return "<a href=\"" + href + "\" target=\"_rwt\">" + value + "</a>";
27 }
28
29
30
31
32
33 public static String getPhoneLink(String value) {
34 return getPhoneLink(value, value);
35 }
36
37
38
39
40
41
42
43
44
45
46 public static String getPhoneLink(String value, String label) {
47 StringBuilder builder = new StringBuilder();
48 builder.append("<a href=\"tel:");
49 builder.append(value).append("\" target=\"_blank\" >").append(label).append("</a>");
50 return builder.toString();
51 }
52
53
54
55
56
57 public static String getMailLink(String value) {
58 return getMailLink(value, value);
59 }
60
61
62
63
64
65
66
67
68
69
70 public static String getMailLink(String value, String label) {
71 StringBuilder builder = new StringBuilder();
72 value = ConnectUtils.replaceAmpersand(value);
73 builder.append("<a href=\"mailto:");
74 builder.append(value).append("\" >").append(label).append("</a>");
75 return builder.toString();
76 }
77
78
79
80
81
82 public static String getUrlLink(String value) {
83 return getUrlLink(value, value);
84 }
85
86
87
88
89
90 public static String getUrlLink(String value, String label) {
91 StringBuilder builder = new StringBuilder();
92 value = ConnectUtils.replaceAmpersand(value);
93 label = ConnectUtils.replaceAmpersand(label);
94 if (!(value.startsWith("http://") || value.startsWith("https://")))
95 value = "http://" + value;
96 builder.append("<a href=\"");
97 builder.append(value + "\" target=\"_blank\" >" + label + "</a>");
98 return builder.toString();
99 }
100
101 public static String getLastUpdateSnippet(Node entity) {
102 StringBuilder builder = new StringBuilder();
103
104
105
106 DateFormat df = new SimpleDateFormat(ConnectConstants.DEFAULT_DATE_TIME_FORMAT);
107
108 try {
109 if (entity.isNodeType(NodeType.MIX_LAST_MODIFIED)) {
110 builder.append("<i>").append("Last updated on ");
111 builder.append(df.format(entity.getProperty(Property.JCR_LAST_MODIFIED).getDate().getTime()));
112 builder.append(", by ");
113 builder.append(entity.getProperty(Property.JCR_LAST_MODIFIED_BY).getString());
114 builder.append(". </i>");
115 }
116 return builder.toString();
117 } catch (RepositoryException re) {
118 throw new RuntimeException("Cannot create organizations content", re);
119 }
120 }
121 }