Class XOPUtils


  • public class XOPUtils
    extends Object
    Contains utility methods related to XOP.
    • Method Detail

      • getContentIDFromURL

        public static String getContentIDFromURL​(String url)
        Extract the content ID from a URL following the cid scheme defined by RFC2392.
        Parameters:
        url - the URL
        Returns:
        the corresponding content ID
        Throws:
        IllegalArgumentException - if the URL doesn't use the cid scheme
      • getURLForContentID

        public static String getURLForContentID​(String contentID)
        Build a cid URL from the given content ID as described in RFC2392.

        Note that this implementation only encodes the percent character (replacing it by "%25"). The reason is given by the following quotes from RFC3986:

        If a reserved character is found in a URI component and no delimiting role is known for that character, then it must be interpreted as representing the data octet corresponding to that character's encoding in US-ASCII. [...]

        Under normal circumstances, the only time when octets within a URI are percent-encoded is during the process of producing the URI from its component parts. This is when an implementation determines which of the reserved characters are to be used as subcomponent delimiters and which can be safely used as data. [...]

        Because the percent ("%") character serves as the indicator for percent-encoded octets, it must be percent-encoded as "%25" for that octet to be used as data within a URI.

        Since RFC2392 doesn't define any subcomponents for the cid scheme and since RFC2045 specifies that only US-ASCII characters are allowed in content IDs, the percent character (which is specifically allowed by RFC2045) is the only character that needs URL encoding.

        Another reason to strictly limit the set of characters to be encoded is that some applications fail to decode cid URLs correctly if they contain percent encoded octets.

        Parameters:
        contentID - the content ID (without enclosing angle brackets)
        Returns:
        the corresponding URL in the cid scheme
      • getXOPEncodedStream

        public static XOPEncodedStream getXOPEncodedStream​(XMLStreamReader reader)
        Get an XOP encoded stream for a given stream reader. Depending on its type and characteristics, this method may wrap or unwrap the stream reader:
        1. If the original reader is an XOPEncodingStreamReader it will be preserved, since it is already XOP encoded.
        2. If the original reader is an XOPDecodingStreamReader, it will be unwrapped to give access to the underlying XOP encoded reader.
        3. If the original reader is a plain XML stream reader implementing the DataHandlerReader extension, it will be wrapped in an XOPEncodingStreamReader so that optimized binary data can be transferred using XOP.
        4. In all other cases, the original reader is simply preserved.
        Parameters:
        reader - the original reader
        Returns:
        the XOP encoded stream