]> git.argeo.org Git - gpl/argeo-suite.git/blob - SuiteContentNamespace.java
be4238f6fa77b2f8128c7d83c20defab5075e239
[gpl/argeo-suite.git] / SuiteContentNamespace.java
1 package org.argeo.app.core;
2
3 import java.net.MalformedURLException;
4 import java.net.URL;
5 import java.util.Objects;
6
7 import org.argeo.api.acr.spi.ContentNamespace;
8
9 public enum SuiteContentNamespace implements ContentNamespace {
10 //
11 // ARGEO
12 //
13 ENTITY("entity", "http://www.argeo.org/ns/entity", "/org/argeo/app/api/entity.xsd", null),
14 //
15 ARGEO_DBK("argeodbk", "http://www.argeo.org/ns/argeodbk", null, null),
16 //
17 // EXTERNAL
18 //
19 DOCBOOK5("dbk", "http://docbook.org/ns/docbook", "docbook.xsd", "http://docbook.org/xml/5.0.1/xsd/docbook.xsd"),
20 //
21 XML_EVENTS("ev", "http://www.w3.org/2001/xml-events", "xml-events-attribs-1.xsd",
22 "http://www.w3.org/MarkUp/SCHEMA/xml-events-attribs-1.xsd"),
23 //
24 XFORMS("xforms", "http://www.w3.org/2002/xforms", "XForms-11-Schema.xsd",
25 "https://www.w3.org/MarkUp/Forms/2007/XForms-11-Schema.xsd"),
26 //
27 XCARD("xcard", "urn:ietf:params:xml:ns:vcard-4.0", "xCard-4.0.xsd", null),
28 //
29 XSL_FO("fo", "http://www.w3.org/1999/XSL/Format", "fop.xsd",
30 "https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk/fop/src/foschema/fop.xsd"),
31 //
32 // XCAL_2_0("xcal", "urn:ietf:params:xml:ns:icalendar-2.0", "xCal-2.0.xsd", null),
33 //
34 XHTML("h", "http://www.w3.org/1999/xhtml", null, "https://www.w3.org/MarkUp/SCHEMA/xhtml11.xsd"),
35 //
36 // ODK
37 //
38 JR("jr", "http://openrosa.org/javarosa", null, null),
39 //
40 ORX("orx", "http://openrosa.org/xforms", null, null),
41 //
42 ORX_LIST("orxList", "http://openrosa.org/xforms/xformsList", null, null),
43 //
44 ORX_MANIFEST("orxManifest", "http://openrosa.org/xforms/xformsManifest", null, null),
45 //
46 ODK("odk", "http://www.opendatakit.org/xforms", null, null),
47 //
48 WGS84("geo", "http://www.w3.org/2003/01/geo/wgs84_pos#", null, null),
49 // Re-add XML in order to solve import issue with xlink
50 XML("xml", "http://www.w3.org/XML/1998/namespace", "xml.xsd", "http://www.w3.org/2001/xml.xsd"),
51 //
52
53 ;
54
55 private final static String RESOURCE_BASE = "/org/argeo/app/core/schemas/";
56
57 private String defaultPrefix;
58 private String namespace;
59 private URL resource;
60 private URL publicUrl;
61
62 SuiteContentNamespace(String defaultPrefix, String namespace, String resourceFileName, String publicUrl) {
63 Objects.requireNonNull(namespace);
64 this.defaultPrefix = defaultPrefix;
65 Objects.requireNonNull(namespace);
66 this.namespace = namespace;
67 if (resourceFileName != null) {
68 if (!resourceFileName.startsWith("/"))
69 resource = getClass().getResource(RESOURCE_BASE + resourceFileName);
70 else
71 resource = getClass().getResource(resourceFileName);
72 // Objects.requireNonNull(resource);
73
74 // try {
75 // // FIXME workaround when in nested OSGi frameworks
76 // // we should use class path, as before
77 // if (!resourceFileName.startsWith("platform:")) {
78 // resource = URI.create("platform:/plugin/org.argeo.app.core" + RESOURCE_BASE + resourceFileName)
79 // .toURL();
80 // } else {
81 // resource = URI.create(resourceFileName).toURL();
82 // }
83 // } catch (MalformedURLException e) {
84 // resource = null;
85 // System.getLogger(CmsContentNamespace.class.getName()).log(ERROR,
86 // "Cannot load " + resourceFileName + ": " + e.getMessage());
87 // // throw new IllegalArgumentException("Cannot convert " + resourceFileName + "
88 // // to URL");
89 // }
90 // Objects.requireNonNull(resource);
91 }
92 if (publicUrl != null)
93 try {
94 this.publicUrl = new URL(publicUrl);
95 } catch (MalformedURLException e) {
96 throw new IllegalArgumentException("Cannot interpret public URL", e);
97 }
98 }
99
100 @Override
101 public String getDefaultPrefix() {
102 return defaultPrefix;
103 }
104
105 @Override
106 public String getNamespaceURI() {
107 return namespace;
108 }
109
110 @Override
111 public URL getSchemaResource() {
112 return resource;
113 }
114
115 public URL getPublicUrl() {
116 return publicUrl;
117 }
118
119 }