1
2
3
4
5
6
7
8 package jp.sourceforge.jindolf.corelib;
9
10 import java.io.FileNotFoundException;
11 import java.net.MalformedURLException;
12 import java.net.URI;
13 import java.net.URISyntaxException;
14 import java.net.URL;
15 import java.util.Collections;
16 import java.util.HashMap;
17 import java.util.Map;
18
19
20
21
22
23 public final class XmlResource{
24
25
26 public static final String O_XSDBASE =
27 "http://jindolf.sourceforge.jp/xml/xsd/";
28
29 public static final String I_XSDBASE = "resources/xsd/";
30
31 public static final String I_XMLBASE = "resources/xml/";
32
33
34 public static final String O_RES_EXTXML =
35 "http://www.w3.org/2001/xml.xsd";
36
37 public static final String O_RES_CORETYPE =
38 O_XSDBASE + "coreType-090829.xsd";
39
40 public static final String O_RES_COREXML =
41 O_XSDBASE + "coreXML-090829.xsd";
42
43
44 public static final String I_RES_EXTXML =
45 I_XSDBASE + "ext/xml-2009-01.xsd";
46
47 public static final String I_RES_CORETYPE =
48 I_XSDBASE + "private/coreType-090829.xsd";
49
50 public static final String I_RES_COREXML =
51 I_XSDBASE + "private/coreXML-090829.xsd";
52
53
54 public static final String I_RES_LANDDEF =
55 I_XMLBASE + "landDefList.xml";
56
57 public static final String I_RES_AVATARDEF =
58 I_XMLBASE + "preDefAvatarList.xml";
59
60
61 public static final URI O_URI_EXTXML;
62
63 public static final URI O_URI_CORETYPE;
64
65 public static final URI O_URI_COREXML;
66
67
68 public static final URI I_URI_EXTXML;
69
70 public static final URI I_URI_CORETYPE;
71
72 public static final URI I_URI_COREXML;
73
74
75 public static final URI I_URI_LANDDEF;
76
77 public static final URI I_URI_AVATARDEF;
78
79
80
81 public static final URL I_URL_COREXML;
82
83 public static final URL I_URL_LANDDEF;
84
85 public static final URL I_URL_AVATARDEF;
86
87
88
89
90
91 public static final Map<URI, URI> RESOLVE_MAP;
92
93
94 private static final Class<?> THISCLASS = XmlResource.class;
95
96
97 static{
98 new XmlResource().hashCode();
99
100 O_URI_EXTXML = loadOuter(O_RES_EXTXML);
101 O_URI_CORETYPE = loadOuter(O_RES_CORETYPE);
102 O_URI_COREXML = loadOuter(O_RES_COREXML);
103
104 try{
105 I_URI_EXTXML = loadInner(I_RES_EXTXML);
106 I_URI_CORETYPE = loadInner(I_RES_CORETYPE);
107 I_URI_COREXML = loadInner(I_RES_COREXML);
108 I_URI_LANDDEF = loadInner(I_RES_LANDDEF);
109 I_URI_AVATARDEF = loadInner(I_RES_AVATARDEF);
110 }catch(FileNotFoundException | URISyntaxException e){
111 throw new ExceptionInInitializerError(e);
112 }
113
114 try{
115 I_URL_COREXML = I_URI_COREXML.toURL();
116 I_URL_LANDDEF = I_URI_LANDDEF.toURL();
117 I_URL_AVATARDEF = I_URI_AVATARDEF.toURL();
118 }catch(MalformedURLException e){
119 throw new ExceptionInInitializerError(e);
120 }
121
122 Map<URI, URI> map = new HashMap<>();
123 map.put(O_URI_EXTXML, I_URI_EXTXML);
124 map.put(O_URI_CORETYPE, I_URI_CORETYPE);
125 map.put(O_URI_COREXML, I_URI_COREXML);
126 RESOLVE_MAP = Collections.unmodifiableMap(map);
127 }
128
129
130
131
132
133 private XmlResource(){
134 super();
135 assert this.getClass().equals(THISCLASS);
136 return;
137 }
138
139
140
141
142
143
144
145
146
147 private static URI loadInner(String res)
148 throws FileNotFoundException,
149 URISyntaxException {
150 URL url = THISCLASS.getResource(res);
151 if(url == null) throw new FileNotFoundException(res);
152 URI result = url.toURI().normalize();
153 return result;
154 }
155
156
157
158
159
160
161 private static URI loadOuter(String http){
162 URI uri = URI.create(http).normalize();
163 return uri;
164 }
165
166 }