KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.snipsnap.app.Application;
29 import org.snipsnap.container.Components;
30 import org.snipsnap.snip.SnipLink;
31 import org.snipsnap.snip.SnipSpaceFactory;
32 import org.snipsnap.user.AuthenticationService;
33
34 /**
35  * SnipLabel connects a Snip to another Snip (should it be possible to reference more than one Snip?)
36  * @author Stephan J. Schmidt
37  * @version $Id: SnipLabel.java 1013 2003-09-29 07:41:13Z leo $
38  */

39 public class SnipLabel extends BaseLabel {
40     public SnipLabel() {
41         super();
42     }
43
44     public SnipLabel(String JavaDoc name, String JavaDoc value) {
45         super(name, value);
46     }
47
48     public String JavaDoc getType() {
49         return "SnipLabel";
50     }
51
52     public String JavaDoc getInputProxy() {
53         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
54         buffer.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"2\">");
55         buffer.append("<tr>");
56         buffer.append("<td>Name: </td>");
57         buffer.append("<td><input type=\"text\" value=\"");
58         buffer.append(name);
59         buffer.append("\" name=\"label.name\"/></td>");
60         buffer.append("</tr><tr>");
61         buffer.append("<td>Link target (Snip): </td>");
62         buffer.append("<td><input type=\"text\" value=\"");
63         buffer.append(value);
64         buffer.append("\" name=\"label.value\"/></td>");
65         buffer.append("</tr></table>");
66         return buffer.toString();
67     }
68
69     public String JavaDoc getSnipLink() {
70         // for now, assume value is exactly the linked Snip name ...
71
return value;
72     }
73
74     public String JavaDoc[] getSnipLinks() {
75         // for now, assume value is exactly the linked Snip name ...
76
return new String JavaDoc[] { value };
77     }
78
79   public String JavaDoc getListProxy() {
80     StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
81     buffer.append("<td>");
82     buffer.append(name);
83     buffer.append("</td><td>");
84     getSnipLink(buffer, value);
85     buffer.append("</td>");
86     return buffer.toString();
87   }
88
89   private StringBuffer JavaDoc getSnipLink(StringBuffer JavaDoc buffer, String JavaDoc name) {
90     // @TODO: move this to SnipLink or Snip
91
AuthenticationService service = (AuthenticationService) Components.getComponent(AuthenticationService.class);
92
93     if (SnipSpaceFactory.getInstance().exists(name)) {
94       SnipLink.appendLink(buffer, name, name);
95     } else if (!service.isAuthenticated(Application.get().getUser())) {
96       buffer.append(name);
97     } else {
98       SnipLink.appendCreateLink(buffer, name);
99     }
100     return buffer;
101   }
102 }
103
Popular Tags