KickJava   Java API By Example, From Geeks To Geeks.

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


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.apache.lucene.document.Document;
29 import org.apache.lucene.document.Field;
30 import org.snipsnap.snip.Snip;
31 import org.snipsnap.serialization.LabelContext;
32
33 import java.util.Map JavaDoc;
34
35 /**
36  * Boolean Label for true/false functionality
37  *
38  * @author Matthias L. Jugel
39  * @version $Id: BooleanLabel.java 1606 2004-05-17 10:56:18Z leo $
40  */

41
42 public class BooleanLabel implements Label {
43   protected String JavaDoc name;
44   protected String JavaDoc value;
45   protected Snip snip;
46
47   public BooleanLabel() {
48     name = "";
49     value = "false";
50   }
51
52   public BooleanLabel(String JavaDoc name, String JavaDoc value) {
53     this.name = name;
54     this.value = value;
55   }
56
57   public void create() {
58   }
59
60   public void remove() {
61   }
62
63   public void change() {
64   }
65
66
67   public LabelContext getContext() {
68     return new LabelContext(snip, this);
69   }
70
71   public void setSnip(Snip snip) {
72     this.snip = snip;
73   }
74
75   public Snip getSnip() {
76     return snip;
77   }
78
79   public String JavaDoc getInputProxy() {
80     StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
81     buffer.append("<input type=\"checkbox\" value=\"");
82     buffer.append(value);
83     buffer.append("\" name=\"label.boolean\"/>");
84     return buffer.toString();
85   }
86
87   public String JavaDoc getListProxy() {
88     StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
89     buffer.append("<td>");
90     buffer.append(name);
91     buffer.append("</td><td>");
92     buffer.append(value);
93     buffer.append("</td>");
94     return buffer.toString();
95   }
96
97   protected String JavaDoc checkValue(String JavaDoc value) {
98     String JavaDoc lcValue = value.toLowerCase();
99     if ("true".equals(lcValue) || "yes".equals(lcValue) ||
100         "false".equals(lcValue) || "no".equals(lcValue)) {
101       return lcValue;
102     } else {
103       return "false";
104     }
105   }
106
107   public void handleInput(Map JavaDoc input) {
108     if (input.containsKey("label.boolean")) {
109       this.value = checkValue((String JavaDoc) input.get("label.boolean"));
110     }
111   }
112
113   public String JavaDoc getType() {
114     return "Boolean";
115   }
116
117   public String JavaDoc getName() {
118     return name;
119   }
120
121   public String JavaDoc getValue() {
122     return value;
123   }
124
125   public boolean isTrue() {
126     return "true".equals(value) || "yes".equals(value);
127   }
128
129   public void setName(String JavaDoc name) {
130     this.name = name;
131   }
132
133   public void setValue(String JavaDoc value) {
134     this.value = checkValue(value);
135   }
136
137   public void index(Document document) {
138     //System.out.println("Label index: " + name + ", " + value);
139
document.add(Field.Text(name, "" + value));
140   }
141 }
142
Popular Tags