01: /*
02: * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/publishing/markups/TKMarkupCharParamClass.java,v 1.5 2000/05/22 15:01:27 careck Exp $
03: *
04: */
05: package com.teamkonzept.publishing.markups;
06:
07: public class TKMarkupCharParamClass extends TKMarkupParamClass {
08:
09: public String checkValue(String raw) {
10:
11: if (raw == null)
12: return raw;
13:
14: String value = raw.trim();
15:
16: if (value.length() == 1)
17: return value;
18: else
19: return null;
20: }
21:
22: public int parseUnquotedValue(String text, int pos,
23: StringBuffer value) throws TKMarkupParserException {
24:
25: if (value != null)
26: value.setLength(0);
27:
28: int oldPos = pos;
29: pos = parsePattern(text, pos, null, "'");
30: if (pos <= oldPos)
31: return oldPos;
32:
33: if (pos < text.length()) {
34:
35: char chr = text.charAt(pos);
36:
37: if ((chr == '\\') && (pos + 1 < text.length())) {
38:
39: if (value == null)
40: pos++;
41: else
42: value.append(text.charAt(++pos));
43:
44: } else if (value != null)
45: value.append(chr);
46:
47: pos++;
48: }
49:
50: int nextOldPos = pos;
51: pos = parsePattern(text, pos, null, "'");
52:
53: if (pos <= nextOldPos)
54: return oldPos;
55: else
56: return pos;
57: }
58:
59: public String wrapValue(String value) {
60:
61: if ((value == null) || (value.length() == 0))
62: return null;
63:
64: StringBuffer buf = new StringBuffer();
65:
66: char chr = value.charAt(0);
67:
68: if (chr == '\'')
69: return "'\\''";
70: else if (chr == '\'')
71: return "'\\\\'";
72:
73: buf.append('\'').append(chr).append('\'');
74:
75: return buf.toString();
76: }
77: }
|