//{HEADER
/**
* This class is part of jnex 'Nexirius Application Framework for Java'
*
* Copyright (C) Nexirius GmbH, CH-4450 Sissach, Switzerland (www.nexirius.ch)
*
* <p>This library is free software; you can redistribute it and/or<br>
* modify it under the terms of the GNU Lesser General Public<br>
* License as published by the Free Software Foundation; either<br>
* version 2.1 of the License, or (at your option) any later version.</p>
*
* <p>This library is distributed in the hope that it will be useful,<br>
* but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br>
* Lesser General Public License for more details.</p>
*
* <p>You should have received a copy of the GNU Lesser General Public<br>
* License along with this library; if not, write to the Free Software<br>
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</p>
* </blockquote>
*
* <p>
* Nexirius GmbH, hereby disclaims all copyright interest in<br>
* the library jnex' 'Nexirius Application Framework for Java' written<br>
* by Marcel Baumann.</p>
*/
//}HEADER
package com.nexirius.framework.htmlview;
import com.nexirius.util.VariableAccessor;
import com.nexirius.util.XString;
import com.nexirius.util.StringVector;
import java.io.Serializable;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;
/**
* this class holds an arbitrary number of variables and their translations
*/
public class VariableStore implements VariableAccessor, Serializable {
public static final String FIELDNAME = "FIELDNAME";
public static final String FULLNAME = "FULLNAME";
public static final String HTML_FULLNAME = "HTML_FULLNAME";
public static final String VALUE = "VALUE";
public static final String LABEL = "LABEL";
public static final String TIP = "TIP";
public static final String INDEX = "INDEX";
public static final String OPTION = "OPTION";
public static final String EVENT = "EVENT";
public static final String STATE = "STATE";
public static final String COUNT = "COUNT";
public static final String REQUEST_URL = "REQUEST_URL";
Hashtable variableTable = new Hashtable();
/**
* Set a new value for a variable
*
* @param name the name of the variable
* @param value the value of the variable
* @return the old value which was stored for this variable (or null)
*/
public String setVariable(String name, String value) {
if (name == null) {
return null;
}
if (name.equals(FULLNAME)) {
XString htmlValue = new XString(value);
htmlValue.replace(" ", "+");
htmlValue.replace(";", "%3B");
setVariable(HTML_FULLNAME, htmlValue.toString());
}
String ret = getValueOf(name);
if (value == null) {
variableTable.remove(name);
return ret;
}
variableTable.put(name, value);
return ret;
}
public StringVector getVariableNames() {
StringVector ret = new StringVector();
Enumeration enumeration = variableTable.keys();
while (enumeration.hasMoreElements()) {
String s = (String) enumeration.nextElement();
ret.sortInsert(s);
}
return ret;
}
/**
* returns the value of the variable
*
* @param name the name of the variable
* @return the value or null (if variable was never set with setVariable)
*/
public String getValueOf(String name) {
if (name == null) {
return null;
}
return (String) variableTable.get(name);
}
/**
* use another variable store and save its varibles into this
*
* @param other
*/
public void set(VariableStore other) {
if (other == null) {
return;
}
Enumeration e = other.variableTable.keys();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
setVariable(key, other.getValueOf(key));
}
}
/**
* translates all the properties into variables
*
* @param props
*/
public void set(Properties props) {
if (props == null) {
return;
}
Enumeration e = props.keys();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
setVariable(key, props.getProperty(key));
}
}
}