Changeset 28849

Show
Ignore:
Timestamp:
27.02.2014 11:19:58 (6 years ago)
Author:
kjdon
Message:

added writeDOM method

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/XMLConverter.java

    r28382 r28849  
    3535 
    3636// other java classes 
     37import java.io.BufferedWriter; 
    3738import java.io.ByteArrayInputStream; 
     39import java.io.FileWriter; 
    3840import java.io.InputStream; 
    3941import java.io.Reader; 
     
    623625        } 
    624626    } 
     627 
     628  public boolean writeDOM(Element elem, File file) { 
     629 
     630    BufferedWriter writer = null; 
     631    boolean success = false; 
     632    try { 
     633      String xml_string = getString(elem); 
     634      // need createNewFile??? 
     635      writer = new BufferedWriter(new FileWriter(file)); 
     636      writer.write(xml_string); 
     637      success = true; 
     638    } 
     639 
     640    catch (Exception e) { 
     641      logger.error(e.getMessage()); 
     642      success = false; 
     643    } 
     644    finally { 
     645      try { 
     646    if (writer != null) { 
     647      writer.close(); 
     648    } 
     649      } catch(Exception e) { 
     650    logger.error("couldn't close the file"+e.getMessage()); 
     651      } 
     652    } 
     653    return success; 
     654  } 
    625655}