org.nees.metadata.util
Class HashIdFactory

java.lang.Object
  extended byorg.nees.metadata.util.IdFactory
      extended byorg.nees.metadata.util.EncodedIdFactory
          extended byorg.nees.metadata.util.HexIdFactory
              extended byorg.nees.metadata.util.HashIdFactory

public class HashIdFactory
extends HexIdFactory

Generates ID's whose local parts are hashes of strings. This is to facilitate using arbitrary strings as local parts even if they do not conform to the subset of XML nmtoken supported by NMDS.

For instance this code:

 HashIdFactory hif = new HashIdFactory();
 hif.setPrefix("x");
 hif.setDigestAlgorithm("SHA-1");
 Identifier id = hif.newId("/C=US/O=National Computational Science Alliance/CN=Joseph M. Futrelle");");
 System.out.println(id.getLocalPart());
 

Will produce the following output:

x.5e4eff87074b049d51efd24197626b8fbaa2fc3f


Field Summary
 java.lang.String DEFAULT_DIGEST_ALGORITHM
          the default hash algorithm is SHA-1
 
Fields inherited from class org.nees.metadata.util.EncodedIdFactory
DEFAULT_STRING_ENCODING
 
Constructor Summary
HashIdFactory()
           
HashIdFactory(java.lang.String namespaceURI)
          Creates a factory that produces Identifiers in a given namespace.
HashIdFactory(java.lang.String namespaceURI, java.lang.String prefix)
           
 
Method Summary
 byte[] decode(java.lang.String encoded)
          Subclasses implement this for specific decoding behavior.
 java.lang.String getDefaultPrefix()
           
 java.lang.String getDigestAlgorithm()
           
 Identifier newId(java.lang.String localString)
          Hashes the local string, appends a prefix, and uses that as the local part of the ID.
 Identifier newId(java.lang.String namespaceURI, java.lang.String localString)
          Hashes the local string, appends a prefix, and uses that as the local part of the ID.
 void setDigestAlgorithm(java.lang.String da)
           
 
Methods inherited from class org.nees.metadata.util.HexIdFactory
encode
 
Methods inherited from class org.nees.metadata.util.EncodedIdFactory
decodeToOctets, decodeToString, decodeToString, getPrefix, getStringEncoding, newId, newId, setPrefix, setStringEncoding
 
Methods inherited from class org.nees.metadata.util.IdFactory
getFactory, getFactory, getNamespaceURI, newId, newIdPromise, setNamespaceURI
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_DIGEST_ALGORITHM

public final java.lang.String DEFAULT_DIGEST_ALGORITHM
the default hash algorithm is SHA-1

See Also:
Constant Field Values
Constructor Detail

HashIdFactory

public HashIdFactory()

HashIdFactory

public HashIdFactory(java.lang.String namespaceURI)
Creates a factory that produces Identifiers in a given namespace.

Parameters:
namespaceURI - the namespace URI

HashIdFactory

public HashIdFactory(java.lang.String namespaceURI,
                     java.lang.String prefix)
Parameters:
namespaceURI - the namespace URI
prefix - the prefix to append to the local part
Method Detail

setDigestAlgorithm

public void setDigestAlgorithm(java.lang.String da)
                        throws java.security.NoSuchAlgorithmException
Parameters:
da - digest algorithm
Throws:
java.security.NoSuchAlgorithmException

getDigestAlgorithm

public java.lang.String getDigestAlgorithm()
Returns:
the digest algorithm

newId

public Identifier newId(java.lang.String localString)
Hashes the local string, appends a prefix, and uses that as the local part of the ID. Uses the namespace URI set for this factory instance.

Overrides:
newId in class EncodedIdFactory
Parameters:
localString - a string to hash and turn into a local part.

newId

public Identifier newId(java.lang.String namespaceURI,
                        java.lang.String localString)
Hashes the local string, appends a prefix, and uses that as the local part of the ID.

Overrides:
newId in class EncodedIdFactory
Parameters:
namespaceURI - the namespace URI to use.
localString - a string to hash and turn into a local part.

getDefaultPrefix

public java.lang.String getDefaultPrefix()
Overrides:
getDefaultPrefix in class HexIdFactory

decode

public byte[] decode(java.lang.String encoded)
              throws EncodingException
Description copied from class: EncodedIdFactory
Subclasses implement this for specific decoding behavior. Throw EncodingException if there's a problem.

Overrides:
decode in class HexIdFactory
Throws:
EncodingException