1 package org
.argeo
.slc
.client
.ui
.dist
.utils
;
3 import java
.text
.DateFormat
;
4 import java
.text
.SimpleDateFormat
;
5 import java
.util
.Calendar
;
7 import javax
.jcr
.PropertyType
;
8 import javax
.jcr
.RepositoryException
;
9 import javax
.jcr
.Value
;
11 import org
.apache
.commons
.logging
.Log
;
12 import org
.apache
.commons
.logging
.LogFactory
;
13 import org
.argeo
.slc
.SlcException
;
14 import org
.argeo
.slc
.SlcNames
;
15 import org
.argeo
.slc
.SlcTypes
;
16 import org
.argeo
.slc
.client
.ui
.dist
.DistConstants
;
18 public class DistUiHelpers
implements DistConstants
, SlcTypes
, SlcNames
{
19 private final static Log log
= LogFactory
.getLog(DistUiHelpers
.class);
20 private final static DateFormat df
= new SimpleDateFormat(DATE_TIME_FORMAT
);
23 * Returns a user-friendly label for a given jcr property name. If the
24 * corresponding mapping is not found, the input String is returned. If
25 * input String is null "(No name)" is returned
27 public static String
getLabelJcrName(String jcrName
) {
28 return (String
) getLabelAndDefaultValueWidth(jcrName
)[0];
32 * Returns a label ( (String) object[0] )and default value width ( (int)
33 * object[1] ) for a given property name
35 public static Object
[] getLabelAndDefaultValueWidth(String propertyName
) {
37 if (propertyName
== null)
38 return new Object
[] { "(No name)", 60 };
41 if (propertyName
.equals(SLC_ARTIFACT
+ "." + SLC_ARTIFACT_ID
)
42 || propertyName
.equals(SLC_ARTIFACT_BASE
+ "."
44 || propertyName
.equals(SLC_ARTIFACT_VERSION_BASE
+ "."
46 || propertyName
.equals(SLC_ARTIFACT_ID
)) {
47 return new Object
[] { "Artifact ID", 200 };
49 else if (propertyName
.equals(SLC_ARTIFACT
+ "." + SLC_GROUP_ID
)
50 || propertyName
.equals(SLC_ARTIFACT_BASE
+ "." + SLC_GROUP_ID
)
51 || propertyName
.equals(SLC_ARTIFACT_VERSION_BASE
+ "."
52 + SLC_GROUP_ID
) || propertyName
.equals(SLC_GROUP_ID
)) {
53 return new Object
[] { "Group ID", 120 };
55 else if (propertyName
.equals(SLC_ARTIFACT
+ "." + SLC_ARTIFACT_VERSION
)
56 || propertyName
.equals(SLC_ARTIFACT_VERSION_BASE
+ "."
57 + SLC_ARTIFACT_VERSION
)
58 || propertyName
.equals(SLC_ARTIFACT_VERSION
)) {
59 return new Object
[] { "Version", 60 };
60 } else if (propertyName
.equals(SLC_ARTIFACT
+ "."
61 + SLC_ARTIFACT_CLASSIFIER
)
62 || propertyName
.equals(SLC_ARTIFACT_CLASSIFIER
)) {
63 return new Object
[] { "Classifier", 60 };
64 } else if (propertyName
.equals(SLC_ARTIFACT
+ "."
65 + SLC_ARTIFACT_EXTENSION
)
66 || propertyName
.equals(SLC_ARTIFACT_EXTENSION
)) {
67 return new Object
[] { "Type", 40 };
68 } else if (propertyName
.equals(SLC_BUNDLE_ARTIFACT
+ "."
70 || propertyName
.equals(SLC_SYMBOLIC_NAME
)) {
71 return new Object
[] { "Symbolic name", 180 };
72 } else if (propertyName
.equals(SLC_BUNDLE_ARTIFACT
+ "."
74 || propertyName
.equals(SLC_BUNDLE_VERSION
)) {
75 return new Object
[] { "Bundle version", 120 };
76 } else if (propertyName
77 .equals(SLC_BUNDLE_ARTIFACT
+ "." + SLC_MANIFEST
)
78 || propertyName
.equals(SLC_MANIFEST
)) {
79 return new Object
[] { "Manifest", 60 };
80 } // TODO remove hard coded strings
81 else if (propertyName
.equals("slc:Bundle-ManifestVersion")) {
82 return new Object
[] { "Bundle Manifest Version", 60 };
83 } else if (propertyName
.equals("slc:Manifest-Version")) {
84 return new Object
[] { "Manifest Version", 60 };
85 } else if (propertyName
.equals("slc:Bundle-Vendor")) {
86 return new Object
[] { "Bundle Vendor", 60 };
87 } else if (propertyName
.equals("slc:Bundle-SymbolicName")) {
88 return new Object
[] { "Bundle symbolic name", 60 };
89 } else if (propertyName
.equals("slc:Bundle-Name")) {
90 return new Object
[] { "Bundle name", 60 };
91 } else if (propertyName
.equals("slc:Bundle-DocURL")) {
92 return new Object
[] { "Doc URL", 120 };
93 } else if (propertyName
.equals("slc:Bundle-Licence")) {
94 return new Object
[] { "Bundle licence", 120 };
95 } else if (propertyName
.equals(SLC_ARTIFACT_VERSION_BASE
+ "."
97 return new Object
[] { "UUID", 0 };
99 if (log
.isTraceEnabled())
100 log
.trace("No Column label provider defined for property: ["
101 + propertyName
+ "]");
102 return new Object
[] { propertyName
, 60 };
106 public static String
formatValueAsString(Value value
) {
110 if (value
.getType() == PropertyType
.BINARY
)
111 strValue
= "<binary>";
112 else if (value
.getType() == PropertyType
.DATE
)
113 strValue
= df
.format(value
.getDate().getTime());
115 strValue
= value
.getString();
117 } catch (RepositoryException e
) {
118 throw new SlcException("unexpected error while formatting value",
123 public static String
formatAsString(Object value
) {
125 if (value
instanceof Calendar
)
126 strValue
= df
.format(((Calendar
) value
).getTime());
128 strValue
= value
.toString();