package lava.net.common; import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; /** * **/ public final class ModifierParser { /** * **/ private ModifierParser() { } /** * **/ public final static Vector parseHeader(VariableNormalizer normalizer, // String raw) { Vector header = new Vector(); char previousGlyph = 0; char glyph = 0; boolean inGlyph = true; StringBuffer previousName = null; StringBuffer name = null; boolean inName = false; StringBuffer value = null; int i = 0, j; char ch; if(raw == null || raw.length() <= 0) return header; if(raw.charAt(raw.length() - 1) != VariableModifier.EOL) raw = raw + String.valueOf(VariableModifier.EOL); while(i < raw.length()) { ch = raw.charAt(i++); if(ch == VariableModifier.EOL) { do { if(glyph == VariableModifier.VALUE_SEPARATOR && // VariableModifier.isGlyph(previousGlyph)) if(previousGlyph == VariableModifier.GLYPH_SET || // previousGlyph == VariableModifier.GLYPH_ASSIGN) glyph = VariableModifier.GLYPH_AUGMENT; else glyph = previousGlyph; if(!VariableModifier.isGlyph(glyph)) break; if(name == null || name.length() <= 0) name = previousName; if(name == null || name.length() <= 0) break; header.addElement(new VariableModifier(glyph,// normalizer.normalizeVariableName(name.toString()),// value == null ? null : new Value(value.toString()))); } while(false); inGlyph = true; inName = false; previousGlyph = glyph; glyph = 0; previousName = name; name = null; value = null; continue; } if(inGlyph) { glyph = ch; inGlyph = false; inName = true; name = new StringBuffer(); } else if(inName) { if(ch == VariableModifier.VALUE_SEPARATOR) { inName = false; value = new StringBuffer(); } else name.append(ch); } else value.append(ch); } return header; } /** * **/ public final static String writeHeader(Vector modifiers) { if(modifiers == null || modifiers.size() <= 0) return ""; StringBuffer raw = new StringBuffer(); VariableModifier modifier; Value value; String v; for(Enumeration e = modifiers.elements();e.hasMoreElements();) { modifier = (VariableModifier)e.nextElement(); value = modifier.getValue(); v = value != null ? value.toString() : null; raw.append(modifier.getGlyph()); raw.append(modifier.getName()); if(v != null && v.length() > 0) { raw.append(VariableModifier.VALUE_SEPARATOR); raw.append(v); } raw.append(VariableModifier.EOL); } return raw.toString(); } /** * **/ public final static String writeHeader(Hashtable tempVars) { if(tempVars == null || tempVars.size() <= 0) return ""; StringBuffer raw = new StringBuffer(); String name; Object value; String v; for(Enumeration e = tempVars.keys();e.hasMoreElements();) { name = (String)e.nextElement(); value = tempVars.get(name); v = value == null ? null : value.toString(); raw.append(VariableModifier.GLYPH_SET); raw.append(name); if(v != null && v.length() > 0) { raw.append(VariableModifier.VALUE_SEPARATOR); raw.append(v); } raw.append(VariableModifier.EOL); } return raw.toString(); } }