LSResourceResolver
Stay organized with collections
Save and categorize content based on your preferences.
LSResourceResolver
provides a way for applications to
redirect references to external resources.
Applications needing to implement custom handling for external
resources can implement this interface and register their implementation
by setting the "resource-resolver" parameter of
DOMConfiguration
objects attached to LSParser
and LSSerializer
. It can also be register on
DOMConfiguration
objects attached to Document
if the "LS" feature is supported.
The LSParser
will then allow the application to intercept
any external entities, including the external DTD subset and external
parameter entities, before including them. The top-level document entity
is never passed to the resolveResource
method.
Many DOM applications will not need to implement this interface, but it
will be especially useful for applications that build XML documents from
databases or other specialized input sources, or for applications that
use URNs.
Note: LSResourceResolver
is based on the SAX2 [SAX] EntityResolver
interface.
See also the Document Object Model (DOM) Level 3 Load
and Save Specification.
Public Methods
Allow the application to resolve external resources.
The LSParser
will call this method before opening any
external resource, including the external DTD subset, external
entities referenced within the DTD, and external entities referenced
within the document element (however, the top-level document entity
is not passed to this method). The application may then request that
the LSParser
resolve the external resource itself, that
it use an alternative URI, or that it use an entirely different input
source.
Application writers can use this method to redirect external
system identifiers to secure and/or local URI, 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).
Parameters
type |
The type of the resource being resolved. For XML [XML 1.0] resources
(i.e. entities), applications must use the value
"http://www.w3.org/TR/REC-xml" . For XML Schema [XML Schema Part 1]
, applications must use the value
"http://www.w3.org/2001/XMLSchema" . Other types of
resources are outside the scope of this specification and therefore
should recommend an absolute URI in order to use this method. |
namespaceURI |
The namespace of the resource being resolved,
e.g. the target namespace of the XML Schema [XML Schema Part 1]
when resolving XML Schema resources. |
publicId |
The public identifier of the external entity being
referenced, or null if no public identifier was
supplied or if the resource is not an entity. |
systemId |
The system identifier, a URI reference [IETF RFC 2396], of the
external resource being referenced, or null if no
system identifier was supplied. |
baseURI |
The absolute base URI of the resource being parsed, or
null if there is no base URI. |
Returns
- A
LSInput
object describing the new input
source, or null
to request that the parser open a
regular URI connection to the resource.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003eLSResourceResolver\u003c/code\u003e allows applications to redirect references to external resources, like entities in XML documents.\u003c/p\u003e\n"],["\u003cp\u003eApplications can implement this interface to customize how external resources are handled by the \u003ccode\u003eLSParser\u003c/code\u003e and \u003ccode\u003eLSSerializer\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThis is particularly useful when building XML from databases or using URNs, offering control over external entity resolution.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eresolveResource\u003c/code\u003e method is called by the parser before opening external resources, letting the application decide how to handle them.\u003c/p\u003e\n"],["\u003cp\u003eBy implementing \u003ccode\u003eLSResourceResolver\u003c/code\u003e, developers can enhance security, use local resources, or utilize catalogs for public identifiers.\u003c/p\u003e\n"]]],["`LSResourceResolver` enables applications to manage external resource references. Implementations can be registered via `DOMConfiguration` objects on `LSParser`, `LSSerializer`, or `Document`. When parsing, `LSParser` calls `resolveResource` to handle external entities (excluding the top-level document). Applications can redirect to secure URIs, use local URIs, or access alternative input sources. `resolveResource` takes resource type, namespace, public/system IDs, and base URI as input and returns an `LSInput` object or null to use a regular URI.\n"],null,["# LSResourceResolver\n\npublic interface **LSResourceResolver** \n`LSResourceResolver` provides a way for applications to\nredirect references to external resources.\n\nApplications needing to implement custom handling for external\nresources can implement this interface and register their implementation\nby setting the \"resource-resolver\" parameter of\n`DOMConfiguration` objects attached to `LSParser`\nand `LSSerializer`. It can also be register on\n`DOMConfiguration` objects attached to `Document`\nif the \"LS\" feature is supported.\n\nThe `LSParser` will then allow the application to intercept\nany external entities, including the external DTD subset and external\nparameter entities, before including them. The top-level document entity\nis never passed to the `resolveResource` method.\n\nMany DOM applications will not need to implement this interface, but it\nwill be especially useful for applications that build XML documents from\ndatabases or other specialized input sources, or for applications that\nuse URNs.\n\n**Note:** `LSResourceResolver` is based on the SAX2 \\[[SAX](http://www.saxproject.org/)\\] `EntityResolver`\ninterface.\n\nSee also the [Document Object Model (DOM) Level 3 Load\nand Save Specification](http://www.w3.org/TR/2004/REC-DOM-Level-3-LS-20040407). \n\n### Public Method Summary\n\n|--------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [LSInput](../../../../../reference/org/w3c/dom/ls/LSInput.html) | [resolveResource](../../../../../reference/org/w3c/dom/ls/LSResourceResolver.html#resolveResource(java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String))([String](../../../../../reference/java/lang/String.html) type, [String](../../../../../reference/java/lang/String.html) namespaceURI, [String](../../../../../reference/java/lang/String.html) publicId, [String](../../../../../reference/java/lang/String.html) systemId, [String](../../../../../reference/java/lang/String.html) baseURI) Allow the application to resolve external resources. |\n\nPublic Methods\n--------------\n\n#### public abstract [LSInput](../../../../../reference/org/w3c/dom/ls/LSInput.html)\n**resolveResource**\n([String](../../../../../reference/java/lang/String.html) type, [String](../../../../../reference/java/lang/String.html) namespaceURI, [String](../../../../../reference/java/lang/String.html) publicId, [String](../../../../../reference/java/lang/String.html) systemId, [String](../../../../../reference/java/lang/String.html) baseURI)\n\nAllow the application to resolve external resources.\n\nThe `LSParser` will call this method before opening any\nexternal resource, including the external DTD subset, external\nentities referenced within the DTD, and external entities referenced\nwithin the document element (however, the top-level document entity\nis not passed to this method). The application may then request that\nthe `LSParser` resolve the external resource itself, that\nit use an alternative URI, or that it use an entirely different input\nsource.\n\nApplication writers can use this method to redirect external\nsystem identifiers to secure and/or local URI, to look up public\nidentifiers in a catalogue, or to read an entity from a database or\nother input source (including, for example, a dialog box). \n\n##### Parameters\n\n| type | The type of the resource being resolved. For XML \\[[XML 1.0](http://www.w3.org/TR/2004/REC-xml-20040204)\\] resources (i.e. entities), applications must use the value `\"http://www.w3.org/TR/REC-xml\"`. For XML Schema \\[[XML Schema Part 1](http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/)\\] , applications must use the value `\"http://www.w3.org/2001/XMLSchema\"`. Other types of resources are outside the scope of this specification and therefore should recommend an absolute URI in order to use this method. |\n| namespaceURI | The namespace of the resource being resolved, e.g. the target namespace of the XML Schema \\[[XML Schema Part 1](http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/)\\] when resolving XML Schema resources. |\n| publicId | The public identifier of the external entity being referenced, or `null` if no public identifier was supplied or if the resource is not an entity. |\n| systemId | The system identifier, a URI reference \\[[IETF RFC 2396](http://www.ietf.org/rfc/rfc2396.txt)\\], of the external resource being referenced, or `null` if no system identifier was supplied. |\n| baseURI | The absolute base URI of the resource being parsed, or `null` if there is no base URI. |\n|--------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n\n##### Returns\n\n- A `LSInput` object describing the new input source, or `null` to request that the parser open a regular URI connection to the resource."]]