/** * Returns a PID object for the requested String. This method will return a * PID for a variety of pid permutations, e.g. demo:1, info:fedora/demo:1, * demo:1/DS1, info:fedora/demo:1/sdef:foo/sdep:bar/methodBaz. * * @param pid * @return a PID object */ // FIXME: does not appear to be used anywhere protected PID getNormalizedPID(String pid) { // strip the leading "info:fedora/" if any if (pid.startsWith(Constants.FEDORA.uri)) { pid = pid.substring(Constants.FEDORA.uri.length()); } // should be left with "demo:foo" or "demo:foo/demo:bar" return PID.getInstance(pid.split("\\/")[0]); }
/** * Get the RELS-EXT xml for an object. */ public static String getRELSEXT(String pid, String content) { StringBuilder x = new StringBuilder(185 + content.length() + pid.length()); x.append("<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"" + " xmlns:foo=\"http://example.org/foo#\">\n" + "<rdf:Description rdf:about=\""); x.append(PID.getInstance(pid).toURI()); x.append("\">\n"); x.append(content); x.append("\n</rdf:Description>\n</rdf:RDF>"); return x.toString(); }
/** * Validates the latest version of all reserved datastreams in the given * object. */ public static void validateReservedDatastreams(DOReader reader) throws ValidationException { try { for (Datastream ds: reader.GetDatastreams(null, null)) { if ("X".equals(ds.DSControlGrp) || "M".equals(ds.DSControlGrp)) { validateReservedDatastream(PID.getInstance(reader.GetObjectPID()), ds.DatastreamID, ds); } } } catch (ValidationException e) { throw e; } catch (ServerException e) { throw new FaultException(e); } }
/** * Validates the latest version of all reserved datastreams in the given * object. */ public static void validateReservedDatastreams(DOReader reader) throws ValidationException { try { for (Datastream ds: reader.GetDatastreams(null, null)) { if ("X".equals(ds.DSControlGrp) || "M".equals(ds.DSControlGrp)) { validateReservedDatastream(PID.getInstance(reader.GetObjectPID()), ds.DatastreamID, ds); } } } catch (ValidationException e) { throw e; } catch (ServerException e) { throw new FaultException(e); } }
private static byte[] getCModelObject() throws Exception { StringBuilder buf = new StringBuilder(); openFOXML(buf, CMODEL_OBJECT_PID); StringBuilder rdf = new StringBuilder(); openRDF(rdf, CMODEL_OBJECT_PID); appendRel(rdf, MODEL.HAS_MODEL.localName, PID .getInstance(Models.CONTENT_MODEL_3_0.uri).toString()); appendRel(rdf, MODEL.HAS_SERVICE.localName, SDEF_OBJECT_PID); closeRDF(rdf); appendInlineDatastream(buf, "RELS-EXT", "application/rdf+xml", Constants.RELS_EXT1_0.uri, rdf.toString()); closeFOXML(buf); return buf.toString().getBytes("UTF-8"); }
private Foxml11Document createFoxmlObject(String spid, String contentLocation) throws Exception { PID pid = PID.getInstance(spid); Date date = new Date(1); Foxml11Document doc = new Foxml11Document(pid.toString()); doc.addObjectProperty(Property.STATE, "A"); if (contentLocation != null && contentLocation.length() > 0) { String ds = "DS"; String dsv = "DS1.0"; doc.addDatastream(ds, State.A, ControlGroup.M, true); doc.addDatastreamVersion(ds, dsv, "text/plain", "label", 1, date); doc.setContentLocation(dsv, contentLocation, org.fcrepo.server.storage.types.Datastream.DS_LOCATION_TYPE_URL); } return doc; }
private Foxml11Document createFoxmlObject(String spid, String contentLocation) throws Exception { PID pid = PID.getInstance(spid); Date date = new Date(1); Foxml11Document doc = new Foxml11Document(pid.toString()); doc.addObjectProperty(Property.STATE, "A"); if (contentLocation != null && contentLocation.length() > 0) { String ds = "DS"; String dsv = "DS1.0"; doc.addDatastream(ds, State.A, ControlGroup.E, true); doc.addDatastreamVersion(ds, dsv, "text/plain", "label", 1, date); doc.setContentLocation(dsv, contentLocation, org.fcrepo.server.storage.types.Datastream.DS_LOCATION_TYPE_URL); } return doc; }
/** * Get the RELS-INT xml for an object. */ public static String getRELSINT(String pid, String content1, String content2) { StringBuilder x = new StringBuilder(); x.append("<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"" + " xmlns:foo=\"http://example.org/foo#\">\n" // relationship(s) from datastream DS1 + "<rdf:Description rdf:about=\""); x.append(PID.getInstance(pid).toURI()); x.append("/DS1\">\n"); x.append(content1); x.append("\n</rdf:Description>\n"); // relationship(s) from datastream DS2 x.append("<rdf:Description rdf:about=\"" + PID.getInstance(pid).toURI() + "/DS2" + "\">\n"); x.append(content2); x.append("\n</rdf:Description>\n</rdf:RDF>"); return x.toString(); }
public void testValidateValidRelsExt() throws Exception { pid = PID.getInstance("demo:888"); InputStream in = new ByteArrayInputStream(RELS_EXT); RelsValidator validator = new RelsValidator(); validator.validate(pid, "RELS-EXT", in); } public void testValidateValidRelsInt() throws Exception {
private Foxml11Document createFoxmlObject(String spid, String contentLocation) throws Exception { PID pid = PID.getInstance(spid); Date date = new Date(1); Foxml11Document doc = new Foxml11Document(pid.toString()); doc.addObjectProperty(Property.STATE, "A"); if (contentLocation != null && contentLocation.length() > 0) { String ds = "DS"; String dsv = "DS1.0"; doc.addDatastream(ds, State.A, ControlGroup.E, true); doc.addDatastreamVersion(ds, dsv, "text/html", "label", 1, date); doc.setContentLocation(dsv, contentLocation, org.fcrepo.server.storage.types.Datastream.DS_LOCATION_TYPE_URL); } return doc; } }
private static void validateRels(String dsId, String rels) throws ValidationException { // need a datastream to validate DatastreamXMLMetadata dsxml = new DatastreamXMLMetadata(); dsxml.xmlContent = rels.getBytes(); ValidationUtility.validateReservedDatastream(PID.getInstance(TEST_PID), dsId, dsxml); }
public void testValidateValidRelsInt() throws Exception { pid = PID.getInstance("demo:888"); InputStream in = new ByteArrayInputStream(RELS_INT); RelsValidator validator = new RelsValidator(); validator.validate(pid, "RELS-INT", in); } public void testValidateInvalidRelsExt() throws Exception {
private static byte[] getSDefObject() throws Exception { StringBuilder buf = new StringBuilder(); openFOXML(buf, SDEF_OBJECT_PID); StringBuilder rdf = new StringBuilder(); openRDF(rdf, SDEF_OBJECT_PID); appendRel(rdf, MODEL.HAS_MODEL.localName, PID .getInstance(Models.SERVICE_DEFINITION_3_0.uri).toString()); closeRDF(rdf); appendInlineDatastream(buf, "RELS-EXT", "application/rdf+xml", Constants.RELS_EXT1_0.uri, rdf.toString()); appendInlineDatastream(buf, "METHODMAP", "text/xml", Constants.SDEF_METHOD_MAP1_0.uri, getSDefMethodMap()); closeFOXML(buf); return buf.toString().getBytes("UTF-8"); }
private Feed createAtomObject(String spid, String contentLocation) throws Exception { PID pid = PID.getInstance(spid); Date date = new Date(1); String title = "title"; String author = "org.fcrepo.test.api.TestManagedDatastreams"; Feed feed = abdera.newFeed(); feed.setId(pid.toURI()); feed.setTitle(title); feed.setUpdated(date); feed.addAuthor(author); if (contentLocation != null && contentLocation.length() > 0) { addAtomManagedDatastream(feed, contentLocation); } return feed; }
private void testEmpty(String dsId) throws Exception { pid = PID.getInstance("demo:demo"); InputStream in; String[] empties = {"", " ", "</>"}; for (String s : empties) { in = new ByteArrayInputStream(s.getBytes()); try { new RelsValidator().validate(pid, dsId, in); fail("Empty " + dsId + " datastream incorrectly passed" + " validation: \"" + s + "\""); } catch (ValidationException e) {} } }
private static void validatePolicy(PolicyParser parser, String policy) throws IOException, SAXException, ValidationException { ValidationUtility.setPolicyParser(parser); // need a datastream to validate DatastreamXMLMetadata dsxml = new DatastreamXMLMetadata(); dsxml.xmlContent = policy.getBytes(); ValidationUtility.validateReservedDatastream(PID.getInstance(TEST_PID), "POLICY", dsxml); }
public void testValidateInvalidRelsExt() throws Exception { pid = PID.getInstance("demo:888"); // use RELS-INT sample as a RELS-EXT datastream InputStream in = new ByteArrayInputStream(RELS_INT); RelsValidator validator = new RelsValidator(); try { validator.validate(pid, "RELS-EXT", in); fail("Multiple Description elements not allowed for RELS-EXT"); } catch (ValidationException e) {} }
/** * equals() should return true for lexically equivalent PIDs. */ @Test public void testEqualsSamePID() throws Exception { PID pid1 = PID.getInstance("test:somepid"); PID pid2 = new PID("test:somepid"); PID pid3 = PID.fromFilename("test_somepid"); assertEquals(pid1, pid2); assertEquals(pid2, pid3); }
/** * hashCode() should return the same value for lexically equivalent PIDs. */ @Test public void testHashCodeSamePID() throws Exception { PID pid1 = PID.getInstance("test:somepid"); PID pid2 = new PID("test:somepid"); PID pid3 = PID.fromFilename("test_somepid"); assertEquals(pid1.hashCode(), pid2.hashCode()); assertEquals(pid2.hashCode(), pid3.hashCode()); }
/** * equals() should return false for lexically distinct PIDs. */ @Test public void testEqualsDifferentPID() throws Exception { PID pid1 = PID.getInstance("test:somepid"); PID pid2 = new PID("test:someotherpid"); PID pid3 = PID.fromFilename("test_yetanotherpid"); assertFalse(pid1.equals(pid2)); assertFalse(pid2.equals(pid1)); assertFalse(pid2.equals(pid3)); assertFalse(pid3.equals(pid2)); }