1 16 17 package org.apache.jetspeed.util; 18 19 import org.apache.turbine.util.RunData; 20 import org.apache.jetspeed.portal.portlets.VelocityPortlet; 21 import org.apache.jetspeed.services.Registry; 22 import org.apache.jetspeed.om.registry.Parameter; 23 import org.apache.jetspeed.om.registry.PortletEntry; 24 import org.apache.jetspeed.portal.Portlet; 25 import org.apache.jetspeed.portal.PortletConfig; 26 27 35 public class PortletConfigState 36 { 37 38 41 public static String getConfigParameter(Portlet portlet, 42 String attrName, 43 String attrDefaultValue) 44 { 45 PortletConfig pc = portlet.getPortletConfig(); 46 return pc.getInitParameter(attrName, attrDefaultValue); 47 } 48 49 52 public static String getInstanceParameter(Portlet portlet, 53 RunData rundata, 54 String attrName) 55 { 56 return portlet.getAttribute( attrName, null, rundata); 57 } 58 59 62 public static void setInstanceParameter(Portlet portlet, 63 RunData rundata, 64 String attrName, 65 String attrValue) 66 { 67 portlet.setAttribute(attrName, attrValue, rundata); 68 } 69 70 public static void clearInstanceParameter(Portlet portlet, 71 RunData rundata, 72 String attrName) 73 { 74 if( portlet.getAttribute(attrName, null, rundata) != null ) 75 portlet.setAttribute(attrName, null, rundata); 76 } 77 78 82 public static String getParameter(Portlet portlet, 83 RunData rundata, 84 String attrName, 85 String attrDefValue) 86 { 87 String str = getInstanceParameter( portlet, rundata, attrName); 88 if (str == null) 89 { 90 str = getConfigParameter(portlet, attrName, attrDefValue); 91 } 92 return str; 93 } 94 95 98 public static String getConfigParameter(VelocityPortlet portlet, 99 String attrName, 100 String attrDefaultValue) 101 { 102 return getConfigParameter((Portlet) portlet, attrName, attrDefaultValue); 103 } 104 105 108 public static String getInstanceParameter(VelocityPortlet portlet, 109 RunData rundata, 110 String attrName) 111 { 112 return getInstanceParameter((Portlet) portlet, rundata, attrName); 113 } 114 115 118 public static void setInstanceParameter(VelocityPortlet portlet, 119 RunData rundata, 120 String attrName, 121 String attrValue) 122 { 123 setInstanceParameter((Portlet) portlet, rundata, attrName, attrValue); 124 } 125 126 public static void clearInstanceParameter(VelocityPortlet portlet, 127 RunData rundata, 128 String attrName) 129 { 130 clearInstanceParameter((Portlet) portlet,rundata,attrName); 131 } 132 133 137 public static String getParameter(VelocityPortlet portlet, 138 RunData rundata, 139 String attrName, 140 String attrDefValue) 141 { 142 return getParameter((Portlet) portlet, rundata, attrName, attrDefValue); 143 } 144 145 150 public static void setPortletConfigParameter(Portlet portlet, String name, String value) 151 { 152 PortletEntry pEntry = (PortletEntry) Registry.getEntry(Registry.PORTLET, portlet.getName()); 153 154 if (pEntry != null) 155 { 156 Parameter param = pEntry.getParameter(name); 157 portlet.getPortletConfig().setInitParameter(name, value); 158 if (param != null) 159 { 160 param.setValue(value); 161 } 162 else 163 { 164 pEntry.addParameter(name, value); 165 } 166 } 167 } 168 } 169 | Popular Tags |