it.eng.spagobi.commons.utilities
Class GeneralUtilities

java.lang.Object
  extended by it.eng.spagobi.commons.utilities.GeneralUtilities

public class GeneralUtilities
extends java.lang.Object

Contains some SpagoBI's general utilities.


Field Summary
static int MAX_DEFAULT_TEMPLATE_SIZE
           
static java.lang.String SPAGOBI_HOST
           
 
Constructor Summary
GeneralUtilities()
           
 
Method Summary
static java.lang.String checkForSystemProperty(java.lang.String input)
          Checks if the String in input contains a reference to System property with the syntax ${property_name}, and, in case, substitutes the reference with the actual value.
static java.lang.String cleanString(java.lang.String original)
          Cleans a string from spaces and tabulation characters.
static it.eng.spago.security.IEngUserProfile createNewUserProfile(java.lang.String userId)
          Creates a new user profile, given his identifier.
static java.lang.String decode(java.lang.String input)
          Questo metodo implementa la stessa logica della funzione javascript escape.
static boolean deleteContentDir(java.io.File dir)
          Delete contents of a directory.
static boolean deleteDir(java.io.File dir)
          Delete a folder and its contents.
static java.lang.String encode(java.lang.String input)
          Questo metodo implementa la stessa logica della funzione javascript escape.
static java.lang.String[] findAttributeValues(java.lang.String attributeValue)
          Find the attribute values in case of multi value attribute.
static java.lang.String findUserId(javax.servlet.http.HttpServletRequest httpRequest)
          Finds the user identifier from http request or from SSO system (by the http request in input).
static java.lang.String findUserId(it.eng.spago.base.SourceBean serviceRequest, javax.servlet.http.HttpServletRequest httpRequest)
          Finds the user identifier from service request or from SSO system (by the http request in input).
static void flushFromInputStreamToOutputStream(java.io.InputStream is, java.io.OutputStream os, boolean closeStreams)
          Given an InputStream as input flushs the content into an OutputStream and then close the input and output stream.
static java.lang.String fromListToString(java.util.List values, java.lang.String separator)
          From list to string.
static java.util.HashMap getAllProfileAttributes(it.eng.spago.security.IEngUserProfile profile)
          Gets the all profile attributes.
static byte[] getByteArrayFromInputStream(java.io.InputStream is)
          Given an InputStream as input, gets the correspondent bytes array.
static java.util.Locale getDefaultLocale()
          Gets the default locale.
static java.lang.String getLocalIPAddressAsString()
          Returns a string containing the localhost IP address.
static java.lang.String getLovMapResult(java.util.Map lovs)
          Gets the lov map result.
static java.lang.String getLovResult(java.lang.String lovLabel)
          Gets the lov result.
static java.lang.String getLovResult(java.lang.String lovLabel, it.eng.spago.security.IEngUserProfile profile)
          Gets the lov result.
static java.lang.String getRelativeFileNames(java.lang.String completeFileName)
          From a String identifying the complete name for a file, gets the relative file names, which are substrings of the starting String, according to the java separator "/".
static java.lang.String getSpagoAdapterHttpUrl()
          Gets the spago adapter http url.
static java.lang.String getSpagoBiContext()
          Returns the context for SpagoBI
static java.lang.String getSpagoBiDashboardServlet()
          Gets the spagoBI's dashboards servlet information as a string.
static java.lang.String getSpagoBiHost()
          Returns the address for SpagoBI as an URL and puts it into a string.
static java.lang.String getSpagoBIProfileBaseUrl(java.lang.String userId)
          Returns the complete HTTP URL and puts it into a string.
static int getTemplateMaxSize()
           
static boolean isErrorHandlerContainingOnlyValidationError(it.eng.spago.error.EMFErrorHandler errorHandler)
          Checks if the Spago errorHandler contains only validation errors.
static void main(java.lang.String[] args)
          The Main method.
static java.lang.String quote(java.lang.String s)
          Quote.
static java.lang.String replace(java.lang.String toParse, java.lang.String replacing, java.lang.String replaced)
          Questo metodo permette di sostituire una parte di una stringa con un'altra.
static java.lang.String replaceInternationalizedMessages(java.lang.String message)
          Substitutes the substrings with sintax "${code,bundle}" or "${code}" (in the second case bundle is assumed to be the default value "messages") with the correspondent internationalized messages in the input String.
static void subsituteBIObjectParametersLovProfileAttributes(BIObject obj, it.eng.spago.base.SessionContainer session)
          Subsitute bi object parameters lov profile attributes.
static java.lang.String substituteParametersInString(java.lang.String statement, java.util.Map valuesMap)
          Substitutes parameters with sintax "$P{parameter_name}" whose value is set in the map.
static java.lang.String substituteProfileAttributesInString(java.lang.String statement, it.eng.spago.security.IEngUserProfile profile)
          Substitutes the profile attributes with sintax "${attribute_name}" with the correspondent value in the string passed at input.
static java.lang.String substituteQuotesIntoString(java.lang.String value)
          Substitute quotes into string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_DEFAULT_TEMPLATE_SIZE

public static final int MAX_DEFAULT_TEMPLATE_SIZE
See Also:
Constant Field Values

SPAGOBI_HOST

public static java.lang.String SPAGOBI_HOST
Constructor Detail

GeneralUtilities

public GeneralUtilities()
Method Detail

main

public static void main(java.lang.String[] args)
The Main method.

Parameters:
args - String for command line arguments

getSpagoAdapterHttpUrl

public static java.lang.String getSpagoAdapterHttpUrl()
Gets the spago adapter http url.

Returns:
the spago adapter http url

getDefaultLocale

public static java.util.Locale getDefaultLocale()
Gets the default locale.

Returns:
the default locale

cleanString

public static java.lang.String cleanString(java.lang.String original)
Cleans a string from spaces and tabulation characters.

Parameters:
original - The input string
Returns:
The cleaned string

isErrorHandlerContainingOnlyValidationError

public static boolean isErrorHandlerContainingOnlyValidationError(it.eng.spago.error.EMFErrorHandler errorHandler)
Checks if the Spago errorHandler contains only validation errors.

Parameters:
errorHandler - The error handler to check
Returns:
true if the errorHandler contains only validation error, false if erroHandler is empty or contains not only validation error.

getByteArrayFromInputStream

public static byte[] getByteArrayFromInputStream(java.io.InputStream is)
Given an InputStream as input, gets the correspondent bytes array.

Parameters:
is - The input straeam
Returns:
An array of bytes obtained from the input stream.

flushFromInputStreamToOutputStream

public static void flushFromInputStreamToOutputStream(java.io.InputStream is,
                                                      java.io.OutputStream os,
                                                      boolean closeStreams)
Given an InputStream as input flushs the content into an OutputStream and then close the input and output stream.

Parameters:
is - The input stream
os - The output stream
closeStreams - the close streams

getRelativeFileNames

public static java.lang.String getRelativeFileNames(java.lang.String completeFileName)
From a String identifying the complete name for a file, gets the relative file names, which are substrings of the starting String, according to the java separator "/".

Parameters:
completeFileName - The string representing the file name
Returns:
relative names substring

getLocalIPAddressAsString

public static java.lang.String getLocalIPAddressAsString()
Returns a string containing the localhost IP address.

Returns:
The IP address String

getSpagoBiContext

public static java.lang.String getSpagoBiContext()
Returns the context for SpagoBI

Returns:
A String with SpagoBI's context

getSpagoBiHost

public static java.lang.String getSpagoBiHost()
Returns the address for SpagoBI as an URL and puts it into a string. The information contained are the Server name and port. Before saving, both them are written into the output console.

Returns:
A String with SpagoBI's adderss

getSpagoBIProfileBaseUrl

public static java.lang.String getSpagoBIProfileBaseUrl(java.lang.String userId)
Returns the complete HTTP URL and puts it into a string.

Parameters:
userId - the user id
Returns:
A String with complete HTTP Url

getSpagoBiDashboardServlet

public static java.lang.String getSpagoBiDashboardServlet()
Gets the spagoBI's dashboards servlet information as a string.

Returns:
A string containing spagoBI's dashboards servlet information

substituteParametersInString

public static java.lang.String substituteParametersInString(java.lang.String statement,
                                                            java.util.Map valuesMap)
                                                     throws java.lang.Exception
Substitutes parameters with sintax "$P{parameter_name}" whose value is set in the map.

Parameters:
statement - The string to be modified (tipically a query)
valuesMap - Map name-value
Returns:
The statement with profile attributes replaced by their values.
Throws:
java.lang.Exception - the exception

substituteProfileAttributesInString

public static java.lang.String substituteProfileAttributesInString(java.lang.String statement,
                                                                   it.eng.spago.security.IEngUserProfile profile)
                                                            throws java.lang.Exception
Substitutes the profile attributes with sintax "${attribute_name}" with the correspondent value in the string passed at input.

Parameters:
statement - The string to be modified (tipically a query)
profile - The IEngUserProfile object
Returns:
The statement with profile attributes replaced by their values.
Throws:
java.lang.Exception - the exception

quote

public static java.lang.String quote(java.lang.String s)
Quote.

Parameters:
s - the s
Returns:
the string

findAttributeValues

public static java.lang.String[] findAttributeValues(java.lang.String attributeValue)
                                              throws java.lang.Exception
Find the attribute values in case of multi value attribute. The sintax is: {splitter character{list of values separated by the splitter}}. Examples: {;{value1;value2;value3....}} {|{value1|value2|value3....}}

Parameters:
attributeValue - The String representing the list of attribute values
Returns:
The array of attribute values
Throws:
java.lang.Exception - in case of sintax error

getAllProfileAttributes

public static java.util.HashMap getAllProfileAttributes(it.eng.spago.security.IEngUserProfile profile)
                                                 throws it.eng.spago.error.EMFInternalError
Gets the all profile attributes.

Parameters:
profile - the profile
Returns:
the all profile attributes
Throws:
it.eng.spago.error.EMFInternalError - the EMF internal error

deleteDir

public static boolean deleteDir(java.io.File dir)
Delete a folder and its contents.

Parameters:
dir - The java file object of the directory
Returns:
the result of the operation

deleteContentDir

public static boolean deleteContentDir(java.io.File dir)
Delete contents of a directory.

Parameters:
dir - The java file object of the directory
Returns:
the result of the operation

replaceInternationalizedMessages

public static java.lang.String replaceInternationalizedMessages(java.lang.String message)
Substitutes the substrings with sintax "${code,bundle}" or "${code}" (in the second case bundle is assumed to be the default value "messages") with the correspondent internationalized messages in the input String. This method calls PortletUtilities.getMessage(key, bundle).

Parameters:
message - The string to be modified
Returns:
The message with the internationalized substrings replaced.

replace

public static java.lang.String replace(java.lang.String toParse,
                                       java.lang.String replacing,
                                       java.lang.String replaced)
Questo metodo permette di sostituire una parte di una stringa con un'altra.

Parameters:
toParse - stringa da manipolare.
replacing - parte di stringa da sostituire.
replaced - stringa nuova.
Returns:
the string

encode

public static java.lang.String encode(java.lang.String input)
Questo metodo implementa la stessa logica della funzione javascript escape.

Parameters:
input - stringa da manipolare.
Returns:
the string

decode

public static java.lang.String decode(java.lang.String input)
Questo metodo implementa la stessa logica della funzione javascript escape.

Parameters:
input - stringa da manipolare.
Returns:
the string

subsituteBIObjectParametersLovProfileAttributes

public static void subsituteBIObjectParametersLovProfileAttributes(BIObject obj,
                                                                   it.eng.spago.base.SessionContainer session)
                                                            throws java.lang.Exception,
                                                                   it.eng.spago.error.EMFInternalError
Subsitute bi object parameters lov profile attributes.

Parameters:
obj - the obj
session - the session
Throws:
java.lang.Exception - the exception
it.eng.spago.error.EMFInternalError - the EMF internal error

substituteQuotesIntoString

public static java.lang.String substituteQuotesIntoString(java.lang.String value)
Substitute quotes into string.

Parameters:
value - the value
Returns:
the string

getLovMapResult

public static java.lang.String getLovMapResult(java.util.Map lovs)
Gets the lov map result.

Parameters:
lovs - the lovs
Returns:
the lov map result

getLovResult

public static java.lang.String getLovResult(java.lang.String lovLabel)
                                     throws java.lang.Exception
Gets the lov result.

Parameters:
lovLabel - the lov label
Returns:
the lov result
Throws:
java.lang.Exception - the exception

getLovResult

public static java.lang.String getLovResult(java.lang.String lovLabel,
                                            it.eng.spago.security.IEngUserProfile profile)
                                     throws java.lang.Exception
Gets the lov result.

Parameters:
lovLabel - the lov label
profile - the profile
Returns:
the lov result
Throws:
java.lang.Exception - the exception

fromListToString

public static java.lang.String fromListToString(java.util.List values,
                                                java.lang.String separator)
From list to string.

Parameters:
values - the values
separator - the separator
Returns:
the string

createNewUserProfile

public static it.eng.spago.security.IEngUserProfile createNewUserProfile(java.lang.String userId)
                                                                  throws java.lang.Exception
Creates a new user profile, given his identifier.

Parameters:
userId - The user identifier
Returns:
The newly created user profile
Throws:
java.lang.Exception - the exception

findUserId

public static java.lang.String findUserId(javax.servlet.http.HttpServletRequest httpRequest)
                                   throws java.lang.Exception
Finds the user identifier from http request or from SSO system (by the http request in input). If SSO is enabled, the identifier specified on http request must be equal to the user identifier detected by the SSO system. In case the http request does not contain the user identifier and SSO in disabled, null is returned.

Parameters:
httpRequest - The http request
Returns:
the current user unique identified
Throws:
java.lang.Exception - in case the SSO is enabled and the user identifier specified on http request is different from the SSO detected one.

findUserId

public static java.lang.String findUserId(it.eng.spago.base.SourceBean serviceRequest,
                                          javax.servlet.http.HttpServletRequest httpRequest)
                                   throws java.lang.Exception
Finds the user identifier from service request or from SSO system (by the http request in input). If SSO is enabled, the identifier specified on service request must be equal to the user identifier detected by the SSO system. In case the service request does not contain the user identifier and SSO in disabled, null is returned.

Parameters:
httpRequest - The http request
serviceRequest - the service request
Returns:
the current user unique identified
Throws:
java.lang.Exception - in case the SSO is enabled and the user identifier specified on service request is different from the SSO detected one.

checkForSystemProperty

public static java.lang.String checkForSystemProperty(java.lang.String input)
Checks if the String in input contains a reference to System property with the syntax ${property_name}, and, in case, substitutes the reference with the actual value.

Returns:
the string with reference to System property replaced with actual value.

getTemplateMaxSize

public static int getTemplateMaxSize()