Changeset 23606 for main/branches/64_bit_Greenstone/greenstone3/src/java/org/greenstone/gsdl3/collection/Collection.java
- Timestamp:
- 2011-01-17T17:42:35+13:00 (13 years ago)
- Location:
- main/branches/64_bit_Greenstone/greenstone3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/branches/64_bit_Greenstone/greenstone3
-
Property svn:mergeinfo
set to
/main/trunk/greenstone3 merged eligible
-
Property svn:mergeinfo
set to
-
main/branches/64_bit_Greenstone/greenstone3/src/java/org/greenstone/gsdl3/collection/Collection.java
r23505 r23606 33 33 import java.io.File; 34 34 import java.util.HashMap; 35 36 import javax.xml.parsers.DocumentBuilder; 37 import javax.xml.parsers.DocumentBuilderFactory; 38 39 import org.xml.sax.*; 40 import javax.xml.parsers.SAXParserFactory; 41 import javax.xml.parsers.ParserConfigurationException; 42 import javax.xml.parsers.SAXParser; 35 43 36 44 import org.apache.log4j.*; … … 330 338 331 339 Element format_element = (Element) GSXML.getChildByTagName(request, GSXML.FORMAT_STRING_ELEM); 332 //String format_string = GSXML.getNodeText(format_element);333 Element format_statement = (Element) format_element.getFirstChild();340 String format_string = GSXML.getNodeText(format_element); 341 //Element format_statement = (Element) format_element.getFirstChild(); 334 342 335 343 //logger.error("Format string: " + format_string); … … 386 394 387 395 // Write format statement 388 String format_string = GSXML.xmlNodeToString(format_statement);396 //String format_string = GSXML.xmlNodeToString(format_statement); 389 397 writer = new BufferedWriter(new FileWriter(format_statement_filename)); 390 398 writer.write(format_string); … … 405 413 logger.error("SAVE format statement"); 406 414 407 // open collectionConfig.xml and read in to w3 Document 408 String collection_config = directory + "collectionConfig.xml"; 409 Document config = this.converter.getDOM(new File(collection_config), "UTF-8"); 415 try{ 416 417 // Convert format string to a document 418 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 419 DocumentBuilder builder = factory.newDocumentBuilder(); 420 //String input = "<html><head><title></title></head><body>" + format_string + "</body></html>"; 421 String input = format_string.substring(0,format_string.length()-1)+"</xml>"; 422 logger.error(input); 423 InputSource is = new InputSource( new StringReader( input ) ); 424 logger.error("About to parse format string"); 425 Document format_statement = (Document) builder.parse( is ); 426 logger.error("Done parsing format string"); 427 428 // open collectionConfig.xml and read in to w3 Document 429 String collection_config = directory + "collectionConfig.xml"; 430 Document config = this.converter.getDOM(new File(collection_config), "UTF-8"); 410 431 411 //String tag_name = ""; 412 int k; 413 int index; 414 Element elem; 415 Node current_node = GSXML.getChildByTagName(config, "CollectionConfig"); 416 NodeList current_node_list; 417 418 if(service.equals("ClassifierBrowse")) 419 { 420 //tag_name = "browse"; 421 // if CLX then need to look in <classifier> X then <format> 422 // default is <browse><format> 423 424 current_node = GSXML.getChildByTagName(current_node, "browse"); 425 426 // find CLX 427 if(classifier != null) 432 //String tag_name = ""; 433 int k; 434 int index; 435 Element elem; 436 Node current_node = GSXML.getChildByTagName(config, "CollectionConfig"); 437 NodeList current_node_list; 438 439 if(service.equals("ClassifierBrowse")) 428 440 { 429 current_node_list = GSXML.getChildrenByTagName(current_node, "classifier"); 430 index = Integer.parseInt(classifier.substring(2)) - 1; 431 // index should be given by X-1 432 current_node = current_node_list.item(index); 433 current_node = GSXML.getChildByTagName(current_node, "format"); 441 //tag_name = "browse"; 442 // if CLX then need to look in <classifier> X then <format> 443 // default is <browse><format> 444 445 current_node = GSXML.getChildByTagName(current_node, "browse"); 446 447 // find CLX 448 if(classifier != null) 449 { 450 current_node_list = GSXML.getChildrenByTagName(current_node, "classifier"); 451 index = Integer.parseInt(classifier.substring(2)) - 1; 452 // index should be given by X-1 453 current_node = current_node_list.item(index); 454 current_node = GSXML.getChildByTagName(current_node, "format"); 455 } 456 else{ 457 current_node = GSXML.getChildByTagName(current_node, "format"); 458 } 434 459 } 435 else{ 436 current_node = GSXML.getChildByTagName(current_node, "format"); 460 else 461 { 462 // look in <format> with no attributes 463 464 current_node_list = GSXML.getChildrenByTagName(current_node, "search"); 465 for(k=0; k<current_node_list.getLength(); k++) 466 { 467 current_node = current_node_list.item(k); 468 // if current_node has no attributes then break 469 elem = (Element) current_node; 470 if(elem.hasAttribute("name")==false) 471 break; 472 } 437 473 } 438 } 439 else 440 { 441 // look in <format> with no attributes 442 443 current_node_list = GSXML.getChildrenByTagName(current_node, "search"); 444 for(k=0; k<current_node_list.getLength(); k++) 474 475 // Current_node should be a format tag 476 elem = (Element) current_node; 477 478 logger.error("Current_node = " + elem.getNodeName()); 479 480 // seems we want to remove current child/ren and replace with format_statement's child/ren? 481 482 // remove existing 483 current_node_list = elem.getChildNodes(); 484 for(k=0; k<current_node_list.getLength(); k++) 445 485 { 446 current_node = current_node_list.item(k); 447 // if current_node has no attributes then break 448 elem = (Element) current_node; 449 if(elem.hasAttribute("name")==false) 450 break; 486 current_node = elem.removeChild(current_node_list.item(k)); 451 487 } 452 } 453 454 // Current_node should be a format tag 455 elem = (Element) current_node; 456 457 logger.error("Current_node = " + elem.getNodeName()); 458 459 // seems we want to remove current child/ren and replace with format_statement's child/ren? 460 461 // remove existing 462 current_node_list = elem.getChildNodes(); 463 for(k=0; k<current_node_list.getLength(); k++) 464 { 465 current_node = elem.removeChild(current_node_list.item(k)); 466 } 467 468 // append new 469 current_node_list = format_statement.getChildNodes(); 470 for(k=0; k<current_node_list.getLength(); k++) 471 { 472 current_node = elem.appendChild(current_node_list.item(k)); 473 } 474 475 //String text = GSXML.getNodeText(elem); 476 //logger.error(text); 477 //text = text.replaceAll("_httpsite_", http_site); 478 //text = text.replaceAll("_httpcollection_", http_collection); 479 //GSXML.setNodeText(d, text); 480 481 // Now convert config document to string for writing to file 482 String new_config = GSXML.xmlNodeToString(config); 483 484 // Write to file (not original! for now) 485 try{ 488 489 // append new but we have a string! 490 GSXML.setNodeText(elem, format_string); 491 492 //current_node_list = format_statement.getChildNodes(); 493 //for(k=0; k<current_node_list.getLength(); k++) 494 //{ 495 // current_node = elem.appendChild(current_node_list.item(k)); 496 //} 497 498 //String text = GSXML.getNodeText(elem); 499 //logger.error(text); 500 //text = text.replaceAll("_httpsite_", http_site); 501 //text = text.replaceAll("_httpcollection_", http_collection); 502 //GSXML.setNodeText(d, text); 503 504 // Now convert config document to string for writing to file 505 String new_config = GSXML.xmlNodeToString(config); 506 507 // Write to file (not original! for now) 486 508 BufferedWriter writer = new BufferedWriter(new FileWriter(collection_config+".new")); 487 509 writer.write(new_config); 488 510 writer.close(); 489 } catch (IOException e) { 490 logger.error("IO Exception "+e); 511 512 } catch( Exception ex ) { 513 logger.error("There was an exception "+ex); 514 515 StringWriter sw = new StringWriter(); 516 PrintWriter pw = new PrintWriter(sw, true); 517 ex.printStackTrace(pw); 518 pw.flush(); 519 sw.flush(); 520 logger.error(sw.toString()); 491 521 } 522 492 523 } 493 524 }
Note:
See TracChangeset
for help on using the changeset viewer.