Ignore:
Timestamp:
2014-04-24T21:34:33+12:00 (10 years ago)
Author:
ak19
Message:

First commit for GLI part of GS2 to GS3 Format Conversion. Contains all the changes needed for the FormatConversionDialog to work, and some cosmetic changes to cdm.Format4gs3Manager.java. Still need to implement undo and redo and think about what needs to happen and how for Remote GS3.

File:
1 edited

Legend:

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

    r26354 r28995  
    2222
    2323// JAXP
     24import javax.xml.parsers.DocumentBuilder;
     25import javax.xml.parsers.DocumentBuilderFactory;
    2426import javax.xml.parsers.FactoryConfigurationError;
    2527import javax.xml.parsers.ParserConfigurationException;
    2628import javax.xml.parsers.SAXParser;
    2729import javax.xml.parsers.SAXParserFactory;
     30
    2831
    2932/** This class is a static class containing useful XML functions */
     
    331334    static final private String HEADER = "<?xml version='1.0' encoding='UTF-8'?><collectionConfig xmlns:gsf='http://www.greenstone.org/greenstone3/schema/ConfigFormat' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>";
    332335    static final private String FOOTER = "</collectionConfig>";
     336
     337
     338    public static Document getDOM(String xml_str)
     339    {   
     340    Document doc = null;
     341    try {
     342        /*SAXParserFactory factory = SAXParserFactory.newInstance();
     343        factory.setNamespaceAware(true);
     344        //factory.setValidating (true);
     345        SAXParser parser = factory.newSAXParser();
     346        InputSource iSource = new InputSource(new StringReader(xml_str));
     347        //              parser.parse (iSource, new DefaultHandler ());
     348       
     349        org.xml.sax.XMLReader reader = parser.getXMLReader();
     350        reader.setContentHandler(new DefaultHandler());
     351        reader.setErrorHandler(new DefaultHandler());
     352        doc = reader.parse(iSource);
     353        */
     354
     355        DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
     356        InputSource is = new InputSource();
     357        is.setCharacterStream(new StringReader(xml_str));
     358        doc = db.parse(is);
     359
     360    } catch (Exception e) {
     361        e.printStackTrace();
     362    }
     363    return doc;
     364    }
    333365
    334366    public static String parse(String xml_str)
     
    9911023    public static void xmlNodeToString(StringBuffer sb, Node e, boolean indent, String indentString, int depth)
    9921024    {
    993         if (e.getNodeType() == Node.TEXT_NODE)
     1025
     1026        if (e.getNodeType() == Node.CDATA_SECTION_NODE)
     1027        {
     1028            if (e.getNodeValue() != "")
     1029            {
     1030                String text = e.getNodeValue();             
     1031                sb.append("<![CDATA[");
     1032                sb.append(text);
     1033                sb.append("]]>");
     1034            }
     1035            return;
     1036        }
     1037
     1038        if (e.getNodeType() == Node.TEXT_NODE)
    9941039        {
    9951040            if (e.getNodeValue() != "")
     
    10571102                hasElements = true;
    10581103            }
    1059             if (children.item(i).getNodeType() == Node.TEXT_NODE && indent)
     1104            if ((children.item(i).getNodeType() == Node.TEXT_NODE || children.item(i).getNodeType() == Node.CDATA_SECTION_NODE) && indent)
    10601105            {
    10611106                if (children.item(i).getNodeValue().trim().length() > 0)
Note: See TracChangeset for help on using the changeset viewer.