1 16 package com.blandware.atleap.webapp.action.core.linkedObjects; 17 18 import com.blandware.atleap.common.Constants; 19 import com.blandware.atleap.model.core.ContentField; 20 import com.blandware.atleap.model.core.ContentFieldValue; 21 import com.blandware.atleap.model.core.ContentResource; 22 import com.blandware.atleap.model.core.MenuItem; 23 import com.blandware.atleap.model.core.Page; 24 import com.blandware.atleap.service.core.ContentResourceManager; 25 import com.blandware.atleap.service.core.PageManager; 26 import com.blandware.atleap.webapp.action.core.BaseAction; 27 import com.blandware.atleap.webapp.util.core.WebappConstants; 28 import com.blandware.atleap.webapp.util.core.WebappUtil; 29 import org.apache.commons.validator.GenericValidator; 30 import org.apache.struts.Globals; 31 import org.apache.struts.action.ActionForm; 32 import org.apache.struts.action.ActionForward; 33 import org.apache.struts.action.ActionMapping; 34 import org.apache.struts.action.ActionMessage; 35 import org.apache.struts.action.ActionMessages; 36 37 import javax.servlet.http.HttpServletRequest ; 38 import javax.servlet.http.HttpServletResponse ; 39 import java.util.ArrayList ; 40 import java.util.List ; 41 import java.util.ListIterator ; 42 import java.util.Locale ; 43 44 62 public final class ViewLinkedObjectsAction extends BaseAction { 63 72 public ActionForward execute(ActionMapping mapping, ActionForm form, 73 HttpServletRequest request, HttpServletResponse response) throws Exception { 74 75 Long id = null; 76 if ( !GenericValidator.isBlankOrNull(request.getParameter("id")) ) { 77 id = Long.valueOf(request.getParameter("id")); 78 } else if (request.getAttribute(WebappConstants.LINKED_OBJECT_ID_KEY) != null) { 79 id = (Long ) request.getAttribute(WebappConstants.LINKED_OBJECT_ID_KEY); 80 } else if (request.getSession().getAttribute(WebappConstants.LINKED_OBJECT_ID_KEY) != null) { 81 id = (Long ) request.getSession().getAttribute(WebappConstants.LINKED_OBJECT_ID_KEY); 82 } else { 83 if ( log.isWarnEnabled() ) { 84 log.warn("Object ID is not specified. Returning to index..."); 85 } 86 return mapping.findForward("admin"); 87 } 88 89 request.getSession().setAttribute(WebappConstants.LINKED_OBJECT_ID_KEY, id); 90 91 String type = request.getParameter("type"); 92 if ( GenericValidator.isBlankOrNull(type) ) { 93 type = (String ) request.getAttribute(WebappConstants.LINKED_OBJECT_TYPE_KEY); 94 } 95 if ( GenericValidator.isBlankOrNull(type) ) { 96 type = (String ) request.getSession().getAttribute(WebappConstants.LINKED_OBJECT_TYPE_KEY); 97 } 98 if ( !"resource".equalsIgnoreCase("type") && !"page".equalsIgnoreCase(type) ) { 99 type = "resource"; 100 } 101 request.getSession().setAttribute(WebappConstants.LINKED_OBJECT_TYPE_KEY, type); 102 103 String redirectUrl = null; 104 if (!GenericValidator.isBlankOrNull(request.getParameter("redirectUrl"))) { 105 redirectUrl = request.getParameter("redirectUrl"); 106 } else if (!GenericValidator.isBlankOrNull((String ) request.getSession().getAttribute(WebappConstants.LINKED_OBJECTS_REDIRECT_URL_KEY))) { 107 redirectUrl = (String ) request.getSession().getAttribute(WebappConstants.LINKED_OBJECTS_REDIRECT_URL_KEY); 108 } 109 request.setAttribute(WebappConstants.LINKED_OBJECTS_REDIRECT_URL_KEY, redirectUrl); 110 111 if ("true".equalsIgnoreCase(request.getParameter("justView"))) { 112 request.getSession().removeAttribute(WebappConstants.LINKED_OBJECT_NEW_URI_KEY); 113 request.getSession().removeAttribute(WebappConstants.LINKED_OBJECT_CONTENT_LOCALE_ID_KEY); 114 request.getSession().removeAttribute(WebappConstants.LINKED_OBJECT_CHARSET_KEY); 115 request.getSession().removeAttribute(WebappConstants.LINKED_OBJECT_WIDTH_KEY); 116 request.getSession().removeAttribute(WebappConstants.LINKED_OBJECT_HEIGHT_KEY); 117 request.getSession().removeAttribute(WebappConstants.LINKED_OBJECTS_UPDATE_ACTION_KEY); 118 request.getSession().removeAttribute(WebappConstants.LINKED_OBJECTS_DELETE_ACTION_KEY); 119 } 120 121 List linkedContentFieldValues = new ArrayList (); 122 List linkedMenuItems = new ArrayList (); 123 if ( "resource".equalsIgnoreCase(type) ) { 124 ContentResourceManager contentResourceManager = (ContentResourceManager) getBean(Constants.CONTENT_RESOURCE_MANAGER_BEAN); 125 ContentResource resource = contentResourceManager.retrieveContentResource(id); 126 if ( resource == null ) { 127 ActionMessages errors = new ActionMessages(); 128 errors.add("resourceNotFound", new ActionMessage("core.contentResource.errors.notFound")); 129 saveErrors(request, errors); 130 return mapping.findForward("admin"); 131 } 132 linkedContentFieldValues = new ArrayList (resource.getLinkedContentFieldValues()); 133 linkedMenuItems = new ArrayList (resource.getLinkedMenuItems()); 134 } else { 135 PageManager pageManager = (PageManager) getBean(Constants.PAGE_MANAGER_BEAN); 136 Page page = pageManager.retrievePage(id); 137 if ( page == null ) { 138 ActionMessages errors = new ActionMessages(); 139 errors.add("pageNotFound", new ActionMessage("core.page.errors.notFound")); 140 saveErrors(request, errors); 141 return mapping.findForward("admin"); 142 } 143 linkedContentFieldValues = new ArrayList (page.getLinkedContentFieldValues()); 144 linkedMenuItems = new ArrayList (page.getLinkedMenuItems()); 145 } 146 147 for ( ListIterator i = linkedContentFieldValues.listIterator(); i.hasNext(); ) { 148 ContentFieldValue contentFieldValue = (ContentFieldValue) i.next(); 149 i.set(new CFVInfo(contentFieldValue, request)); 150 } 151 152 for ( ListIterator i = linkedMenuItems.listIterator(); i.hasNext(); ) { 153 MenuItem menuItem = (MenuItem) i.next(); 154 i.set(new MenuItemInfo(menuItem, request)); 155 } 156 157 request.setAttribute(WebappConstants.LINKED_CONTENT_FIELD_VALUES_COLLECTION_KEY, linkedContentFieldValues); 158 request.setAttribute(WebappConstants.LINKED_MENU_ITEMS_COLLECTION_KEY, linkedMenuItems); 159 160 if (request.getSession().getAttribute(WebappConstants.LINKED_OBJECTS_UPDATE_ACTION_KEY) != null) { 161 saveToken(request); 162 } 163 164 return mapping.findForward("viewLinkedObjects"); 165 } 166 167 170 public static class CFVInfo { 171 172 175 protected String fieldOwnerInfo; 176 177 180 protected String fieldIdentifier; 181 182 185 protected String language; 186 187 190 protected Long fieldId; 191 192 195 protected Long fieldValueId; 196 197 203 public CFVInfo(ContentFieldValue contentFieldValue, HttpServletRequest request) { 204 ContentField contentField = contentFieldValue.getContentField(); 205 this.fieldId = contentField.getId(); 206 this.fieldIdentifier = contentField.getIdentifier(); 207 this.fieldOwnerInfo = WebappUtil.getLocalizableInfo(contentField.getOwner(), request); 208 this.language = contentFieldValue.getContentLocale().getIdentifier(); 209 this.fieldValueId = contentFieldValue.getId(); 210 } 211 212 217 public String getFieldOwnerInfo() { 218 return fieldOwnerInfo; 219 } 220 221 226 public void setFieldOwnerInfo(String fieldOwnerInfo) { 227 this.fieldOwnerInfo = fieldOwnerInfo; 228 } 229 230 235 public String getFieldIdentifier() { 236 return fieldIdentifier; 237 } 238 239 244 public void setFieldIdentifier(String fieldIdentifier) { 245 this.fieldIdentifier = fieldIdentifier; 246 } 247 248 253 public String getLanguage() { 254 return language; 255 } 256 257 262 public void setLanguage(String language) { 263 this.language = language; 264 } 265 266 271 public Long getFieldId() { 272 return fieldId; 273 } 274 275 280 public void setFieldId(Long fieldId) { 281 this.fieldId = fieldId; 282 } 283 284 289 public Long getFieldValueId() { 290 return fieldValueId; 291 } 292 293 298 public void setFieldValueId(Long fieldValueId) { 299 this.fieldValueId = fieldValueId; 300 } 301 302 } 303 304 307 public static class MenuItemInfo { 308 309 312 protected String title; 313 314 317 protected String ownerInfo; 318 319 322 protected Long menuItemId; 323 324 327 protected Long ownerId; 328 329 332 protected boolean dynamic; 333 334 340 public MenuItemInfo(MenuItem menuItem, HttpServletRequest request) { 341 Locale locale = (Locale ) request.getSession().getAttribute(Globals.LOCALE_KEY); 342 this.title = WebappUtil.getFieldValue(menuItem.getTitle(), locale.getLanguage(), request, true); 343 this.ownerInfo = WebappUtil.getLocalizableInfo(menuItem.getOwner(), request); 344 this.ownerId = null; 345 if ( menuItem.getOwner() != null ) { 346 this.ownerId = menuItem.getOwner().getId(); 347 } 348 this.menuItemId = menuItem.getId(); 349 this.dynamic = menuItem.isDynamic(); 350 } 351 352 357 public String getTitle() { 358 return title; 359 } 360 361 366 public void setTitle(String title) { 367 this.title = title; 368 } 369 370 375 public String getOwnerInfo() { 376 return ownerInfo; 377 } 378 379 384 public void setOwnerInfo(String ownerInfo) { 385 this.ownerInfo = ownerInfo; 386 } 387 388 393 public Long getMenuItemId() { 394 return menuItemId; 395 } 396 397 402 public void setMenuItemId(Long menuItemId) { 403 this.menuItemId = menuItemId; 404 } 405 406 411 public Long getOwnerId() { 412 return ownerId; 413 } 414 415 420 public void setOwnerId(Long ownerId) { 421 this.ownerId = ownerId; 422 } 423 424 429 public boolean isDynamic() { 430 return dynamic; 431 } 432 433 438 public void setDynamic(boolean dynamic) { 439 this.dynamic = dynamic; 440 } 441 } 442 } | Popular Tags |