com.objectplanet.survey.plugin.api
Class PluginUtil

java.lang.Object
  extended by com.objectplanet.survey.plugin.api.PluginUtil

public class PluginUtil
extends java.lang.Object

Utility class for the plugins.

Author:
Irina Brun
Created:
24. march 2003

Field Summary
static int LOGGING_LEVEL_ERROR
          Loggs only errors.
static int LOGGING_LEVEL_MESSAGE
          Loggs all messages, warnings and errors
static int LOGGING_LEVEL_WARNING
          Loggs all warnings and errors
 
Constructor Summary
PluginUtil()
           
 
Method Summary
static void debug(java.lang.String txt)
          log statements with level = debug.
static void error(java.lang.String txt)
          log statements with level <= error.
static void fatal(java.lang.String txt)
          log statements with level = fatal
static java.lang.String getCharacterEncoding()
          Gets the system character encoding (from setup screen)
static int getDaysUntilExpiration()
          Return days until expirations for the current license.
static int getEdition()
           
static java.lang.String getEditionName(java.lang.String language)
          Get the edition name of the current license
static java.lang.String getExportFileExtension()
          Gets the preferred file extension when exporting files.
static java.lang.String getExportKeepFiles()
          Gets the preferred keep file property.
static java.lang.String getHostId()
          Get the host ID for the current Opinio installation.
static long getLongTime()
          Get long time: return the date attribute of the SystemTime object
static int getMaxUsers()
          Returns max allowed users for the current license.
static java.lang.String getMessage(java.lang.String key, java.lang.String language)
          Get message from i18n resources
static java.lang.String getMessage(java.lang.String key, java.lang.String[] params, java.lang.String language)
          Get message from i18n resources
static java.lang.String getPluginVersion()
          Return the version of the plugin api.
static java.lang.String getSurveySystemVersion()
          Return the version of the survey system.
static java.lang.String getSurveyUrl(javax.servlet.http.HttpServletRequest request, long surveyId)
          Gets the url to the survey module (where respondent answer the survey).
static java.lang.String getSystemHome()
          Get system home: location of the opinio files.
static java.lang.String getSystemUrl(javax.servlet.http.HttpServletRequest request)
          Get system url: Usually looks like http://server-address/opinio
static User getSystemUser()
          Get system user.
static User getUserFromSession(javax.servlet.http.HttpServletRequest request)
          Get the user object from session.
static void info(java.lang.String txt)
          log statements with level <= info.
static boolean isDebugEnabled()
          Return true if debug is enabled.
static boolean isLockedByAnotherUser(long userId, long surveyId)
          Check if survey is locked by another user.
static boolean isNullOrEmpty(java.lang.String string)
          Returns true if string is null or empty
static boolean isUnix()
          Returns true current OS is Unix or Unix-like (For example Linux).
static boolean isWindows()
          Returns true current OS is Windows
static void log(java.lang.String logText, int level)
          Deprecated. This log method is no longer used. Will not log to any file! Use log.debug(), log.info(), log.warn(), log.error(), log.fatal() instead.
static void log(java.lang.Throwable e)
          Deprecated. This log method is no longer used. Will not log to any file! Use log.debug(), log.info(), log.warn(), log.error(), log.fatal() instead.
static void sendEmail(Email email)
          Send email.
static void sendEmail(java.lang.String fromName, java.lang.String fromEmail, java.lang.String toEmail, java.lang.String subject, java.lang.String message, java.lang.String emailType)
          Send email.
static void setLicenseCode(java.lang.String licenseCode)
          Sets the Opinio license code.
static boolean stopAllThreads()
          Stop All Threads: Gets the stop all threads attribute of the System Globals object
static void storeProps(java.util.Properties properties, java.io.File file)
          Stores a property object to an output stream
static void warn(java.lang.String txt)
          log statements with level <= warn
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGING_LEVEL_ERROR

public static final int LOGGING_LEVEL_ERROR
Loggs only errors.

See Also:
Constant Field Values

LOGGING_LEVEL_MESSAGE

public static final int LOGGING_LEVEL_MESSAGE
Loggs all messages, warnings and errors

See Also:
Constant Field Values

LOGGING_LEVEL_WARNING

public static final int LOGGING_LEVEL_WARNING
Loggs all warnings and errors

See Also:
Constant Field Values
Constructor Detail

PluginUtil

public PluginUtil()
Method Detail

getPluginVersion

public static java.lang.String getPluginVersion()
Return the version of the plugin api.

Returns:
The plugin version

getSurveySystemVersion

public static java.lang.String getSurveySystemVersion()
Return the version of the survey system.

Returns:
The version

getEdition

public static int getEdition()

getEditionName

public static java.lang.String getEditionName(java.lang.String language)
Get the edition name of the current license

Parameters:
language -
Returns:
The edition name of the current license.

getMaxUsers

public static int getMaxUsers()
Returns max allowed users for the current license. This is controlled by the license key. If no valid license key is entered, the value will be set to 1.

Returns:
The maxUsers value.

getDaysUntilExpiration

public static int getDaysUntilExpiration()
Return days until expirations for the current license. Returns the int value 0 if the license is invalid, has expired or can't expire (Lite version)

Returns:
The number of days until license expiration

getSurveyUrl

public static java.lang.String getSurveyUrl(javax.servlet.http.HttpServletRequest request,
                                            long surveyId)
                                     throws SurveySystemException
Gets the url to the survey module (where respondent answer the survey). Usually looks like http://server-address/opinio/s?s=surveyId (or customId)

Parameters:
request - Request object
surveyId - Survey id
Returns:
The survey url
Throws:
SurveySystemException - If any error occurs.

getSystemUser

public static User getSystemUser()
Get system user. The user has with full access to all resources.

Returns:
The systemUser value

isLockedByAnotherUser

public static boolean isLockedByAnotherUser(long userId,
                                            long surveyId)
                                     throws SurveySystemException
Check if survey is locked by another user. Returns false if the survey is not locked or locked by current user.

Parameters:
userId - id of current user.
surveyId - id of survey to check lock for.
Returns:
True if survey is locked by another user, false otherwise.
Throws:
SurveySystemException

getUserFromSession

public static User getUserFromSession(javax.servlet.http.HttpServletRequest request)
Get the user object from session.

Parameters:
request - The HttpServletRequest object
Returns:
The user

log

public static void log(java.lang.String logText,
                       int level)
Deprecated. This log method is no longer used. Will not log to any file! Use log.debug(), log.info(), log.warn(), log.error(), log.fatal() instead.

Logs a message. This method is deprecated.

Parameters:
logText - Message to log.
level - Logging level(defined above)

debug

public static void debug(java.lang.String txt)
log statements with level = debug. Logging level in the log4j.properties must be set to debug level to get these messages logged: log4j.logger.com.objectplanet.survey.plugin.api=debug

Parameters:
txt - The text to log

info

public static void info(java.lang.String txt)
log statements with level <= info. Logging level in the log4j.properties must be set to at least info level to get these messages logged: log4j.logger.com.objectplanet.survey.plugin.api=info

Parameters:
txt - The text to log

isDebugEnabled

public static boolean isDebugEnabled()
Return true if debug is enabled.


warn

public static void warn(java.lang.String txt)
log statements with level <= warn

Parameters:
txt - The text to log

error

public static void error(java.lang.String txt)
log statements with level <= error. Logging level in the log4j.properties must be set to at least error level to get these messages logged: log4j.logger.com.objectplanet.survey.plugin.api=error

Parameters:
txt - The text to log.

fatal

public static void fatal(java.lang.String txt)
log statements with level = fatal

Parameters:
txt - Description of the Parameter

log

public static void log(java.lang.Throwable e)
Deprecated. This log method is no longer used. Will not log to any file! Use log.debug(), log.info(), log.warn(), log.error(), log.fatal() instead.

This method is deprecated.

Parameters:
e - Exception to log.

sendEmail

public static void sendEmail(java.lang.String fromName,
                             java.lang.String fromEmail,
                             java.lang.String toEmail,
                             java.lang.String subject,
                             java.lang.String message,
                             java.lang.String emailType)
                      throws java.lang.IllegalArgumentException,
                             javax.mail.internet.AddressException,
                             SurveySystemException
Send email. Main email server should be set before calling this methods or IllegalArgumentException will be thrown.

Parameters:
fromName - Who sends the message (name)
fromEmail - Who sends the message(email address)
toEmail - Recipient's address
subject - The subject of the email
message - The body of the message
emailType - The type and the mmessage (text:"text/plain" or html:"text/html")
Throws:
javax.mail.internet.AddressException - If invalid fromEmail or toEmail
SurveySystemException - If error occurs.
java.lang.IllegalArgumentException - If illegal parameters.

sendEmail

public static void sendEmail(Email email)
                      throws java.lang.IllegalArgumentException,
                             javax.mail.internet.AddressException,
                             SurveySystemException
Send email. Main email server should be set before calling this methods or IllegalArgumentException will be thrown.

Parameters:
Email - Email object
Throws:
SurveySystemException - If error occurs.
java.lang.IllegalArgumentException
javax.mail.internet.AddressException

storeProps

public static void storeProps(java.util.Properties properties,
                              java.io.File file)
                       throws java.io.IOException
Stores a property object to an output stream

Parameters:
properties - The property object to store
file - File to store properties to
Throws:
java.io.IOException - IOException

getExportFileExtension

public static java.lang.String getExportFileExtension()
Gets the preferred file extension when exporting files. This file extension can be set in opinio.properties. Default is zip

Returns:
The extension

getExportKeepFiles

public static java.lang.String getExportKeepFiles()
Gets the preferred keep file property. It determines if files should be kept on disk after exporting raw data. This property can be set in opinio.properties. Default is 'false'

Returns:
The keep file property

getSystemHome

public static java.lang.String getSystemHome()
Get system home: location of the opinio files.

Returns:
The system home

getSystemUrl

public static java.lang.String getSystemUrl(javax.servlet.http.HttpServletRequest request)
Get system url: Usually looks like http://server-address/opinio

Returns:
The system url

getLongTime

public static long getLongTime()
Get long time: return the date attribute of the SystemTime object

Returns:
date

stopAllThreads

public static boolean stopAllThreads()
Stop All Threads: Gets the stop all threads attribute of the System Globals object

Returns:
stop all threads attribute

setLicenseCode

public static void setLicenseCode(java.lang.String licenseCode)
Sets the Opinio license code.

Parameters:
licenseCode - The new license code.

getHostId

public static java.lang.String getHostId()
Get the host ID for the current Opinio installation. This is used to generate the license key by ObjectPlanet.


getCharacterEncoding

public static java.lang.String getCharacterEncoding()
Gets the system character encoding (from setup screen)

Returns:

getMessage

public static java.lang.String getMessage(java.lang.String key,
                                          java.lang.String language)
Get message from i18n resources

Parameters:
message - key
language -
Returns:

getMessage

public static java.lang.String getMessage(java.lang.String key,
                                          java.lang.String[] params,
                                          java.lang.String language)
Get message from i18n resources

Parameters:
message - key
language -
parameters - to the message
Returns:

isNullOrEmpty

public static boolean isNullOrEmpty(java.lang.String string)
Returns true if string is null or empty

Parameters:
string - String to check
Returns:

isWindows

public static boolean isWindows()
Returns true current OS is Windows

Returns:
True if current OS is Windows, false otherwise.

isUnix

public static boolean isUnix()
Returns true current OS is Unix or Unix-like (For example Linux).

Returns:
True if current OS is Unix or Unix-like, false otherwise.

Copyright ? ObjectPlanet Inc. All Rights Reserved.

Built on December 20 2016