KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > snip > label > TaxonomyLabel


1 /*
2  * This file is part of "SnipSnap Wiki/Weblog".
3  *
4  * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
5  * All Rights Reserved.
6  *
7  * Please visit http://snipsnap.org/ for updates and contact.
8  *
9  * --LICENSE NOTICE--
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program 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
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  * --LICENSE NOTICE--
24  */

25
26 package org.snipsnap.snip.label;
27
28 import java.util.Collection JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.List JavaDoc;
31
32 import org.snipsnap.app.Application;
33 import org.snipsnap.container.Components;
34 import org.snipsnap.snip.Snip;
35 import org.snipsnap.snip.SnipLink;
36 import org.snipsnap.snip.SnipSpace;
37 import org.snipsnap.snip.SnipSpaceFactory;
38 import org.snipsnap.snip.label.BaseLabel;
39 import org.snipsnap.snip.label.Label;
40 import org.snipsnap.snip.label.Labels;
41 import org.snipsnap.user.AuthenticationService;
42
43 /**
44  *
45  * Taxonomy labels link category-snips to form a taxonomy.
46  * The label links to another snip which is the "parent" of this snip
47  * like OO (parent) -> Java (this)
48  *
49  * @author Franziska Wohl
50  * @version $Id: TaxonomyLabel.java 1606 2004-05-17 10:56:18Z leo $
51  */

52 public class TaxonomyLabel extends BaseLabel {
53
54   public TaxonomyLabel() {
55     name = "Taxonomy";
56     value = "";
57   }
58
59   public TaxonomyLabel(String JavaDoc value) {
60     this();
61     this.value = value;
62   }
63
64   /**
65    * Type of label
66    *
67    * @return
68    */

69   public String JavaDoc getType() {
70     return "TaxonomyLabel";
71   }
72
73   /* Ausgabe der Category-List
74    */

75   public String JavaDoc getInputProxy() {
76     StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
77     SnipSpace snipspace = (SnipSpace) Components.getComponent(SnipSpace.class);
78     List JavaDoc snipList = snipspace.getAll();
79
80     buffer.append("Taxonomy: ");
81
82 // Should be refactored to a TaxonomyBase Label (see Category Label)
83
Iterator JavaDoc iterator = snipList.iterator();
84     buffer.append("<select name=\"label.value\" size=\"1\">");
85     while (iterator.hasNext()) {
86       Snip snip = (Snip) iterator.next();
87       Labels labels = snip.getLabels();
88       boolean noLabelsAll = labels.getAll().isEmpty();
89       if (!noLabelsAll) {
90         Collection JavaDoc LabelsCat;
91         LabelsCat = labels.getLabels("TypeLabel");
92         if (!LabelsCat.isEmpty()) {
93           Iterator JavaDoc iter = LabelsCat.iterator();
94           while (iter.hasNext()) {
95             Label label = (Label) iter.next();
96             if (label.getValue().equals("Category")) {
97               String JavaDoc category = snip.getName();
98               buffer.append("<option>");
99               buffer.append(category);
100               buffer.append("</option>");
101             }
102           }
103         }
104       }
105     }
106     buffer.append("</select>");
107
108     return buffer.toString();
109   }
110
111   public String JavaDoc getListProxy() {
112     StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
113     buffer.append("<td>");
114     buffer.append("Parent:");
115     buffer.append("</td><td>");
116     getSnipLink(buffer, this.value);
117     buffer.append("</td><td>");
118     return buffer.toString();
119   }
120
121   private StringBuffer JavaDoc getSnipLink(StringBuffer JavaDoc buffer, String JavaDoc name) {
122     AuthenticationService service = (AuthenticationService) Components.getComponent(AuthenticationService.class);
123
124     if (SnipSpaceFactory.getInstance().exists(name)) {
125       SnipLink.appendLink(buffer, name, name);
126     } else if (!service.isAuthenticated(Application.get().getUser())) {
127       buffer.append(name);
128     } else {
129       SnipLink.appendCreateLink(buffer, name);
130     }
131     return buffer;
132   }
133 }
134
Popular Tags