1 16 17 package org.apache.jetspeed.modules.actions.controls; 18 19 import org.apache.turbine.modules.Action; 21 import org.apache.turbine.util.RunData; 22 23 import org.apache.jetspeed.portal.Portlet; 25 import org.apache.jetspeed.portal.PortletSet; 26 import org.apache.jetspeed.portal.PortletControl; 27 import org.apache.jetspeed.services.rundata.JetspeedRunData; 28 import org.apache.jetspeed.om.profile.Profile; 29 import org.apache.jetspeed.om.profile.ProfileLocator; 30 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 31 import org.apache.jetspeed.services.logging.JetspeedLogger; 32 import org.apache.jetspeed.services.Profiler; 33 import org.apache.jetspeed.services.statemanager.SessionState; 34 import org.apache.jetspeed.util.template.JetspeedLink; 35 import org.apache.jetspeed.util.template.JetspeedLinkFactory; 36 import org.apache.jetspeed.services.security.PortalResource; 37 import org.apache.jetspeed.services.JetspeedSecurity; 38 import org.apache.jetspeed.om.security.JetspeedUser; 39 40 import java.util.Enumeration ; 41 import java.util.Stack ; 42 43 50 public class Customize extends Action 51 { 52 53 56 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(Customize.class.getName()); 57 58 61 public void doPerform( RunData rundata ) throws Exception 62 { 63 JetspeedRunData jdata = (JetspeedRunData)rundata; 64 65 if (jdata.getUser() == null) 66 { 67 return; 68 } 69 if(jdata.getProfile() == null) 70 { 71 return; 72 } 73 74 String editMediaType = jdata.getParameters().getString ("mtype"); 76 String resetStack = jdata.getParameters().getString ("reset"); 77 String peid = jdata.getParameters().getString("js_peid"); 78 79 SessionState customizationState = jdata.getPageSessionState(); 81 82 Profile profile = null; 84 85 if ( (resetStack != null) 87 && ((resetStack.equalsIgnoreCase("on")) || (resetStack.equalsIgnoreCase("1")))) 88 { 89 jdata.cleanupFromCustomization(); 91 } 92 93 if (jdata.getCustomizedProfile() == null) 95 { 96 ProfileLocator locator = (ProfileLocator)jdata.getProfile().clone(); 97 98 if (editMediaType != null) 99 { 100 locator.setMediaType(editMediaType); 101 } 102 103 profile = (Profile) Profiler.getProfile(locator).clone(); 105 jdata.setCustomizedProfile(profile); 106 } 107 108 else 110 { 111 profile = jdata.getCustomizedProfile(); 113 } 114 115 if ( peid == null ) 118 { 119 peid = profile.getRootSet().getID(); 121 jdata.setJs_peid(peid); 122 } 123 124 Portlet found = null; 126 Stack sets = new Stack (); 127 sets.push(profile.getRootSet()); 128 129 while ((found==null) && (sets.size() > 0)) 130 { 131 PortletSet set = (PortletSet)sets.pop(); 132 133 if (set.getID().equals(peid)) 134 { 135 found = set; 136 } 137 else 138 { 139 Enumeration en = set.getPortlets(); 140 while((found==null) && en.hasMoreElements()) 141 { 142 Portlet p = (Portlet)en.nextElement(); 143 144 Portlet real = p; 146 while (real instanceof PortletControl) 147 { 148 real = ((PortletControl)p).getPortlet(); 149 } 150 151 if (real instanceof PortletSet) 152 { 153 if (real.getID().equals(peid)) 154 { 155 found=real; 156 } 157 else 158 { 159 sets.push(real); 161 } 162 } 163 else if (p.getID().equals(peid)) 164 { 165 found = p; 166 } 167 } 168 } 169 } 170 171 if (found!=null) 172 { 173 PortalResource portalResource = new PortalResource(found); 174 try 175 { 176 JetspeedLink jsLink = JetspeedLinkFactory.getInstance(rundata); 177 portalResource.setOwner(jsLink.getUserName()); 178 JetspeedLinkFactory.putInstance(jsLink); 179 } 180 catch (Exception e) 181 { 182 logger.warn(e.toString()); 183 portalResource.setOwner(null); 184 } 185 186 if(!JetspeedSecurity.checkPermission((JetspeedUser) jdata.getUser(), 187 portalResource, 188 JetspeedSecurity.PERMISSION_CUSTOMIZE)) 189 { 190 logger.warn("User " + jdata.getUser().getUserName() + " has no customize permission for portlet with id " + peid); 191 jdata.setMessage("Sorry, you have no customize permission for this portlet"); 192 return; 193 } 194 jdata.setCustomized(found); 195 jdata.setScreenTemplate("Customize"); 196 } 197 198 } 199 200 206 public static void save(RunData data) 207 { 208 try 209 { 210 Profile profile = ((JetspeedRunData) data).getCustomizedProfile(); 211 profile.store(); 212 } 213 catch (Exception e) 214 { 215 logger.error("Error while saving profile", e); 216 } 217 218 } 220 224 public static void exit(RunData data) 225 { 226 JetspeedLink jsLink = null; 227 ((JetspeedRunData) data).cleanupFromCustomization(); 228 229 try 231 { 232 jsLink = JetspeedLinkFactory.getInstance(data); 233 String mtype = data.getParameters().getString("mtype"); 234 if (mtype != null) 235 { 236 jsLink.setMediaType(mtype); 237 jsLink.addQueryData("mtype", mtype); 238 } 239 240 } 241 catch (Exception e) 242 { 243 logger.error("exit error", e); 244 } 245 data.setRedirectURI(jsLink.toString()); 246 JetspeedLinkFactory.putInstance(jsLink); 247 jsLink = null; 248 249 } } 251 252 | Popular Tags |