~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to logger/StrutsExceptions/src/java/org/netbeans/modules/exceptions/web/action/DetailAction.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
6
 * The contents of this file are subject to the terms of either the GNU
 
7
 * General Public License Version 2 only ("GPL") or the Common
 
8
 * Development and Distribution License("CDDL") (collectively, the
 
9
 * "License"). You may not use this file except in compliance with the
 
10
 * License. You can obtain a copy of the License at
 
11
 * http://www.netbeans.org/cddl-gplv2.html
 
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
13
 * specific language governing permissions and limitations under the
 
14
 * License.  When distributing the software, include this License Header
 
15
 * Notice in each file and include the License file at
 
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
17
 * particular file as subject to the "Classpath" exception as provided
 
18
 * by Sun in the GPL Version 2 section of the License file that
 
19
 * accompanied this code. If applicable, add the following below the
 
20
 * License Header, with the fields enclosed by brackets [] replaced by
 
21
 * your own identifying information:
 
22
 * "Portions Copyrighted [year] [name of copyright owner]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * The Original Software is NetBeans. The Initial Developer of the Original
 
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
 
28
 * Microsystems, Inc. All Rights Reserved.
 
29
 *
 
30
 * If you wish your version of this file to be governed by only the CDDL
 
31
 * or only the GPL Version 2, indicate your decision by adding
 
32
 * "[Contributor] elects to include this software in this distribution
 
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 
34
 * single choice of license, a recipient has the option to distribute
 
35
 * your version of this file under either the CDDL, the GPL Version 2 or
 
36
 * to extend the choice of license to its licensees as provided above.
 
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 
38
 * Version 2 license, then the option applies only if the new code is
 
39
 * made subject to such option by the copyright holder.
 
40
 */
 
41
package org.netbeans.modules.exceptions.web.action;
 
42
 
 
43
import java.security.Principal;
 
44
import java.util.ArrayList;
 
45
import java.util.Collection;
 
46
import java.util.Collections;
 
47
import java.util.Iterator;
 
48
import java.util.Map;
 
49
import java.util.logging.Handler;
 
50
import java.util.logging.LogRecord;
 
51
import javax.servlet.http.HttpServletRequest;
 
52
import javax.servlet.http.HttpServletResponse;
 
53
import org.apache.struts.action.ActionForm;
 
54
import org.apache.struts.action.ActionMapping;
 
55
import org.apache.struts.action.ActionForward;
 
56
import org.netbeans.modules.exceptions.entity.Comment;
 
57
import org.netbeans.modules.exceptions.entity.Exceptions;
 
58
import org.netbeans.modules.exceptions.entity.Nbuser;
 
59
import org.netbeans.modules.exceptions.utils.LoggerUtils;
 
60
import org.netbeans.modules.exceptions.utils.PersistenceUtils;
 
61
/**
 
62
 *
 
63
 * @author Jan Horvath
 
64
 * @version
 
65
 */
 
66
 
 
67
public class DetailAction extends ExceptionsAbstractAction {
 
68
    
 
69
    /* forward name="success" path="" */
 
70
    private final static String SUCCESS = "success";
 
71
    private final static String LOGGER = "logger";
 
72
    
 
73
    /**
 
74
     * This is the action called from the Struts framework.
 
75
     * @param mapping The ActionMapping used to select this instance.
 
76
     * @param form The optional ActionForm bean for this request.
 
77
     * @param request The HTTP Request we are processing.
 
78
     * @param response The HTTP Response we are processing.
 
79
     * @throws java.lang.Exception
 
80
     * @return
 
81
     */
 
82
    public ActionForward execute(ActionMapping mapping, ActionForm  form,
 
83
            HttpServletRequest request, HttpServletResponse response)
 
84
            throws Exception {
 
85
        Integer id = null;
 
86
        Integer newduplicateof = null;
 
87
        Integer newissuezillaid = null;
 
88
        String component = request.getParameter("component");
 
89
        String subcomponent = request.getParameter("subcomponent");
 
90
        String comment = request.getParameter("comment");
 
91
        String username = request.getParameter("username");
 
92
        String duplicateof = request.getParameter("duplicateof");
 
93
        
 
94
        try {
 
95
            id = new Integer(request.getParameter("id"));
 
96
        } catch (NumberFormatException e) {
 
97
        }
 
98
        try {
 
99
            newduplicateof = new Integer(duplicateof);
 
100
        } catch (NumberFormatException e) {
 
101
        }
 
102
        try {
 
103
            newissuezillaid = new Integer(request.getParameter("issuezillaid"));
 
104
        } catch (NumberFormatException e) {
 
105
        }
 
106
        
 
107
        
 
108
        Exceptions exceptions = (Exceptions) PersistenceUtils.getInstance().getEntity(Exceptions.class, id);
 
109
        
 
110
        // make updates
 
111
        boolean merge = false;
 
112
        if ((newissuezillaid != null) && (exceptions !=null)) {
 
113
            exceptions.setIssuezillaid(newissuezillaid);
 
114
            exceptions.setIssueManChanged(true);
 
115
            merge = true;
 
116
        }
 
117
        
 
118
        if ((duplicateof != null) && (exceptions !=null)) {
 
119
            Exceptions duplExc = null;
 
120
            if (newduplicateof != null) {
 
121
                duplExc = (Exceptions) PersistenceUtils.getInstance().getEntity(Exceptions.class, newduplicateof);
 
122
            }
 
123
//            if (duplicateof != null) {
 
124
                exceptions.setDuplicateof(duplExc);
 
125
                exceptions.setDuplicateManChanged(true);
 
126
                merge = true;
 
127
//            }
 
128
        }
 
129
        
 
130
        if ((subcomponent != null) && (subcomponent.length() > 0) && (component != null) && (component.length() > 0)) {
 
131
            exceptions.setComponentAndSubcomponent(component, subcomponent);
 
132
            exceptions.setComponentManChanged(true);
 
133
            merge = true;
 
134
        }
 
135
        
 
136
        if ((comment != null) && (comment.length() > 0)) {
 
137
            Comment commentEntity = new Comment();
 
138
            commentEntity.setComment(comment);
 
139
            Principal p = request.getUserPrincipal();
 
140
            if (p != null) {
 
141
                System.err.println("** " + p.getName());
 
142
                Collection col = PersistenceUtils.getInstance().find(Nbuser.class,(Map) java.util.Collections.singletonMap("name", Collections.singletonList(p.getName())));
 
143
                if (!col.isEmpty()) {
 
144
                    Nbuser nbuser = (Nbuser) col.iterator().next();
 
145
                    commentEntity.setNbuserId(nbuser);
 
146
                }
 
147
                commentEntity.setExceptionId(exceptions);
 
148
                exceptions.getCommentCollection().add(commentEntity);
 
149
            }
 
150
            merge = true;
 
151
        }
 
152
        
 
153
        if (merge) {
 
154
            if (checkPrivileges(request)) {
 
155
                PersistenceUtils.getInstance().merge(exceptions);
 
156
            } else {
 
157
                return mapping.findForward(LOGIN);
 
158
            }
 
159
            
 
160
            response.sendRedirect("detail.do?id=" + exceptions.getId());
 
161
        }
 
162
        
 
163
        request.setAttribute("exceptions", exceptions);
 
164
        
 
165
        
 
166
        
 
167
        
 
168
        
 
169
        
 
170
        String logger = request.getParameter("logger");
 
171
        if ((logger != null) && (exceptions != null)) {
 
172
            //get logger
 
173
            H handler = new H();
 
174
            LoggerUtils.getLogRecord(exceptions.getLoggername(), handler);
 
175
            ArrayList lines = new ArrayList();
 
176
            for (Iterator<LogRecord> it = handler.nr.iterator(); it.hasNext();) {
 
177
                LogRecord record = it.next();
 
178
                lines.add(LoggerUtils.getLine(record));
 
179
            }
 
180
            request.setAttribute("logger",lines);
 
181
            return mapping.findForward(LOGGER);
 
182
        }
 
183
        
 
184
        request.setAttribute("components", PersistenceUtils.getInstance().getComponents().getComponentsSet());
 
185
        
 
186
        return mapping.findForward(SUCCESS);
 
187
        
 
188
    }
 
189
    
 
190
    class H extends Handler {
 
191
        public ArrayList<LogRecord> nr = new ArrayList<LogRecord>();
 
192
        
 
193
        public void publish(LogRecord arg0) {
 
194
            nr.add(arg0);
 
195
        }
 
196
        
 
197
        public void flush() {
 
198
        }
 
199
        
 
200
        public void close() throws SecurityException {
 
201
        }
 
202
        
 
203
    }
 
204
}