1 54 55 56 package org.apache.jetspeed.modules.actions.portlets; 57 58 import java.util.Vector ; 60 61 import org.apache.jetspeed.portal.portlets.VelocityPortlet; 63 import org.apache.jetspeed.modules.actions.portlets.VelocityPortletAction; 64 import org.apache.jetspeed.util.PortletConfigState; 65 import org.apache.jetspeed.services.rundata.JetspeedRunData; 66 import org.apache.jetspeed.services.statemanager.SessionState; 67 68 import org.apache.jetspeed.services.cms.CmsService; 69 import org.apache.jetspeed.services.cms.manager.CmsManager; 70 import org.apache.jetspeed.services.cms.manager.CmsFactory; 71 import org.apache.jetspeed.services.cms.JetspeedCMSException; 72 import org.apache.jetspeed.om.cms.Catalog; 73 74 75 import org.apache.turbine.util.Log; 77 import org.apache.turbine.util.RunData; 78 import org.apache.turbine.services.TurbineServices; 79 80 81 import org.apache.velocity.context.Context; 83 84 85 93 public class CmsAdminAction extends VelocityPortletAction 94 { 95 96 97 private static final String CUSTOMIZE_TEMPLATE = "customize-template"; 98 99 private static final String FROM_URI = "fromuri"; 100 101 private static final String FROM_URI_DEFAULT_VALUE = "/catalog"; 102 103 private static final String TO_URI = "touri"; 104 105 private static final String NEW_CATALOG_EVENT = "NewCatalog"; 106 107 private static final String INSERT_CATALOG_EVENT = "InsertCatalog"; 108 109 private static final String NEW_CATALOG_TEMPLATE = "new-catalog-template"; 110 111 private static final String SUMMARY_CATALOG_TEMPLATE = "summary-catalog-template"; 112 113 private static final String CATALOG_PARAM = "catalog"; 114 115 private static final String CATALOG_PATH_PARAM = "catalogPath"; 116 117 private static final String SUB_CATALOG_PARAM = "subCatalog"; 118 119 private static final String CUSTOMIZE_EVENT_PARAM = "customizeEvent"; 120 121 private static final String MODE_PARAM = "mode"; 122 123 private static final String ADD_MODE_VALUE = "add"; 124 125 126 127 132 protected void buildMaximizedContext( VelocityPortlet portlet, 133 Context context, 134 RunData rundata ) 135 throws JetspeedCMSException 136 { 137 138 try 139 { 140 buildNormalContext( portlet, context, rundata); 141 } 142 catch (JetspeedCMSException e) 143 { 144 throw e; 145 } 146 147 } 148 149 154 protected void buildConfigureContext( VelocityPortlet portlet, 155 Context context, 156 RunData rundata ) 157 { 158 try { 159 160 SessionState state = this.getSessionState(portlet, rundata); 161 162 String customizeEvent = rundata.getParameters().getString(CUSTOMIZE_EVENT_PARAM); 163 164 if (customizeEvent == null) 165 { 166 setTemplate(rundata, getParameterUsingFallback(portlet, rundata, CUSTOMIZE_TEMPLATE, null)); 167 } 168 else 169 { 170 if (customizeEvent.equals(NEW_CATALOG_EVENT)) 171 { 172 this.doNewCatalog(portlet,context,rundata); 173 } 174 175 if (customizeEvent.equals(INSERT_CATALOG_EVENT)) 176 { 177 this.doInsertCatalog(portlet,context,rundata); 178 } 179 } 180 context.put(CATALOG_PATH_PARAM, state.getAttribute(CATALOG_PATH_PARAM)); 182 context.put(CATALOG_PARAM, state.getAttribute(CATALOG_PARAM)); 183 } 184 catch (JetspeedCMSException e) 185 { 186 e.printStackTrace(); 187 } 188 189 190 } 191 192 196 protected void buildNormalContext( VelocityPortlet portlet, 197 Context context, 198 RunData rundata ) 199 throws JetspeedCMSException 200 { 201 202 try 203 { 204 205 SessionState state = this.getSessionState(portlet, rundata); 206 207 String fromcatalogName = this.getParameterUsingFallback(portlet, rundata, FROM_URI, FROM_URI_DEFAULT_VALUE); 208 String tocatalogName = rundata.getParameters().getString(TO_URI); 209 210 211 212 if (tocatalogName == null) 213 { 214 if (state.getAttribute(CATALOG_PARAM) == null) 216 { 217 tocatalogName = fromcatalogName; 218 } 219 else 221 { 222 context.put(CATALOG_PATH_PARAM, state.getAttribute(CATALOG_PATH_PARAM)); 223 context.put(CATALOG_PARAM, state.getAttribute(CATALOG_PARAM)); 224 return; 225 } 226 227 } 228 229 Vector catalogPath = this.getCmsManager().getCatalogs(fromcatalogName, tocatalogName); 231 232 Catalog catalog = (Catalog) catalogPath.lastElement(); 234 this.getCmsManager().populateCatalog(catalog,true,true,1); 236 237 state.setAttribute(CATALOG_PATH_PARAM, catalogPath); 240 state.setAttribute(CATALOG_PARAM, catalog); 241 242 243 context.put(CATALOG_PATH_PARAM, catalogPath); 245 context.put(CATALOG_PARAM, catalog); 246 247 } 248 catch ( Exception e ) { 249 throw new JetspeedCMSException("Impossible to build the normal context"); 250 } 251 252 253 } 254 255 256 259 protected void doNewCatalog( VelocityPortlet portlet, 260 Context context, 261 RunData rundata ) 262 throws JetspeedCMSException 263 { 264 265 try 266 { 267 Catalog catalog = (Catalog) CmsFactory.getCmsOmInstance("Catalog"); 268 setTemplate(rundata, getParameterUsingFallback(portlet, rundata, NEW_CATALOG_TEMPLATE, null)); 269 context.put(SUB_CATALOG_PARAM, catalog); 270 context.put(MODE_PARAM, ADD_MODE_VALUE); 271 272 } 273 catch (Exception e) 274 { 275 throw new JetspeedCMSException("Impossible to create Catalog object"); 276 } 277 278 } 279 280 283 protected void doInsertCatalog( VelocityPortlet portlet, 284 Context context, 285 RunData rundata ) 286 throws JetspeedCMSException 287 { 288 289 try 290 { 291 292 Catalog newCatalog = (Catalog) CmsFactory.getCmsOmInstance("Catalog"); 293 294 rundata.getParameters().setProperties(newCatalog); 296 297 Catalog parentCatalog = (Catalog) this.getSessionState(portlet, rundata) 298 .getAttribute(CATALOG_PARAM); 299 300 newCatalog.setParentUri(parentCatalog.getUri()); 301 302 newCatalog.setUri(newCatalog.getParentUri() + 303 "/" + newCatalog.getLogicalName()); 304 305 this.getCmsManager().createResource(newCatalog); 307 308 this.getCmsManager().populateCatalog(parentCatalog); 310 311 setTemplate(rundata, getParameterUsingFallback(portlet, rundata, SUMMARY_CATALOG_TEMPLATE, null)); 312 313 context.put(CATALOG_PARAM, parentCatalog); 314 context.put(MODE_PARAM, ADD_MODE_VALUE); 315 316 317 } 318 catch (Exception e) 319 { 320 throw new JetspeedCMSException("Impossible to create Catalog object"); 321 } 322 323 } 324 325 326 protected String getParameterUsingFallback(VelocityPortlet portlet, RunData rundata, 327 String attrName, String attrDefValue) 328 { 329 return PortletConfigState.getParameter(portlet, rundata, attrName, attrDefValue); 330 } 331 332 protected CmsManager getCmsManager() 333 throws JetspeedCMSException 334 { 335 try 336 { 337 return ((CmsService) TurbineServices.getInstance() 338 .getService(CmsService.SERVICE_NAME)) 339 .getCmsManager(); 340 } 341 catch (Exception e) 342 { 343 throw new JetspeedCMSException("Impossible to get the CMS service"); 344 } 345 } 346 347 348 protected SessionState getSessionState(VelocityPortlet portlet,RunData rundata) { 349 350 return ((JetspeedRunData) rundata).getPortletSessionState(portlet.getID()); 351 } 352 353 354 } 355 | Popular Tags |