Changeset 16988

Show
Ignore:
Timestamp:
25.08.2008 12:32:17 (11 years ago)
Author:
kjdon
Message:

added xmlNodeToStringWithoutIndenting for use with format statements for gs3, so don't get more and more spaces added in each time its saved

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • gli/trunk/src/org/greenstone/gatherer/util/XMLTools.java

    r16331 r16988  
    624624            f.setLineWidth (0); // Why isn't this working! 
    625625            f.setPreserveSpace (false); 
    626              
    627             f.setNonEscapingElements (nonEscapingTagNames); 
     626            if (nonEscapingTagNames != null) { 
     627          f.setNonEscapingElements (nonEscapingTagNames); 
     628        } 
    628629            // Create the necessary writer stream for serialization. 
    629630            OutputStreamWriter osw = new OutputStreamWriter (os, "UTF-8"); 
     
    644645    /** Write an XML document to a given file */ 
    645646    static public void writeXMLFile (File xml_file, Document document) { 
    646         try { 
    647             OutputStream os = new FileOutputStream (xml_file); 
    648             // Create an output format for our document. 
    649             OutputFormat f = new OutputFormat (document); 
    650             f.setEncoding ("UTF-8"); 
    651             f.setIndenting (true); 
    652             f.setLineWidth (0); // Why isn't this working! 
    653             f.setPreserveSpace (false); 
    654             // Create the necessary writer stream for serialization. 
    655             OutputStreamWriter osw = new OutputStreamWriter (os, "UTF-8"); 
    656             Writer w               = new BufferedWriter (osw); 
    657             // Generate a new serializer from the above. 
    658             XMLSerializer s        = new XMLSerializer (w, f); 
    659             s.asDOMSerializer (); 
    660             // Finally serialize the document to file. 
    661             s.serialize (document); 
    662             // And close. 
    663             os.close (); 
    664         } 
    665         catch (Exception exception) { 
    666             DebugStream.printStackTrace (exception); 
    667         } 
    668     } 
    669      
     647      writeXMLFile(xml_file, document, null); 
     648    } 
     649 
    670650    public static void printXMLNode (Node e) { 
    671651        printXMLNode (e, 0) ; 
     
    770750         
    771751    } 
     752 
     753  public static String xmlNodeToStringWithoutIndenting (Node e) { 
     754    StringBuffer sb = new StringBuffer (""); 
     755    xmlNodeToStringWithoutNewline(sb, e, -1); 
     756    return sb.toString(); 
     757  } 
    772758    public static String xmlNodeToStringWithoutNewline (Node e){ 
    773759        StringBuffer sb = new StringBuffer (""); 
     
    780766        for (int i=0 ; i<depth ; i++) 
    781767            sb.append (' ') ; 
    782          
     768       
    783769        if (e.getNodeType () == Node.TEXT_NODE){ 
    784770            if (e.getNodeValue () != "") { 
     
    811797            int len = children.getLength (); 
    812798            for (int i = 0; i < len; i++) { 
     799          if (depth >= 0) { 
    813800                xmlNodeToStringWithoutNewline (sb,children.item (i), depth + 1); 
     801          } else { 
     802        xmlNodeToStringWithoutNewline (sb,children.item (i), depth); 
     803          } 
    814804            } 
    815805