KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Base class for Labels with simple default behaviour
37  *
38  * @author Stephan J. Schmidt
39  * @version $Id: BaseLabel.java 1263 2003-12-12 08:58:25Z stephan $
40  */

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