Source code: org/acs/damsel/client/add/AddSlideShowAction.java
1 package org.acs.damsel.client.add;
2
3 import java.sql.*;
4 import java.util.*;
5 import javax.servlet.http.*;
6 import java.sql.*;
7 import java.util.*;
8
9 import org.acs.damsel.srvr.db.AssetDB;
10
11 import org.acs.damsel.srvr.asset.*;
12 import org.acs.damsel.srvr.collection.*;
13 import org.acs.damsel.srvr.db.*;
14 import org.acs.damsel.srvr.user.*;
15 import org.acs.damsel.srvr.collection.CollectionView;
16 import org.acs.damsel.client.ClientApp;
17 import org.apache.struts.action.*;
18 import org.apache.log4j.*;
19
20 public class AddSlideShowAction extends Action {
21 public ActionForward execute(ActionMapping actionMapping,
22 ActionForm actionForm,
23 HttpServletRequest httpServletRequest,
24 HttpServletResponse httpServletResponse) {
25 /**@todo use ClientApp instead of AssetDB! May require creating a slideShowMgr... */
26
27 AddSlideShowForm addSlideShowForm = (AddSlideShowForm) actionForm;
28 String submitType = addSlideShowForm.getSubmitType();
29 /*Get rid of blank spaces */
30 String slideShowName = addSlideShowForm.getSlideShowName();
31 addSlideShowForm.setSlideShowName(slideShowName);
32
33 CollectionView slideShowCV = (CollectionView) httpServletRequest.getSession().
34 getAttribute(
35 "slideShowCV");
36 /* System.out.println("This is the asset in colview: " +
37 slideShowCV.returnAsset(0).getAssetDescriptors().
38 getAssetDescriptor("FileName").getValue()); */
39 ActionErrors errors;
40
41 /*Remove selected assets */
42 if (submitType.equals("remove")) {
43 if (slideShowCV != null) {
44 /*Obtain checked assets */
45 String asset;
46 String potentialName;
47 Iterator it;
48 Asset ass;
49 for (Enumeration e = httpServletRequest.getParameterNames();
50 e.hasMoreElements(); ) {
51 potentialName = (String) e.nextElement();
52 if (potentialName.length() > 6) {
53 if (potentialName.substring(0, 6).equals("asset_")) {
54 asset = potentialName.substring(6);
55 /*Remove the current asset */
56 it = slideShowCV.iterator();
57 boolean found = false;
58 while (it.hasNext() && !found) {
59 ass = (Asset) it.next();
60 try {
61 if (ass.getFileName().equals(asset)) {
62 slideShowCV.removeAsset(ass);
63 found = true;
64 }
65 }
66 catch (SQLException ex1) { //thrown in Asset.getFileName()
67 }
68 }
69 }
70 }
71 }
72 }
73 return actionMapping.findForward("refresh");
74 }
75
76 /*Shout at the user if they entered a blank slide show name */
77 if (addSlideShowForm.getSlideShowName().trim().equals("")) {
78 errors = new ActionErrors();
79 errors.add("slideShow", new ActionError("no.slideshow.name.given"));
80 this.saveErrors(httpServletRequest, errors);
81 return actionMapping.findForward("refresh");
82 }
83
84 /*Vectors used in addSlideShowSuccess.jsp (will be pushed on to the session) */
85 Vector slideShowTags = new Vector();
86 Vector slideShowAssets = new Vector();
87
88 /*Save slide show */
89 if (submitType.equals("saveAndView")) {
90 try {
91 /*Add the SlideShowName, Delay and Owner to the slideshowtable */
92 AssetDB assetDB = AssetDB.instance();
93 slideShowName = addSlideShowForm.getSlideShowName();
94 String delay = addSlideShowForm.getDelay();
95 User user = (User) httpServletRequest.getSession().getAttribute("User");
96 /*Does not check if the user is null as this action should not be able
97 to be accessed if the user is not logged in!! */
98 addSlideShowForm.setOwner(user.getUserName());
99 /**@todo we are setting a 511 permissionID here, make sure it is set
100 * properly in some other page... */
101 int affected = assetDB.addSlideShow(slideShowName, delay,
102 user.getUserName(), "511");
103
104 /*Notify the user if they already have a slideshow with their specified name */
105 if (affected == 0) {
106 errors = new ActionErrors();
107 errors.add("slideShow", new ActionError("slideshow.already.exists"));
108 this.saveErrors(httpServletRequest, errors);
109 return actionMapping.findForward("refresh");
110 }
111
112 /*Add the SlideShowName and metadatatags to the slideshowtagstable*/
113 String potentialName;
114 String tag;
115 for (Enumeration e = httpServletRequest.getParameterNames();
116 e.hasMoreElements(); ) {
117 potentialName = (String) e.nextElement();
118 if (potentialName.length() > 9) {
119 if (potentialName.substring(0, 9).equals("metadata_")) {
120 tag = potentialName.substring(9);
121 slideShowTags.add(tag);
122 assetDB.addSlideShowTag(slideShowName, tag, user.getUserName());
123 }
124 }
125 }
126
127 /*Add the SlideShowName and asset file names to the slideshowassetstable */
128 if (slideShowCV != null) {
129 Iterator it = slideShowCV.iterator();
130 String asset;
131 while (it.hasNext()) {
132 asset = ( (Asset) it.next()).getFileName();
133 slideShowAssets.add(asset);
134 assetDB.addSlideShowAsset(slideShowName, asset, user.getUserName());
135 }
136 }
137
138 if (user == null) {
139 return actionMapping.findForward("failure");
140 }
141 String ownerName = (String) addSlideShowForm.getOwner();
142 SlideShow slideShow = ClientApp.instance().getUserMgr().getSlideShow(
143 ownerName, slideShowName);
144 httpServletRequest.getSession().setAttribute("slideShow", slideShow);
145 }
146 catch (SQLException ex) {
147 }
148 }
149
150 /*Push vectors used in addSlideShowSuccess on to the session */
151 httpServletRequest.getSession().setAttribute("slideShowTags", slideShowTags);
152 httpServletRequest.getSession().setAttribute("slideShowAssets",
153 slideShowAssets);
154
155 return actionMapping.findForward("success");
156 }
157 }