Package edu.ucsb.nceas.metacat.service
Class XMLSchemaService
java.lang.Object
edu.ucsb.nceas.metacat.shared.BaseService
edu.ucsb.nceas.metacat.service.XMLSchemaService
-
Field Summary
Fields inherited from class edu.ucsb.nceas.metacat.shared.BaseService
_serviceName
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
areAllSchemasRegistered
(Vector<XMLSchema> schemaList) Checks to see that all schemas are registered.void
refresh the persistant values in this service.static String
Returns the namespace for an xml document.findNamespaceAndSchemaLocalLocation
(String formatId, String namespace) Get the namespace-schemaLocation pairs string based on given formatId and namespace.findNoNamespaceSchemaLocalLocation
(String formatId, String noNamespaceSchemaLocation) Get the local (official) location for a no-namespace schema based on the given format id or no-name-space schema location uri.static String
Get the attribute value of the noNamespaceSchemaLcation of the given xmlfindSchemasInXML
(Reader xml) See if schemas have been specified in the xml:schemalocation attribute.static String
Get a base url from the schema url.static XMLSchemaService
Get the single instance of XMLService.getNameSpaceAndLocation
(String formatId) Get the all schema-location pairs registered for the formatId.Gets the name space and location string.Gets a list of name spaces.Get the list of format ids which are the non-xml metadata typeGets the registered schema list without the name space.Gets the registered schema list.static String
Get a schema file name from the schema uri.static boolean
isNamespaceRegistered
(String namespace) Test if the given namespace registered in Metacatstatic boolean
isSchemaRegistered
(XMLSchema xmlSchema) Returns true if the schema is registered.void
Populate the list of registered schemas.boolean
void
stop()
boolean
Report whether xml parsing is set to use full schema parsing.Methods inherited from class edu.ucsb.nceas.metacat.shared.BaseService
refresh
-
Field Details
-
NAMESPACEKEYWORD
- See Also:
-
SCHEMA_DIR
- See Also:
-
NONXML
-
-
Method Details
-
getInstance
Get the single instance of XMLService.- Returns:
- the single instance of XMLService
-
refreshable
public boolean refreshable()- Specified by:
refreshable
in classBaseService
-
doRefresh
refresh the persistant values in this service.- Specified by:
doRefresh
in classBaseService
- Throws:
ServiceException
-
stop
- Specified by:
stop
in classBaseService
- Throws:
ServiceException
-
getRegisteredSchemaList
Gets the registered schema list. This list holds schemas that exist in the xml_catalog table that also have associated files in the schema directory.- Returns:
- a list of XMLSchema objects holding registered schema information
-
getRegisteredNoNamespaceSchemaList
Gets the registered schema list without the name space. This list holds schemas without the name space that exist in the xml_catalog table that also have associated files in the schema directory.- Returns:
- a list of XMLNoNamespaceSchema objects
-
getNameSpaceAndLocationStringWithoutFormatId
Gets the name space and location string. This is a convenience method. The string will have space delimited namespaces and locations that are held in the registered schema list. This is the old way Metacat worked. Usually, we will call the method getNameSapceAndLocation(String formatId) first. If the method return null, we will call this method.- Returns:
- a string that holds space delimited registered namespaces and locations.
-
getNameSpaceAndLocation
Get the all schema-location pairs registered for the formatId. The null will be returned, if we can find it.- Parameters:
formatId
-- Returns:
-
getNameSpaceList
Gets a list of name spaces. This is a convenience method. The list will have all namespaces that are held in the registered schema list.- Returns:
- a list that holds registered namespaces.
-
getNonXMLMetadataFormatList
Get the list of format ids which are the non-xml metadata type- Returns:
- a list that holds the format ids for non-xml metadata type
-
useFullSchemaValidation
public boolean useFullSchemaValidation()Report whether xml parsing is set to use full schema parsing. If full schema parsing is true, new schemas will be validated before being entered into the database and file system.- Returns:
- true if the xml.useFullSchemaValidation property is set to true, false otherwise.
-
populateRegisteredSchemaList
public void populateRegisteredSchemaList()Populate the list of registered schemas. This reads all schemas in the xml_catalog table and then makes sure the schema actually exists and is readable on disk. -
areAllSchemasRegistered
Checks to see that all schemas are registered. If a single one in the list is not, this will return false.- Parameters:
schemaList
- a list of schemas as they appear in xml.- Returns:
- true if all schemas are registered.
-
isSchemaRegistered
Returns true if the schema is registered.- Parameters:
schema
- a single schema as it appears in xml- Returns:
- true if the schema is registered, false otherwise.
-
isNamespaceRegistered
Test if the given namespace registered in Metacat- Parameters:
namespace
- the namespace will be tested- Returns:
- true if the namespace is registered; otherwise false.
-
findNamespaceAndSchemaLocalLocation
public String findNamespaceAndSchemaLocalLocation(String formatId, String namespace) throws MetacatException Get the namespace-schemaLocation pairs string based on given formatId and namespace. The algorithm is: 1. Look up all pairs of namespace--schemalocation for the given formatId in the xml_catalog table. If we find it, return all of the pairs. 2. If we can't find anything on the step 1, look up the record for the given namespace. If we find it, return all of pairs namespace-location without formatid. 3. Return null if we can't find anything.- Parameters:
formatId
- the given format idnamespace
- the given namespace- Returns:
- the string of the namespace-schemaLocation pairs (separated by white spaces) The null will be returned, if we can't find one.
- Throws:
MetacatException
-
findNoNamespaceSchemaLocalLocation
public String findNoNamespaceSchemaLocalLocation(String formatId, String noNamespaceSchemaLocation) throws MetacatException Get the local (official) location for a no-namespace schema based on the given format id or no-name-space schema location uri. The format id has the higher priority 1. Compare the given format id with all registered no-namespace schema. If a match is found, return it. 2. If the step 1 return null, compare the given noNamespaceSchemaLocationuri.- Parameters:
formatId
-noNamespaceSchemaLocation
-- Returns:
- Throws:
MetacatException
-
findSchemasInXML
See if schemas have been specified in the xml:schemalocation attribute. If so, return a vector of the system ids.- Parameters:
xml
- the document we want to look in for schema location- Returns:
- a vector of XMLSchema objects, or an empty vector if none are found
- Throws:
IOException
-
findDocumentNamespace
public static String findDocumentNamespace(Reader xml) throws IOException, edu.ucsb.nceas.utilities.PropertyNotFoundException, SAXException Returns the namespace for an xml document.- Parameters:
xml
- the document to search- Returns:
- a string holding the namespace. Null will be returned if there is no namespace.
- Throws:
SAXException
edu.ucsb.nceas.utilities.PropertyNotFoundException
IOException
-
findNoNamespaceSchemaLocationAttr
public static String findNoNamespaceSchemaLocationAttr(Reader xml) throws edu.ucsb.nceas.utilities.PropertyNotFoundException, SAXException, IOException Get the attribute value of the noNamespaceSchemaLcation of the given xml- Parameters:
xml
- the xml obect needs to be searched- Returns:
- the attribute value of the noNamespaceSchemaLcation. The null will return if it can't be found.
- Throws:
SAXException
edu.ucsb.nceas.utilities.PropertyNotFoundException
IOException
-
getSchemaFileNameFromUri
Get a schema file name from the schema uri.- Parameters:
uri
- the uri from which to extract the file name- Returns:
- a string holding the file name
-
getBaseUrlFromSchemaURL
Get a base url from the schema url. If url=http://www.example.com/example.xsd, http://www.example.com/ will be returned.- Parameters:
uri
- the uri from which to extract the base url- Returns:
- a string holding the base url. null will be return if it is not url.
-