📄 cmsflexcachekey.java
字号:
}
}
}
str.append(")");
}
if (m_schemes != null) {
String s = (String)key.m_schemes.iterator().next();
if ((m_schemes.size() > 0) && (! m_schemes.contains(s.toLowerCase()))) return null;
str.append("schemes=(");
str.append(s);
str.append(");");
}
if (m_ports != null) {
Integer i = (Integer)key.m_ports.iterator().next();
if ((m_ports.size() > 0) && (! m_ports.contains(i))) return null;
str.append("ports=(");
str.append(i);
str.append(");");
}
if (m_timeout > 0) {
str.append("timeout=(");
str.append(m_timeout);
str.append(");");
}
return str.toString();
}
/**
* @see java.lang.Object#toString()
*
* @return a complete String representation for this key
*/
public String toString() {
StringBuffer str = new StringBuffer(100);
if (m_always < 0) {
str.append("never");
if (m_parseError) {
str.append(";parse-error");
}
return str.toString();
}
if (m_noparams != null) {
// Add "no-cachable" parameters
if (m_noparams.size() == 0) {
str.append("no-params;");
} else {
str.append("no-params=(");
Iterator i = m_noparams.iterator();
while (i.hasNext()) {
Object o = i.next();
str.append(o);
if (i.hasNext()) str.append(",");
}
str.append(");");
}
}
if (m_always > 0) {
str.append("always");
if (m_parseError) {
str.append(";parse-error");
}
return str.toString();
}
if (m_uri != null) {
if (m_uri.equals("uri")) {
str.append("uri;");
} else {
str.append("uri=(");
str.append(m_uri);
str.append(");");
}
}
if (m_user >= 0) {
// Add user data
if (m_user == Integer.MAX_VALUE) {
str.append("user;");
} else {
str.append("user=(");
str.append(m_user);
str.append(");");
}
}
if (m_groups != null) {
// Add group data
if (m_groups.size() == 0) {
str.append("groups;");
} else {
str.append("groups=(");
Iterator i = m_groups.iterator();
while (i.hasNext()) {
str.append(i.next());
if (i.hasNext()) str.append(",");
}
str.append(");");
}
}
if (m_params != null) {
// Add parameters
if (m_params.size() == 0) {
str.append("params;");
} else {
str.append("params=(");
Iterator i = m_params.keySet().iterator();
while (i.hasNext()) {
Object o = i.next();
str.append(o);
try {
// TODO: handle multiple occurences of the same parameter value
String param[] = (String[])m_params.get(o);
if (! "&?&".equals(param[0])) {
str.append("=");
str.append(param[0]);
}
} catch(Exception e) {
if (DEBUG) System.err.println("Exception! o=" + o + " Exception is " + e );
}
if (i.hasNext()) str.append(",");
}
str.append(");");
}
}
if (m_timeout >= 0) {
// Add timeout
str.append("timeout=(");
str.append(m_timeout);
str.append(");");
}
if (m_publish) {
// Add publish parameters
str.append("publish-clear;");
}
if (m_schemes != null) {
// Add schemes
if (m_schemes.size() == 0) {
str.append("schemes;");
} else {
str.append("schemes=(");
Iterator i = m_schemes.iterator();
while (i.hasNext()) {
str.append(i.next());
if (i.hasNext()) str.append(",");
}
str.append(");");
}
}
if (m_ports != null) {
// Add ports
if (m_ports.size() == 0) {
str.append("ports;");
} else {
str.append("ports=(");
Iterator i = m_ports.iterator();
while (i.hasNext()) {
str.append(i.next());
if (i.hasNext()) str.append(",");
}
str.append(");");
}
}
if (m_parseError) {
str.append("parse-error;");
}
return str.toString();
}
/**
* Parse a String in the Flex cache language and construct
* the key data structure from this.<p>
*
* @param key the String to parse (usually read from the file property "cache")
*/
private void parseFlexKey(String key) {
java.util.StringTokenizer toker = new java.util.StringTokenizer(key,";");
try {
while (toker.hasMoreElements()) {
String t = toker.nextToken();
String k = null;
String v = null;
int idx = t.indexOf("=");
if (idx >= 0) {
k = t.substring(0, idx).trim();
if (t.length() > idx) v = t.substring(idx+1).trim();
} else {
k = t.trim();
}
m_always = 0;
if (DEBUG) System.err.println("Parsing token:" + t + " key=" + k + " value=" + v);
switch (cacheCmds.indexOf(k)) {
case 0: // always
case 13:
m_always = 1;
// Continue processing (make sure we find a "never" behind "always")
break;
case 1: // never
case 11:
m_always = -1;
// No need for any further processing
return;
case 2: // uri
m_uri = "uri";
// being != null is enough
break;
case 3: // user
m_user = Integer.MAX_VALUE;
// being > 0 is enough
break;
case 4: // groups
if (v != null) {
// A list of groups is present
m_groups = parseValueMap(v).keySet();
} else {
// Cache all groups
m_groups = new java.util.HashSet(0);
}
break;
case 5: // params
m_params = parseValueMap(v);
break;
case 6: // no-params
if (v != null) {
// No-params are present
m_noparams = parseValueMap(v).keySet();
} else {
// Never cache with parameters
m_noparams = new java.util.HashSet(0);
}
break;
case 7: // timeout
m_timeout = Integer.parseInt(v);
break;
case 8: // publish
m_publish = true;
break;
case 9: // schemes
m_schemes = parseValueMap(v).keySet();
break;
case 10: // ports
m_ports = parseValueMap(v).keySet();
break;
case 12: // previous parse error - ignore
break;
default: // unknown directive, throw error
m_parseError = true;
}
}
} catch (Exception e) {
// Any Exception here indicates a parsing error
if (DEBUG) System.err.println("----- Error in key parsing: " + e.toString());
m_parseError = true;
}
if (m_parseError) {
// If string is invalid set cache to "never"
m_always = -1;
}
}
/**
* A helper method for the parsing process which parses
* Strings like groups=(a, b, c).<p>
*
* @param value the String to parse
* @return a Map that contains of the parsed values, only the keyset of the Map is needed later
*/
private java.util.Map parseValueMap(String value) {
if (value.charAt(0) == '(') value = value.substring(1);
int len;
if (value.charAt(len = (value.length()-1)) == ')') value = value.substring(0, len);
if (value.charAt(len-1) == ',') value = value.substring(0, len-1);
if (DEBUG) System.err.println("Parsing map: " + value);
java.util.StringTokenizer toker = new java.util.StringTokenizer(value, ",");
java.util.Map result = new java.util.HashMap();
while (toker.hasMoreTokens()) {
result.put(toker.nextToken().trim(), new String[] { "&?&" } );
}
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -