KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > render > macro > list > ExampleListFormatter


1 /*
2  * This file is part of "SnipSnap Radeox Rendering Engine".
3  *
4  * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
5  * All Rights Reserved.
6  *
7  * Please visit http://radeox.org/ for updates and contact.
8  *
9  * --LICENSE NOTICE--
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  * --LICENSE NOTICE--
24  */

25 package org.snipsnap.render.macro.list;
26
27 import java.io.IOException JavaDoc;
28 import java.io.Writer JavaDoc;
29 import java.util.Collection JavaDoc;
30 import java.util.Iterator JavaDoc;
31
32 /**
33  * Tutorial example list formatter.
34  *
35  * @author Stephan J. Schmidt
36  * @version $Id: ExampleListFormatter.java 1606 2004-05-17 10:56:18Z leo $
37  */

38 public class ExampleListFormatter implements ListFormatter {
39   public String JavaDoc getName() {
40     return "number";
41   }
42
43   /**
44    * Create a simple list.
45    */

46   public void format(Writer JavaDoc writer, Linkable current, String JavaDoc listComment, Collection JavaDoc c, String JavaDoc emptyText, boolean showSize)
47       throws IOException JavaDoc {
48     writer.write("<div class=\"list\"><div class=\"list-title\">");
49     writer.write(listComment);
50     if (showSize) {
51       writer.write(" (");
52       writer.write("" + c.size());
53       writer.write(")");
54     }
55     writer.write("</div>");
56     if (c.size() > 0) {
57       writer.write("<ol>");
58       Iterator JavaDoc nameIterator = c.iterator();
59       while (nameIterator.hasNext()) {
60         writer.write("<li>");
61         Object JavaDoc object = nameIterator.next();
62         if (object instanceof Linkable) {
63           writer.write(((Linkable) object).getLink());
64         } else if (object instanceof Nameable) {
65           writer.write(((Nameable) object).getName());
66         } else {
67           writer.write(object.toString());
68         }
69         writer.write("</li>");
70       }
71       writer.write("</ol>");
72     } else {
73       writer.write(emptyText);
74     }
75     writer.write("</div>");
76   }
77 }
78
Popular Tags