📄 servlethelper.java
字号:
public static long getParamAsLong( HttpServletRequest request, String paramName ) throws IncorrectParameterException { String value = getParamAsString( request, paramName, false ); try { return Long.parseLong( value ); } catch( NumberFormatException nfe ) { throw new IncorrectParameterException( paramName, value ); } } /** * Gets all values of the given parameter from HTTP request as long array. * * @param request HTTP request * @param paramName parameter name * @return parameter values * @throws IncorrectParameterException */ public static long[] getAllParamValuesAsLong( HttpServletRequest request, String paramName ) throws IncorrectParameterException { String[] paramValues = getAllParamValuesAsString( request, paramName ); long[] values = new long[paramValues.length]; for( int i = 0; i < paramValues.length; i++ ) { try { values[i] = Long.parseLong( paramValues[i] ); } catch( NumberFormatException nfe ) { throw new IncorrectParameterException( paramName, paramValues[i] ); } } return values; } /** * Gets the parameter value from HTTP request as integer. * * @param request HTTP request * @param paramName parameter name * @return parameter value * @throws IncorrectParameterException */ public static int getParamAsInt( HttpServletRequest request, String paramName ) throws IncorrectParameterException { String value = getParamAsString( request, paramName, false ); try { return Integer.parseInt( value ); } catch( NumberFormatException nfe ) { throw new IncorrectParameterException( paramName, value ); } } /** * Gets the parameter value from HTTP request as boolean. * * @param request HTTP request * @param paramName parameter name * @return parameter value * @throws IncorrectParameterException */ public static boolean getParamAsBoolean( HttpServletRequest request, String paramName ) throws IncorrectParameterException { String value = getParamAsString( request, paramName, false ); return( value == null ) ? false : ( value.equalsIgnoreCase( "1" ) || value.equalsIgnoreCase( "true" ) ); } public static String getInitParamAsString(ServletConfig config, String paramName) throws IncorrectParameterException { String paramValue = config.getInitParameter(paramName); if(paramValue == null) throw new IncorrectParameterException(paramName); return paramValue; } public static long getInitParamAsLong(ServletConfig config, String paramName) throws IncorrectParameterException { String paramValue = config.getInitParameter(paramName); if(paramValue == null) throw new IncorrectParameterException(paramName); return Long.parseLong(paramValue); } public static int getInitParamAsInt(ServletConfig config, String paramName) throws IncorrectParameterException { return Integer.parseInt(getInitParamAsString(config, paramName)); } /** * Gets compound record ID. * * @param req HTTP request * @return CompoundKey object * @throws ServletException */ public static CompoundKey getCompoundRecordId( HttpServletRequest req ) throws ServletException { CompoundKey compoundPkey = new CompoundKey(); compoundPkey.addKey( getParamAsString( req, "recordId", true ) ); String recordId2 = getParamAsString( req, "recordId2", false ); if( !StringHelper.isEmpty( recordId2 ) ) { compoundPkey.addKey( recordId2 ); } String recordId3 = getParamAsString( req, "recordId3", false ); if( !StringHelper.isEmpty( recordId3 ) ) { compoundPkey.addKey( recordId3 ); } String recordId4 = getParamAsString( req, "recordId4", false ); if( !StringHelper.isEmpty( recordId4 ) ) { compoundPkey.addKey( recordId4 ); } return compoundPkey; } /** * Gets EJB reference. * * @param ctx ServletContext * @param jndiName JNDI name * @param homeClass home class * @return remote object */ public static Object getRemoteObject( ServletContext ctx, String jndiName, Class homeClass ) { return getCacheObjectManager( ctx ).getRemoteObject( jndiName, homeClass ); } /** * Gets EJB local reference. * * @param ctx ServletContext * @param jndiName JNDI name * @param homeClass home class * @return local object */ public static Object getLocalObject( ServletContext ctx, String jndiName, Class homeClass ) { return getCacheObjectManager( ctx ).getLocalObject( jndiName, homeClass ); } /** * Gets EJB remote home object. * * @param ctx ServletContext * @param jndiName JNDI name * @param homeClass home class * @return remote home object */ public static Object getRemoteHome( ServletContext ctx, String jndiName, Class homeClass ) { return getCacheObjectManager( ctx ).getRemoteHome( jndiName, homeClass ); } /** * Gets EJB local home interface. * * @param ctx ServletContext * @param jndiName JNDI name * @param homeClass home class * @return local home object */ public static Object getLocalHome( ServletContext ctx, String jndiName, Class homeClass ) { return getCacheObjectManager( ctx ).getLocalHome( jndiName, homeClass ); } /** * Gets Cache manager EJB reference. * * @param ctx ServletContext * @return CacheObjectManager object */ private static CacheObjectManager getCacheObjectManager( ServletContext ctx ) { CacheObjectManager com = null; if( ( com = ( CacheObjectManager ) ctx.getAttribute( ATTR_CACHE_OBJECT ) ) == null ) { synchronized( ctx ) { if( ( com = ( CacheObjectManager ) ctx.getAttribute( ATTR_CACHE_OBJECT ) ) == null ) { com = new CacheObjectManager(); ctx.setAttribute( ATTR_CACHE_OBJECT, com ); } } } return com; } public static String getPopupMenuCaption(ServletContext ctx, String langID, String captionID) { String key = langID + captionID; String strCaption = popupMenuCaptions.getProperty(key); if (strCaption == null) { CaptionManagerLocal cm = ( CaptionManagerLocal ) getLocalObject( ctx, JNDINames.CaptionManager, CaptionManagerLocalHome.class ); strCaption = cm.getPopupMenuCaption( langID, captionID ); popupMenuCaptions.setProperty(key, strCaption); } return strCaption; } public static String getServerMessage(ServletContext ctx, String langID, String captionID) { String key = langID + captionID; String strCaption = serverMessages.getProperty(key); if (strCaption == null) { CaptionManagerLocal cm = ( CaptionManagerLocal ) getLocalObject( ctx, JNDINames.CaptionManager, CaptionManagerLocalHome.class ); strCaption = cm.getServerMessage( langID, captionID ); serverMessages.setProperty(key, strCaption); } return strCaption; } public static String getFocusCaption(ServletContext ctx, String langID, String captionID) { String key = langID + captionID; String strCaption = focusCaptions.getProperty(key); if (strCaption == null) { CaptionManagerLocal cm = ( CaptionManagerLocal ) getLocalObject( ctx, JNDINames.CaptionManager, CaptionManagerLocalHome.class ); strCaption = cm.getServerMessage( langID, captionID ); focusCaptions.setProperty(key, strCaption); } return strCaption; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -