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 class BooleanLabel implements Label { 43 protected String name; 44 protected String value; 45 protected Snip snip; 46 47 public BooleanLabel() { 48 name = ""; 49 value = "false"; 50 } 51 52 public BooleanLabel(String name, String 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 getInputProxy() { 80 StringBuffer buffer = new StringBuffer (); 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 getListProxy() { 88 StringBuffer buffer = new StringBuffer (); 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 checkValue(String value) { 98 String 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 input) { 108 if (input.containsKey("label.boolean")) { 109 this.value = checkValue((String ) input.get("label.boolean")); 110 } 111 } 112 113 public String getType() { 114 return "Boolean"; 115 } 116 117 public String getName() { 118 return name; 119 } 120 121 public String 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 name) { 130 this.name = name; 131 } 132 133 public void setValue(String value) { 134 this.value = checkValue(value); 135 } 136 137 public void index(Document document) { 138 document.add(Field.Text(name, "" + value)); 140 } 141 } 142 | Popular Tags |