org.nees.metadata.util
Class Base64IdFactory

java.lang.Object
  extended byorg.nees.metadata.util.IdFactory
      extended byorg.nees.metadata.util.EncodedIdFactory
          extended byorg.nees.metadata.util.Base64IdFactory
Direct Known Subclasses:
LogicalNameIdFactory, X509IdFactory

public class Base64IdFactory
extends EncodedIdFactory

Generates ID's whose local parts are base64-encoded. This is to facilitate using arbitrary octet strings as local parts even if they do not conform to the subset of XML nmtoken supported by NMDS. Also provides the optional convenience of encoding a character string into an octet string. Base64 encoding is made to conform to Nmtoken by converting + to _ and / to .

For instance this code:

 HexIdFactory hif = new HexIdFactory();
 hif.setPrefix("x");
 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... FIXME


Field Summary
 
Fields inherited from class org.nees.metadata.util.EncodedIdFactory
DEFAULT_STRING_ENCODING
 
Constructor Summary
Base64IdFactory()
           
Base64IdFactory(java.lang.String namespaceURI)
          Creates a factory that produces Identifiers in a given namespace.
Base64IdFactory(java.lang.String namespaceURI, java.lang.String prefix)
           
 
Method Summary
 byte[] decode(java.lang.String s)
          Base64 decodes the string.
 java.lang.String encode(byte[] octets)
          Base64 encodes the data.
 java.lang.String getDefaultPrefix()
           
 
Methods inherited from class org.nees.metadata.util.EncodedIdFactory
decodeToOctets, decodeToString, decodeToString, getPrefix, getStringEncoding, newId, newId, 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
 

Constructor Detail

Base64IdFactory

public Base64IdFactory()

Base64IdFactory

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

Parameters:
namespaceURI - the namespace URI

Base64IdFactory

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

getDefaultPrefix

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

encode

public java.lang.String encode(byte[] octets)
Base64 encodes the data. Also changes "+" to "_" and "/" to "." and "=" to "-".

Specified by:
encode in class EncodedIdFactory
Parameters:
octets - the binary data to encode
Returns:
the String encoding of it

decode

public byte[] decode(java.lang.String s)
Base64 decodes the string. Also changes "+" to "_" and "/" to "."

Specified by:
decode in class EncodedIdFactory