1 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 ; 34 35 41 42 public abstract class BaseLabel implements Label { 43 protected String name; 44 protected String value; 45 protected Snip snip; 46 47 public BaseLabel() { 48 name = ""; 49 value = ""; 50 } 51 52 public BaseLabel(String name, String 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 getInputProxy() { 79 StringBuffer buffer = new StringBuffer (); 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 getListProxy() { 90 StringBuffer buffer = new StringBuffer (); 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 input) { 100 if (input.containsKey("label.name")) { 101 this.name = (String ) input.get("label.name"); 102 } 103 if (input.containsKey("label.value")) { 104 this.value = (String ) input.get("label.value"); 105 } 106 } 107 108 public abstract String getType(); 109 110 public String getName() { 111 return name; 112 } 113 114 public String getValue() { 115 return value; 116 } 117 118 public void setName(String name) { 119 this.name = name; 120 } 121 122 public void setValue(String value) { 123 this.value = value; 124 } 125 126 public void index(Document document) { 127 document.add(Field.Text(name, value)); 129 } 130 } 131 | Popular Tags |