Search in sources :

Example 6 with XLink

use of org.apache.sis.xml.XLink in project sis by apache.

the class ModifiableIdentifierMap method setHRef.

/**
 * Sets the {@code xlink:href} value, which may be null. If an explicit {@code xlink:href} identifier exists,
 * then it will removed before to set the new {@code href} in the {@link XLink} object. The intent is to give
 * precedence to the {@link XLink#getHRef()} property in every cases where the {@code href} is parsable as a
 * {@link URI}, and use the value associated to the {@code HREF} key only as a fallback when the string can not
 * be parsed.
 *
 * @param  href  the new value, or {@code null} for removing the value.
 * @return the previous value, or {@code null} if none.
 *
 * @see #getHRef()
 */
private URI setHRef(final URI href) {
    URI old = store(IdentifierSpace.HREF, null);
    final Identifier identifier = getIdentifier(IdentifierSpace.XLINK);
    if (identifier instanceof SpecializedIdentifier<?>) {
        final Object link = ((SpecializedIdentifier<?>) identifier).value;
        if (link instanceof XLink) {
            if (old == null) {
                old = ((XLink) link).getHRef();
            }
            ((XLink) link).setHRef(href);
            return old;
        }
    }
    if (href != null) {
        final XLink link = new XLink();
        link.setHRef(href);
        store(IdentifierSpace.XLINK, link);
    }
    return old;
}
Also used : Identifier(org.opengis.metadata.Identifier) URI(java.net.URI) XLink(org.apache.sis.xml.XLink)

Aggregations

XLink (org.apache.sis.xml.XLink)6 Anchor (org.apache.sis.internal.jaxb.gcx.Anchor)2 Identifier (org.opengis.metadata.Identifier)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Context (org.apache.sis.internal.jaxb.Context)1 PT_FreeText (org.apache.sis.internal.jaxb.lan.PT_FreeText)1 SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)1 IdentifierMap (org.apache.sis.xml.IdentifierMap)1 Test (org.junit.Test)1 InternationalString (org.opengis.util.InternationalString)1