Project

General

Profile

« Previous | Next » 

Revision 2347

Added by sgarg about 20 years ago

Added code to check id document is passed as part of the params. This is done toprevent NullPointerException which results in sending null to the user.

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
1500 1500
        try {
1501 1501
            // Get the document indicated
1502 1502
            String[] doctext = (String[]) params.get("doctext");
1503

  
1504 1503
            String pub = null;
1505 1504
            if (params.containsKey("public")) {
1506 1505
                pub = ((String[]) params.get("public"))[0];
......
1516 1515
                } catch (NullPointerException npe) {
1517 1516
                }
1518 1517
            }
1518

  
1519
            if(doctext == null){
1520
                out.println("<?xml version=\"1.0\"?>");
1521
                out.println("<error>");
1522
                out.println("Document text not submitted");
1523
                out.println("</error>");
1524
                return;
1525
            }
1526

  
1519 1527
            StringReader xml = new StringReader(doctext[0]);
1520 1528
            boolean validate = false;
1521 1529
            DocumentImplWrapper documentWrapper = null;
......
2117 2125
        try {
2118 2126
            response.setContentType("text/xml");
2119 2127
            PrintWriter out = response.getWriter();
2120
            
2128

  
2121 2129
            // Check that the user is authenticated as an administrator account
2122 2130
            boolean adminIsAuthenticated = false;
2123 2131
            for (int i = 0; i < administrators.length; i++) {
......
2127 2135
            }
2128 2136
            if (!adminIsAuthenticated) {
2129 2137
                out.print("<error>");
2130
                out.print("The user \"" + username + 
2138
                out.print("The user \"" + username +
2131 2139
                        "\" is not authorized for this action.");
2132 2140
                out.print("</error>");
2133 2141
                return;
2134 2142
            }
2135
    
2143

  
2136 2144
            // Get all of the parameters in the correct formats
2137 2145
            String[] ipAddress = (String[])params.get("ipaddress");
2138 2146
            String[] principal = (String[])params.get("principal");
......
2161 2169
            } catch (ParseException e) {
2162 2170
                System.out.println("Failed to created Timestamp from input.");
2163 2171
            }
2164
    
2172

  
2165 2173
            // Request the report by passing the filter parameters
2166 2174
            out.println(EventLog.getInstance().getReport(ipAddress, principal,
2167 2175
                    docid, event, startDate, endDate));
......
2183 2191
     * @param response the http response object for writing output
2184 2192
     * @param username the username of the authenticated user
2185 2193
     */
2186
    private void handleBuildIndexAction(Hashtable params, 
2194
    private void handleBuildIndexAction(Hashtable params,
2187 2195
            HttpServletRequest request, HttpServletResponse response,
2188 2196
            String username)
2189 2197
    {
......
2194 2202
        try {
2195 2203
            response.setContentType("text/xml");
2196 2204
            PrintWriter out = response.getWriter();
2197
            
2205

  
2198 2206
            // Check that the user is authenticated as an administrator account
2199 2207
            boolean adminIsAuthenticated = false;
2200 2208
            for (int i = 0; i < administrators.length; i++) {
......
2204 2212
            }
2205 2213
            if (!adminIsAuthenticated) {
2206 2214
                out.print("<error>");
2207
                out.print("The user \"" + username + 
2215
                out.print("The user \"" + username +
2208 2216
                        "\" is not authorized for this action.");
2209 2217
                out.print("</error>");
2210 2218
                return;
......
2242 2250
    }
2243 2251

  
2244 2252
    /**
2245
     * Build the index for one document by reading the document and 
2253
     * Build the index for one document by reading the document and
2246 2254
     * calling its buildIndex() method.
2247 2255
     *
2248 2256
     * @param docid the document (with revision) to rebuild

Also available in: Unified diff