01: /*
02: * This file is part of "SnipSnap Radeox Rendering Engine".
03: *
04: * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
05: * All Rights Reserved.
06: *
07: * Please visit http://radeox.org/ for updates and contact.
08: *
09: * --LICENSE NOTICE--
10: * Licensed under the Apache License, Version 2.0 (the "License");
11: * you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software
17: * distributed under the License is distributed on an "AS IS" BASIS,
18: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19: * See the License for the specific language governing permissions and
20: * limitations under the License.
21: * --LICENSE NOTICE--
22: */
23: package org.radeox.macro.list;
24:
25: import java.io.IOException;
26: import java.io.Writer;
27: import java.util.Collection;
28: import java.util.Iterator;
29:
30: import org.radeox.util.Linkable;
31: import org.radeox.util.Nameable;
32:
33: /**
34: * Simple list formatter.
35: *
36: * @author Matthias L. Jugel
37: * @version $Id: SimpleList.java 7756 2006-04-13 12:25:49Z ian@caret.cam.ac.uk $
38: */
39: public class SimpleList implements ListFormatter {
40: public String getName() {
41: return "simple";
42: }
43:
44: public void format(Writer writer, Linkable current,
45: String listComment, Collection c, String emptyText,
46: boolean showSize) throws IOException {
47: writer.write("<div class=\"list\"><div class=\"list-title\">");
48: writer.write(listComment);
49: if (showSize) {
50: writer.write(" (");
51: writer.write("" + c.size());
52: writer.write(")");
53: }
54: writer.write("</div>");
55: if (c.size() > 0) {
56: writer.write("<blockquote>");
57: Iterator nameIterator = c.iterator();
58: while (nameIterator.hasNext()) {
59: Object object = nameIterator.next();
60: if (object instanceof Linkable) {
61: writer.write(((Linkable) object).getLink());
62: } else if (object instanceof Nameable) {
63: writer.write(((Nameable) object).getName());
64: } else {
65: writer.write(object.toString());
66: }
67:
68: if (nameIterator.hasNext()) {
69: writer.write(", ");
70: }
71: }
72: writer.write("</blockquote>");
73: } else {
74: writer.write(emptyText);
75: }
76: writer.write("</div>");
77: }
78: }
|