/** * 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); } }
/** * Return the normalized form of the given pid string, or throw a * MalformedPIDException. * @param pidString * @return String normalized version of the pid * @throws MalformedPIDException */ public static String normalize(String pidString) throws MalformedPIDException { if (pidString == null) { throw new MalformedPIDException("PID is null."); } return normalize(pidString, 0, pidString.length()); }
public static PID pidFromFilename(String filename) throws MalformedPidException { try { return PID.fromFilename(filename); } catch (MalformedPIDException e) { throw new MalformedPidException(e.getMessage()); } }
/** * 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)); }
public static PID getPID(String pidString) throws MalformedPidException { try { return new PID(pidString); } catch (MalformedPIDException e) { throw new MalformedPidException(e.getMessage()); } }
private String subjectAsURI(String subj) { // already a uri? if (subj.startsWith(Constants.FEDORA.uri)) { return subj; } // no, convert to uri return PID.toURI(subj); }
private static String uriEncode(String s) { try { return URLEncoder.encode(s, "UTF-8"); } catch (UnsupportedEncodingException wontHappen) { throw new FaultException(wontHappen); } }
/** * {@inheritDoc} */ @Override public boolean equals(Object o) { return o instanceof PID && m_normalized.equals(((PID) o).toString()); }
/** * 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); }
/** * 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); } }
public static PID getPID(String pidString) throws MalformedPidException { try { return new PID(pidString); } catch (MalformedPIDException e) { throw new MalformedPidException(e.getMessage()); } }
public static PID pidFromFilename(String filename) throws MalformedPidException { try { return PID.fromFilename(filename); } catch (MalformedPIDException e) { throw new MalformedPidException(e.getMessage()); } }
private static String uriDecode(String s) { try { return URLDecoder.decode(s, "UTF-8"); } catch (UnsupportedEncodingException wontHappen) { throw new FaultException(wontHappen); } }
/** * Return the normalized form of the given pid string, or throw a * MalformedPIDException. * @param pidString * @return String normalized version of the pid * @throws MalformedPIDException */ public static String normalize(String pidString) throws MalformedPIDException { if (pidString == null) { throw new MalformedPIDException("PID is null."); } return normalize(pidString, 0, pidString.length()); }
/** * 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; }
private static String uriEncode(String s) { try { return URLEncoder.encode(s, "UTF-8"); } catch (UnsupportedEncodingException wontHappen) { throw new FaultException(wontHappen); } }
private static String uriDecode(String s) { try { return URLDecoder.decode(s, "UTF-8"); } catch (UnsupportedEncodingException wontHappen) { throw new FaultException(wontHappen); } }
private static BlobStoreConnection getConnection(BlobStore store, Map<String, String> hints) { try { return store.openConnection(null, hints); } catch (IOException e) { throw new FaultException( "System error getting blob store connection", e); } }