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: * Tutorial example list formatter.
35: *
36: * @author Stephan J. Schmidt
37: * @version $Id: ExampleListFormatter.java 7707 2006-04-12 17:30:19Z
38: * ian@caret.cam.ac.uk $
39: */
40: public class ExampleListFormatter implements ListFormatter {
41: public String getName() {
42: return "number";
43: }
44:
45: /**
46: * Create a simple list.
47: */
48: public void format(Writer writer, Linkable current,
49: String listComment, Collection c, String emptyText,
50: boolean showSize) throws IOException {
51: writer.write("<div class=\"list\"><div class=\"list-title\">");
52: writer.write(listComment);
53: if (showSize) {
54: writer.write(" (");
55: writer.write("" + c.size());
56: writer.write(")");
57: }
58: writer.write("</div>");
59: if (c.size() > 0) {
60: writer.write("<ol>");
61: Iterator nameIterator = c.iterator();
62: while (nameIterator.hasNext()) {
63: writer.write("<li>");
64: Object object = nameIterator.next();
65: if (object instanceof Linkable) {
66: writer.write(((Linkable) object).getLink());
67: } else if (object instanceof Nameable) {
68: writer.write(((Nameable) object).getName());
69: } else {
70: writer.write(object.toString());
71: }
72: writer.write("</li>");
73: }
74: writer.write("</ol>");
75: } else {
76: writer.write(emptyText);
77: }
78: writer.write("</div>");
79: }
80: }
|