01: /* ****************************************************************************
02: * ChainedException.java
03: * ****************************************************************************/
04:
05: /* J_LZ_COPYRIGHT_BEGIN *******************************************************
06: * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
07: * Use is subject to license terms. *
08: * J_LZ_COPYRIGHT_END *********************************************************/
09:
10: package org.openlaszlo.utils;
11:
12: import java.text.*;
13: import java.util.*;
14:
15: public class ListFormat extends Format {
16: protected final String junction;
17:
18: public ListFormat(String junction) {
19: this .junction = junction;
20: }
21:
22: public ListFormat() {
23: this ("and");
24: }
25:
26: public StringBuffer format(Object obj, StringBuffer buffer,
27: FieldPosition pos) {
28: List list = (List) obj;
29: int listSize = list.size();
30: for (ListIterator iter = list.listIterator(); iter.hasNext();) {
31: if (iter.hasPrevious()) {
32: if (listSize > 2)
33: buffer.append(',');
34: buffer.append(' ');
35: if (iter.nextIndex() == listSize - 1) {
36: buffer.append(junction);
37: buffer.append(' ');
38: }
39: }
40: buffer.append(iter.next());
41: }
42: return buffer;
43: }
44:
45: public Object parseObject(String source, ParsePosition parsePosition) {
46: throw new RuntimeException(
47: /* (non-Javadoc)
48: * @i18n.test
49: * @org-mes="unimplemented functionality"
50: */
51: org.openlaszlo.i18n.LaszloMessages.getMessage(ListFormat.class
52: .getName(), "051018-52"));
53: }
54: }
|