Hello Stephane Le 30/03/2017 à 20:18, Stephane Fellah a écrit :
> I am parsing a number of ISO 19139 documents that have reference to > ISO components using xlink:href to external resources. > For example, I have the following xlink reference for ResponsibleParty: > > <gmd:citedResponsibleParty > xlink:href="https://www.ngdc.noaa.gov/docucomp/1df27e57-4768-42de-909b-52f530601fba > <https://www.ngdc.noaa.gov/docucomp/1df27e57-4768-42de-909b-52f530601fba>" > xlink:title="U.S Department of Commerce, U.S Census Bureau, Geography > Division (distributor)"/> > > By default, the Apache Unmarshaler does not resolve this link. As I > understand, we need to register a ReferenceResolver > <https://sis.apache.org/apidocs/org/apache/sis/xml/ReferenceResolver.html> to > fetch the component, > I have two questions: > 1) Is there any implementation of ReferenceResolver that fetches the > external component. If not, can you describe the best approach to > implement it > 2) Is there a way to access to the xlink:href value so I can use to > uniquely identify the ISO component in my system. There is not yet a ReferenceResolver implementation fetching external resources. It is our plan to provide one, but we didn't yet. In the meantime, an implementation like below should do the trick (I didn't tested): class MyResolver extends ReferenceResolver { @Override public <T> T resolve(MarshalContext context, Class<T> type, XLink link) { T content = super.resolve(context, type, link); if (content == null) { URI href = link.getHRef(); if (href != null) { // TODO: we should probably check if the object is available in some cache first. content = type.cast(XML.unmarshal(href)); } } return content; } } We could do something like that by default in Apache SIS, but I didn't yet because I had not clear answer to the following questions. Do you have opinion on the following? * Do we really want to open a network connection when we meet a xlink:href="http://..." attribute in metadata file, or do we want to have network connections disabled by default and ask the user to enable this functionality explicitly? * We probably need a caching mechanism. Should the cache be valid only inside a XML document, or for the JVM lifetime, or even longer (by creating a local cache on disk)? * Would it be okay to consider the external document as immutable, or do we need to detect changes in order to invalidate the cache? Martin
