@Override public XLink anchor(final MarshalContext context, final Object value, final CharSequence text) { final URI linkage; synchronized (anchors) { linkage = anchors.get(value); } if (linkage != null) { final XLink xlink = new XLink(); xlink.setHRef(linkage); return xlink; } return super.anchor(context, value, text); } });
/** * Sets the {@code href} attribute value. * * @param href the new attribute value. * @throws URISyntaxException if the given string can not be parsed as a URI. * @category xlink */ public final void setHRef(final String href) throws URISyntaxException { xlink(true).setHRef(toURI(href)); }
/** * Sets the {@code href} attribute value. * * @param href the new attribute value. * @throws URISyntaxException if the given string can not be parsed as a URI. * @category xlink */ public final void setHRef(final String href) throws URISyntaxException { xlink(true).setHRef(toURI(href)); }
final XLink link = new XLink(); link.setType(XLink.Type.SIMPLE); link.setHRef(new URI("org:apache:sis:href")); assertEquals("XLink[type=\"simple\", href=\"org:apache:sis:href\"]", link.toString()); try { link.setHRef(null); fail("The XLink should be unmodifiable."); } catch (UnsupportedOperationException e) {
/** * Tests explicitly the special handling of {@code href} values. */ @Test public void testHRefSubstitution() { final List<Identifier> identifiers = new ArrayList<>(); final IdentifierMap map = new ModifiableIdentifierMap(identifiers); assertNull(map.put(HREF, "myHREF")); assertEquals("Shall contain the entry we added.", "myHREF", map.get(HREF)); // Check the XLink object final XLink link = map.getSpecialized(XLINK); assertEquals("Added href shall be stored as XLink attribute.", "myHREF", String.valueOf(link.getHRef())); assertEquals("Identifier list shall contain the XLink.", link.toString(), getSingleton(identifiers).getCode()); // Modidfy the XLink object directly link.setHRef(URI.create("myNewHREF")); assertEquals("Change in XLink shall be reflected in href.", "myNewHREF", map.get(HREF)); }
if (id != null && resolver.canSubstituteByReference(context, type, value, id)) try { final XLink link = new XLink(); link.setHRef(new URI(null, null, id)); reference = new ObjectReference(null, link); return;
if (id != null && resolver.canSubstituteByReference(context, type, value, id)) try { final XLink link = new XLink(); link.setHRef(new URI(null, null, id)); reference = new ObjectReference(null, link); return;
/** * Tests (un)marshalling of an object with a {@code xlink:href} attribute without element definition. * The XML fragment is: * * {@preformat xml * <mdb:MD_Metadata> * <mdb:identificationInfo xlink:href="http://test.net"/> * </mdb:MD_Metadata> * } * * @throws JAXBException if an error occurred during (un)marshalling. * @throws URISyntaxException if the URI used in this test is malformed. */ @Test public void testLinkOnly() throws JAXBException, URISyntaxException { final XLink xlink = new XLink(); xlink.setHRef(new URI("http://test.net")); final DefaultDataIdentification identification = new DefaultDataIdentification(); identification.getIdentifierMap().putSpecialized(IdentifierSpace.XLINK, xlink); final DefaultMetadata metadata = new DefaultMetadata(); metadata.setIdentificationInfo(Collections.singleton(identification)); assertXmlEquals(LINK_ONLY_XML, marshal(metadata), "xmlns:*"); verify(true, unmarshal(DefaultMetadata.class, LINK_ONLY_XML)); }
xlink.setHRef(href); return new SpecializedIdentifier<>(IdentifierSpace.XLINK, xlink);
xlink.setHRef(href); return new SpecializedIdentifier<>(IdentifierSpace.XLINK, xlink);
public void testWithElement() throws JAXBException, URISyntaxException { final XLink xlink = new XLink(); xlink.setHRef(new URI("http://test.net")); final DefaultDataIdentification identification = new DefaultDataIdentification(); identification.getIdentifierMap().putSpecialized(IdentifierSpace.XLINK, xlink);
assertFalse("Hash code can not be zero.", hashCode == 0); link.setHRef(new URI("org:apache:sis:href")); assertEquals(XLink.Type.LOCATOR, link.getType()); assertEquals("XLink[type=\"locator\", href=\"org:apache:sis:href\", role=\"org:apache:sis:role\", title=\"Some title\", label=\"SomeLabel\"]", link.toString());