📄 jspmyadminvar.java
字号:
/*
* jspMyAdminVar.java 0.6 2001/08/25
* Copyright (c) 2001 zsolyfree@yahoo.com under the GPL (www.gnu.org/copyleft/)
*
* TERMS OF USAGE:
* This file was written and developed by Zsolt Mali (zsolyfree@yahoo.com)
* for educational and demonstration purposes only. You have all rights to use,
* modify, and redistribute this file as you like. The only
* requirement is that you must retain this notice, without modifications, at
* the top of your source code. No warranties or guarantees are expressed or
* implied. DO NOT use this code in a production environment without
* understanding the limitations and weaknesses pretaining to or caused by the
* use of these scripts, directly or indirectly. USE AT YOUR OWN RISK!
*/
package com.jspmyadmin;
import java.util.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.jsp.*;
import javax.servlet.http.*;
public class jspMyAdminVar {
/**
* Class description goes here.
*
* @version 0.9 2001/07/02 23:22:28
* @author Zsolt Mali
*/
Hashtable parameters = new Hashtable();
PageContext page ;
/**
* constructor jspMyAdminVar
*
* @author Zsolt Mali
* @param page the PageContext object of the current page
*/
public jspMyAdminVar ( PageContext pagesource) {
this.page=pagesource;
reLoad();
}//end constructor --> jspMyAdminVar
/**
* ReLoad all the existent parameters from a page
*
*
* @author Zsolt Mali
*/
public void reLoad() {
this.parameters.clear();
parseParameters( this.page, this.page.SESSION_SCOPE );
parseParameters( this.page);
parseParameters( this.page.getRequest() );
}//end method --> public void reLoad()
/**
* this is for testing scope only
*
*
* @author Zsolt Mali
*/
public void test() {
Enumeration e=retKeys();
while ( e.hasMoreElements() ) {
try {
Object key = e.nextElement();
this.page.getOut().println((String)key + "=" + get( key ).toString() + "<br>");
}
catch (IOException ex) {
System.out.println("Unable to write");
}
}
}//end method --> public void test()
/**
* Return all the keys from the Hashtable
*
*
* @author Zsolt Mali
*/
public Enumeration retKeys() {
return this.parameters.keys();
}//end method --> public Enumeration retKeys()
/**
* Return all the values from the Hashtable
*
*
* @author Zsolt Mali
*/
public Enumeration retValues() {
return this.parameters.elements();
}//end method --> public Enumeration retValues()
/**
* Return true if the specified key exist in the parameters
* else return false
*
*
* @author Zsolt Mali
* @param key the searched key
*/
public boolean existKey( Object key ) {
return this.parameters.containsKey( key );
}//end method --> public boolean existKey()
/**
* Return true if the specified value exist in the parameters
* else return false
*
*
* @author Zsolt Mali
* @param value the searched value
*/
public boolean existValue( Object value ) {
return this.parameters.contains( value );
}//end method --> public boolean existValue()
/**
* Return true if the specified key exist in the parameters and his value is not "" or null
* else return false
*
*
* @author Zsolt Mali
* @param value the searched value
*/
public boolean notEmpty( Object key ) {
if ( (this.parameters.containsKey( key )) && (get(key)!=null) && (!((Object)get(key)).toString().equals(""))) {
return true;
}
return false;
}//end method --> public boolean existValue()
/**
* If exist the specified key in the list returns his value, else returns null
*
*
* @author Zsolt Mali
* @param key the searched key
*/
public Object get( Object key ) {
if ( this.parameters.containsKey( key ) != false ) {
return this.parameters.get( key );
}
else {
return null;
}
}//end method --> public Object get()
/**
* If exist the specified key in the list returns his String value, else returns null
*
*
* @author Zsolt Mali
* @param key the searched key
*/
public String get( String key ) {
if ( this.parameters.containsKey( key ) != false ) {
return (String)this.parameters.get( key );
}
else {
return null;
}
}//end method --> public Object get()
/**
* If exist the specified key in the list returns his int value, else returns null
*
*
* @author Zsolt Mali
* @param key the searched key
*/
public int getInt( String key ) throws NumberFormatException {
if ( this.parameters.containsKey( key ) != false ) {
return Integer.parseInt((String)this.parameters.get( key ));
}
else {
return 0;
}
}//end method --> public Object get()
/**
* Append a new key --> value pair to hashtable
*
*
* @author Zsolt Mali
* @param key the key
* @param value the value of the key
*/
public void set( Object key, Object value ) {
this.parameters.put( key, value);
}//end method --> public void set( Object key, Object value)
/**
* Append a new key --> value pair to hashtable and to request object
*
*
* @author Zsolt Mali
* @param key the key
* @param value the value of the key
*/
public void setRequestAttribute( String key, Object value ) {
this.parameters.put( key, value);
this.page.getRequest().setAttribute(key , value);
}//end method --> public void setRequestAttribute( Object key, Object value)
/**
* Parse the request object of the PageContext and makes/adds keys and
* value pairs to a Hashtable
*
* @author Zsolt Mali
* @param request the request object
*/
public void parseParameters(ServletRequest request) {
Enumeration en = request.getAttributeNames();
while ( en.hasMoreElements() ) {
String name = (String)en.nextElement();
Object value = request.getAttribute(name);
if ( value != null ) {
parameters.put(name,value);
}
}
Enumeration enum = request.getParameterNames();
while ( enum.hasMoreElements() ) {
String name = (String)enum.nextElement();
String value = request.getParameter(name);
if ( !value.equals("") ) {
parameters.put(name,value);
}
}
}//end method --> public void parseParameters(ServletRequest request)
/**
* Parse the session object of a PageContext and makes/adds keys and
* to a Hashtable
*
* @author Zsolt Mali
* @param session the session object
*/
public void parseParameters( HttpSession session ) {
String[] enum = session.getValueNames();
for (int i=0 ; i<enum.length ; i++ ) {
String name = enum[i];
Object value = session.getValue(name);
if ( value != null ) {
parameters.put(name,value);
}
}
}//end method --> public void parseParameters( HttpSession session )
/**
* Parse the PageContext and makes/adds attributenames and values
* to a Hashtable
*
* @author Zsolt Mali
* @param page the PageContext object
*/
public void parseParameters( PageContext page ) {
Enumeration enum = page.getAttributeNamesInScope(page.PAGE_SCOPE);
while ( enum.hasMoreElements() ) {
String name = (String)enum.nextElement();
Object value = page.getAttribute(name);
if ( value != null ) {
parameters.put(name,value);
}
}
}//end method --> public void parseParameters( page session )
/**
* Parse the PageContext and makes/adds attributenames and values
* to a Hashtable
*
* @author Zsolt Mali
* @param page the PageContext object
*/
public void parseParameters( PageContext page, int scope ) {
Enumeration enum = page.getAttributeNamesInScope(scope);
while ( enum.hasMoreElements() ) {
String name = (String)enum.nextElement();
Object value = page.getAttribute(name , scope);
if ( value != null ) {
parameters.put(name,value);
}
}
}//end method --> public void parseParameters( page session )
}//end class jspMyAdminVar
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -