Class XMLSchemaService

java.lang.Object
edu.ucsb.nceas.metacat.shared.BaseService
edu.ucsb.nceas.metacat.service.XMLSchemaService

public class XMLSchemaService extends BaseService
  • Field Details

  • Method Details

    • getInstance

      public static XMLSchemaService getInstance()
      Get the single instance of XMLService.
      Returns:
      the single instance of XMLService
    • refreshable

      public boolean refreshable()
      Specified by:
      refreshable in class BaseService
    • doRefresh

      public void doRefresh() throws ServiceException
      refresh the persistant values in this service.
      Specified by:
      doRefresh in class BaseService
      Throws:
      ServiceException
    • stop

      public void stop() throws ServiceException
      Specified by:
      stop in class BaseService
      Throws:
      ServiceException
    • getRegisteredSchemaList

      public Vector<XMLSchema> 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

      public Vector<XMLNoNamespaceSchema> 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

      public String 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

      public String getNameSpaceAndLocation(String formatId)
      Get the all schema-location pairs registered for the formatId. The null will be returned, if we can find it.
      Parameters:
      formatId -
      Returns:
    • getNameSpaceList

      public Vector<String> 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

      public Vector<String> 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

      public static boolean areAllSchemasRegistered(Vector<XMLSchema> schemaList)
      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

      public static boolean isSchemaRegistered(XMLSchema xmlSchema)
      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

      public static boolean isNamespaceRegistered(String namespace)
      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 id
      namespace - 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

      public static Vector<XMLSchema> findSchemasInXML(Reader xml) throws IOException
      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

      public static String getSchemaFileNameFromUri(String uri)
      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

      public static String getBaseUrlFromSchemaURL(String url)
      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.