2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.slc
.client
.ui
.dist
.utils
;
18 import java
.text
.DateFormat
;
19 import java
.text
.SimpleDateFormat
;
20 import java
.util
.Calendar
;
22 import javax
.jcr
.PropertyType
;
23 import javax
.jcr
.RepositoryException
;
24 import javax
.jcr
.Value
;
26 import org
.apache
.commons
.logging
.Log
;
27 import org
.apache
.commons
.logging
.LogFactory
;
28 import org
.argeo
.ArgeoException
;
29 import org
.argeo
.slc
.client
.ui
.dist
.DistConstants
;
30 import org
.argeo
.slc
.jcr
.SlcNames
;
31 import org
.argeo
.slc
.jcr
.SlcTypes
;
33 public class DistUiHelpers
implements DistConstants
, SlcTypes
, SlcNames
{
34 private final static Log log
= LogFactory
.getLog(DistUiHelpers
.class);
35 private final static DateFormat df
= new SimpleDateFormat(DATE_TIME_FORMAT
);
38 * Returns a user-friendly label for a given jcr property name. If the
39 * corresponding mapping is not found, the input String is returned. If
40 * input String is null "(No name)" is returned
42 public static String
getLabelJcrName(String jcrName
) {
43 return (String
) getLabelAndDefaultValueWidth(jcrName
)[0];
47 * Returns a label ( (String) object[0] )and default value width ( (int)
48 * object[1] ) for a given property name
50 public static Object
[] getLabelAndDefaultValueWidth(String propertyName
) {
52 if (propertyName
== null)
53 return new Object
[] { "(No name)", 60 };
56 if (propertyName
.equals(SLC_ARTIFACT
+ "." + SLC_ARTIFACT_ID
)
57 || propertyName
.equals(SLC_ARTIFACT_BASE
+ "."
59 || propertyName
.equals(SLC_ARTIFACT_VERSION_BASE
+ "."
61 || propertyName
.equals(SLC_ARTIFACT_ID
)) {
62 return new Object
[] { "Artifact ID", 200 };
64 else if (propertyName
.equals(SLC_ARTIFACT
+ "." + SLC_GROUP_ID
)
65 || propertyName
.equals(SLC_ARTIFACT_BASE
+ "." + SLC_GROUP_ID
)
66 || propertyName
.equals(SLC_ARTIFACT_VERSION_BASE
+ "."
67 + SLC_GROUP_ID
) || propertyName
.equals(SLC_GROUP_ID
)) {
68 return new Object
[] { "Group ID", 120 };
70 else if (propertyName
.equals(SLC_ARTIFACT
+ "." + SLC_ARTIFACT_VERSION
)
71 || propertyName
.equals(SLC_ARTIFACT_VERSION_BASE
+ "."
72 + SLC_ARTIFACT_VERSION
)
73 || propertyName
.equals(SLC_ARTIFACT_VERSION
)) {
74 return new Object
[] { "Version", 60 };
75 } else if (propertyName
.equals(SLC_ARTIFACT
+ "."
76 + SLC_ARTIFACT_CLASSIFIER
)
77 || propertyName
.equals(SLC_ARTIFACT_CLASSIFIER
)) {
78 return new Object
[] { "Classifier", 60 };
79 } else if (propertyName
.equals(SLC_ARTIFACT
+ "."
80 + SLC_ARTIFACT_EXTENSION
)
81 || propertyName
.equals(SLC_ARTIFACT_EXTENSION
)) {
82 return new Object
[] { "Type", 40 };
83 } else if (propertyName
.equals(SLC_BUNDLE_ARTIFACT
+ "."
85 || propertyName
.equals(SLC_SYMBOLIC_NAME
)) {
86 return new Object
[] { "Symbolic name", 180 };
87 } else if (propertyName
.equals(SLC_BUNDLE_ARTIFACT
+ "."
89 || propertyName
.equals(SLC_BUNDLE_VERSION
)) {
90 return new Object
[] { "Bundle version", 120 };
91 } else if (propertyName
92 .equals(SLC_BUNDLE_ARTIFACT
+ "." + SLC_MANIFEST
)
93 || propertyName
.equals(SLC_MANIFEST
)) {
94 return new Object
[] { "Manifest", 60 };
95 } // TODO remove hard coded strings
96 else if (propertyName
.equals("slc:Bundle-ManifestVersion")) {
97 return new Object
[] { "Bundle Manifest Version", 60 };
98 } else if (propertyName
.equals("slc:Manifest-Version")) {
99 return new Object
[] { "Manifest Version", 60 };
100 } else if (propertyName
.equals("slc:Bundle-Vendor")) {
101 return new Object
[] { "Bundle Vendor", 60 };
102 } else if (propertyName
.equals("slc:Bundle-SymbolicName")) {
103 return new Object
[] { "Bundle symbolic name", 60 };
104 } else if (propertyName
.equals("slc:Bundle-Name")) {
105 return new Object
[] { "Bundle name", 60 };
106 } else if (propertyName
.equals("slc:Bundle-DocURL")) {
107 return new Object
[] { "Doc URL", 120 };
108 } else if (propertyName
.equals("slc:Bundle-Licence")) {
109 return new Object
[] { "Bundle licence", 120 };
110 } else if (propertyName
.equals(SLC_ARTIFACT_VERSION_BASE
+ "."
112 return new Object
[] { "UUID", 0 };
114 if (log
.isTraceEnabled())
115 log
.trace("No Column label provider defined for property: ["
116 + propertyName
+ "]");
117 return new Object
[] { propertyName
, 60 };
121 public static String
formatValueAsString(Value value
) {
125 if (value
.getType() == PropertyType
.BINARY
)
126 strValue
= "<binary>";
127 else if (value
.getType() == PropertyType
.DATE
)
128 strValue
= df
.format(value
.getDate().getTime());
130 strValue
= value
.getString();
132 } catch (RepositoryException e
) {
133 throw new ArgeoException("unexpected error while formatting value",
138 public static String
formatAsString(Object value
) {
140 if (value
instanceof Calendar
)
141 strValue
= df
.format(((Calendar
) value
).getTime());
143 strValue
= value
.toString();