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 43 52 public class TaxonomyLabel extends BaseLabel { 53 54 public TaxonomyLabel() { 55 name = "Taxonomy"; 56 value = ""; 57 } 58 59 public TaxonomyLabel(String value) { 60 this(); 61 this.value = value; 62 } 63 64 69 public String getType() { 70 return "TaxonomyLabel"; 71 } 72 73 75 public String getInputProxy() { 76 StringBuffer buffer = new StringBuffer (); 77 SnipSpace snipspace = (SnipSpace) Components.getComponent(SnipSpace.class); 78 List snipList = snipspace.getAll(); 79 80 buffer.append("Taxonomy: "); 81 82 Iterator iterator = snipList.iterator(); 84 buffer.append("<select name=\"label.value\" size=\"1\">"); 85 while (iterator.hasNext()) { 86 Snip snip = (Snip) iterator.next(); 87 Labels labels = snip.getLabels(); 88 boolean noLabelsAll = labels.getAll().isEmpty(); 89 if (!noLabelsAll) { 90 Collection LabelsCat; 91 LabelsCat = labels.getLabels("TypeLabel"); 92 if (!LabelsCat.isEmpty()) { 93 Iterator iter = LabelsCat.iterator(); 94 while (iter.hasNext()) { 95 Label label = (Label) iter.next(); 96 if (label.getValue().equals("Category")) { 97 String category = snip.getName(); 98 buffer.append("<option>"); 99 buffer.append(category); 100 buffer.append("</option>"); 101 } 102 } 103 } 104 } 105 } 106 buffer.append("</select>"); 107 108 return buffer.toString(); 109 } 110 111 public String getListProxy() { 112 StringBuffer buffer = new StringBuffer (); 113 buffer.append("<td>"); 114 buffer.append("Parent:"); 115 buffer.append("</td><td>"); 116 getSnipLink(buffer, this.value); 117 buffer.append("</td><td>"); 118 return buffer.toString(); 119 } 120 121 private StringBuffer getSnipLink(StringBuffer buffer, String name) { 122 AuthenticationService service = (AuthenticationService) Components.getComponent(AuthenticationService.class); 123 124 if (SnipSpaceFactory.getInstance().exists(name)) { 125 SnipLink.appendLink(buffer, name, name); 126 } else if (!service.isAuthenticated(Application.get().getUser())) { 127 buffer.append(name); 128 } else { 129 SnipLink.appendCreateLink(buffer, name); 130 } 131 return buffer; 132 } 133 } 134 | Popular Tags |