org.jasig.portal
Class MediaManager

java.lang.Object
  extended by org.jasig.portal.MediaManager

public class MediaManager
extends java.lang.Object

A tool for managing various media properties. Given a request object, MediaManager determines a client browser type (media). MediaManager also provides information on the mime type that generated response should carry.

Version:
$Revision: 1.35.4.2 $
Author:
Peter Kharchenko

Nested Class Summary
(package private)  class MediaManager.OrderedProps
          COPIED FROM XALAN SOURCE Stores the keys and values from a file (similar to a properties file) and can return the first value which has a key contained in its string.
 
Field Summary
private static org.apache.commons.logging.Log log
           
private static MediaManager MEDIAMANAGER
           
protected  MediaManager.OrderedProps mediaProps
           
private static java.lang.String mediaPropsUrl
           
protected  MediaManager.OrderedProps mimeProps
           
private static java.lang.String mimePropsUrl
           
static java.lang.String NULL_USER_AGENT
          A user agent string to use when the user-agent header value itself is null.
private static boolean omitDoctype
          As of uPortal 2.5.1, this property is "no" (meaning false) in the distributed portal.properties.
private static boolean outputIndenting
           
protected  MediaManager.OrderedProps serializerProps
           
private static java.lang.String serializerPropsUrl
           
static java.lang.String UNKNOWN
           
 
Constructor Summary
private MediaManager()
          Constructs a MediaManager
private MediaManager(java.lang.String mediaPropsFile, java.lang.String mimePropsFile, java.lang.String serializerPropsFile)
          Constructor that initializes all of the property tables.
 
Method Summary
 java.lang.String getDefaultMedia()
          Return a default media type.
 java.lang.String getMedia(BrowserInfo bi)
          Determines a media name from the browser info object.
 java.lang.String getMedia(javax.servlet.http.HttpServletRequest req)
          Determines a media name from the request object.
static MediaManager getMediaManager()
          7/25/05 - UP-1181 - change MediaManager into a singleton Returns the default MediaManager singleton
 java.lang.String getReturnMimeType(javax.servlet.http.HttpServletRequest req)
          Determines a mime name from the request object.
 java.lang.String getReturnMimeType(java.lang.String mediaType)
          Determines a mime name from a media type name.
 BaseMarkupSerializer getSerializer(javax.servlet.http.HttpServletRequest req, java.io.OutputStream out)
          Automatically determines the media type from the request object,
 BaseMarkupSerializer getSerializer(javax.servlet.http.HttpServletRequest req, java.io.Writer out)
          Automatically determines the media type from the request object,
 BaseMarkupSerializer getSerializer(java.lang.String mediaType, java.io.OutputStream out)
          Another version of getSerializer() with OutputStream as one of the parameters.
 BaseMarkupSerializer getSerializer(java.lang.String mediaType, java.io.Writer out)
          Determines and configures a serialzier that is proper for the specified media type.
 BaseMarkupSerializer getSerializerByName(java.lang.String serializerName, java.io.OutputStream out)
          Gets a serializer by name which writes to the provided OutputStream
 BaseMarkupSerializer getSerializerByName(java.lang.String serializerName, java.io.Writer out)
          Gets a serializer by name which writes to the provided Writer
 void setMediaProps(java.lang.String uri)
          Initializes media properties table.
 void setMimeProps(java.lang.String uri)
          Initializes mime properties table.
 void setSerializerProps(java.lang.String uri)
          Initializes serializer properties table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final org.apache.commons.logging.Log log

mediaProps

protected MediaManager.OrderedProps mediaProps

mimeProps

protected MediaManager.OrderedProps mimeProps

serializerProps

protected MediaManager.OrderedProps serializerProps

outputIndenting

private static boolean outputIndenting

omitDoctype

private static boolean omitDoctype
As of uPortal 2.5.1, this property is "no" (meaning false) in the distributed portal.properties. This Java code continues to default the property to true to maintain the behavior of 2.5.0 when the property is not specified in portal.properties. In a future release of uPortal, this property will default to false in order to restore agreement between default here and default in portal.properties.


mediaPropsUrl

private static final java.lang.String mediaPropsUrl

mimePropsUrl

private static final java.lang.String mimePropsUrl

serializerPropsUrl

private static final java.lang.String serializerPropsUrl

MEDIAMANAGER

private static final MediaManager MEDIAMANAGER

NULL_USER_AGENT

public static final java.lang.String NULL_USER_AGENT
A user agent string to use when the user-agent header value itself is null.

See Also:
Constant Field Values

UNKNOWN

public static final java.lang.String UNKNOWN
See Also:
Constant Field Values
Constructor Detail

MediaManager

private MediaManager()
Constructs a MediaManager


MediaManager

private MediaManager(java.lang.String mediaPropsFile,
                     java.lang.String mimePropsFile,
                     java.lang.String serializerPropsFile)
Constructor that initializes all of the property tables. This is equivalent to running a base constructor and setMediaProps(), setMimeProps() and setSerializerProps() afterwards.

Parameters:
mediaPropsFile - location of the media properties file
mimePropsFile - location of the mime properties file
serializerPropsFile - location of the serializer properties file
Method Detail

getMediaManager

public static MediaManager getMediaManager()
7/25/05 - UP-1181 - change MediaManager into a singleton Returns the default MediaManager singleton


setMediaProps

public void setMediaProps(java.lang.String uri)
Initializes media properties table.

Parameters:
uri - location of the media properties file, complete with the filename

setMimeProps

public void setMimeProps(java.lang.String uri)
Initializes mime properties table.

Parameters:
uri - location of the mime properties file, complete with the filename

setSerializerProps

public void setSerializerProps(java.lang.String uri)
Initializes serializer properties table.

Parameters:
uri - location of the serializer properties file, complete with the filename

getMedia

public java.lang.String getMedia(javax.servlet.http.HttpServletRequest req)
Determines a media name from the request object.

Parameters:
req - the request object
Returns:
media name

getMedia

public java.lang.String getMedia(BrowserInfo bi)
Determines a media name from the browser info object.

Parameters:
bi - the browser info
Returns:
media name

getDefaultMedia

public java.lang.String getDefaultMedia()
Return a default media type. The default media type is the first media listed in the media.properties file

Returns:
default media name

getReturnMimeType

public java.lang.String getReturnMimeType(javax.servlet.http.HttpServletRequest req)
Determines a mime name from the request object.

Parameters:
req - the request object
Returns:
mime type string

getReturnMimeType

public java.lang.String getReturnMimeType(java.lang.String mediaType)
Determines a mime name from a media type name.

Parameters:
mediaType - the media type name
Returns:
mime type string

getSerializer

public BaseMarkupSerializer getSerializer(java.lang.String mediaType,
                                          java.io.Writer out)
Determines and configures a serialzier that is proper for the specified media type. "serializer.properties" file contains mapping of media names to serializer names. Prior to using a serializer returned by this function, make sure to set it up by calling asContentHandler(), asDocumentHandler() or asDOMSerializer().

Parameters:
mediaType - media name
out - output writer
Returns:
the serializer

getSerializerByName

public BaseMarkupSerializer getSerializerByName(java.lang.String serializerName,
                                                java.io.OutputStream out)
                                         throws java.io.UnsupportedEncodingException
Gets a serializer by name which writes to the provided OutputStream

Parameters:
serializerName -
out -
Returns:
the serializer
Throws:
java.io.UnsupportedEncodingException

getSerializerByName

public BaseMarkupSerializer getSerializerByName(java.lang.String serializerName,
                                                java.io.Writer out)
Gets a serializer by name which writes to the provided Writer

Parameters:
serializerName -
out -
Returns:
the serializer

getSerializer

public BaseMarkupSerializer getSerializer(java.lang.String mediaType,
                                          java.io.OutputStream out)
                                   throws java.io.UnsupportedEncodingException
Another version of getSerializer() with OutputStream as one of the parameters.

Parameters:
mediaType - media type string
out - output stream
Returns:
the markup serializer
Throws:
java.io.UnsupportedEncodingException

getSerializer

public BaseMarkupSerializer getSerializer(javax.servlet.http.HttpServletRequest req,
                                          java.io.Writer out)
Automatically determines the media type from the request object,

Parameters:
req - the request object
out - the output writer object
Returns:
the markup serializer

getSerializer

public BaseMarkupSerializer getSerializer(javax.servlet.http.HttpServletRequest req,
                                          java.io.OutputStream out)
                                   throws java.io.UnsupportedEncodingException
Automatically determines the media type from the request object,

Parameters:
req - the request object
out - the output stream object
Returns:
the markup serializer
Throws:
java.io.UnsupportedEncodingException