1 package org.apache.jetspeed.modules.parameters; 2 3 18 19 import java.util.ArrayList ; 20 import java.util.Collections ; 21 import java.util.Comparator ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 import java.util.Map ; 25 26 import org.apache.jetspeed.om.registry.Parameter; 27 import org.apache.jetspeed.om.registry.PortletInfoEntry; 28 import org.apache.jetspeed.om.registry.RegistryEntry; 29 import org.apache.jetspeed.om.security.JetspeedUser; 30 import org.apache.jetspeed.services.JetspeedSecurity; 31 import org.apache.jetspeed.services.Registry; 32 import org.apache.jetspeed.services.rundata.JetspeedRunData; 33 import org.apache.jetspeed.services.security.PortalResource; 34 import org.apache.turbine.services.localization.Localization; 35 import org.apache.turbine.util.RunData; 36 import org.apache.velocity.context.Context; 37 38 53 54 public class RegistryEntryListBox extends VelocityParameterPresentationStyle 55 { 56 public static final String OPTION_REGISTRY = "registry"; 57 public static final String OPTION_SORT = "sort"; 58 public static final String OPTION_SELECT_HIDDEN = "select-hidden"; 59 public static final String OPTION_NULL_IF_EMPTY = "null-if-empty"; 60 public static final String OPTION_SET_LABEL = "set-label"; 61 public static final String OPTION_DISABLED_IF_WML = "disabled-if-wml"; 62 public static final String OPTION_SELECT_IF_SIMPLE = "select-if-simple"; 63 64 73 public void buildContext(RunData data, String name, String value, Map parms, Context context) 74 { 75 JetspeedRunData jdata = (JetspeedRunData)data; 77 String mediaType = jdata.getProfile().getMediaType(); 78 String regName = (String )getParm(OPTION_REGISTRY, Registry.PORTLET); 79 boolean sort = (new Boolean ((String )getParm(OPTION_SORT, "true"))).booleanValue(); 80 boolean selectHidden = (new Boolean ((String )getParm(OPTION_SELECT_HIDDEN, "false"))).booleanValue(); 81 String nullIfEmpty = (String )getParm(OPTION_NULL_IF_EMPTY, "true"); 82 boolean setLabel = (new Boolean ((String )getParm(OPTION_SET_LABEL, "false"))).booleanValue(); 83 boolean disabledIfWML = (new Boolean ((String )getParm(OPTION_DISABLED_IF_WML, "false"))).booleanValue(); 84 boolean selectIfSimple = (new Boolean ((String )getParm(OPTION_SELECT_IF_SIMPLE, "false"))).booleanValue(); 85 String defaultEntry = null; 86 87 List list = new ArrayList (); 89 for (Iterator i = Registry.get(regName).listEntryNames(); i.hasNext();) 90 { 91 RegistryEntry entry = Registry.getEntry(regName, (String )i.next()); 92 boolean selected = false; 93 selected = JetspeedSecurity.checkPermission((JetspeedUser) data.getUser(), new PortalResource(entry), "customize"); 94 if (selected && !selectHidden) 95 { 96 selected = !entry.isHidden(); 97 } 98 if (selected && (entry instanceof PortletInfoEntry)) 99 { 100 selected = ((PortletInfoEntry) entry).hasMediaType(mediaType); 101 } 102 if (selected && selectIfSimple) 103 { 104 Parameter simpleParam = ((PortletInfoEntry) entry).getParameter("simple"); 105 if (simpleParam != null) 106 { 107 selected = new Boolean (simpleParam.getValue()).booleanValue(); 108 } 109 else 110 { 111 selected = false; 112 } 113 } 114 if (selected) 115 { 116 list.add(entry); 117 } 118 } 119 120 if (sort) 122 Collections.sort(list, 123 new Comparator () 124 { 125 public int compare(Object o1, Object o2) 126 { 127 String t1 = (((RegistryEntry) o1).getTitle() != null) 128 ? ((RegistryEntry) o1).getTitle() 129 : ((RegistryEntry) o1).getName(); 130 String t2 = (((RegistryEntry) o2).getTitle() != null) 131 ? ((RegistryEntry) o2).getTitle() 132 : ((RegistryEntry) o2).getName(); 133 134 return t1.compareTo(t2); 135 } 136 }); 137 138 String label = null; 140 if (regName.equals(Registry.PORTLET)) 141 { 142 label = Localization.getString(data, "CUSTOMIZER_PORTLET"); 143 } 144 else if (regName.equals(Registry.SECURITY)) 145 { 146 label = Localization.getString(data, "CUSTOMIZER_SECURITY_REF"); 147 } 154 else if (regName.equals(Registry.MEDIA_TYPE)) 155 { 156 label = Localization.getString(data, "CUSTOMIZER_MEDIATYPE"); 157 } 158 else if (regName.equals(Registry.PORTLET_CONTROLLER)) 159 { 160 label = Localization.getString(data, "CUSTOMIZER_LAYOUT"); 161 } 162 else if (regName.equals(Registry.PORTLET_CONTROL)) 163 { 164 label = Localization.getString(data, "CUSTOMIZER_DECORATION"); 165 } 166 else if (regName.equals(Registry.CLIENT)) 167 { 168 label = "Client"; 169 } 170 else 171 { 172 label = ""; 173 } 174 context.put("entries", list); 175 context.put("nullIfEmpty", nullIfEmpty); 176 if (setLabel) 177 context.put("label", label); 178 if (disabledIfWML && mediaType.equalsIgnoreCase("wml")) 179 context.put("disabled", "disabled"); 180 context.put("defaultEntry", defaultEntry); 181 } 182 183 } | Popular Tags |