KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Simple list formatter.
34  *
35  * @author Matthias L. Jugel
36  * @version $Id: SimpleList.java 1606 2004-05-17 10:56:18Z leo $
37  */

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