Ignore:
Timestamp:
2016-08-12T19:47:27+12:00 (8 years ago)
Author:
ak19
Message:

All the changes to get the new collectionConfig.xml Editor (ConfigFileEditor.java) to work.

File:
1 edited

Legend:

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

    r29730 r30701  
    1313import java.io.IOException;
    1414import java.io.StringReader;
     15import java.io.StringWriter; // for elementToString()
    1516
    1617// SAX
     
    2829import javax.xml.parsers.SAXParser;
    2930import javax.xml.parsers.SAXParserFactory;
     31// for elementToString():
     32import javax.xml.transform.OutputKeys;
     33import javax.xml.transform.Transformer;
     34import javax.xml.transform.TransformerFactory;
     35import javax.xml.transform.dom.DOMSource;
     36import javax.xml.transform.stream.StreamResult;
    3037
    3138
     
    523530        if (xml_file.exists() == false)
    524531        {
     532            System.err.println("@@@ file " + xml_file + " does not exist.");
    525533            return null;
    526534        }
     
    12241232        }
    12251233    }
     1234
     1235
     1236   
     1237    // This method will convert an Element to a String too, like xmlNodeToString() above.
     1238    // But for a document root element (doc.getDocumentElement()), this method will additionally
     1239    // return its processing instruction line at the start (<?xml ... ?>).
     1240    // This method copied into GLI from src/java/org/greenstone/gsdl3/util/GSXML.java
     1241    public static String elementToString(Element e, boolean indent)
     1242    {
     1243    String str = "";
     1244    try
     1245        {
     1246        TransformerFactory tf = TransformerFactory.newInstance();
     1247        Transformer trans = tf.newTransformer();
     1248        StringWriter sw = new StringWriter();
     1249        if (indent)
     1250            {
     1251            trans.setOutputProperty(OutputKeys.INDENT, "yes");
     1252            }
     1253        else
     1254            {
     1255            trans.setOutputProperty(OutputKeys.INDENT, "no");
     1256            }
     1257        trans.transform(new DOMSource(e), new StreamResult(sw));
     1258        str += sw.toString();
     1259        }
     1260    catch (Exception ex)
     1261        {
     1262        str += "Exception: couldn't write " + e + " to log";
     1263        }
     1264    finally
     1265        {
     1266        return str;
     1267        }
     1268    }
    12261269}
Note: See TracChangeset for help on using the changeset viewer.