Source code: org/acs/damsel/client/edit/MyFavoritesAction.java
1 package org.acs.damsel.client.edit;
2
3 import org.apache.struts.action.*;
4 import javax.servlet.http.*;
5 import org.apache.log4j.*;
6
7 import org.acs.damsel.srvr.asset.*;
8 import org.acs.damsel.client.ClientApp;
9 import org.acs.damsel.srvr.user.*;
10 import java.sql.*;
11 import java.util.Enumeration;
12 import org.acs.damsel.client.edit.*;
13 import java.util.Vector;
14 import java.util.Iterator;
15 import org.acs.damsel.srvr.collection.*;
16
17 public class MyFavoritesAction
18 extends Action {
19 public ActionForward execute(ActionMapping actionMapping,
20 ActionForm actionForm,
21 HttpServletRequest httpServletRequest,
22 HttpServletResponse httpServletResponse) {
23 MyFavoritesForm myFavoritesForm = (MyFavoritesForm) actionForm;
24 String imageLink = (String) myFavoritesForm.getImageLink();
25 User user = (User) httpServletRequest.getSession().getAttribute("User");
26 Asset asset = new Asset();
27 Logger log = Logger.getLogger(MyFavoritesAction.class);
28 Vector deletedAssets = new Vector();
29 // If the remove button has been clicked, the assets are removed from the
30 // users my favorites and is forwarded to a successful removal page.
31 if (imageLink.equals("remove")) {
32 boolean isSomethingChecked = false;
33 for (Enumeration e = httpServletRequest.getParameterNames();
34 e.hasMoreElements(); ) {
35 String potentialName = (String) e.nextElement();
36 String fileName = new String();
37 UserMgr uMgr = ClientApp.instance().getUserMgr();
38 if (potentialName.length() > 8 &&
39 potentialName.substring(0, 9).equals("checkbox_")) {
40 isSomethingChecked = true;
41 try {
42 fileName = potentialName.substring(9);
43 asset = ClientApp.instance().getRepositoryMgr().getAsset(fileName);
44 int affected = uMgr.removeAssetFromFavorites(asset, user);
45 deletedAssets.add(asset);
46 }
47 catch (SQLException ex1) {
48 log.warn("Unexpected SQLException caught in MyFavoritesAction : " +
49 ex1.getMessage());
50 }
51 }
52 }
53 /*Put the assets vector on the form */
54 myFavoritesForm.setDeletedAssets(deletedAssets);
55 if (isSomethingChecked)
56 return actionMapping.findForward("remove");
57 else
58 return actionMapping.findForward("refresh");
59 }
60
61 /*If the slideshow button is clicked, go to add slide show page */
62 if (imageLink.equals("slideshow")) {
63 CollectionView cv = new CollectionView();
64 for (Enumeration e = httpServletRequest.getParameterNames();
65 e.hasMoreElements(); ) {
66 String potentialName = (String) e.nextElement();
67 String fileName = new String();
68 if (potentialName.length() > 8 &&
69 potentialName.substring(0, 9).equals("checkbox_")) {
70 try {
71 /*Add selected assets to a collection view */
72 fileName = potentialName.substring(9);
73 asset = ClientApp.instance().getRepositoryMgr().getAsset(fileName);
74 cv.addAsset(asset);
75 }
76 catch (SQLException ex1) {
77 log.warn("Unexpected SQLException caught in MyFavoritesAction : " +
78 ex1.getMessage());
79 }
80 }
81 }
82 /*Push the collection view onto the session */
83 httpServletRequest.getSession().setAttribute("slideShowCV", cv);
84 return actionMapping.findForward("slideShow");
85 }
86
87 // If a thumbnail link has been clicked, forward to the asset view page.
88 if (!imageLink.equals("imageLink")) {
89 try {
90 asset = ClientApp.instance().getRepositoryMgr().getAsset(imageLink);
91 }
92 catch (SQLException ex) {
93 log.warn("Unexpected SQLException caught in MyFavoritesAction : " + ex.getMessage());
94 }
95 myFavoritesForm.setAsset(asset);
96 //Determine the collection that the Asset is in and post it to the session
97 String collectionName = new String();
98 Vector cNames = ClientApp.instance().getCollectionMgr().collectionNames();
99 for (Iterator i = cNames.iterator(); i.hasNext();) {
100 collectionName = (String) i.next();
101
102 if (ClientApp.instance().getCollectionMgr().getCollection(collectionName).contains(asset)) {
103 break;
104 }
105
106 }
107 httpServletRequest.getSession().setAttribute("collectionName", collectionName);
108 httpServletRequest.getSession().setAttribute("myFavoritesForm", myFavoritesForm);
109 httpServletRequest.getSession().setAttribute("searchType", "myFavorites");
110 return actionMapping.findForward("assetView");
111 }
112 else {
113 return actionMapping.findForward("success");
114 }
115 }
116 }