User: user57
Date: 01/10/02 14:34:57
Added: src/main/org/jboss/survey/util Debug.java Helper.java
SurveyPresentation.java UserPresentation.java
Log:
o moved jboss-website/website/survey to jboss-website/survey (it's own
module)
Revision Changes Path
1.1 website-survey/src/main/org/jboss/survey/util/Debug.java
Index: Debug.java
===================================================================
// ----------------------------------------------------------------------------
// File: Debug.java
// Copyright ( c ) 2001 eBuilt, Inc. All rights reserved.
// Version: $Revision: 1.1 $
// Last Checked In: $Date: 2001/10/02 21:34:57 $
// Last Checked In By: $Author: user57 $
// ----------------------------------------------------------------------------
package org.jboss.survey.util;
import java.io.Serializable;
/**
* Debug Constants for the Sony ADOS
*
* @author Andreas Schaefer
* @version $Revision: 1.1 $
**/
public class Debug
{
// -------------------------------------------------------------------------
// Static
// -------------------------------------------------------------------------
public static final int NONE = 0;
public static final int CRITICAL = 1;
public static final int REGULAR = 2;
public static final int VERBOSE = 3;
public static final int LEVEL = CRITICAL;
// -------------------------------------------------------------------------
// Members
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// Constructor
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// Methods
// -------------------------------------------------------------------------
}
// ----------------------------------------------------------------------------
// EOF
1.1 website-survey/src/main/org/jboss/survey/util/Helper.java
Index: Helper.java
===================================================================
// ----------------------------------------------------------------------------
// File: Helper.java
// Copyright ( c ) 2001 eBuilt, Inc. All rights reserved.
// Version: $Revision: 1.1 $
// Last Checked In: $Date: 2001/10/02 21:34:57 $
// Last Checked In By: $Author: user57 $
package org.jboss.survey.util;
// import com.madplanet.web.util.Debug;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.StringTokenizer;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
/**
* Contains some static helper methods
*
* @author Andreas Schaefer
* @version $Revision: 1.1 $
**/
public class Helper
{
// -------------------------------------------------------------------------
// Static
// -------------------------------------------------------------------------
public static SimpleDateFormat sDateFormatter = new SimpleDateFormat(
"MM/dd/yyyy" );
public static int BOGUS_NUMBER = -2;
// -------------------------------------------------------------------------
// Members
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// Constructor
// -------------------------------------------------------------------------
/**
* Default (no-args) constructor
**/
public Helper()
{
}
// -------------------------------------------------------------------------
// Methods
// -------------------------------------------------------------------------
/**
* Looks up and returns the argument from the given request
*
* @param pRequest HTTP Request Object
* @param pName Name of the Parameter to look up
* @param pDefault Default value to be returned if not found or if the found
* parameter is not a valid integer
**/
public static int getIntParameter(
HttpServletRequest pRequest,
String pName,
int pDefault
) {
try
{
String aValue = pRequest.getParameter( pName );
if( aValue != null )
{
return new Integer( aValue ).intValue();
}
}
catch( Exception e )
{
}
return pDefault;
}
public static String getStringParameter(
HttpServletRequest pRequest,
String pName,
String pDefault
) {
try
{
String aValue = pRequest.getParameter( pName );
if( aValue != null )
{
return aValue;
}
}
catch( Exception e )
{
}
return pDefault;
}
public static boolean getBooleanParameter(
HttpServletRequest pRequest,
String pName,
boolean pDefault
) {
try
{
String aValue = pRequest.getParameter( pName );
if( aValue != null )
{
return aValue.equalsIgnoreCase( "true" ) || aValue.equals( "1" ) ||
aValue.equalsIgnoreCase( "on" );
}
}
catch( Exception e )
{
}
return pDefault;
}
public static Date getDateParameter(
HttpServletRequest pRequest,
String pName,
Date pDefault
) {
try
{
String aValue = pRequest.getParameter( pName );
if( aValue != null && checkDate( aValue ) )
{
return sDateFormatter.parse( aValue );
}
}
catch( Exception e )
{
e.printStackTrace( System.err );
}
return pDefault;
}
/**
* Checks to see if a date is in a valid format.
*
* @param pDate The string containing the date to check
* @return Returns true if the date is valid, false otherwise
**/
public static boolean checkDate( String pDate )
{
if( pDate != null )
{
// if date doesn't fit correct format, return null
StringTokenizer aDateTokenizer = new StringTokenizer( pDate, "/" );
int aMonth = aDateTokenizer.hasMoreTokens() ? Integer.parseInt(
aDateTokenizer.nextToken() ) : BOGUS_NUMBER;
int aDate = aDateTokenizer.hasMoreTokens() ? Integer.parseInt(
aDateTokenizer.nextToken() ) : BOGUS_NUMBER;
String aYear = aDateTokenizer.hasMoreTokens() ? aDateTokenizer.nextToken()
: null;
if ( aMonth == BOGUS_NUMBER || aMonth > 12 || aMonth < 1 )
{
System.out.println("Bogus month: " + aMonth);
return false;
}
if ( aDate == BOGUS_NUMBER || aDate > 31 || aDate < 1 )
{
System.out.println("Bogus date: " + aDate);
return false;
}
if ( aYear == null || aYear.length() < 4 )
{
System.out.println("Bogus year: " + aYear);
return false;
}
try
{
sDateFormatter.parse( pDate );
}
catch ( ParseException pPE )
{
System.out.println( "Exception checking date: " + pPE.getMessage() );
return false;
}
// date passed checks
return true;
}
return false;
}
public static Object getAttribute(
HttpServletRequest pRequest,
String pName,
Object pDefault
) {
try
{
Object aValue = pRequest.getAttribute( pName );
if( aValue != null )
{
return aValue;
}
}
catch( Exception e )
{
}
return pDefault;
}
public static int getIntAttribute(
HttpSession pSession,
String pName,
int pDefault
) {
try
{
Object aValue = pSession.getAttribute( pName );
if( aValue instanceof Integer )
{
return ( (Integer) aValue ).intValue();
}
}
catch( Exception e )
{
}
return pDefault;
}
public static String getStringAttribute(
HttpSession pSession,
String pName,
String pDefault
) {
Object aValue = pSession.getAttribute( pName );
if( aValue != null )
{
return aValue + "";
}
return pDefault;
}
public static boolean getBooleanAttribute(
HttpSession pSession,
String pName,
boolean pDefault
) {
try
{
Object aValue = pSession.getAttribute( pName );
if( aValue instanceof Boolean )
{
return ( (Boolean) aValue ).booleanValue();
}
}
catch( Exception e )
{
}
return pDefault;
}
public static Object getAttribute(
HttpSession pSession,
String pName,
Object pDefault
) {
try
{
Object aValue = pSession.getAttribute( pName );
if( aValue != null )
{
return aValue;
}
}
catch( Exception e )
{
}
return pDefault;
}
/**
* Gets the next number from a number generator
*
* @param pName Name of the generator to use
*
* @return Next generated number
*
* @throws ServiceUnavailableException
*/
/*
public static int getGeneratedNumber( String pName )
throws
ServiceUnavailableException
{
try
{
Object aEJBRef = new InitialContext().lookup( "ejb/SequenceGeneratorHome" );
SequenceGeneratorHome aHome = (SequenceGeneratorHome)
PortableRemoteObject.narrow(
aEJBRef,
SequenceGeneratorHome.class
);
SequenceGenerator aGenerator = aHome.create();
return aGenerator.getNextNumber( pName );
}
catch( CreateException ce )
{
ce.printStackTrace( System.err );
throw new ServiceUnavailableException( "Service Object unavailable" );
}
catch( RemoteException re )
{
re.printStackTrace( System.err );
throw new ServiceUnavailableException( "Service unavailable or Network
down" );
}
catch( NamingException ne )
{
ne.printStackTrace( System.err );
throw new ServiceUnavailableException( "Object Lookup is broken" );
}
}
*/
/**
* Formats the given Date to a MM/DD/YYYY
*
* @param pDate Date to be formated
*
* @return Date formated into MM/DD/YYYY or an empty when given date is null
**/
public static String getDateFormat( Date pDate )
{
if( pDate == null )
{
return "";
}
return sDateFormatter.format( pDate );
}
/**
* Checks to make sure that the String passed in contains only alpha-
* numeric characters.
*
* @param pString The string to check
* @return Returns true if the string only contains alphabetical or numeric
* characters, false otherwise
**/
public static boolean isAlphaNumeric( String pString )
{
char[] aChars = pString.toCharArray();
for( int i = 0; i < aChars.length; i++ )
{
char aChar = aChars[ i ];
if ( ! Character.isLetterOrDigit( aChar ) )
{
return false;
}
}
return true;
}
/**
* Checks to make sure that the String passed in contains only alphabetical
* characters.
*
* @param pString The string to check
* @return Returns true if the string consists of only alphabetical
* characters, false otherwise
**/
public static boolean isAlpha( String pString )
{
char[] aChars = pString.toCharArray();
for( int i = 0; i < aChars.length; i++ )
{
char aChar = aChars[ i ];
if ( ! Character.isLetter( aChar ) )
{
return false;
}
}
return true;
}
/**
* Describes the instance and its content for debugging purpose
*
* @return Debugging information about the instance and its content
**/
public String toString()
{
return "Helper [ " + " ]";
}
/**
* Checks if the given instance is the same (same address) as
* this instance.
*
* @return The result from the super class equals() method
**/
public boolean equals( Object pTest )
{
return super.equals( pTest );
}
/**
* Returns the hashcode of this instance
*
* @return Hashcode of its super class
**/
public int hashCode()
{
return super.hashCode();
}
}
// ----------------------------------------------------------------------------
// EOF
1.1
website-survey/src/main/org/jboss/survey/util/SurveyPresentation.java
Index: SurveyPresentation.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.survey.util;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
/**
* Provides the Presentation for Survey Values
*
* @author Andreas Schaefer
* @version $Revision: 1.1 $
**/
public class SurveyPresentation {
// -------------------------------------------------------------------------
// Static
// -------------------------------------------------------------------------
public static final int YES_NO = 0;
public static final int OTHER_SERVER = 1;
// -------------------------------------------------------------------------
// Members
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// Constructor
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// Methods
// -------------------------------------------------------------------------
public String getPresentation(
int pType,
int pValue
) {
String lReturn = "";
switch( pType ) {
case YES_NO:
switch( pValue ) {
case 1:
lReturn = "Yes";
break;
case 0:
lReturn = "No";
break;
default:
lReturn = "None";
}
break;
case OTHER_SERVER:
switch( pValue ) {
case 0:
lReturn = "BEA WebLogic";
break;
case 1:
lReturn = "IBM WebSphere";
break;
case 2:
lReturn = "ATG Dynamo";
break;
case 3:
lReturn = "Sun iPlanet";
break;
case 4:
lReturn = "Borland Inprise";
break;
case 5:
lReturn = "HP/Bluestone";
break;
case 6:
lReturn = "Oracle IIS/Orion";
break;
case 7:
lReturn = "Macromedia JRun";
break;
case 8:
lReturn = "Enhydra/JoNas";
break;
case 9:
lReturn = "Other";
break;
}
}
return lReturn;
}
public String getPresentation(
int pType,
boolean pValue
) {
if( pValue ) {
return "Yes";
} else {
return "No";
}
}
}
// ----------------------------------------------------------------------------
// EOF
1.1
website-survey/src/main/org/jboss/survey/util/UserPresentation.java
Index: UserPresentation.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.survey.util;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
/**
* Provides the Presentation for User Values
*
* @author Andreas Schaefer
* @version $Revision: 1.1 $
**/
public class UserPresentation {
// -------------------------------------------------------------------------
// Static
// -------------------------------------------------------------------------
public static final int YES_NO = 0;
public static final int INDUSTRY_TYPE = 1;
public static final int NR_OF_EMPLOYEES = 2;
public static final int SUPPORT = 3;
// -------------------------------------------------------------------------
// Members
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// Constructor
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// Methods
// -------------------------------------------------------------------------
public String getPresentation(
int pType,
int pValue
) {
String lReturn = "";
switch( pType ) {
case YES_NO:
switch( pValue ) {
case 2:
lReturn = "Yes";
break;
case 1:
lReturn = "No";
break;
default:
lReturn = "None";
}
break;
case INDUSTRY_TYPE:
Collection lList = new ArrayList();
if( ( pValue & 1 ) > 0 ) {
lList.add( "Independent Software Vendor" );
}
if( ( pValue & 2 ) > 0 ) {
lList.add( "System Integration / Consulting" );
}
if( ( pValue & 4 ) > 0 ) {
lList.add( "ISP/ASP Service Provider" );
}
if( ( pValue & 8 ) > 0 ) {
lList.add( "Communications (Telco, Wireless, Internet)" );
}
if( ( pValue & 16 ) > 0 ) {
lList.add( "Education" );
}
if( ( pValue & 32 ) > 0 ) {
lList.add( "Financial Services" );
}
if( ( pValue & 64 ) > 0 ) {
lList.add( "Health Care" );
}
if( ( pValue & 128 ) > 0 ) {
lList.add( "Manufacturing" );
}
if( ( pValue & 256 ) > 0 ) {
lList.add( "Publishing" );
}
if( ( pValue & 512 ) > 0 ) {
lList.add( "Transportation" );
}
if( ( pValue & 1024 ) > 0 ) {
lList.add( "Other" );
}
Iterator i = lList.iterator();
while( i.hasNext() ) {
String lLine = (String) i.next();
if( lReturn.length() == 0 ) {
lReturn = lLine;
} else {
lReturn = lReturn + ", " + lLine;
}
}
break;
case NR_OF_EMPLOYEES:
switch( pValue ) {
case 0:
lReturn = "1 - 25";
break;
case 1:
lReturn = "26 - 51";
break;
case 2:
lReturn = "51 - 100";
break;
case 4:
lReturn = "101 - 1000";
break;
case 40:
lReturn = "over 1000";
break;
}
break;
case SUPPORT:
lList = new ArrayList();
if( ( pValue & 1 ) > 0 ) {
lList.add( "Training" );
}
if( ( pValue & 2 ) > 0 ) {
lList.add( "Support" );
}
if( ( pValue & 4 ) > 0 ) {
lList.add( "Consulting" );
}
if( ( pValue & 8 ) > 0 ) {
lList.add( "Sell Software" );
}
i = lList.iterator();
while( i.hasNext() ) {
String lLine = (String) i.next();
if( lReturn.length() == 0 ) {
lReturn = lLine;
} else {
lReturn = lReturn + ", " + lLine;
}
}
break;
}
return lReturn;
}
}
// ----------------------------------------------------------------------------
// EOF
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development