Revision 9583
Added by Jing Tao about 8 years ago
XMLSchemaService.java | ||
---|---|---|
37 | 37 |
import java.sql.PreparedStatement; |
38 | 38 |
import java.sql.ResultSet; |
39 | 39 |
import java.sql.SQLException; |
40 |
import java.util.Hashtable; |
|
40 | 41 |
import java.util.Vector; |
41 | 42 |
import java.util.regex.Matcher; |
42 | 43 |
import java.util.regex.Pattern; |
... | ... | |
77 | 78 |
private static Vector<String> nameSpaceList = new Vector<String>(); |
78 | 79 |
|
79 | 80 |
// a convenience string that holds all name spaces and locations in a space |
80 |
// delimited format |
|
81 |
private static String nameSpaceAndLocationString = ""; |
|
81 |
// delimited format. Those items don't have a format id. This is the old way we handle the schema location
|
|
82 |
private static String nameSpaceAndLocationStringWithoutFormatId = "";
|
|
82 | 83 |
|
84 |
//this hash table is design for schema variants. Two schemas have the same name space, |
|
85 |
//but they have different content (location). So we different format id to |
|
86 |
//distinguish them. The key of the hash table is the format id, the values is all the namespace schema location |
|
87 |
//delimited string for this format id. |
|
88 |
private static Hashtable<String, String> formatId_NamespaceLocationHash = new Hashtable<String, String>(); |
|
83 | 89 |
/** |
84 | 90 |
* private constructor since this is a singleton |
85 | 91 |
*/ |
... | ... | |
142 | 148 |
/** |
143 | 149 |
* Gets the name space and location string. This is a convenience method. |
144 | 150 |
* The string will have space delimited namespaces and locations that are |
145 |
* held in the registered schema list. |
|
151 |
* held in the registered schema list. This is the old way Metacat worked. |
|
152 |
* Usually, we will call the method getNameSapceAndLocation(String formatId) first. |
|
153 |
* If the method return null, we will call this method. |
|
146 | 154 |
* |
147 | 155 |
* @return a string that holds space delimited registered namespaces and |
148 | 156 |
* locations. |
149 | 157 |
*/ |
150 |
public String getNameSpaceAndLocationString() { |
|
151 |
return nameSpaceAndLocationString; |
|
158 |
public String getNameSpaceAndLocationStringWithoutFormatId() {
|
|
159 |
return nameSpaceAndLocationStringWithoutFormatId;
|
|
152 | 160 |
} |
153 | 161 |
|
162 |
|
|
154 | 163 |
/** |
164 |
* Get the all schema-location pairs registered for the formatId. |
|
165 |
* The null will be returned, if we can find it. |
|
166 |
* @param formatId |
|
167 |
* @return |
|
168 |
*/ |
|
169 |
public String getNameSpaceAndLocation(String formatId) { |
|
170 |
if(formatId == null) { |
|
171 |
return null; |
|
172 |
} else { |
|
173 |
return formatId_NamespaceLocationHash.get(formatId); |
|
174 |
} |
|
175 |
} |
|
176 |
|
|
177 |
/** |
|
155 | 178 |
* Gets a list of name spaces. This is a convenience method. The list will |
156 | 179 |
* have all namespaces that are held in the registered schema list. |
157 | 180 |
* |
... | ... | |
196 | 219 |
registeredSchemaList = new Vector<XMLSchema>(); |
197 | 220 |
|
198 | 221 |
// get the system id from the xml_catalog table for all schemas. |
199 |
String sql = "SELECT public_id, system_id FROM xml_catalog where " |
|
222 |
String sql = "SELECT public_id, system_id, format_id FROM xml_catalog where "
|
|
200 | 223 |
+ "entry_type ='" + DocumentImpl.SCHEMA + "'"; |
201 | 224 |
try { |
202 | 225 |
// check out DBConnection |
... | ... | |
213 | 236 |
while (resultSet.next()) { |
214 | 237 |
String fileNamespace = resultSet.getString(1); |
215 | 238 |
String fileLocation = resultSet.getString(2); |
216 |
logMetacat.debug("XMLService.populateRegisteredSchemaList - Registering schema: " + fileNamespace + " " + fileLocation); |
|
217 |
XMLSchema xmlSchema = new XMLSchema(fileNamespace); |
|
239 |
String formatId = resultSet.getString(3); |
|
240 |
logMetacat.debug("XMLService.populateRegisteredSchemaList - Registering schema: " + fileNamespace + " " + fileLocation+ " and format id "+formatId); |
|
241 |
XMLSchema xmlSchema = new XMLSchema(fileNamespace, fileLocation, formatId); |
|
218 | 242 |
if(fileLocation.startsWith("http://") || fileLocation.startsWith("https://")) |
219 | 243 |
{ |
220 | 244 |
//System.out.println("processing an http schemal location"); |
... | ... | |
310 | 334 |
* in the registered schema list. |
311 | 335 |
*/ |
312 | 336 |
private static void createRegisteredNameSpaceAndLocationString() { |
313 |
boolean firstRow = true; |
|
314 |
nameSpaceAndLocationString = ""; |
|
337 |
boolean firstRowWithoutFormatid = true; |
|
338 |
boolean firstRowWithFormatid = true; |
|
339 |
nameSpaceAndLocationStringWithoutFormatId = ""; |
|
315 | 340 |
|
316 | 341 |
for (XMLSchema xmlSchema : registeredSchemaList) { |
317 |
if (!firstRow) { |
|
318 |
nameSpaceAndLocationString += " "; |
|
319 |
} |
|
320 |
nameSpaceAndLocationString += xmlSchema.getFileNamespace() + " " |
|
321 |
+ xmlSchema.getLocalFileUri(); |
|
322 |
firstRow = false; |
|
342 |
String formatId = xmlSchema.getFormatId(); |
|
343 |
if( formatId == null ||formatId.trim().equals("")) { |
|
344 |
//this is to handle the old way - no schema variants |
|
345 |
if (!firstRowWithoutFormatid) { |
|
346 |
nameSpaceAndLocationStringWithoutFormatId += " "; |
|
347 |
} |
|
348 |
nameSpaceAndLocationStringWithoutFormatId += xmlSchema.getFileNamespace() + " " |
|
349 |
+ xmlSchema.getLocalFileUri(); |
|
350 |
firstRowWithoutFormatid = false; |
|
351 |
} else { |
|
352 |
//it has a format id on the xml_catalog table. It is a variant. |
|
353 |
if(!formatId_NamespaceLocationHash.containsKey(xmlSchema.getFormatId())) { |
|
354 |
//the hash table hasn't stored the value. So put it on the hash. |
|
355 |
formatId_NamespaceLocationHash.put(formatId, xmlSchema.getFileNamespace() + " " |
|
356 |
+ xmlSchema.getLocalFileUri()); |
|
357 |
} else { |
|
358 |
//the hash table already has it. We will attache the new pair to the exist value |
|
359 |
String value = formatId_NamespaceLocationHash.get(formatId); |
|
360 |
value += " "+ xmlSchema.getFileNamespace() + " " |
|
361 |
+ xmlSchema.getLocalFileUri(); |
|
362 |
formatId_NamespaceLocationHash.put(formatId, value); |
|
363 |
} |
|
364 |
} |
|
365 |
|
|
323 | 366 |
} |
324 | 367 |
} |
325 | 368 |
|
... | ... | |
419 | 462 |
+ targetLine |
420 | 463 |
+ ". There should be an even number of uri/files in location."); |
421 | 464 |
} |
465 |
String formatId = null; |
|
422 | 466 |
XMLSchema xmlSchema = new XMLSchema(parsedUri.get(j), parsedUri |
423 |
.get(j + 1)); |
|
467 |
.get(j + 1), formatId);
|
|
424 | 468 |
schemaList.add(xmlSchema); |
425 | 469 |
} |
426 | 470 |
i = matcher.end(); |
Also available in: Unified diff
If a format id in the system metadata is registered in the xml_catalog table, we will use the schema location for the format id to validate the xml instance;
otherwise, we will use our previous way.