Class UIDGenerator
- java.lang.Object
-
- org.apache.axiom.util.UIDGenerator
-
public final class UIDGenerator extends Object
Contains utility methods to generate unique IDs of various kinds.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringgenerateContentId()Generates a unique ID suitable for usage as a MIME content ID.static StringgenerateMimeBoundary()Generates a MIME boundary.static StringgenerateUID()Generate a general purpose unique ID.static URIgenerateURN()Generate a URN with uuid NID (namespace identifier).static StringgenerateURNString()Generate a URN with uuid NID (namespace identifier).
-
-
-
Method Detail
-
generateContentId
public static String generateContentId()
Generates a unique ID suitable for usage as a MIME content ID.RFC2045 (MIME) specifies that the value of the Content-ID header must match the msg-id production, which is defined by RFC2822 as follows:
msg-id = [CFWS] "<" id-left "@" id-right ">" [CFWS] id-left = dot-atom-text / no-fold-quote / obs-id-left id-right = dot-atom-text / no-fold-literal / obs-id-right dot-atom-text = 1*atext *("." 1*atext) atext = ALPHA / DIGIT / "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "/" / "=" / "?" / "^" / "_" / "`" / "{" / "|" / "}" / "~"In addition, RFC2392 specifies that when used in an URL with scheme "cid:", the content ID must be URL encoded. Since not all implementations handle this correctly, any characters considered "unsafe" in an URL (and requiring encoding) should be avoided in a content ID.This method generates content IDs that satisfy these requirements. It guarantees a high level of uniqueness, but makes no provisions to guarantee randomness. The implementation is thread safe, but doesn't use synchronization.
- Returns:
- The generated content ID. Note that this value does not include the angle brackets of the msg-id production, but only represents the bare content ID.
-
generateMimeBoundary
public static String generateMimeBoundary()
Generates a MIME boundary.Valid MIME boundaries are defined by the following production in RFC2046:
boundary := 0*69<bchars> bcharsnospace bchars := bcharsnospace / " " bcharsnospace := DIGIT / ALPHA / "'" / "(" / ")" / "+" / "_" / "," / "-" / "." / "/" / ":" / "=" / "?"It should be noted that the boundary in general will also appear as a parameter in the content type of the MIME package. According to RFC2045 (which defines the Content-Type header), it will require quoting if it contains characters from the following production:
tspecials := "(" / ")" / "<" / ">" / "@" / "," / ";" / ":" / "\" / <"> / "/" / "[" / "]" / "?" / "="This method produces a boundary that doesn't contain any of these characters and therefore doesn't need to be quoted. To avoid accidental collisions, the returned value is unique and doesn't overlap with any other type of unique ID returned by methods in this class. The implementation is thread safe, but doesn't use synchronization.
- Returns:
- the generated MIME boundary
-
generateUID
public static String generateUID()
Generate a general purpose unique ID. The returned value is the hexadecimal representation of a 192 bit value, i.e. it is 48 characters long. The implementation guarantees a high level of uniqueness, but makes no provisions to guarantee randomness. It is thread safe, but doesn't use synchronization.- Returns:
- the generated unique ID
-
generateURNString
public static String generateURNString()
Generate a URN with uuid NID (namespace identifier). These URNs have the following form: urn:uuid:dae6fae1-93df-4824-bc70-884c9edb5973. The UUID is generated using a cryptographically strong pseudo random number generator.- Returns:
- the generated URN
-
generateURN
public static URI generateURN()
Generate a URN with uuid NID (namespace identifier). This method does the same asgenerateURNString(), but returns aURIobject.- Returns:
- the generated URN
-
-