001: /*
002: * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/publishing/markups/TKMarkupParam.java,v 1.6 2000/06/01 15:02:56 alex Exp $
003: *
004: */
005: package com.teamkonzept.publishing.markups;
006:
007: import com.teamkonzept.lib.*;
008:
009: public class TKMarkupParam implements TKSortable {
010:
011: public String name;
012:
013: // bitte NICHT ˆffentlich machen
014: private String value;
015:
016: public TKMarkupParam(String name, String value) {
017:
018: this .name = name.toUpperCase();
019: this .value = value;
020: }
021:
022: public TKMarkupParam(TKMarkupParam param) {
023:
024: this .name = param.name;
025: this .value = param.value();
026: }
027:
028: public static String paramValue(TKHashtable params, String id) {
029:
030: if ((params == null) || (id == null))
031: return null;
032:
033: TKMarkupParam param = (TKMarkupParam) params.get(id
034: .toUpperCase());
035: return param == null ? null : param.value();
036: }
037:
038: public String wrapUntypedValue() {
039:
040: if (value() == null)
041: return null;
042:
043: else if (TKMarkupParser.quotingRequired(value()))
044:
045: return TKMarkupParser.par2quotes(value());
046:
047: else
048: return value();
049: }
050:
051: public String wrapValue() {
052:
053: return wrapUntypedValue();
054: }
055:
056: public String toString() {
057:
058: if (value() == null)
059: return name;
060:
061: StringBuffer buf = new StringBuffer();
062:
063: buf.append(name).append('=').append(wrapValue());
064:
065: return new String(buf);
066: }
067:
068: public String toId() {
069:
070: if (value() == null)
071: return name;
072:
073: StringBuffer buf = new StringBuffer();
074:
075: buf.append(name).append('=').append(wrapUntypedValue());
076:
077: return new String(buf);
078: }
079:
080: public String convert2Tmpl() {
081:
082: if (value() == null)
083: return name;
084:
085: StringBuffer buf = new StringBuffer();
086: buf.append(name).append('=').append(
087: TKMarkupParser.par2tmpl(value()));
088:
089: return new String(buf);
090: }
091:
092: public String convert2Xml() {
093:
094: if (value() == null)
095: return name;
096:
097: StringBuffer buf = new StringBuffer();
098: buf.append(name).append('=').append(wrapValue());
099:
100: return new String(buf);
101: }
102:
103: public int cmp(TKSortable other) {
104:
105: if (!(other instanceof TKMarkupParam))
106: return toString().compareTo(other.toString());
107:
108: TKMarkupParam otherParam = (TKMarkupParam) other;
109:
110: if ((name == null) && (otherParam.name != null))
111: return -1;
112: else if ((name != null) && (otherParam.name == null))
113: return 1;
114: else if ((name == null) && (otherParam.name == null))
115: return 0;
116: else
117: return name.compareTo(otherParam.name);
118: };
119:
120: public String value() {
121:
122: if (value == null)
123: return null;
124: if (value.length() == 0)
125: value = null;
126: return value;
127: }
128:
129: public void setValue(String newValue) {
130:
131: if ((newValue == null) || (newValue.length() == 0))
132: value = null;
133: else
134: value = newValue;
135: }
136: //{{DECLARE_CONTROLS
137: //}}
138: }
|