edu.ucsb.nceas.metacat.service

## Class XMLSchemaService

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

-     public class XMLSchemaService
      extends BaseService

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `NAMESPACEKEYWORD`
    `static java.lang.String` | `SCHEMA_DIR`

    - ### Fields inherited from class edu.ucsb.nceas.metacat.shared.BaseService

      `_serviceName`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static boolean` | `areAllSchemasRegistered(java.util.Vector<XMLSchema> schemaList)` Checks to see that all schemas are registered.
    `void` | `doRefresh()` refresh the persistant values in this service.
    `static java.lang.String` | `findDocumentNamespace(java.io.StringReader xml)` Returns the namespace for an xml document.
    `java.lang.String` | `findNamespaceAndSchemaLocalLocation(java.lang.String formatId, java.lang.String namespace)` Get the namespace-schemaLocation pairs string based on given formatId and namespace.
    `java.lang.String` | `findNoNamespaceSchemaLocalLocation(java.lang.String formatId, java.lang.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 java.lang.String` | `findNoNamespaceSchemaLocationAttr(java.io.StringReader xml)` Get the attribute value of the noNamespaceSchemaLcation of the given xml
    `static java.util.Vector<XMLSchema>` | `findSchemasInXML(java.io.StringReader xml)` See if schemas have been specified in the xml:schemalocation attribute.
    `static java.lang.String` | `getBaseUrlFromSchemaURL(java.lang.String url)` Get a base url from the schema url.
    `static XMLSchemaService` | `getInstance()` Get the single instance of XMLService.
    `java.lang.String` | `getNameSpaceAndLocation(java.lang.String formatId)` Get the all schema-location pairs registered for the formatId.
    `java.lang.String` | `getNameSpaceAndLocationStringWithoutFormatId()` Gets the name space and location string.
    `java.util.Vector<java.lang.String>` | `getNameSpaceList()` Gets a list of name spaces.
    `java.util.Vector<XMLNoNamespaceSchema>` | `getRegisteredNoNamespaceSchemaList()` Gets the registered schema list without the name space.
    `java.util.Vector<XMLSchema>` | `getRegisteredSchemaList()` Gets the registered schema list.
    `static java.lang.String` | `getSchemaFileNameFromUri(java.lang.String uri)` Get a schema file name from the schema uri.
    `static boolean` | `isNamespaceRegistered(java.lang.String namespace)` Test if the given namespace registered in Metacat
    `static boolean` | `isSchemaRegistered(XMLSchema xmlSchema)` Returns true if the schema is registered.
    `void` | `populateRegisteredSchemaList()` Populate the list of registered schemas.
    `boolean` | `refreshable()`
    `void` | `stop()`
    `boolean` | `useFullSchemaValidation()` Report whether xml parsing is set to use full schema parsing.

    - ### Methods inherited from class edu.ucsb.nceas.metacat.shared.BaseService

      `refresh`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### NAMESPACEKEYWORD

          public static final java.lang.String NAMESPACEKEYWORD

      See Also:
        Constant Field Values

    - #### SCHEMA_DIR

          public static final java.lang.String SCHEMA_DIR

      See Also:
        Constant Field Values

  - ### Method Detail

    - #### 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 java.util.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 java.util.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 java.lang.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 java.lang.String getNameSpaceAndLocation(java.lang.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 java.util.Vector<java.lang.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.

    - #### 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(java.util.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(java.lang.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 java.lang.String findNamespaceAndSchemaLocalLocation(java.lang.String formatId,
                                                                      java.lang.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 java.lang.String findNoNamespaceSchemaLocalLocation(java.lang.String formatId,
                                                                     java.lang.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 java.util.Vector<XMLSchema> findSchemasInXML(java.io.StringReader xml)
                                                              throws java.io.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:
        `java.io.IOException`

    - #### findDocumentNamespace

          public static java.lang.String findDocumentNamespace(java.io.StringReader xml)
                                                        throws java.io.IOException,
                                                               edu.ucsb.nceas.utilities.PropertyNotFoundException,
                                                               org.xml.sax.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:
        `org.xml.sax.SAXException`
        `edu.ucsb.nceas.utilities.PropertyNotFoundException`
        `java.io.IOException`

    - #### findNoNamespaceSchemaLocationAttr

          public static java.lang.String findNoNamespaceSchemaLocationAttr(java.io.StringReader xml)
                                                                    throws edu.ucsb.nceas.utilities.PropertyNotFoundException,
                                                                           org.xml.sax.SAXException,
                                                                           java.io.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:
        `org.xml.sax.SAXException`
        `edu.ucsb.nceas.utilities.PropertyNotFoundException`
        `java.io.IOException`

    - #### getSchemaFileNameFromUri

          public static java.lang.String getSchemaFileNameFromUri(java.lang.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 java.lang.String getBaseUrlFromSchemaURL(java.lang.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.

Copyright © 2020 Regents of the University of California. All Rights Reserved.