+ // TODO this must be moved to a better place once the standard has been
+ // defined
+ // Enable licence encoding in a single JCR Value
+ private final static String LICENSE_SEPARATOR = ";";
+ // The human readable name of the licence
+ private final static String LICENSE_NAME = "description";
+ // A link on the internet with some more info on this licence
+ private final static String LICENSE_LINK = "link";
+
+ private License parseLicenseString(String licenseStr) {
+ String uri = null, name = null, link = null, text = null;
+ // TODO enhance this
+ String[] values = licenseStr.split(LICENSE_SEPARATOR);
+ for (String value : values) {
+ if (value.startsWith(LICENSE_NAME))
+ name = value.substring(LICENSE_NAME.length() + 1); // +1 for the
+ // '='
+ else if (value.startsWith(LICENSE_LINK))
+ link = value.substring(LICENSE_LINK.length() + 1);
+ else if (uri == null)
+ uri = value;
+ // TODO manage text
+ }
+ return new SimpleLicense(name, uri, link, text);
+ }
+
+ class SimpleLicense implements License {
+ private final String name;
+ private final String uri;
+ private final String link;
+ private final String text;
+
+ public SimpleLicense(String name, String uri, String link, String text) {
+ if (uri == null)
+ throw new SlcException(
+ "Cannot manage a licence with a null URI ");
+ this.uri = uri;
+
+ this.name = name;
+ this.link = link;
+ this.text = text;
+ }
+
+ public String getUri() {
+ return uri;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public String getName() {
+ return name != null ? name : uri;
+ }
+
+ public String getLink() {
+ return link;
+ }
+ }
+