KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > exceptions > web > MapIssueAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.exceptions.web;
20
21 import java.security.NoSuchAlgorithmException JavaDoc;
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23 import javax.servlet.http.HttpServletResponse JavaDoc;
24 import org.apache.struts.action.ActionForm;
25 import org.apache.struts.action.ActionMapping;
26 import org.apache.struts.action.ActionForward;
27 import org.netbeans.modules.exceptions.entity.Issue;
28 /**
29  *
30  * @author Jan Horvath
31  * @version
32  */

33
34 public class MapIssueAction extends MyAction {
35     
36     /* forward name="success" path="" */
37     private final static String JavaDoc SUCCESS = "success";
38     private final static String JavaDoc ERROR = "error";
39     
40     /**
41      * This is the action called from the Struts framework.
42      * @param mapping The ActionMapping used to select this instance.
43      * @param form The optional ActionForm bean for this request.
44      * @param request The HTTP Request we are processing.
45      * @param response The HTTP Response we are processing.
46      * @throws java.lang.Exception
47      * @return
48      */

49     public ActionForward execute(ActionMapping mapping, ActionForm form,
50             HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
51             throws Exception JavaDoc {
52         Integer JavaDoc id = null;
53         Integer JavaDoc issuezillaId = null;
54         String JavaDoc sum = request.getParameter("sum");
55         try {
56             id = new Integer JavaDoc(request.getParameter("id"));
57             issuezillaId = new Integer JavaDoc(request.getParameter("issue"));
58         } catch (NumberFormatException JavaDoc e) {
59             return mapping.findForward(ERROR);
60         }
61         if (!md5sum(id + "=" + issuezillaId).equals(sum)) return mapping.findForward(ERROR);
62         Issue issue = (Issue) getEntity(Issue.class, id);
63         issue.setIssuezillaid(issuezillaId);
64         merge(issue);
65         request.setAttribute("issue", issue);
66         return mapping.findForward(SUCCESS);
67     }
68     
69     private String JavaDoc md5sum(String JavaDoc str) {
70         StringBuffer JavaDoc sum = new StringBuffer JavaDoc();
71         try {
72             java.security.MessageDigest JavaDoc md5 = java.security.MessageDigest.getInstance("MD5");
73             md5.update(str.getBytes());
74             byte[] sign = md5.digest();
75             for (byte b : sign) {
76                 sum.append(byteToHex(b));
77             }
78         } catch (NoSuchAlgorithmException JavaDoc ex) {
79             java.util.logging.Logger.getLogger("global").log(java.util.logging.Level.SEVERE,
80                     ex.getMessage(), ex);
81         }
82         return sum.toString();
83     }
84     
85     private String JavaDoc byteToHex(byte data) {
86         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
87         buf.append(Character.forDigit((data >>> 4) & 0x0F, 16));
88         buf.append(Character.forDigit((data & 0x0F), 16));
89         return buf.toString();
90     }
91 }
92
Popular Tags