]> git.argeo.org Git - lgpl/argeo-commons.git/blob - CmsContentNamespace.java
fe334cb5b9d5430aa7c28fddc6e438b2c120cc65
[lgpl/argeo-commons.git] / CmsContentNamespace.java
1 package org.argeo.cms.acr;
2
3 import java.net.MalformedURLException;
4 import java.net.URI;
5 import java.net.URL;
6 import java.util.Objects;
7
8 import org.argeo.api.acr.ArgeoNamespace;
9 import org.argeo.api.acr.spi.ContentNamespace;
10
11 /** Content namespaces supported by CMS. */
12 public enum CmsContentNamespace implements ContentNamespace {
13 //
14 // ARGEO
15 //
16 CR(ArgeoNamespace.CR_DEFAULT_PREFIX, ArgeoNamespace.CR_NAMESPACE_URI, "cr.xsd", null),
17 //
18 SLC("slc", "http://www.argeo.org/ns/slc", null, null),
19 //
20 ARGEO("argeo", "http://www.argeo.org/ns/argeo", null, null),
21 //
22 // EXTERNAL
23 //
24 XSD("xs", "http://www.w3.org/2001/XMLSchema", "XMLSchema.xsd", "http://www.w3.org/2001/XMLSchema.xsd"),
25 //
26 XML("xml", "http://www.w3.org/XML/1998/namespace", "xml.xsd", "http://www.w3.org/2001/xml.xsd"),
27 //
28 XLINK("xlink", "http://www.w3.org/1999/xlink", "xlink.xsd", "https://www.w3.org/1999/xlink.xsd"),
29 //
30 WEBDAV("D", "DAV:", null, "https://raw.githubusercontent.com/lookfirst/sardine/master/webdav.xsd"),
31 //
32 XSLT("xsl", "http://www.w3.org/1999/XSL/Transform", "schema-for-xslt20.xsd",
33 "https://www.w3.org/2007/schema-for-xslt20.xsd"),
34 //
35 SVG("svg", "http://www.w3.org/2000/svg", "SVG.xsd",
36 "https://raw.githubusercontent.com/oreillymedia/HTMLBook/master/schema/svg/SVG.xsd"),
37 //
38 DSML("dsml", "urn:oasis:names:tc:DSML:2:0:core", "DSMLv2.xsd",
39 "https://www.oasis-open.org/committees/dsml/docs/DSMLv2.xsd"),
40 //
41 ;
42
43 private final static String RESOURCE_BASE = "/org/argeo/cms/acr/schemas/";
44
45 private String defaultPrefix;
46 private String namespace;
47 private URL resource;
48 private URL publicUrl;
49
50 CmsContentNamespace(String defaultPrefix, String namespace, String resourceFileName, String publicUrl) {
51 Objects.requireNonNull(namespace);
52 this.defaultPrefix = defaultPrefix;
53 Objects.requireNonNull(namespace);
54 this.namespace = namespace;
55 if (resourceFileName != null) {
56 // resource = getClass().getResource(RESOURCE_BASE + resourceFileName);
57 try {
58 // FIXME workaround when in nested OSGi frameworks
59 resource = URI.create("platform:/plugin/org.argeo.cms" + RESOURCE_BASE + resourceFileName).toURL();
60 } catch (MalformedURLException e) {
61 throw new IllegalArgumentException("Cannot convert " + resourceFileName + " to URL");
62 }
63 Objects.requireNonNull(resource);
64 }
65 if (publicUrl != null)
66 try {
67 this.publicUrl = new URL(publicUrl);
68 } catch (MalformedURLException e) {
69 throw new IllegalArgumentException("Cannot interpret public URL", e);
70 }
71 }
72
73 @Override
74 public String getDefaultPrefix() {
75 return defaultPrefix;
76 }
77
78 @Override
79 public String getNamespaceURI() {
80 return namespace;
81 }
82
83 @Override
84 public URL getSchemaResource() {
85 return resource;
86 }
87
88 public URL getPublicUrl() {
89 return publicUrl;
90 }
91
92 }