Top Description Inners Fields Constructors Methods
liquibase.parser.core.xml

public Class LiquibaseEntityResolver

extends Object
implements EntityResolver2
Class Inheritance
All Implemented Interfaces
org.xml.sax.ext.EntityResolver2, org.xml.sax.EntityResolver
Imports
liquibase.GlobalConfiguration, .Scope, liquibase.logging.Logger, liquibase.resource.ClassLoaderResourceAccessor, .CompositeResourceAccessor, .InputStreamList, .Resource, .ResourceAccessor, liquibase.util.LiquibaseUtil, org.xml.sax.InputSource, .SAXException, org.xml.sax.ext.EntityResolver2, java.io.IOException, .InputStream, java.net.URL, .URLClassLoader, java.util.Arrays, .List, java.util.regex.Matcher, .Pattern

Finds the Liquibase schema from the classpath rather than fetching it over the Internet. Also resolve external entities using a resourceAccessor if it's provided

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
LiquibaseEntityResolver.CombinedClassLoader

Only currently implementing getResource() since that's the only method used by our logic

Field Summary

Modifier and TypeField and Description
private static boolean
hasWarnedAboutMismatchedXsdVersion

The warning message should only be printed once.

private boolean
private static final Pattern
private static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public InputSource
getExternalSubset(String
Identifies the document root element. This name comes from a DOCTYPE declaration (where available) or from the actual root element.
name
,
String
The document's base URI, serving as an additional hint for selecting the external subset. This is always an absolute URI, unless it is null because the XMLReader was given an InputSource without one.
baseURI
)

Implements org.xml.sax.ext.EntityResolver2.getExternalSubset.

Allows applications to provide an external subset for documents that don't explicitly define one.

protected ClassLoader
getSearchClassloader()

Return the classloader used to look for XSD files in the classpath.

public InputSource
resolveEntity(String
Identifies the external entity being resolved. Either "[dtd]" for the external subset, or a name starting with "%" to indicate a parameter entity, or else the name of a general entity. This is never null when invoked by a SAX2 parser.
name
,
String
The public identifier of the external entity being referenced (normalized as required by the XML specification), or null if none was supplied.
publicId
,
String
The URI with respect to which relative systemIDs are interpreted. This is always an absolute URI, unless it is null (likely because the XMLReader was given an InputSource without one). This URI is defined by the XML specification to be the one associated with the "<" starting the relevant declaration.
baseURI
,
String
The system identifier of the external entity being referenced; either a relative or absolute URI. This is never null when invoked by a SAX2 parser; only declared entities, and any external subset, are resolved by such parsers.
systemId
)

Implements org.xml.sax.ext.EntityResolver2.resolveEntity.

Allows applications to map references to external entities into input sources, or tell the parser it should use conventional URI resolution.

public InputSource
resolveEntity(String
The public identifier of the external entity being referenced, or null if none was supplied.
publicId
,
String
The system identifier of the external entity being referenced.
systemId
)

Implements org.xml.sax.EntityResolver.resolveEntity.

Allow the application to resolve external entities.

public void
setShouldWarnOnMismatchedXsdVersion(boolean shouldWarnOnMismatchedXsdVersion)

When set to true, a warning will be printed to the console if the XSD version used does not match the version of Liquibase.

private void
warnForMismatchedXsdVersion(String systemId)

Print a warning message to the logs and UI if the build version does not match the XSD version.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

hasWarnedAboutMismatchedXsdVersionback to summary
private static boolean hasWarnedAboutMismatchedXsdVersion

The warning message should only be printed once.

shouldWarnOnMismatchedXsdVersionback to summary
private boolean shouldWarnOnMismatchedXsdVersion
XSD_VERSION_PATTERNback to summary
private static final Pattern XSD_VERSION_PATTERN
XSD_VERSION_REGEXback to summary
private static final String XSD_VERSION_REGEX

Constructor Detail

LiquibaseEntityResolverback to summary
public LiquibaseEntityResolver()

Method Detail

getExternalSubsetback to summary
public InputSource getExternalSubset(String name, String baseURI) throws SAXException, IOException

Implements org.xml.sax.ext.EntityResolver2.getExternalSubset.

Doc from org.xml.sax.ext.EntityResolver2.getExternalSubset.

Allows applications to provide an external subset for documents that don't explicitly define one. Documents with DOCTYPE declarations that omit an external subset can thus augment the declarations available for validation, entity processing, and attribute processing (normalization, defaulting, and reporting types including ID). This augmentation is reported through the startDTD() method as if the document text had originally included the external subset; this callback is made before any internal subset data or errors are reported.

This method can also be used with documents that have no DOCTYPE declaration. When the root element is encountered, but no DOCTYPE declaration has been seen, this method is invoked. If it returns a value for the external subset, that root element is declared to be the root element, giving the effect of splicing a DOCTYPE declaration at the end the prolog of a document that could not otherwise be valid. The sequence of parser callbacks in that case logically resembles this:

... comments and PIs from the prolog (as usual)
startDTD ("rootName", source.getPublicId (), source.getSystemId ());
startEntity ("[dtd]");
... declarations, comments, and PIs from the external subset
endEntity ("[dtd]");
endDTD ();
... then the rest of the document (as usual)
startElement (..., "rootName", ...);

Note that the InputSource gets no further resolution. Implementations of this method may wish to invoke resolveEntity() to gain benefits such as use of local caches of DTD entities. Also, this method will never be used by a (non-validating) processor that is not including external parameter entities.

Uses for this method include facilitating data validation when interoperating with XML processors that would always require undesirable network accesses for external entities, or which for other reasons adopt a "no DTDs" policy. Non-validation motives include forcing documents to include DTDs so that attributes are handled consistently. For example, an XPath processor needs to know which attributes have type "ID" before it can process a widely used type of reference.

Warning

Returning an external subset modifies the input document. By providing definitions for general entities, it can make a malformed document appear to be well formed.

Parameters
name:String

Identifies the document root element. This name comes from a DOCTYPE declaration (where available) or from the actual root element.

baseURI:String

The document's base URI, serving as an additional hint for selecting the external subset. This is always an absolute URI, unless it is null because the XMLReader was given an InputSource without one.

Returns:InputSource

An InputSource object describing the new external subset to be used by the parser, or null to indicate that no external subset is provided.

Annotations
@Override
Exceptions
SAXException:
Any SAX exception, possibly wrapping another exception.
IOException:
Probably indicating a failure to create a new InputStream or Reader, or an illegal URL.
getSearchClassloaderback to summary
protected ClassLoader getSearchClassloader()

Return the classloader used to look for XSD files in the classpath.

resolveEntityback to summary
public InputSource resolveEntity(String name, String publicId, String baseURI, String systemId) throws SAXException, IOException

Implements org.xml.sax.ext.EntityResolver2.resolveEntity.

Doc from org.xml.sax.ext.EntityResolver2.resolveEntity.

Allows applications to map references to external entities into input sources, or tell the parser it should use conventional URI resolution. This method is only called for external entities which have been properly declared. This method provides more flexibility than the EntityResolver interface, supporting implementations of more complex catalogue schemes such as the one defined by the OASIS XML Catalogs specification.

Parsers configured to use this resolver method will call it to determine the input source to use for any external entity being included because of a reference in the XML text. That excludes the document entity, and any external entity returned by getExternalSubset(). When a (non-validating) processor is configured not to include a class of entities (parameter or general) through use of feature flags, this method is not invoked for such entities.

Note that the entity naming scheme used here is the same one used in the LexicalHandler, or in the ContentHandler.skippedEntity() method.

Parameters
name:String

Identifies the external entity being resolved. Either "[dtd]" for the external subset, or a name starting with "%" to indicate a parameter entity, or else the name of a general entity. This is never null when invoked by a SAX2 parser.

publicId:String

The public identifier of the external entity being referenced (normalized as required by the XML specification), or null if none was supplied.

baseURI:String

The URI with respect to which relative systemIDs are interpreted. This is always an absolute URI, unless it is null (likely because the XMLReader was given an InputSource without one). This URI is defined by the XML specification to be the one associated with the "<" starting the relevant declaration.

systemId:String

The system identifier of the external entity being referenced; either a relative or absolute URI. This is never null when invoked by a SAX2 parser; only declared entities, and any external subset, are resolved by such parsers.

Returns:InputSource

An InputSource object describing the new input source to be used by the parser. Returning null directs the parser to resolve the system ID against the base URI and open a connection to resulting URI.

Annotations
@Override
@SuppressWarnings:squid:S2095
Exceptions
SAXException:
Any SAX exception, possibly wrapping another exception.
IOException:
Probably indicating a failure to create a new InputStream or Reader, or an illegal URL.
resolveEntityback to summary
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException

Implements org.xml.sax.EntityResolver.resolveEntity.

Doc from org.xml.sax.EntityResolver.resolveEntity.

Allow the application to resolve external entities.

The parser will call this method before opening any external entity except the top-level document entity. Such entities include the external DTD subset and external parameter entities referenced within the DTD (in either case, only if the parser reads external parameter entities), and external general entities referenced within the document element (if the parser reads external general entities). The application may request that the parser locate the entity itself, that it use an alternative URI, or that it use data provided by the application (as a character or byte input stream).

Application writers can use this method to redirect external system identifiers to secure and/or local URIs, to look up public identifiers in a catalogue, or to read an entity from a database or other input source (including, for example, a dialog box). Neither XML nor SAX specifies a preferred policy for using public or system IDs to resolve resources. However, SAX specifies how to interpret any InputSource returned by this method, and that if none is returned, then the system ID will be dereferenced as a URL.

If the system identifier is a URL, the SAX parser must resolve it fully before reporting it to the application.

Parameters
publicId:String

The public identifier of the external entity being referenced, or null if none was supplied.

systemId:String

The system identifier of the external entity being referenced.

Returns:InputSource

An InputSource object describing the new input source, or null to request that the parser open a regular URI connection to the system identifier.

Annotations
@Override
Exceptions
SAXException:
Any SAX exception, possibly wrapping another exception.
IOException:
A Java-specific IO exception, possibly the result of creating a new InputStream or Reader for the InputSource.
setShouldWarnOnMismatchedXsdVersionback to summary
public void setShouldWarnOnMismatchedXsdVersion(boolean shouldWarnOnMismatchedXsdVersion)

When set to true, a warning will be printed to the console if the XSD version used does not match the version of Liquibase. If "latest" is used as the XSD version, no warning is printed.

warnForMismatchedXsdVersionback to summary
private void warnForMismatchedXsdVersion(String systemId)

Print a warning message to the logs and UI if the build version does not match the XSD version. This is a best effort check, this method will never throw an exception.

liquibase.parser.core.xml back to summary

private Class LiquibaseEntityResolver.CombinedClassLoader

extends ClassLoader
Class Inheritance

Only currently implementing getResource() since that's the only method used by our logic

Field Summary

Modifier and TypeField and Description
private final List<ClassLoader>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public URL
getResource(String
The resource name
name
)

Overrides java.lang.ClassLoader.getResource.

Finds the resource with the given name.

Inherited from java.lang.ClassLoader:
clearAssertionStatusdefineClassdefineClassdefineClassdefineClassdefinePackagefindClassfindClassfindLibraryfindLoadedClassfindResourcefindResourcefindResourcesfindSystemClassgetClassLoadingLockgetDefinedPackagegetDefinedPackagesgetNamegetPackagegetPackagesgetParentgetPlatformClassLoadergetResourceAsStreamgetResourcesgetSystemClassLoadergetSystemResourcegetSystemResourceAsStreamgetSystemResourcesgetUnnamedModuleisRegisteredAsParallelCapableloadClassloadClassregisterAsParallelCapableresolveClassresourcessetClassAssertionStatussetDefaultAssertionStatussetPackageAssertionStatussetSigners

Field Detail

classLoadersback to summary
private final List<ClassLoader> classLoaders

Constructor Detail

CombinedClassLoaderback to summary
public CombinedClassLoader()

Method Detail

getResourceback to summary
public URL getResource(String name)

Overrides java.lang.ClassLoader.getResource.

Doc from java.lang.ClassLoader.getResource.

Finds the resource with the given name. A resource is some data (images, audio, text, etc) that can be accessed by class code in a way that is independent of the location of the code.

The name of a resource is a '/'-separated path name that identifies the resource.

Resources in named modules are subject to the encapsulation rules specified by Module.getResourceAsStream. Additionally, and except for the special case where the resource has a name ending with ".class", this method will only find resources in packages of named modules when the package is opened unconditionally (even if the caller of this method is in the same module as the resource).

Parameters
name:String

The resource name

Returns:URL

URL object for reading the resource; null if the resource could not be found, a URL could not be constructed to locate the resource, the resource is in a package that is not opened unconditionally, or access to the resource is denied by the security manager.

Annotations
@Override