1 25 26 package org.snipsnap.snip.label; 27 28 import java.util.Collection ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 32 import org.snipsnap.app.Application; 33 import org.snipsnap.container.Components; 34 import org.snipsnap.snip.Snip; 35 import org.snipsnap.snip.SnipLink; 36 import org.snipsnap.snip.SnipSpace; 37 import org.snipsnap.snip.SnipSpaceFactory; 38 import org.snipsnap.snip.label.BaseLabel; 39 import org.snipsnap.snip.label.Label; 40 import org.snipsnap.snip.label.Labels; 41 import org.snipsnap.user.AuthenticationService; 42 import org.snipsnap.util.URLEncoderDecoder; 43 44 50 public class CategoryLabel extends BaseLabel { 51 52 private String type = "CategoryLabel"; 53 54 public CategoryLabel() { 55 name = "Category"; 56 value = ""; 57 } 58 59 public CategoryLabel(String value) { 60 this(); 61 this.value = value; 62 } 63 64 68 public String getType() { 69 return type; 70 } 71 72 78 public String getInputProxy() { 79 StringBuffer buffer = new StringBuffer (); 80 SnipSpace snipspace = (SnipSpace) Components.getComponent(SnipSpace.class); 81 List snipList = snipspace.getAll(); 82 83 buffer.append("Category: "); 84 Iterator iterator = snipList.iterator(); 85 buffer.append("<select name=\"label.value\" size=\"1\">"); 86 while (iterator.hasNext()) { 87 Snip snip = (Snip) iterator.next(); 88 Labels labels = snip.getLabels(); 89 boolean noLabelsAll = labels.getAll().isEmpty(); 90 91 if (!noLabelsAll) { 92 Collection LabelsCat; 93 LabelsCat = labels.getLabels("TypeLabel"); 95 if (!LabelsCat.isEmpty()) { Iterator iter = LabelsCat.iterator(); 97 while (iter.hasNext()) { 98 Label label = (Label) iter.next(); 100 if (label.getValue().equals("Category")) { 101 String category = snip.getName(); 102 buffer.append("<option>"); 103 buffer.append(category); 104 buffer.append("</option>"); 105 } 106 } 107 } 108 } 109 } 110 buffer.append("</select>"); 111 112 return buffer.toString(); 113 } 114 115 public String getListProxy() { 116 StringBuffer buffer = new StringBuffer (); 117 buffer.append("<td>"); 118 buffer.append("Category:"); 119 buffer.append("</td><td>"); 120 getSnipLink(buffer, value); 121 buffer.append("</td><td>"); 122 return buffer.toString(); 123 } 124 125 128 private StringBuffer getSnipLink(StringBuffer buffer, String name) { 129 AuthenticationService service = (AuthenticationService) Components.getComponent(AuthenticationService.class); 130 131 if (SnipSpaceFactory.getInstance().exists(name)) { 132 String [] strings = name.split("/"); 133 String string = strings[strings.length - 1]; 134 SnipLink.appendLink(buffer, name, string); 135 } else if (!service.isAuthenticated(Application.get().getUser())) { 136 buffer.append(name); 137 } else { 138 SnipLink.appendCreateLink(buffer, name); 139 } 140 return buffer; 141 } 142 } 143 | Popular Tags |