Package org.eclipse.lemminx.extensions.contentmodel.uriresolver

## Class XMLCacheResolverExtension

- java.lang.Object
- - org.eclipse.lemminx.extensions.contentmodel.uriresolver.XMLCacheResolverExtension

All Implemented Interfaces:
  `org.apache.xerces.xni.parser.XMLEntityResolver`, `URIResolverExtension`

    public class XMLCacheResolverExtension
    extends Object
    implements URIResolverExtension

URI resolver which, on the first access, downloads the XML Schema or DTD from "http(s)" or "ftp" URIs to the file system. On subsequent calls, the locally cached file is used instead of being remotely accessed. This cache drastically improves the resolution performance of some XML Schemas (ex: xml.xsd)

### Field Summary

### Fields inherited from interface org.eclipse.lemminx.uriresolver.URIResolverExtension

`DEFAULT`

### Constructor Summary

Constructors
`XMLCacheResolverExtension()`

### Method Summary

All Methods Instance Methods Concrete Methods
`boolean` `canUseCache​(String url)` Returns `true` if cache is enabled and url comes from "http(s)" or "ftp" and `false` otherwise.
`void` `evictCache()` Remove the cache directory (.lemminx/cache) if it exists.
`void` `forceDownloadExternalResource​(String url)` Force the given `url` to download.
`Path` `getCachedResource​(String url)` Returns the cached resource path from the given url and null otherwise.
`boolean` `isDownloadExternalResources()` Returns true if the external resources can be downloaded and false otherwise.
`boolean` `isUseCache()` Returns `true` if cache must be used, `false` otherwise.
`String` `resolve​(String baseLocation, String publicId, String systemId)`
`org.apache.xerces.xni.parser.XMLInputSource` `resolveEntity​(org.apache.xerces.xni.XMLResourceIdentifier resourceIdentifier)`
`void` `setDownloadExternalResources​(boolean downloadExternalResources)` Set true if the external resources can be downloaded and false otherwise.
`void` `setUseCache​(boolean useCache)` Set `true` if cache must be used, `false` otherwise.

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

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

### Methods inherited from interface org.eclipse.lemminx.uriresolver.URIResolverExtension

`getName`

### Constructor Detail

#### XMLCacheResolverExtension

    public XMLCacheResolverExtension()

### Method Detail

#### resolve

    public String resolve​(String baseLocation,
                          String publicId,
                          String systemId)

Specified by:
  `resolve` in interface `URIResolverExtension`
Parameters:
  `baseLocation` - - the location of the resource that contains the uri
  `publicId` - - an optional public identifier (i.e. namespace name), or null if none
  `systemId` - - an absolute or relative URI, or null if none
Returns:
  an absolute URI representation of the 'logical' location of the resource

#### resolveEntity

    public org.apache.xerces.xni.parser.XMLInputSource resolveEntity​(org.apache.xerces.xni.XMLResourceIdentifier resourceIdentifier)
                                                              throws org.apache.xerces.xni.XNIException,
                                                                     IOException

Specified by:
  `resolveEntity` in interface `URIResolverExtension`
Specified by:
  `resolveEntity` in interface `org.apache.xerces.xni.parser.XMLEntityResolver`
Throws:
  `org.apache.xerces.xni.XNIException`
  `IOException`

#### getCachedResource

    public Path getCachedResource​(String url)
                           throws IOException,
                                  CacheResourceDownloadedException

Returns the cached resource path from the given url and null otherwise.

Parameters:
  `url` - the url to download.
Returns:
  the cached resource path from the given url and null otherwise.
Throws:
  `IOException`
  `CacheResourceDownloadedException` - throws when resource is downloading.

#### canUseCache

    public boolean canUseCache​(String url)

Returns `true` if cache is enabled and url comes from "http(s)" or "ftp" and `false` otherwise.

Parameters:
  `url` -
Returns:
  `true` if cache is enabled and url comes from "http(s)" or "ftp" and `false` otherwise.

#### setUseCache

    public void setUseCache​(boolean useCache)

Set `true` if cache must be used, `false` otherwise.

Parameters:
  `useCache` - `true` if cache must be used, `false` otherwise.

#### isUseCache

    public boolean isUseCache()

Returns `true` if cache must be used, `false` otherwise.

Returns:
  `true` if cache must be used, `false` otherwise.

#### isDownloadExternalResources

    public boolean isDownloadExternalResources()

Returns true if the external resources can be downloaded and false otherwise.

Returns:
  true if the external resources can be downloaded and false otherwise.

#### setDownloadExternalResources

    public void setDownloadExternalResources​(boolean downloadExternalResources)

Set true if the external resources can be downloaded and false otherwise.

Parameters:
  `downloadExternalResources` - the external resources

#### evictCache

    public void evictCache()
                    throws IOException

Remove the cache directory (.lemminx/cache) if it exists.

Throws:
  `IOException` - if the delete of directory (.lemminx/cache) cannot be done.

#### forceDownloadExternalResource

    public void forceDownloadExternalResource​(String url)

Force the given `url` to download.

Parameters:
  `url` - the url to download.