Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/acs/damsel/client/remove/RemoveAssetFromCollectionAction.java


1   package org.acs.damsel.client.remove;
2   
3   import java.util.*;
4   import javax.servlet.http.*;
5   import org.acs.damsel.srvr.asset.*;
6   import org.acs.damsel.srvr.*;
7   import org.acs.damsel.srvr.db.*;
8   import org.apache.log4j.*;
9   import org.apache.struts.action.*;
10  
11  public class RemoveAssetFromCollectionAction
12      extends Action {
13  
14    private Logger log = Logger.getLogger(RemoveAssetFromCollectionAction.class);
15  
16    public RemoveAssetFromCollectionAction() {
17      BasicConfigurator.resetConfiguration();
18      PropertyConfigurator.configure(Config.instance().getLogPropertiesFileName());
19    }
20  
21    public ActionForward execute(ActionMapping actionMapping,
22                                 ActionForm actionForm,
23                                 HttpServletRequest httpServletRequest,
24                                 HttpServletResponse httpServletResponse) {
25      RemoveAssetFromCollectionForm removeAssetFromCollectionForm = (
26          RemoveAssetFromCollectionForm) actionForm;
27  
28      ActionErrors errors;
29  
30      try {
31        AssetDB assetDB = AssetDB.instance();
32        String value;
33        String name;
34        String potentialName;
35        Vector assetsToDelete = new Vector();
36  
37        //if new collection was selected from list of collections, then...
38        if (removeAssetFromCollectionForm.isChangedCollection()) {
39          removeAssetFromCollectionForm.setChangedCollection(false);
40          return actionMapping.findForward("reset");
41        }
42        else {
43          //if delete button was clicked, then...
44          for (Enumeration e = httpServletRequest.getParameterNames();
45               e.hasMoreElements(); ) {
46            potentialName = (String) e.nextElement();
47            if (potentialName.startsWith("delete")) {
48              name = potentialName.substring(potentialName.indexOf("delete") + 6).
49                  toString();
50              value = httpServletRequest.getParameter(potentialName);
51              if (value.equals("true")) {
52                Asset asset = assetDB.getAsset(name);
53                assetsToDelete.addElement(name);
54                assetDB.removeAssetFromCollection(asset,
55                                                  removeAssetFromCollectionForm.
56                                                  getCollectionSelect());
57              }
58            }
59          }
60          httpServletRequest.getSession().setAttribute("assetsToDelete",assetsToDelete);
61          return actionMapping.findForward("success");
62        }
63  
64      }
65  
66      catch (Exception ex) {
67        log.warn(ex.getClass() + " encountered in EditUserAction: " +
68                 ex.getMessage());
69        errors = new ActionErrors();
70        errors.add("removeAsset", new ActionError("removeAsset.not.successful"));
71        this.saveErrors(httpServletRequest, errors);
72        return actionMapping.findForward("failure");
73      }
74    }
75  }