com.endeca.portlet.util
Class EndecaPortletUtil

java.lang.Object
  extended by com.endeca.portlet.util.EndecaPortletUtil

public class EndecaPortletUtil
extends java.lang.Object

Author:
Endeca Technologies, Inc. Contains various utility methods used by EndecaPortlet.

Constructor Summary
EndecaPortletUtil()
           
 
Method Summary
static java.lang.String getApplicationContextPath(javax.portlet.PortletRequest request)
          Get the context path for the specified application
static java.lang.String getApplicationDataSourceId(javax.servlet.http.HttpServletRequest request)
          Retrieves the value of the data source for the current application
static DataSource getDataSource(javax.portlet.PortletRequest request)
          Retrieve the DataSource that this portlet listens to.
static java.util.Map<java.lang.String,java.lang.String> getDataSourceDisplayNameMap(java.util.Map<java.lang.String,MDEXState> originalDataSourceMap)
          Function to resolve duplicate DataSource names for display.
static java.lang.String getDataSourceId(javax.portlet.PortletRequest request)
          Retrieve the dataSourceId of the data source that this portlet listens to.
static java.lang.String getDefaultDataSourceId()
          Retrieves the value of the default data source
static java.lang.String getDefaultLocale(Container container)
          Returns the default locale for the container.
static java.lang.String getDisplayName(DataSource dataSource, java.lang.String key)
          Retrieves the global display name for the specified attribute
static java.lang.String getDisplayName(DataSource dataSource, java.lang.String key, java.util.Locale locale)
          Retrieves the locale display name for the specified attribute
static java.lang.String getDisplayName(javax.portlet.PortletRequest request, java.lang.String key)
          Retrieves the global display name for the specified attribute
static java.lang.String getDisplayName(javax.portlet.PortletRequest request, java.lang.String key, java.util.Locale locale)
          Retrieves the locale display name for the specified attribute
static java.lang.String getFullyQualifiedTransitionContext(javax.portlet.PortletRequest request, java.lang.String viewTransitionPageContext)
          Returns a fully-qualified target page context path.
static java.lang.String getRequestLocale(javax.portlet.PortletRequest request, Container container)
          Returns the locale to be used for the current request.
static java.util.List<com.endeca.mdex.sconfig._2010.types.SemanticEntity> getSemanticEntities(DataSource dataSource)
          Get Semantic entities (Data views).
static java.util.List<com.endeca.mdex.sconfig._2010.types.SemanticEntity> getSemanticEntities(DataSource dataSource, boolean forceUncached)
          Get Semantic entities (Data views).
static boolean hasPrivilege(javax.portlet.PortletRequest request, Container container, java.lang.String privilege)
           
static boolean hasUpdatePrivileges(javax.portlet.PortletRequest request, Container container)
           
static boolean hasViewPrivileges(javax.portlet.PortletRequest request, Container container)
           
static boolean isLiferay(Container container)
           
static void writeErrorMessageResponse(java.lang.String message, javax.portlet.RenderResponse response)
          Convenience method for outputting a message directly to a render response.
static void writeErrorMessageResponse(java.lang.String message, javax.portlet.ResourceResponse response)
           
static void writeErrorObjectResponse(java.lang.Object obj, javax.portlet.ResourceResponse response)
          Sets the HTTP status code of a response to 500 and logs an error message
static void writeJSONArrayResponse(org.json.JSONArray jsonArr, javax.portlet.ResourceResponse response)
          Convenience method for outputting a JSONArray to a resource response.
static void writeJSONResponse(org.json.JSONObject jsonObj, javax.portlet.RenderResponse response)
          Deprecated. Should use writeObjectResponse
static void writeJSONResponse(org.json.JSONObject jsonObj, javax.portlet.RenderResponse response, java.lang.String callback)
          Deprecated. Should use writeObjectResponse
static void writeJSONResponse(org.json.JSONObject jsonObj, javax.portlet.ResourceResponse response)
          Deprecated. Should use writeObjectResponse
static void writeJSONResponse(org.json.JSONObject jsonObj, javax.portlet.ResourceResponse response, java.lang.String callback)
          Deprecated. Should use writeObjectResponse
static void writeMessageResponse(java.lang.String message, javax.portlet.RenderResponse response)
          Convenience method for outputting a message directly to a render response.
static void writeMessageResponse(java.lang.String message, javax.portlet.ResourceResponse response)
           
static void writeObjectResponse(java.lang.Object obj, javax.portlet.RenderResponse response)
          Convenience method for outputting an Object to a render response.
static void writeObjectResponse(java.lang.Object obj, javax.portlet.RenderResponse response, java.lang.Class<?> view)
           
static void writeObjectResponse(java.lang.Object obj, javax.portlet.RenderResponse response, java.lang.Class<?> view, org.codehaus.jackson.map.ObjectMapper mapper)
           
static void writeObjectResponse(java.lang.Object obj, javax.portlet.RenderResponse response, java.lang.Class<?> view, java.lang.String callback)
           
static void writeObjectResponse(java.lang.Object obj, javax.portlet.RenderResponse response, java.lang.Class<?> view, java.lang.String callback, org.codehaus.jackson.map.ObjectMapper mapper)
          Convenience method for outputting an Object to a render response, with the name of a JavaScript callback function to be appended to the response.
static void writeObjectResponse(java.lang.Object obj, javax.portlet.RenderResponse response, org.codehaus.jackson.map.ObjectMapper mapper)
           
static void writeObjectResponse(java.lang.Object obj, javax.portlet.RenderResponse response, java.lang.String callback)
           
static void writeObjectResponse(java.lang.Object obj, javax.portlet.RenderResponse response, java.lang.String callback, org.codehaus.jackson.map.ObjectMapper mapper)
           
static void writeObjectResponse(java.lang.Object obj, javax.portlet.ResourceResponse response)
           
static void writeObjectResponse(java.lang.Object obj, javax.portlet.ResourceResponse response, java.lang.Class<?> view)
           
static void writeObjectResponse(java.lang.Object obj, javax.portlet.ResourceResponse response, java.lang.Class<?> view, org.codehaus.jackson.map.ObjectMapper mapper)
           
static void writeObjectResponse(java.lang.Object obj, javax.portlet.ResourceResponse response, java.lang.Class<?> view, java.lang.String callback)
           
static void writeObjectResponse(java.lang.Object obj, javax.portlet.ResourceResponse response, java.lang.Class<?> view, java.lang.String callback, org.codehaus.jackson.map.ObjectMapper mapper)
          Convenience method for outputting an Object to a resource response, with the name of a JavaScript callback function to be appended to the response.
static void writeObjectResponse(java.lang.Object obj, javax.portlet.ResourceResponse response, org.codehaus.jackson.map.ObjectMapper mapper)
           
static void writeObjectResponse(java.lang.Object obj, javax.portlet.ResourceResponse response, java.lang.String callback)
           
static void writeObjectResponse(java.lang.Object obj, javax.portlet.ResourceResponse response, java.lang.String callback, org.codehaus.jackson.map.ObjectMapper mapper)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EndecaPortletUtil

public EndecaPortletUtil()
Method Detail

hasPrivilege

public static boolean hasPrivilege(javax.portlet.PortletRequest request,
                                   Container container,
                                   java.lang.String privilege)

hasUpdatePrivileges

public static boolean hasUpdatePrivileges(javax.portlet.PortletRequest request,
                                          Container container)

hasViewPrivileges

public static boolean hasViewPrivileges(javax.portlet.PortletRequest request,
                                        Container container)

isLiferay

public static boolean isLiferay(Container container)

getDataSource

public static DataSource getDataSource(javax.portlet.PortletRequest request)
Retrieve the DataSource that this portlet listens to. Returns null if the data source could not be retrieved.

Parameters:
request - the current request
Returns:
the DataSource

getDataSourceId

public static java.lang.String getDataSourceId(javax.portlet.PortletRequest request)
Retrieve the dataSourceId of the data source that this portlet listens to.

Parameters:
request - the current request
Returns:
the dataSourceId

getDisplayName

public static java.lang.String getDisplayName(javax.portlet.PortletRequest request,
                                              java.lang.String key)
Retrieves the global display name for the specified attribute

Parameters:
request -
key -
Returns:

getDisplayName

public static java.lang.String getDisplayName(javax.portlet.PortletRequest request,
                                              java.lang.String key,
                                              java.util.Locale locale)
Retrieves the locale display name for the specified attribute

Parameters:
request - the current request
key - the attribute for which to fetch a display name
locale - the locale key
Returns:
the display name for the attribute, or the attribute name if no display name was found

getDisplayName

public static java.lang.String getDisplayName(DataSource dataSource,
                                              java.lang.String key)
Retrieves the global display name for the specified attribute

Parameters:
dataSource -
key -
Returns:

getDisplayName

public static java.lang.String getDisplayName(DataSource dataSource,
                                              java.lang.String key,
                                              java.util.Locale locale)
Retrieves the locale display name for the specified attribute

Parameters:
dataSource - the current datasource
key - the attribute for which to fetch a display name
locale - the locale parameter
Returns:
the display name for the attribute, or the attribute name if no display name was found

getDefaultLocale

public static java.lang.String getDefaultLocale(Container container)
Returns the default locale for the container.

Parameters:
container - the current container
Returns:
the locale

getRequestLocale

public static java.lang.String getRequestLocale(javax.portlet.PortletRequest request,
                                                Container container)
Returns the locale to be used for the current request.

Parameters:
request - the request
container - the current container
Returns:
the locale

getApplicationDataSourceId

public static java.lang.String getApplicationDataSourceId(javax.servlet.http.HttpServletRequest request)
Retrieves the value of the data source for the current application

Returns:
the default data source

getApplicationContextPath

public static java.lang.String getApplicationContextPath(javax.portlet.PortletRequest request)
Get the context path for the specified application

Parameters:
request -
Returns:

getDefaultDataSourceId

public static java.lang.String getDefaultDataSourceId()
Retrieves the value of the default data source

Returns:
the default data source

getFullyQualifiedTransitionContext

public static java.lang.String getFullyQualifiedTransitionContext(javax.portlet.PortletRequest request,
                                                                  java.lang.String viewTransitionPageContext)
Returns a fully-qualified target page context path. The method always interprets links configured by the power use as relative to the current application (regardless of whether they begin with a slash or not)


writeJSONResponse

public static void writeJSONResponse(org.json.JSONObject jsonObj,
                                     javax.portlet.RenderResponse response)
                              throws java.io.IOException
Deprecated. Should use writeObjectResponse

Convenience method for outputting a JSONObject to a render response.

Parameters:
jsonObj - the JSON Object
response - the resource response
Throws:
java.io.IOException

writeJSONResponse

public static void writeJSONResponse(org.json.JSONObject jsonObj,
                                     javax.portlet.ResourceResponse response)
                              throws java.io.IOException
Deprecated. Should use writeObjectResponse

Convenience method for outputting a JSONObject to a resource response.

Parameters:
jsonObj - the JSON Object
response - the resource response
Throws:
java.io.IOException

writeJSONResponse

public static void writeJSONResponse(org.json.JSONObject jsonObj,
                                     javax.portlet.RenderResponse response,
                                     java.lang.String callback)
                              throws java.io.IOException
Deprecated. Should use writeObjectResponse

Convenience method for outputting a JSONObject to a render response, with the name of a JavaScript callback function to be appended to the JSON response.

Parameters:
jsonObj - the JSON Object
response - the render response
callback - the name of the JavaScript callback function
Throws:
java.io.IOException

writeJSONResponse

public static void writeJSONResponse(org.json.JSONObject jsonObj,
                                     javax.portlet.ResourceResponse response,
                                     java.lang.String callback)
                              throws java.io.IOException
Deprecated. Should use writeObjectResponse

Convenience method for outputting a JSONObject to a resource response, with the name of a JavaScript callback function to be appended to the JSON response.

Parameters:
jsonObj - the JSON Object
response - the resource response
callback - the name of the JavaScript callback function
Throws:
java.io.IOException

writeObjectResponse

public static void writeObjectResponse(java.lang.Object obj,
                                       javax.portlet.RenderResponse response)
                                throws java.io.IOException
Convenience method for outputting an Object to a render response.

Parameters:
obj - the Object
response - the resource response
Throws:
java.io.IOException

writeObjectResponse

public static void writeObjectResponse(java.lang.Object obj,
                                       javax.portlet.ResourceResponse response)
                                throws java.io.IOException
Throws:
java.io.IOException

writeObjectResponse

public static void writeObjectResponse(java.lang.Object obj,
                                       javax.portlet.RenderResponse response,
                                       java.lang.Class<?> view)
                                throws java.io.IOException
Throws:
java.io.IOException

writeObjectResponse

public static void writeObjectResponse(java.lang.Object obj,
                                       javax.portlet.ResourceResponse response,
                                       java.lang.Class<?> view)
                                throws java.io.IOException
Throws:
java.io.IOException

writeObjectResponse

public static void writeObjectResponse(java.lang.Object obj,
                                       javax.portlet.RenderResponse response,
                                       java.lang.String callback)
                                throws java.io.IOException
Throws:
java.io.IOException

writeObjectResponse

public static void writeObjectResponse(java.lang.Object obj,
                                       javax.portlet.ResourceResponse response,
                                       java.lang.String callback)
                                throws java.io.IOException
Throws:
java.io.IOException

writeObjectResponse

public static void writeObjectResponse(java.lang.Object obj,
                                       javax.portlet.RenderResponse response,
                                       org.codehaus.jackson.map.ObjectMapper mapper)
                                throws java.io.IOException
Throws:
java.io.IOException

writeObjectResponse

public static void writeObjectResponse(java.lang.Object obj,
                                       javax.portlet.ResourceResponse response,
                                       org.codehaus.jackson.map.ObjectMapper mapper)
                                throws java.io.IOException
Throws:
java.io.IOException

writeObjectResponse

public static void writeObjectResponse(java.lang.Object obj,
                                       javax.portlet.RenderResponse response,
                                       java.lang.Class<?> view,
                                       java.lang.String callback)
                                throws java.io.IOException
Throws:
java.io.IOException

writeObjectResponse

public static void writeObjectResponse(java.lang.Object obj,
                                       javax.portlet.ResourceResponse response,
                                       java.lang.Class<?> view,
                                       java.lang.String callback)
                                throws java.io.IOException
Throws:
java.io.IOException

writeObjectResponse

public static void writeObjectResponse(java.lang.Object obj,
                                       javax.portlet.RenderResponse response,
                                       java.lang.Class<?> view,
                                       org.codehaus.jackson.map.ObjectMapper mapper)
                                throws java.io.IOException
Throws:
java.io.IOException

writeObjectResponse

public static void writeObjectResponse(java.lang.Object obj,
                                       javax.portlet.ResourceResponse response,
                                       java.lang.Class<?> view,
                                       org.codehaus.jackson.map.ObjectMapper mapper)
                                throws java.io.IOException
Throws:
java.io.IOException

writeObjectResponse

public static void writeObjectResponse(java.lang.Object obj,
                                       javax.portlet.RenderResponse response,
                                       java.lang.String callback,
                                       org.codehaus.jackson.map.ObjectMapper mapper)
                                throws java.io.IOException
Throws:
java.io.IOException

writeObjectResponse

public static void writeObjectResponse(java.lang.Object obj,
                                       javax.portlet.ResourceResponse response,
                                       java.lang.String callback,
                                       org.codehaus.jackson.map.ObjectMapper mapper)
                                throws java.io.IOException
Throws:
java.io.IOException

writeObjectResponse

public static void writeObjectResponse(java.lang.Object obj,
                                       javax.portlet.RenderResponse response,
                                       java.lang.Class<?> view,
                                       java.lang.String callback,
                                       org.codehaus.jackson.map.ObjectMapper mapper)
                                throws java.io.IOException
Convenience method for outputting an Object to a render response, with the name of a JavaScript callback function to be appended to the response.

Parameters:
obj - the Object
response - the render response
callback - the name of the JavaScript callback function
mapper - the ObjectMapper for the object. If null, a generic object mapper is used.
Throws:
java.io.IOException

writeObjectResponse

public static void writeObjectResponse(java.lang.Object obj,
                                       javax.portlet.ResourceResponse response,
                                       java.lang.Class<?> view,
                                       java.lang.String callback,
                                       org.codehaus.jackson.map.ObjectMapper mapper)
                                throws java.io.IOException
Convenience method for outputting an Object to a resource response, with the name of a JavaScript callback function to be appended to the response.

Parameters:
obj - the Object
response - the resource response
callback - the name of the JavaScript callback function
mapper - the ObjectMapper for the object. If null, a generic object mapper is used.
Throws:
java.io.IOException

writeMessageResponse

public static void writeMessageResponse(java.lang.String message,
                                        javax.portlet.RenderResponse response)
                                 throws java.io.IOException
Convenience method for outputting a message directly to a render response.

Parameters:
obj - the Object
response - the resource response
Throws:
java.io.IOException

writeMessageResponse

public static void writeMessageResponse(java.lang.String message,
                                        javax.portlet.ResourceResponse response)
                                 throws java.io.IOException
Throws:
java.io.IOException

writeErrorObjectResponse

public static void writeErrorObjectResponse(java.lang.Object obj,
                                            javax.portlet.ResourceResponse response)
                                     throws java.io.IOException,
                                            javax.portlet.PortletException
Sets the HTTP status code of a response to 500 and logs an error message

Throws:
javax.portlet.PortletException
java.io.IOException

writeErrorMessageResponse

public static void writeErrorMessageResponse(java.lang.String message,
                                             javax.portlet.RenderResponse response)
                                      throws java.io.IOException
Convenience method for outputting a message directly to a render response.

Parameters:
obj - the Object
response - the resource response
Throws:
java.io.IOException

writeErrorMessageResponse

public static void writeErrorMessageResponse(java.lang.String message,
                                             javax.portlet.ResourceResponse response)
                                      throws java.io.IOException
Throws:
java.io.IOException

writeJSONArrayResponse

public static void writeJSONArrayResponse(org.json.JSONArray jsonArr,
                                          javax.portlet.ResourceResponse response)
                                   throws java.io.IOException
Convenience method for outputting a JSONArray to a resource response.

Parameters:
jsonArr - the JSON Array
response - the resource response
Throws:
java.io.IOException

getDataSourceDisplayNameMap

public static java.util.Map<java.lang.String,java.lang.String> getDataSourceDisplayNameMap(java.util.Map<java.lang.String,MDEXState> originalDataSourceMap)
Function to resolve duplicate DataSource names for display. If two or more dataSources have the same name, then their display name is appended with the dataSourceId. The output is a map of DataSource Id/DisplayName pairs.

Parameters:
originalDataSourceMap - Map having dataSource Id/MDEXState pairs.
Returns:
Map having dataSource Id/non-unique display name

getSemanticEntities

public static java.util.List<com.endeca.mdex.sconfig._2010.types.SemanticEntity> getSemanticEntities(DataSource dataSource)
                                                                                              throws javax.portlet.PortletException
Get Semantic entities (Data views). And sort type is: The base view is first, followed by an alphabetic sort of the views by the View's Display Name.

Parameters:
dataSource -
Returns:
Throws:
javax.portlet.PortletException

getSemanticEntities

public static java.util.List<com.endeca.mdex.sconfig._2010.types.SemanticEntity> getSemanticEntities(DataSource dataSource,
                                                                                                     boolean forceUncached)
                                                                                              throws javax.portlet.PortletException
Get Semantic entities (Data views). And sort type is: The base view is first, followed by an alphabetic sort of the views by the View's Display Name.

Parameters:
dataSource -
forceUncached -
Returns:
Throws:
javax.portlet.PortletException