Project

General

Profile

« Previous | Next » 

Revision 5490

Added by berkley over 14 years ago

merged with version from 1.9.3 branch to fix bug with character encodings

View differences:

src/edu/ucsb/nceas/metacat/DBQuery.java
74 74
    static final int WRITE = 2;
75 75

  
76 76
    static final int READ = 4;
77
    
78
    private String qformat = "xml";
77 79

  
78 80
    //private Connection conn = null;
79 81
    private String parserName = null;
......
366 368
      if (qformat != null && qformat.equals(MetacatUtil.XMLFORMAT))
367 369
      {
368 370
        //xml format
369
        if(response != null)
370
            response.setContentType("text/xml");
371
        StringBuffer sb = createResultDocument(xmlquery, qspec, out, user, groups, useXMLIndex, 
372
          pagesize, pagestart, sessionid);
373
        //System.out.println("result from createResultDocument: " + sb.toString());
371
        response.setContentType("text/xml");
372
        createResultDocument(xmlquery, qspec, out, user, groups, useXMLIndex, 
373
          pagesize, pagestart, sessionid, qformat);
374 374
      }//if
375 375
      else
376 376
      {
......
379 379
        PrintWriter nonout = null;
380 380
        StringBuffer xml = createResultDocument(xmlquery, qspec, nonout, user,
381 381
                                                groups, useXMLIndex, pagesize, 
382
                                                pagestart, sessionid);
382
                                                pagestart, sessionid, qformat);
383 383
        
384 384
        //transfer the xml to html
385 385
        try
......
418 418
      }//else
419 419

  
420 420
  }
421
    
422
    
421 423
  
422 424
  /**
423 425
   * Transforms a hashtable of documents to an xml or html result and sent
......
439 441
                                              String user, String[] groups,
440 442
                                              boolean useXMLIndex)
441 443
    {
442
    	return createResultDocument(xmlquery,qspec,out, user,groups, useXMLIndex, 0, 0,"");
444
    	return createResultDocument(xmlquery,qspec,out, user,groups, useXMLIndex, 0, 0,"", qformat);
443 445
    }
444 446

  
445 447
  /*
......
453 455
                                            PrintWriter out,
454 456
                                            String user, String[] groups,
455 457
                                            boolean useXMLIndex, int pagesize,
456
                                            int pagestart, String sessionid)
458
                                            int pagestart, String sessionid, 
459
                                            String qformat)
457 460
  {
458 461
    DBConnection dbconn = null;
459 462
    int serialNumber = -1;
......
495 498
        	logMetacat.debug("DBQuery.createResultDocument - Not in map query");
496 499
        	resultContent = findResultDoclist(qspec, out, user, groups,
497 500
                    dbconn, useXMLIndex, pagesize, pagestart, 
498
                    sessionid, givenDocids);
501
                    sessionid, givenDocids, qformat);
499 502
        }
500 503
        else
501 504
        {
......
507 510
        		givenDocids = (Vector)docidOverride.elementAt(i);
508 511
        		StringBuffer subset = findResultDoclist(qspec, out, user, groups,
509 512
                        dbconn, useXMLIndex, pagesize, pagestart, 
510
                        sessionid, givenDocids);
513
                        sessionid, givenDocids, qformat);
511 514
        		resultContent.append(subset);
512 515
        	}
513 516
        }
......
551 554
                                      PrintWriter out,
552 555
                                      String user, String[]groups,
553 556
                                      DBConnection dbconn, boolean useXMLIndex,
554
                                      int pagesize, int pagestart, String sessionid, Vector givenDocids)
557
                                      int pagesize, int pagestart, String sessionid, 
558
                                      Vector givenDocids, String qformat)
555 559
                                      throws Exception
556 560
    {
557 561
      StringBuffer resultsetBuffer = new StringBuffer();
......
726 730
          //logMetacat.warn("############doing subset cache");
727 731
          count = 0;
728 732
          handleSubsetResult(qspec, resultsetBuffer, out, docListResult,
729
                              user, groups,dbconn, useXMLIndex);
733
                              user, groups,dbconn, useXMLIndex, qformat);
730 734
          //reset docListResult
731 735
          docListResult = new ResultDocumentSet();
732 736
        }
......
780 784
     {
781 785
      
782 786
       handleSubsetResult(qspec,resultsetBuffer, out, docListResult,
783
                              user, groups,dbconn, useXMLIndex);
787
                              user, groups,dbconn, useXMLIndex, qformat);
784 788
     }
785 789

  
786 790
     resultsetBuffer.append("\n<lastpage>" + lastpage + "</lastpage>\n");
......
809 813
                                           StringBuffer resultset,
810 814
                                           PrintWriter out, ResultDocumentSet partOfDoclist,
811 815
                                           String user, String[]groups,
812
                                       DBConnection dbconn, boolean useXMLIndex)
816
                                       DBConnection dbconn, boolean useXMLIndex,
817
                                       String qformat)
813 818
                                       throws Exception
814 819
   {
815 820
     double startReturnFieldTime = System.currentTimeMillis();
......
878 883

  
879 884
     //add return fields for the documents in partOfDoclist
880 885
     partOfDoclist = addReturnfield(partOfDoclist, qspec, user, groups,
881
                                        dbconn, useXMLIndex);
886
                                        dbconn, useXMLIndex, qformat);
882 887
     long extendedQueryRunTime = startExtendedQuery - System.currentTimeMillis();
883 888
     long extendedQueryWarnLimit = 
884 889
    	 Long.parseLong(PropertyService.getProperty("dbquery.extendedQueryRunTimeWarnLimit"));
......
1150 1155
    private ResultDocumentSet addReturnfield(ResultDocumentSet docListResult,
1151 1156
                                      QuerySpecification qspec,
1152 1157
                                      String user, String[]groups,
1153
                                      DBConnection dbconn, boolean useXMLIndex )
1158
                                      DBConnection dbconn, boolean useXMLIndex,
1159
                                      String qformat)
1154 1160
                                      throws Exception
1155 1161
    {
1156 1162
      PreparedStatement pstmt = null;
......
1173 1179
        Hashtable returnFieldValue = new Hashtable();
1174 1180
        while (keylist.hasNext())
1175 1181
        {
1182
          String key = (String)keylist.next();
1176 1183
          doclist.append("'");
1177
          doclist.append((String) keylist.next());
1184
          doclist.append(key);
1178 1185
          doclist.append("',");
1179 1186
        }
1180 1187
        if (doclist.length() > 0)
......
1195 1202
               dbconn.increaseUsageCount(1);
1196 1203
               pstmt.execute();
1197 1204
               rs = pstmt.getResultSet();
1198
//               MetacatUtil.writeDebugToDelimiteredFile(" "+ (extendedQueryEnd - extendedQueryStart), false);
1199 1205
               tableHasRows = rs.next();
1200 1206
               while (tableHasRows) {
1201 1207
                   ReturnFieldValue returnValue = new ReturnFieldValue();
1202 1208
                   docid = rs.getString(1).trim();
1203 1209
                   fieldname = rs.getString(2);
1204
                   fielddata = rs.getString(3);
1210
                   
1211
                   if(qformat.toLowerCase().trim().equals("xml"))
1212
                   {
1213
                       byte[] b = rs.getBytes(3);
1214
                       fielddata = new String(b, 0, b.length);
1215
                   }
1216
                   else
1217
                   {
1218
                       fielddata = rs.getString(3);
1219
                   }
1220
                   
1221
                   //System.out.println("raw fielddata: " + fielddata);
1205 1222
                   fielddata = MetacatUtil.normalize(fielddata);
1223
                   //System.out.println("normalized fielddata: " + fielddata);
1206 1224
                   String parentId = rs.getString(4);
1207 1225
                   fieldtype = rs.getString(5);
1208 1226
                   StringBuffer value = new StringBuffer();
......
1216 1234
	                	   //try merging the data
1217 1235
	                	   ReturnFieldValue existingRFV =
1218 1236
	                		   getArrayValue(parentidList, parentId);
1219

  
1220 1237
	                	   if (existingRFV != null && !existingRFV.getFieldType().equals("ATTRIBUTE")) {
1221 1238
	                		   fielddata = existingRFV.getFieldValue() + fielddata;
1222 1239
	                	   }
1223 1240
                	   }
1224 1241
                	   //System.out.println("fieldname: " + fieldname + " fielddata: " + fielddata);
1242

  
1225 1243
                       value.append("<param name=\"");
1226 1244
                       value.append(fieldname);
1227 1245
                       value.append("\">");
......
1236 1254
                       putInArray(parentidList, parentId, returnValue);
1237 1255
                   }
1238 1256
                   else {
1257
                       
1239 1258
                       // need to merge nodedata if they have same parent id and
1240 1259
                       // node type is text
1241 1260
                       fielddata = (String) ( (ReturnFieldValue)
1242 1261
                                             getArrayValue(
1243 1262
                           parentidList, parentId)).getFieldValue()
1244 1263
                           + fielddata;
1264
                       //System.out.println("fieldname: " + fieldname + " fielddata: " + fielddata);
1245 1265
                       value.append("<param name=\"");
1246 1266
                       value.append(fieldname);
1247 1267
                       value.append("\">");
......
1286 1306
//                   + " execute extended query: "
1287 1307
//                   + (docListResultEnd - extendedQueryEnd));
1288 1308
           }
1289

  
1290
         
1291
           
1292
           
1293 1309
       }//if doclist lenght is great than zero
1294

  
1295 1310
     }//if has extended query
1296 1311

  
1297 1312
      return docListResult;
......
1425 1440

  
1426 1441
        Vector tempVector = null;
1427 1442

  
1428
        for (int count = 0; count < parentidList.size(); count++) 
1429
        {
1443
        for (int count = 0; count < parentidList.size(); count++) {
1430 1444
            tempVector = (Vector) parentidList.get(count);
1431 1445

  
1432
            if (key.compareTo((String) tempVector.get(0)) == 0) 
1433
            { 
1434
                return (ReturnFieldValue) tempVector.get(1); 
1435
            }
1446
            if (key.compareTo((String) tempVector.get(0)) == 0) { return (ReturnFieldValue) tempVector
1447
                    .get(1); }
1436 1448
        }
1437 1449
        return null;
1438 1450
    }

Also available in: Unified diff