/** * Returns the presentation form that matches the given string, or returns a new one if none * match it. * * @param code The name of the code to fetch or to create. * @return A code matching the given name. */ public static PresentationForm valueOf(String code) { return valueOf(PresentationForm.class, code); } }
/** * Returns the presentation form that matches the given string, or returns a * new one if none match it. More specifically, this methods returns the first instance for * which <code>{@linkplain #name() name()}.{@linkplain String#equals equals}(code)</code> * returns {@code true}. If no existing instance is found, then a new one is created for * the given name. * * @param code the name of the code to fetch or to create. * @return a code matching the given name. */ public static PresentationForm valueOf(String code) { return valueOf(PresentationForm.class, code); } }
/** * Returns the presentation form that matches the given string, or returns a * new one if none match it. More specifically, this methods returns the first instance for * which <code>{@linkplain #name() name()}.{@linkplain String#equals equals}(code)</code> * returns {@code true}. If no existing instance is found, then a new one is created for * the given name. * * @param code the name of the code to fetch or to create. * @return a code matching the given name. */ public static PresentationForm valueOf(String code) { return valueOf(PresentationForm.class, code); } }
/** * Tests marshalling of a code list which is not in the list of standard codes. * * @throws JAXBException if an error occurred while marshalling the XML. */ @Test public void testExtraCodes() throws JAXBException { final DefaultCitation id = new DefaultCitation(); id.setPresentationForms(Arrays.asList( PresentationForm.valueOf("IMAGE_DIGITAL"), // Existing code with UML id="imageDigital" PresentationForm.valueOf("test"))); // New code final String xml = marshal(id); /* * "IMAGE_DIGITAL" is marshalled as "imageDigital" because is contains a UML id, which is lower-case. */ assertXmlEquals( "<cit:CI_Citation xmlns:cit=\"" + Namespaces.CIT + "\">\n" + " <cit:presentationForm>\n" + " <cit:CI_PresentationFormCode codeListValue=\"imageDigital\">Image digital</cit:CI_PresentationFormCode>\n" + " </cit:presentationForm>\n" + " <cit:presentationForm>\n" + " <cit:CI_PresentationFormCode codeListValue=\"test\">Test</cit:CI_PresentationFormCode>\n" + " </cit:presentationForm>\n" + "</cit:CI_Citation>\n", xml, "xmlns:*", "codeList", "codeSpace"); } }
/** * Tests the formatting of a {@link DefaultDataIdentification} object with custom code list elements */ @Test public void testTreeWithCustomElements() { final DefaultCitation citation = new DefaultCitation(); citation.setAlternateTitles(Arrays.asList( new SimpleInternationalString("Apple"), new SimpleInternationalString("Orange"), new SimpleInternationalString("Kiwi"))); citation.setPresentationForms(Arrays.asList( PresentationForm.IMAGE_DIGITAL, PresentationForm.valueOf("AUDIO_DIGITAL"), // Existing form PresentationForm.valueOf("test"))); // Custom form final String text = format.format(citation.asTreeTable()); assertMultilinesEquals( "Citation\n" + " ├─Alternate title (1 of 3)………… Apple\n" + " ├─Alternate title (2 of 3)………… Orange\n" + " ├─Alternate title (3 of 3)………… Kiwi\n" + " ├─Presentation form (1 of 3)…… Image digital\n" + " ├─Presentation form (2 of 3)…… AUDIO-DIGITAL\n" + // Missing localization resource for that one. " └─Presentation form (3 of 3)…… Test\n", text); } }
/** * Tests XML unmarshalling for a metadata version. * The version is not specified since it should be detected automatically. * * @param file file containing the metadata to unmarshal. */ private void testUnmarshalling(final String file) throws JAXBException { final DefaultCitation c = unmarshalFile(DefaultCitation.class, file); assertTitleEquals("title", "Fight against poverty", c); final CitationDate date = getSingleton(c.getDates()); assertEquals("date", date.getDate(), TestUtilities.date("2015-10-17 00:00:00")); assertEquals("dateType", DateType.valueOf("adopted"), date.getDateType()); assertEquals("presentationForm", PresentationForm.valueOf("physicalObject"), getSingleton(c.getPresentationForms())); final Iterator<ResponsibleParty> it = c.getCitedResponsibleParties().iterator(); final Contact contact = assertResponsibilityEquals(Role.ORIGINATOR, "Maid Marian", it.next()); assertEquals("Contact instruction", "Send carrier pigeon.", String.valueOf(contact.getContactInstructions())); final OnlineResource resource = contact.getOnlineResource(); assertEquals("Resource name", "IP over Avian Carriers", String.valueOf(resource.getName())); assertEquals("Resource description", "High delay, low throughput, and low altitude service.", String.valueOf(resource.getDescription())); assertEquals("Resource linkage", "https://tools.ietf.org/html/rfc1149", String.valueOf(resource.getLinkage())); assertEquals("Resource function", OnLineFunction.OFFLINE_ACCESS, resource.getFunction()); // Thanks to xlink:href, the Contact shall be the same instance as above. assertSame("contact", contact, assertResponsibilityEquals(Role.valueOf("funder"), "Robin Hood", it.next())); assertFalse(it.hasNext()); }
/** * Tests XML marshalling for the given metadata version. * * @param file file containing the expected metadata. * @param version the metadata version to marshal. */ private void testMarshalling(final String file, final Version version) throws JAXBException { final DefaultOnlineResource rs = new DefaultOnlineResource(URI.create("https://tools.ietf.org/html/rfc1149")); rs.setName("IP over Avian Carriers"); rs.setDescription(new SimpleInternationalString("High delay, low throughput, and low altitude service.")); rs.setFunction(OnLineFunction.OFFLINE_ACCESS); final DefaultContact contact = new DefaultContact(rs); contact.setContactInstructions(new SimpleInternationalString("Send carrier pigeon.")); contact.getIdentifierMap().putSpecialized(IdentifierSpace.ID, "ip-protocol"); final DefaultCitation c = new DefaultCitation("Fight against poverty"); final DefaultResponsibleParty r1 = new DefaultResponsibleParty(Role.ORIGINATOR); final DefaultResponsibleParty r2 = new DefaultResponsibleParty(Role.valueOf("funder")); r1.setParties(Collections.singleton(new DefaultIndividual("Maid Marian", null, contact))); r2.setParties(Collections.singleton(new DefaultIndividual("Robin Hood", null, contact))); c.setCitedResponsibleParties(Arrays.asList(r1, r2)); c.getDates().add(new DefaultCitationDate(TestUtilities.date("2015-10-17 00:00:00"), DateType.valueOf("adopted"))); c.getPresentationForms().add(PresentationForm.valueOf("physicalObject")); /* * Check that XML file built by the marshaller is the same as the example file. */ assertMarshalEqualsFile(file, c, version, "xmlns:*", "xsi:schemaLocation"); }