Source code: org/acs/damsel/client/edit/EditAssetAction.java
1 package org.acs.damsel.client.edit;
2
3 import java.util.*;
4 import javax.servlet.http.*;
5
6 import org.acs.damsel.client.*;
7 import org.acs.damsel.srvr.*;
8 import org.acs.damsel.srvr.asset.*;
9 import org.acs.damsel.srvr.repository.*;
10 import org.apache.log4j.*;
11 import org.apache.struts.action.*;
12 import java.sql.*;
13
14 public class EditAssetAction extends Action {
15
16 private Logger log = Logger.getLogger(EditAssetAction.class);
17
18 public EditAssetAction() {
19 BasicConfigurator.resetConfiguration();
20 PropertyConfigurator.configure(Config.instance().getLogPropertiesFileName());
21 }
22
23 public ActionForward execute(ActionMapping actionMapping,
24 ActionForm actionForm,
25 HttpServletRequest httpServletRequest,
26 HttpServletResponse httpServletResponse) {
27
28 EditAssetForm editAssetForm = (EditAssetForm) actionForm;
29 Asset asset = editAssetForm.getAsset();
30
31 String descriptorValue = null;
32 String descriptorName = null;
33 Vector assetDescriptorValueList = new Vector();
34 Vector assetDescriptorNameList = new Vector();
35
36 AssetDescriptor ad = new AssetDescriptor();
37 AssetDescriptorCollection adc = new AssetDescriptorCollection();
38
39 // The input forms on the edit asset page are dynamically generated according
40 // to the Schema associated with the Collection to which the asset belongs.
41 // The form names are prefixed with "form_" to distinguish
42 // them from other parameters, like the submit button.
43 // This loops through the list of parameters and picks off the form entries.
44 // It then updates the value of each AssetDescriptor with the value entered
45 // into the corresponding textfield. Note that this does not currently do
46 // any validation. Once the AssetDescriptors have been updated the entire
47 // asset is updated in the database.
48 for (Enumeration e = httpServletRequest.getParameterNames();
49 e.hasMoreElements(); ) {
50 String potentialName = (String) e.nextElement();
51 if (potentialName.substring(0, 5).equals("form_")) {
52 ad = new AssetDescriptor();
53 descriptorName = potentialName.substring(5);
54 descriptorValue = (String) httpServletRequest.getParameter(
55 potentialName);
56 // This sets the value of the text within a corresponding
57 // AssetDescriptor to a new user specified value.
58 assetDescriptorNameList.addElement(descriptorName);
59 assetDescriptorValueList.addElement(descriptorValue);
60 asset.getAssetDescriptors().getAssetDescriptor(descriptorName).setValue(descriptorValue);
61 }
62 }
63 RepositoryMgr rmgr = ClientApp.instance().getRepositoryMgr();
64 try {
65 httpServletRequest.getSession().setAttribute("assetDescriptorNameList",assetDescriptorNameList);
66 httpServletRequest.getSession().setAttribute("assetDescriptorValueList",assetDescriptorValueList);
67 rmgr.updateAsset(asset);
68 }
69 catch (SQLException ex) {
70 log.warn("Unexpected SQLException in EditAssetAction: " + ex.getMessage());
71 }
72
73 return actionMapping.findForward("success");
74 }
75 }