/** * Construct a PID given a filename of the form produced by toFilename(), * throwing a MalformedPIDException if it's not well-formed. * @param filenameString default translation of PID to filename * @return PID the PID producing the input filename * @throws MalformedPIDException */ public static PID fromFilename(String filenameString) throws MalformedPIDException { String decoded = filenameString.replaceFirst("_", ":"); if (decoded.endsWith("%")) { decoded = decoded.substring(0, decoded.length() - 1) + "."; } return new PID(decoded); }
/** * Construct a PID given a filename of the form produced by toFilename(), * throwing a MalformedPIDException if it's not well-formed. * @param filenameString default translation of PID to filename * @return PID the PID producing the input filename * @throws MalformedPIDException */ public static PID fromFilename(String filenameString) throws MalformedPIDException { String decoded = filenameString.replaceFirst("_", ":"); if (decoded.endsWith("%")) { decoded = decoded.substring(0, decoded.length() - 1) + "."; } return new PID(decoded); }
public static PID getPID(String pidString) throws MalformedPidException { try { return new PID(pidString); } catch (MalformedPIDException e) { throw new MalformedPidException(e.getMessage()); } }
public static PID getPID(String pidString) throws MalformedPidException { try { return new PID(pidString); } catch (MalformedPIDException e) { throw new MalformedPidException(e.getMessage()); } }
protected String getSubjectURI(String subject) throws MalformedPIDException { String strippedSubject; if (subject.startsWith(Constants.FEDORA.uri)) { strippedSubject = subject.substring(Constants.FEDORA.uri.length()); } else { strippedSubject = subject; } String parts[] = strippedSubject.split("/"); PID pid = new PID(parts[0]); String subjectURI; if (parts.length == 1) { subjectURI = pid.toURI(); } else if (parts.length == 2) { subjectURI = pid.toURI() + "/" + parts[1]; // add datastream } else { logger.warn("Invalid subject argument for getRelationships: " + subject + ". Should be pid or datastream (URI form optional"); subjectURI = null; } return subjectURI; }
/** * Factory method that throws an unchecked exception if it's not * well-formed. * @param pidString the String value of the PID * @return PID */ public static PID getInstance(String pidString) { try { return new PID(pidString); } catch (MalformedPIDException e) { throw new FaultException("Malformed PID: " + e.getMessage(), e); } }
/** * Factory method that throws an unchecked exception if it's not * well-formed. * @param pidString the String value of the PID * @return PID */ public static PID getInstance(String pidString) { try { return new PID(pidString); } catch (MalformedPIDException e) { throw new FaultException("Malformed PID: " + e.getMessage(), e); } }
/** * Convert a policy name to a filename that can be used to persist the policy. * Policy names must be valid PIDs (the DO managing the policy) * @param policyName * @return * @throws PolicyIndexException */ private File nameToFile(String policyName) throws PolicyIndexException { PID pid; try { pid = new PID(policyName); } catch (MalformedPIDException e) { throw new PolicyIndexException("Invalid policy name. Policy name must be a valid PID - " + policyName); } return new File(DB_HOME + "/" + pid.toFilename() + ".xml"); } /**
PID pid; try { pid = new PID(parts[0]); } catch (MalformedPIDException e1) { logger.warn("Invalid Fedora resource identifier: {}. PID part of URI is malformed", res);
/** * Generate a new pid that is guaranteed to be unique, within the given * namespace. */ public synchronized PID generatePID(String namespace) throws IOException { int i = getHighestID(namespace); i++; try { m_lastPID = new PID(namespace + ":" + i); } catch (MalformedPIDException e) { throw new IOException(e.getMessage()); } setHighestID(namespace, i); return m_lastPID; }
/** * Generate a new pid that is guaranteed to be unique, within the given * namespace. */ public synchronized PID generatePID(String namespace) throws IOException { int i = getHighestID(namespace); i++; try { m_lastPID = new PID(namespace + ":" + i); } catch (MalformedPIDException e) { throw new IOException(e.getMessage()); } setHighestID(namespace, i); return m_lastPID; }
/** * Cause the given PID to never be generated by the PID generator. */ public synchronized void neverGeneratePID(String pid) throws IOException { logger.debug("Never generating PID: {}", pid); try { PID p = new PID(pid); String ns = p.getNamespaceId(); int id = Integer.parseInt(p.getObjectId()); if (id > getHighestID(ns)) { setHighestID(ns, id); } } catch (MalformedPIDException mpe) { throw new IOException(mpe.getMessage()); } catch (NumberFormatException nfe) { // if the id part is not numeric, we already know we'll // never generate that id because all generated ids are numeric. } }
/** * Cause the given PID to never be generated by the PID generator. */ public synchronized void neverGeneratePID(String pid) throws IOException { logger.debug("Never generating PID: {}", pid); try { PID p = new PID(pid); String ns = p.getNamespaceId(); int id = Integer.parseInt(p.getObjectId()); if (id > getHighestID(ns)) { setHighestID(ns, id); } } catch (MalformedPIDException mpe) { throw new IOException(mpe.getMessage()); } catch (NumberFormatException nfe) { // if the id part is not numeric, we already know we'll // never generate that id because all generated ids are numeric. } }
/** * 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)); }
PID pid; try { pid = new PID(feed.getId().toString()); } catch (MalformedPIDException e) { throw new ObjectIntegrityException(e.getMessage(), e);
PID pid; try { pid = new PID(feed.getId().toString()); } catch (MalformedPIDException e) { throw new ObjectIntegrityException(e.getMessage(), e);