Project

General

Profile

« Previous | Next » 

Revision 4487

Added by daigle about 16 years ago

Add some generic typing

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
27 27
package edu.ucsb.nceas.metacat;
28 28

  
29 29
import java.io.BufferedInputStream;
30
import java.io.BufferedReader;
31 30
import java.io.File;
32 31
import java.io.FileInputStream;
33 32
import java.io.FileReader;
......
66 65

  
67 66
import org.apache.log4j.Logger;
68 67
import org.apache.log4j.PropertyConfigurator;
69
import org.ecoinformatics.eml.EMLParser;
68
//import org.ecoinformatics.eml.EMLParser;
70 69

  
71 70
import au.com.bytecode.opencsv.CSVWriter;
72 71

  
......
586 585
				Enumeration<String> paramlist =(Enumeration<String>)request.getParameterNames();
587 586
				while (paramlist.hasMoreElements()) {
588 587

  
589
					name = (String) paramlist.nextElement();
588
					name = paramlist.nextElement();
590 589
					value = request.getParameterValues(name);
591 590

  
592 591
					// Decode the docid and mouse click information
......
623 622
					return;
624 623
				}
625 624

  
626
				String action = ((String[]) params.get("action"))[0];
625
				String action = (params.get("action"))[0];
627 626
				logMetacat.info("Action is: " + action);
628 627

  
629 628
				// This block handles session management for the servlet
......
906 905
			dq = new DataQuery();
907 906
		}
908 907
		
909
    	String dataqueryXML = ((String[])params.get("dataquery"))[0];
908
    	String dataqueryXML = (params.get("dataquery"))[0];
910 909

  
911 910
    	ResultSet rs = null;
912 911
		try {
......
963 962
			cm = new CartManager();
964 963
		}
965 964
		
966
    	String editOperation = ((String[])params.get("operation"))[0];
965
    	String editOperation = (params.get("operation"))[0];
967 966
    	
968
    	String[] docids = (String[]) params.get("docid");
969
    	String[] field = (String[])params.get("field");
970
    	String[] path = (String[])params.get("path");
967
    	String[] docids = params.get("docid");
968
    	String[] field = params.get("field");
969
    	String[] path = params.get("path");
971 970
    	
972
    	Map fields = null;
971
    	Map<String,String> fields = null;
973 972
    	if (field != null && path != null) {
974
    		fields = new HashMap();
973
    		fields = new HashMap<String,String>();
975 974
    		fields.put(field[0], path[0]);
976 975
    	}
977 976
    	
......
1005 1004
        /*
1006 1005
		 * Perform spatial query against spatial cache
1007 1006
		 */
1008
        float _xmax = Float.valueOf( ((String[]) params.get("xmax"))[0] ).floatValue();
1009
        float _ymax = Float.valueOf( ((String[]) params.get("ymax"))[0] ).floatValue();
1010
        float _xmin = Float.valueOf( ((String[]) params.get("xmin"))[0] ).floatValue();
1011
        float _ymin = Float.valueOf( ((String[]) params.get("ymin"))[0] ).floatValue();
1007
        float _xmax = Float.valueOf( (params.get("xmax"))[0] ).floatValue();
1008
        float _ymax = Float.valueOf( (params.get("ymax"))[0] ).floatValue();
1009
        float _xmin = Float.valueOf( (params.get("xmin"))[0] ).floatValue();
1010
        float _ymin = Float.valueOf( (params.get("ymin"))[0] ).floatValue();
1012 1011
        SpatialQuery sq = new SpatialQuery();
1013 1012
        Vector<String> docids = sq.filterByBbox( _xmin, _ymin, _xmax, _ymax );
1014 1013
        // logMetacat.info(" --- Spatial Query completed. Passing on the SQuery
......
1036 1035
		 */
1037 1036
        String[] qformatArray = new String[1];
1038 1037
        try {
1039
            String _skin = ((String[]) params.get("skin"))[0];
1038
            String _skin = (params.get("skin"))[0];
1040 1039
            qformatArray[0] = _skin;
1041 1040
        } catch (java.lang.NullPointerException e) {
1042 1041
            // should be "default" but keep this for backwards compatibility
......
1095 1094
            return;
1096 1095
        }
1097 1096
        
1098
        String un = ((String[]) params.get("username"))[0];
1097
        String un = (params.get("username"))[0];
1099 1098
        logMetacat.info("user " + un + " is trying to login");
1100
        String pw = ((String[]) params.get("password"))[0];
1099
        String pw = (params.get("password"))[0];
1101 1100
        
1102 1101
        String qformat = "xml";
1103 1102
        if(params.get("qformat") != null){
1104
            qformat = ((String[]) params.get("qformat"))[0];
1103
            qformat = (params.get("qformat"))[0];
1105 1104
        }
1106 1105
        
1107 1106
        try {
......
1155 1154
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
1156 1155
        String qformat = "xml";
1157 1156
        if(params.get("qformat") != null){
1158
            qformat = ((String[]) params.get("qformat"))[0];
1157
            qformat = params.get("qformat")[0];
1159 1158
        }
1160 1159
        
1161 1160
        // close the connection
......
1209 1208
     * @param response the response object linked to the client
1210 1209
     * @param conn the database connection
1211 1210
     */
1212
    private void handleSQuery(PrintWriter out, Hashtable params,
1211
    private void handleSQuery(PrintWriter out, Hashtable<String, String[]> params,
1213 1212
            HttpServletResponse response, String user, String[] groups,
1214 1213
            String sessionid) throws PropertyNotFoundException {
1215 1214
        double startTime = System.currentTimeMillis() / 1000;
......
1283 1282
        try {
1284 1283
            // read the params
1285 1284
            if (params.containsKey("docid")) {
1286
                docs = (String[]) params.get("docid");
1285
                docs = params.get("docid");
1287 1286
            }
1288 1287
            // Create a DBuery to handle export
1289 1288
            queryObj = new DBQuery();
......
1360 1359
     * @param user the username sent the request
1361 1360
     * @param groups the user's groupnames
1362 1361
     */
1363
    private void handleReadInlineDataAction(Hashtable params,
1362
    private void handleReadInlineDataAction(Hashtable<String, String[]> params,
1364 1363
            HttpServletRequest request, HttpServletResponse response,
1365 1364
            String user, String passWord, String[] groups) {
1366 1365
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
......
1372 1371
        try {
1373 1372
            // read the params
1374 1373
            if (params.containsKey("inlinedataid")) {
1375
                docs = (String[]) params.get("inlinedataid");
1374
                docs = params.get("inlinedataid");
1376 1375
            }
1377 1376
            // Get the docid
1378 1377
            inlineDataId = docs[0];
......
1393 1392
            } else {
1394 1393
                //check data access level
1395 1394
                try {
1396
                    Hashtable unReadableInlineDataList =
1395
                    Hashtable<String,String> unReadableInlineDataList =
1397 1396
                            PermissionController.getUnReadableInlineDataIdList(docId,
1398 1397
                            user, groups, false);
1399 1398
                    String inlineDataIdWithoutRev = MetaCatUtil.getInlineDataIdWithoutRev(inlineDataId);
......
1455 1454
        }
1456 1455
    }
1457 1456
    
1458
    /*
1459
     * Get the nodeid from xml_nodes for the inlinedataid
1460
     */
1461
    private long getInlineDataNodeId(String inLineDataId, String docId)
1462
    throws SQLException {
1463
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
1464
        long nodeId = 0;
1465
        String INLINE = "inline";
1466
        boolean hasRow;
1467
        PreparedStatement pStmt = null;
1468
        DBConnection conn = null;
1469
        int serialNumber = -1;
1470
        String sql = "SELECT nodeid FROM xml_nodes WHERE docid=? AND nodedata=? "
1471
                + "AND nodetype='TEXT' AND parentnodeid IN "
1472
                + "(SELECT nodeid FROM xml_nodes WHERE docid=? AND "
1473
                + "nodetype='ELEMENT' AND nodename='" + INLINE + "')";
1474
        
1475
        try {
1476
            //check out DBConnection
1477
            conn = DBConnectionPool
1478
                    .getDBConnection("AccessControlList.isAllowFirst");
1479
            serialNumber = conn.getCheckOutSerialNumber();
1480
            
1481
            pStmt = conn.prepareStatement(sql);
1482
            //bind value
1483
            pStmt.setString(1, docId);//docid
1484
            pStmt.setString(2, inLineDataId);//inlinedataid
1485
            pStmt.setString(3, docId);
1486
            // excute query
1487
            pStmt.execute();
1488
            ResultSet rs = pStmt.getResultSet();
1489
            hasRow = rs.next();
1490
            // get result
1491
            if (hasRow) {
1492
                nodeId = rs.getLong(1);
1493
            }//if
1494
            
1495
        } catch (SQLException e) {
1496
            throw e;
1497
        } finally {
1498
            try {
1499
                pStmt.close();
1500
            } finally {
1501
                DBConnectionPool.returnDBConnection(conn, serialNumber);
1502
            }
1503
        }
1504
        logMetacat.debug("The nodeid for inlinedataid " + inLineDataId
1505
                + " is: " + nodeId);
1506
        return nodeId;
1507
    }
1457
//    /*
1458
//     * Get the nodeid from xml_nodes for the inlinedataid
1459
//     */
1460
//    private long getInlineDataNodeId(String inLineDataId, String docId)
1461
//    throws SQLException {
1462
//        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
1463
//        long nodeId = 0;
1464
//        String INLINE = "inline";
1465
//        boolean hasRow;
1466
//        PreparedStatement pStmt = null;
1467
//        DBConnection conn = null;
1468
//        int serialNumber = -1;
1469
//        String sql = "SELECT nodeid FROM xml_nodes WHERE docid=? AND nodedata=? "
1470
//                + "AND nodetype='TEXT' AND parentnodeid IN "
1471
//                + "(SELECT nodeid FROM xml_nodes WHERE docid=? AND "
1472
//                + "nodetype='ELEMENT' AND nodename='" + INLINE + "')";
1473
//        
1474
//        try {
1475
//            //check out DBConnection
1476
//            conn = DBConnectionPool
1477
//                    .getDBConnection("AccessControlList.isAllowFirst");
1478
//            serialNumber = conn.getCheckOutSerialNumber();
1479
//            
1480
//            pStmt = conn.prepareStatement(sql);
1481
//            //bind value
1482
//            pStmt.setString(1, docId);//docid
1483
//            pStmt.setString(2, inLineDataId);//inlinedataid
1484
//            pStmt.setString(3, docId);
1485
//            // excute query
1486
//            pStmt.execute();
1487
//            ResultSet rs = pStmt.getResultSet();
1488
//            hasRow = rs.next();
1489
//            // get result
1490
//            if (hasRow) {
1491
//                nodeId = rs.getLong(1);
1492
//            }//if
1493
//            
1494
//        } catch (SQLException e) {
1495
//            throw e;
1496
//        } finally {
1497
//            try {
1498
//                pStmt.close();
1499
//            } finally {
1500
//                DBConnectionPool.returnDBConnection(conn, serialNumber);
1501
//            }
1502
//        }
1503
//        logMetacat.debug("The nodeid for inlinedataid " + inLineDataId
1504
//                + " is: " + nodeId);
1505
//        return nodeId;
1506
//    }
1508 1507
    
1509 1508
    /**
1510 1509
     * Handle the "read" request of metadata/data files from Metacat or any
......
1517 1516
     * @param user the username sent the request
1518 1517
     * @param groups the user's groupnames
1519 1518
     */
1520
    private void handleReadAction(Hashtable params, HttpServletRequest request,
1519
    private void handleReadAction(Hashtable<String, String[]> params, HttpServletRequest request,
1521 1520
            HttpServletResponse response, String user, String passWord,
1522 1521
            String[] groups) {
1523 1522
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
......
1535 1534
            
1536 1535
            // read the params
1537 1536
            if (params.containsKey("docid")) {
1538
                docs = (String[]) params.get("docid");
1537
                docs = params.get("docid");
1539 1538
            }
1540 1539
            if (params.containsKey("qformat")) {
1541
                qformat = ((String[]) params.get("qformat"))[0];
1540
                qformat = params.get("qformat")[0];
1542 1541
            }
1543 1542
            // the param for only metadata (eml)
1544 1543
            // we don't support read a eml document without inline data now.
......
1559 1558
            for (int i = 0; i < docs.length; i++) {
1560 1559
            	String providedFileName = null;
1561 1560
            	if (params.containsKey(docs[i])) {
1562
                    providedFileName = ((String[]) params.get(docs[i]))[0];
1561
                    providedFileName = params.get(docs[i])[0];
1563 1562
                }
1564 1563
                try {
1565 1564
                    
1566 1565
                    URL murl = new URL(docs[i]);
1567
                    Hashtable murlQueryStr = MetaCatUtil.parseQuery(
1566
                    Hashtable<String,String> murlQueryStr = MetaCatUtil.parseQuery(
1568 1567
                            murl.getQuery());
1569 1568
                    // case docid="http://.../?docid=aaa"
1570 1569
                    // or docid="metacat://.../?docid=bbb"
1571 1570
                    if (murlQueryStr.containsKey("docid")) {
1572 1571
                        // get only docid, eliminate the rest
1573
                        docid = (String) murlQueryStr.get("docid");
1572
                        docid = murlQueryStr.get("docid");
1574 1573
                        if (zip) {
1575 1574
                            addDocToZip(request, docid, providedFileName, zout, user, groups);
1576 1575
                        } else {
......
1715 1714
    private void readFromMetacat(HttpServletRequest request,
1716 1715
            HttpServletResponse response, String docid, String qformat,
1717 1716
            String abstrpath, String user, String[] groups, boolean zip,
1718
            ZipOutputStream zout, boolean withInlineData, Hashtable params)
1717
            ZipOutputStream zout, boolean withInlineData, Hashtable<String, String[]> params)
1719 1718
            throws ClassNotFoundException, IOException, SQLException,
1720 1719
            McdbException, Exception {
1721 1720
    	String documentDir = PropertyService.getProperty("application.documentfilepath");
......
2048 2047
     * database connection
2049 2048
     */
2050 2049
    private void handleInsertOrUpdateAction(HttpServletRequest request,
2051
            HttpServletResponse response, PrintWriter out, Hashtable params,
2050
            HttpServletResponse response, PrintWriter out, Hashtable<String, String[]> params,
2052 2051
            String user, String[] groups) {
2053 2052
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
2054 2053
        DBConnection dbConn = null;
......
2057 2056
        String qformat = null;
2058 2057
        if(params.containsKey("qformat"))
2059 2058
        {
2060
          qformat = ((String[])params.get("qformat"))[0];
2059
          qformat = params.get("qformat")[0];
2061 2060
        }
2062 2061
        
2063 2062
        if(params.get("docid") == null){
......
2087 2086
            // Get the document indicated
2088 2087
            System.out.println("params: " + params.toString());
2089 2088
            
2090
            String[] doctext = (String[]) params.get("doctext");
2089
            String[] doctext = params.get("doctext");
2091 2090
            String pub = null;
2092 2091
            if (params.containsKey("public")) {
2093
                pub = ((String[]) params.get("public"))[0];
2092
                pub = params.get("public")[0];
2094 2093
            }
2095 2094
            
2096 2095
            StringReader dtd = null;
2097 2096
            if (params.containsKey("dtdtext")) {
2098
                String[] dtdtext = (String[]) params.get("dtdtext");
2097
                String[] dtdtext = params.get("dtdtext");
2099 2098
                try {
2100 2099
                    if (!dtdtext[0].equals("")) {
2101 2100
                        dtd = new StringReader(dtdtext[0]);
......
2136 2135
                            // set eml2 base	 validation parser
2137 2136
                            String rule = DocumentImpl.EML200;
2138 2137
                            // using emlparser to check id validation
2139
                            EMLParser parser = new EMLParser(doctext[0]);
2138
//                            EMLParser parser = new EMLParser(doctext[0]);
2140 2139
                            documentWrapper = new DocumentImplWrapper(rule, true);
2141 2140
                        } else if (namespace.compareTo(
2142 2141
                                DocumentImpl.EML2_1_0NAMESPACE) == 0) {
2143 2142
                            // set eml2 base validation parser
2144 2143
                            String rule = DocumentImpl.EML210;
2145 2144
                            // using emlparser to check id validation
2146
                            EMLParser parser = new EMLParser(doctext[0]);
2145
//                            EMLParser parser = new EMLParser(doctext[0]);
2147 2146
                            documentWrapper = new DocumentImplWrapper(rule, true);
2148 2147
                        } else {
2149 2148
                            // set schema base validation parser
......
2155 2154
                    }
2156 2155
                }
2157 2156
                
2158
                String[] action = (String[]) params.get("action");
2159
                String[] docid = (String[]) params.get("docid");
2157
                String[] action = params.get("action");
2158
                String[] docid = params.get("docid");
2160 2159
                String newdocid = null;
2161 2160
                
2162 2161
                String doAction = null;
......
2273 2272
    throws IOException {
2274 2273
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
2275 2274
        StringBuffer cbuff = new StringBuffer();
2276
        java.util.Stack st = new java.util.Stack();
2275
        java.util.Stack<String> st = new java.util.Stack<String>();
2277 2276
        boolean validate = false;
2278 2277
        boolean commented = false;
2279 2278
        int c;
......
2317 2316
        // check the stack whether it contains the keywords:
2318 2317
        // "<!DOCTYPE", "PUBLIC" or "SYSTEM", and ">" in this order
2319 2318
        if (st.size() == 4) {
2320
            if (((String) st.pop()).equals(">")
2321
            && (((String) st.peek()).equals("PUBLIC") | ((String) st
2322
                    .pop()).equals("SYSTEM"))
2323
                    && ((String) st.pop()).equals("<!DOCTYPE")) {
2319
            if ((st.pop()).equals(">")
2320
            && ((st.peek()).equals("PUBLIC") | (st.pop()).equals("SYSTEM"))
2321
                    && (st.pop()).equals("<!DOCTYPE")) {
2324 2322
                validate = true && !commented;
2325 2323
            }
2326 2324
        }
......
2335 2333
     * Handle the database delete request and delete an XML document from the
2336 2334
     * database connection
2337 2335
     */
2338
    private void handleDeleteAction(PrintWriter out, Hashtable params,
2336
    private void handleDeleteAction(PrintWriter out, Hashtable<String, String[]> params,
2339 2337
            HttpServletRequest request, HttpServletResponse response,
2340 2338
            String user, String[] groups) {
2341 2339
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
2342
        String[] docid = (String[]) params.get("docid");
2340
        String[] docid = params.get("docid");
2343 2341
        
2344 2342
        if(docid == null){
2345 2343
            response.setContentType("text/xml");
......
2397 2395
    /**
2398 2396
     * Handle the validation request and return the results to the requestor
2399 2397
     */
2400
    private void handleValidateAction(PrintWriter out, Hashtable params) {
2398
    private void handleValidateAction(PrintWriter out, Hashtable<String, String[]> params) {
2401 2399
        
2402 2400
        // Get the document indicated
2403 2401
        String valtext = null;
......
2405 2403
        int serialNumber = -1;
2406 2404
        
2407 2405
        try {
2408
            valtext = ((String[]) params.get("valtext"))[0];
2406
            valtext = params.get("valtext")[0];
2409 2407
        } catch (Exception nullpe) {
2410 2408
            
2411 2409
            String docid = null;
2412 2410
            try {
2413 2411
                // Find the document id number
2414
                docid = ((String[]) params.get("docid"))[0];
2412
                docid = params.get("docid")[0];
2415 2413
                
2416 2414
                // Get the document indicated from the db
2417 2415
                DocumentImpl xmldoc = new DocumentImpl(docid);
......
2435 2433
                    .getDBConnection("MetaCatServlet.handleValidateAction");
2436 2434
            serialNumber = dbConn.getCheckOutSerialNumber();
2437 2435
            DBValidate valobj = new DBValidate(dbConn);
2438
            boolean valid = valobj.validateString(valtext);
2436
//            boolean valid = valobj.validateString(valtext);
2439 2437
            
2440 2438
            // set content type and other response header fields first
2441 2439
            
......
2460 2458
     * "rev;doctype"
2461 2459
     */
2462 2460
    private void handleGetRevisionAndDocTypeAction(PrintWriter out,
2463
            Hashtable params) {
2461
            Hashtable<String, String[]> params) {
2464 2462
        // To store doc parameter
2465 2463
        String[] docs = new String[10];
2466 2464
        // Store a single doc id
2467 2465
        String givenDocId = null;
2468 2466
        // Get docid from parameters
2469 2467
        if (params.containsKey("docid")) {
2470
            docs = (String[]) params.get("docid");
2468
            docs = params.get("docid");
2471 2469
        }
2472 2470
        // Get first docid form string array
2473 2471
        givenDocId = docs[0];
......
2499 2497
     * connection in XML format
2500 2498
     */
2501 2499
    private void handleGetAccessControlAction(PrintWriter out,
2502
            Hashtable params, HttpServletResponse response, String username,
2500
            Hashtable<String,String[]> params, HttpServletResponse response, String username,
2503 2501
            String[] groupnames) {
2504 2502
        DBConnection dbConn = null;
2505 2503
        int serialNumber = -1;
2506
        String docid = ((String[]) params.get("docid"))[0];
2504
        String docid = params.get("docid")[0];
2507 2505
        
2508 2506
        try {
2509 2507
            
......
2549 2547
     * Handle "getdoctypes" action. Read all doctypes from db connection in XML
2550 2548
     * format
2551 2549
     */
2552
    private void handleGetDoctypesAction(PrintWriter out, Hashtable params,
2550
    private void handleGetDoctypesAction(PrintWriter out, Hashtable<String, String[]> params,
2553 2551
            HttpServletResponse response) {
2554 2552
        try {
2555 2553
            DBUtil dbutil = new DBUtil();
......
2567 2565
     * Handle the "getdtdschema" action. Read DTD or Schema file for a given
2568 2566
     * doctype from Metacat catalog system
2569 2567
     */
2570
    private void handleGetDTDSchemaAction(PrintWriter out, Hashtable params,
2568
    private void handleGetDTDSchemaAction(PrintWriter out, Hashtable<String, String[]> params,
2571 2569
            HttpServletResponse response) {
2572 2570
        
2573 2571
        String doctype = null;
2574
        String[] doctypeArr = (String[]) params.get("doctype");
2572
        String[] doctypeArr = params.get("doctype");
2575 2573
        
2576 2574
        // get only the first doctype specified in the list of doctypes
2577 2575
        // it could be done for all doctypes in that list
2578 2576
        if (doctypeArr != null) {
2579
            doctype = ((String[]) params.get("doctype"))[0];
2577
            doctype = params.get("doctype")[0];
2580 2578
        }
2581 2579
        
2582 2580
        try {
......
2593 2591
        
2594 2592
    }
2595 2593
    
2596
    private void handleIdIsRegisteredAction(PrintWriter out, Hashtable params,
2594
    private void handleIdIsRegisteredAction(PrintWriter out, Hashtable<String, String[]> params,
2597 2595
            HttpServletResponse response) {
2598 2596
        String id = null;
2599 2597
        boolean exists = false;
2600 2598
        if(params.get("docid") != null) {
2601
            id = ((String[]) params.get("docid"))[0];
2599
            id = params.get("docid")[0];
2602 2600
        }
2603 2601
        
2604 2602
        try {
......
2622 2620
     * Handle the "getalldocids" action. return a list of all docids registered
2623 2621
     * in the system
2624 2622
     */
2625
    private void handleGetAllDocidsAction(PrintWriter out, Hashtable params,
2623
    private void handleGetAllDocidsAction(PrintWriter out, Hashtable<String, String[]> params,
2626 2624
            HttpServletResponse response) {
2627 2625
        String scope = null;
2628 2626
        if(params.get("scope") != null) {
2629
            scope = ((String[]) params.get("scope"))[0];
2627
            scope = params.get("scope")[0];
2630 2628
        }
2631 2629
        
2632 2630
        try {
2633 2631
            DBUtil dbutil = new DBUtil();
2634
            Vector docids = dbutil.getAllDocids(scope);
2632
            Vector<String> docids = dbutil.getAllDocids(scope);
2635 2633
            out.println("<?xml version=\"1.0\"?>");
2636 2634
            out.println("<idList>");
2637 2635
            out.println("  <scope>" + scope + "</scope>");
2638 2636
            for(int i=0; i<docids.size(); i++) {
2639
                String docid = (String)docids.elementAt(i);
2637
                String docid = docids.elementAt(i);
2640 2638
                out.println("  <docid>" + docid + "</docid>");
2641 2639
            }
2642 2640
            out.println("</idList>");
......
2653 2651
     * Handle the "getlastdocid" action. Get the latest docid with rev number
2654 2652
     * from db connection in XML format
2655 2653
     */
2656
    private void handleGetMaxDocidAction(PrintWriter out, Hashtable params,
2654
    private void handleGetMaxDocidAction(PrintWriter out, Hashtable<String, String[]> params,
2657 2655
            HttpServletResponse response) {
2658 2656
        
2659
        String scope = ((String[]) params.get("scope"))[0];
2657
        String scope = params.get("scope")[0];
2660 2658
        if (scope == null) {
2661
            scope = ((String[]) params.get("username"))[0];
2659
            scope = params.get("username")[0];
2662 2660
        }
2663 2661
        
2664 2662
        try {
......
2687 2685
     * @param request the http request object for getting request details
2688 2686
     * @param response the http response object for writing output
2689 2687
     */
2690
    private void handleGetLogAction(Hashtable params, HttpServletRequest request,
2688
    private void handleGetLogAction(Hashtable<String, String[]> params, HttpServletRequest request,
2691 2689
            HttpServletResponse response, String username, String[] groups) {
2692 2690
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
2693 2691
        try {
......
2704 2702
            }
2705 2703
            
2706 2704
            // Get all of the parameters in the correct formats
2707
            String[] ipAddress = (String[])params.get("ipaddress");
2708
            String[] principal = (String[])params.get("principal");
2709
            String[] docid = (String[])params.get("docid");
2710
            String[] event = (String[])params.get("event");
2711
            String[] startArray = (String[]) params.get("start");
2712
            String[] endArray = (String[]) params.get("end");
2705
            String[] ipAddress = params.get("ipaddress");
2706
            String[] principal = params.get("principal");
2707
            String[] docid = params.get("docid");
2708
            String[] event = params.get("event");
2709
            String[] startArray = params.get("start");
2710
            String[] endArray = params.get("end");
2713 2711
            String start = null;
2714 2712
            String end = null;
2715 2713
            if (startArray != null) {
......
2759 2757
	 * @param username
2760 2758
	 *            the username of the authenticated user
2761 2759
	 */
2762
    private void handleBuildIndexAction(Hashtable params,
2760
    private void handleBuildIndexAction(Hashtable<String, String[]> params,
2763 2761
            HttpServletRequest request, HttpServletResponse response,
2764 2762
            String username, String[] groups) {
2765 2763
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
2766 2764
        
2767 2765
        // Get all of the parameters in the correct formats
2768
        String[] docid = (String[])params.get("docid");
2766
        String[] docid = params.get("docid");
2769 2767
        
2770 2768
        // Rebuild the indices for appropriate documents
2771 2769
        try {
......
2786 2784
            if (docid == null || docid.length == 0) {
2787 2785
                // Process all of the documents
2788 2786
                try {
2789
                    Vector documents = getDocumentList();
2790
                    Iterator it = documents.iterator();
2787
                    Vector<String> documents = getDocumentList();
2788
                    Iterator<String> it = documents.iterator();
2791 2789
                    while (it.hasNext()) {
2792
                        String id = (String) it.next();
2790
                        String id = it.next();
2793 2791
                        buildDocumentIndex(id, out);
2794 2792
                    }
2795 2793
                } catch (SQLException se) {
......
2849 2847
        // Parse the multipart form, and save the parameters in a Hashtable and
2850 2848
        // save the FileParts in a hashtable
2851 2849
        
2852
        Hashtable params = new Hashtable();
2853
        Hashtable fileList = new Hashtable();
2850
        Hashtable<String,String[]> params = new Hashtable<String,String[]>();
2851
        Hashtable<String,String> fileList = new Hashtable<String,String>();
2854 2852
        int sizeLimit = 1000;
2855 2853
        try {
2856 2854
        	sizeLimit = 
......
2873 2871
                if (part.isParam()) {
2874 2872
                    // it's a parameter part
2875 2873
                    ParamPart paramPart = (ParamPart) part;
2876
                    String value = paramPart.getStringValue();
2877
                    params.put(name, value);
2874
                    String[] values = new String[1];
2875
                    values[0] = paramPart.getStringValue();
2876
                    params.put(name, values);
2878 2877
                    if (name.equals("action")) {
2879
                        action = value;
2878
                        action = values[0];
2880 2879
                    }
2881 2880
                } else if (part.isFile()) {
2882 2881
                    // it's a file part
......
2982 2981
     */
2983 2982
    private void handleInsertMultipartAction(HttpServletRequest request, 
2984 2983
            HttpServletResponse response,
2985
            PrintWriter out, Hashtable params, Hashtable fileList,
2984
            PrintWriter out, Hashtable<String,String[]> params, Hashtable<String,String> fileList,
2986 2985
            String username, String[] groupnames)
2987 2986
    {
2988 2987
      Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
......
3000 2999
      
3001 3000
      if (params.containsKey("docid")) 
3002 3001
      {
3003
          docid = (String) params.get("docid");
3002
          docid = params.get("docid")[0];
3004 3003
      }
3005 3004
      
3006 3005
      if(params.containsKey("qformat")) 
3007 3006
      {
3008
          qformat = (String)params.get("qformat");
3007
          qformat = params.get("qformat")[0];
3009 3008
      }
3010 3009
      
3011 3010
      // Make sure we have a docid and datafile
......
3014 3013
        logMetacat.info("Uploading data docid: " + docid);
3015 3014
        // Get a reference to the file part of the form
3016 3015
        //FilePart filePart = (FilePart) fileList.get("datafile");
3017
        String fileName = (String) fileList.get("filename");
3016
        String fileName = fileList.get("filename");
3018 3017
        System.out.println("filename: " + fileName);
3019 3018
        logMetacat.info("Uploading filename: " + fileName);
3020 3019
        // Check if the right file existed in the uploaded data
......
3033 3032
              File dataDirectory = new File(datafilepath);
3034 3033
              dataDirectory.mkdirs();
3035 3034
              File newFile = null;
3036
              File tempFile = null;
3037
              String tempFileName = (String) fileList.get("name");
3035
    //          File tempFile = null;
3036
              String tempFileName = fileList.get("name");
3038 3037
              String newFileName = dataDirectory + File.separator + docid;
3039 3038
              long size = 0;
3040 3039
              boolean fileExists = false;
......
3083 3082
                  numread = fr.read(c, 0, 1024);
3084 3083
                }
3085 3084
                
3086
                Enumeration keys = params.keys();
3085
                Enumeration<String> keys = params.keys();
3087 3086
                while(keys.hasMoreElements())
3088 3087
                { //convert the params to arrays
3089
                  String key = (String)keys.nextElement();
3090
                  String param = (String)params.get(key);
3088
                  String key = keys.nextElement();
3089
                  String[] paramValue = params.get(key);
3091 3090
                  String[] s = new String[1];
3092
                  s[0] = param;
3091
                  s[0] = paramValue[0];
3093 3092
                  params.put(key, s);
3094 3093
                }
3095 3094
                //add the doctext to the params
......
3121 3120
     * registering it in the Metacat db
3122 3121
     */
3123 3122
    private void handleUploadAction(HttpServletRequest request,
3124
            PrintWriter out, Hashtable params, Hashtable fileList,
3123
            PrintWriter out, Hashtable<String, String[]> params, Hashtable<String,String> fileList,
3125 3124
            String username, String[] groupnames, HttpServletResponse response) {
3126 3125
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
3127 3126
        //PrintWriter out = null;
3128 3127
        //Connection conn = null;
3129
        String action = null;
3128
//        String action = null;
3130 3129
        String docid = null;
3131 3130
        String qformat = null;
3132 3131
        String output = "";
......
3139 3138
         */
3140 3139
        
3141 3140
        if (params.containsKey("docid")) {
3142
            docid = (String) params.get("docid");
3141
            docid = params.get("docid")[0];
3143 3142
        }
3144 3143
        
3145 3144
        if(params.containsKey("qformat")) {
3146
            qformat = (String)params.get("qformat");
3145
            qformat = params.get("qformat")[0];
3147 3146
        }
3148 3147
        
3149 3148
        // Make sure we have a docid and datafile
......
3151 3150
            logMetacat.info("Uploading data docid: " + docid);
3152 3151
            // Get a reference to the file part of the form
3153 3152
            //FilePart filePart = (FilePart) fileList.get("datafile");
3154
            String fileName = (String) fileList.get("filename");
3153
            String fileName = fileList.get("filename");
3155 3154
            logMetacat.info("Uploading filename: " + fileName);
3156 3155
            // Check if the right file existed in the uploaded data
3157 3156
            if (fileName != null) {
......
3166 3165
                        File dataDirectory = new File(datafilepath);
3167 3166
                        dataDirectory.mkdirs();
3168 3167
                        File newFile = null;
3169
                        File tempFile = null;
3170
                        String tempFileName = (String) fileList.get("name");
3168
    //                    File tempFile = null;
3169
                        String tempFileName = fileList.get("name");
3171 3170
                        String newFileName = dataDirectory + File.separator + docid;
3172 3171
                        long size = 0;
3173 3172
                        boolean fileExists = false;
......
3221 3220
                        // not get force replication info from another metacat
3222 3221
                        ForceReplicationHandler frh = new ForceReplicationHandler(
3223 3222
                                docid, "insert", false, null);
3223
                        logMetacat.debug("ForceReplicationHandler created: " + frh.toString());
3224 3224
                        
3225 3225
                        // set content type and other response header fields
3226 3226
                        // first
......
3276 3276
    /*
3277 3277
     * A method to handle set access action
3278 3278
     */
3279
    private void handleSetAccessAction(PrintWriter out, Hashtable params,
3279
    private void handleSetAccessAction(PrintWriter out, Hashtable<String, String[]> params,
3280 3280
            String username) {
3281 3281
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
3282 3282
        String[] docList = null;
......
3287 3287
        String permission = null;
3288 3288
        String permType = null;
3289 3289
        String permOrder = null;
3290
        Vector errorList = new Vector();
3290
        Vector<String> errorList = new Vector<String>();
3291 3291
        String error = null;
3292
        Vector successList = new Vector();
3292
        Vector<String> successList = new Vector<String>();
3293 3293
        String success = null;
3294 3294
        boolean isEmlPkgMember = false;
3295 3295
        
3296 3296
        // Get parameters
3297 3297
        if (params.containsKey("docid")) {
3298
            docList = (String[]) params.get("docid");
3298
            docList = params.get("docid");
3299 3299
        }
3300 3300
        if (params.containsKey("principal")) {
3301
            principalList = (String[]) params.get("principal");
3301
            principalList = params.get("principal");
3302 3302
        }
3303 3303
        if (params.containsKey("permission")) {
3304
            permissionList = (String[]) params.get("permission");
3304
            permissionList = params.get("permission");
3305 3305
            
3306 3306
        }
3307 3307
        if (params.containsKey("permType")) {
3308
            permTypeList = (String[]) params.get("permType");
3308
            permTypeList = params.get("permType");
3309 3309
            
3310 3310
        }
3311 3311
        if (params.containsKey("permOrder")) {
3312
            permOrderList = (String[]) params.get("permOrder");
3312
            permOrderList = params.get("permOrder");
3313 3313
            
3314 3314
        }
3315 3315
        
......
3332 3332
        }
3333 3333
        
3334 3334
        // Get package doctype set
3335
        Vector packageSet = null;
3335
        Vector<String> packageSet = null;
3336 3336
        try {
3337 3337
        	packageSet = 
3338 3338
        		MetaCatUtil.getOptionList(PropertyService.getProperty("xml.packagedoctypeset"));
......
3344 3344
        if (packageSet != null) {
3345 3345
            for (int i = 0; i < packageSet.size(); i++) {
3346 3346
                logMetacat.debug("doctype in package set: "
3347
                        + (String) packageSet.elementAt(i));
3347
                        + packageSet.elementAt(i));
3348 3348
            }
3349 3349
        }
3350 3350
        
......
3430 3430
            }
3431 3431
            ForceReplicationHandler frh = 
3432 3432
            	new ForceReplicationHandler(accessionNumber, isXml, null);
3433
            logMetacat.debug("ForceReplicationHandler created: " + frh.toString());
3433 3434
            
3434 3435
        }
3435 3436
        outputResponse(successList, errorList, out);
......
3467 3468
            pstmt.execute();
3468 3469
            rs = pstmt.getResultSet();
3469 3470
            boolean hasRow = rs.next();
3470
            int perm = 0;
3471
        //    int perm = 0;
3471 3472
            if (hasRow) {
3472 3473
                fieldValue = rs.getString(1);
3473 3474
            } else {
......
3497 3498
     *
3498 3499
     * @ returns the array of identifiers
3499 3500
     */
3500
    private Vector getDocumentList() throws SQLException {
3501
    private Vector<String> getDocumentList() throws SQLException {
3501 3502
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
3502
        Vector docList = new Vector();
3503
        Vector<String> docList = new Vector<String>();
3503 3504
        PreparedStatement pstmt = null;
3504 3505
        ResultSet rs = null;
3505 3506
        DBConnection conn = null;
......
3544 3545
    /*
3545 3546
     * A method to output setAccess action result
3546 3547
     */
3547
    private void outputResponse(Vector successList, Vector errorList,
3548
    private void outputResponse(Vector<String> successList, Vector<String> errorList,
3548 3549
            PrintWriter out) {
3549 3550
        boolean error = false;
3550 3551
        boolean success = false;
......
3554 3555
        if (successList != null) {
3555 3556
            for (int i = 0; i < successList.size(); i++) {
3556 3557
                out.println(SUCCESS);
3557
                out.println((String) successList.elementAt(i));
3558
                out.println(successList.elementAt(i));
3558 3559
                out.println(SUCCESSCLOSE);
3559 3560
                success = true;
3560 3561
            }
......
3563 3564
        if (errorList != null) {
3564 3565
            for (int i = 0; i < errorList.size(); i++) {
3565 3566
                out.println(ERROR);
3566
                out.println((String) errorList.elementAt(i));
3567
                out.println(errorList.elementAt(i));
3567 3568
                out.println(ERRORCLOSE);
3568 3569
                error = true;
3569 3570
            }
......
3582 3583
     * append rev for it. The rev come from xml_documents
3583 3584
     */
3584 3585
    private static String appendRev(String docid) throws Exception {
3585
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
3586
//        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
3586 3587
        String newAccNum = null;
3587 3588
        String separator = PropertyService.getProperty("document.accNumSeparator");
3588 3589
        int firstIndex = docid.indexOf(separator);

Also available in: Unified diff