Ignore:
Timestamp:
2010-06-24T13:45:34+12:00 (14 years ago)
Author:
ak19
Message:
  1. Changes to get Fedora to work with Greenstone3: to let the Greenstone3 Reader Interface work with a Fedora Repository behind the scenes. 2. No longer returns XML Strings formatted for display, but unformatted, since when it's converted to XML DOM on the Greenstone end, new lines introduced due to whitespace interfere with Greenstone 3's default parsing of the XML.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • other-projects/gs3-webservices-java-client/trunk/src/GS3Fedora/org/greenstone/fedora/services/FedoraCommons.java

    r15222 r22300  
    8888    }
    8989   
    90     /** Given an Element, this will return its String representation properly
     90    /** Given a DOM node, this will return its String representation properly
    9191     * indented for display.
    92      * @return a string representation of e, formatted for display.
    93      * @param e is the element to be converted to its string representation.
     92     * @return a string representation of n, formatted for display.
     93     * @param n is the DOM node to be converted to its string representation.
    9494    */
    95     public static String elementToFormattedString(Element e)
    96         throws TransformerException
     95    public static String displayAsString(Node n)
    9796    {
    98         DOMSource domSource = new DOMSource(e);
    99         Transformer transformer = TransformerFactory.newInstance().newTransformer();
    100         transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    101         //transformer.setOutputProperty(OutputKeys.METHOD, "xml");
    102         //transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
    103         transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
    104         transformer.setOutputProperty(OutputKeys.INDENT, "yes");
     97        try {
     98       
     99        DOMSource domSource = new DOMSource(n);
     100        Transformer transformer = TransformerFactory.newInstance().newTransformer();
     101        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
     102        //transformer.setOutputProperty(OutputKeys.METHOD, "xml");
     103        //transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
     104        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
     105        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
     106       
     107        StringWriter sw = new StringWriter();
     108        transformer.transform(domSource, new StreamResult(sw));
     109        return sw.toString();
     110        } catch(Exception e) {
     111        System.err.println("Couldn't display node as String.");
     112        return "";
     113        }
     114       
     115    }
    105116
    106         StringWriter sw = new StringWriter();
    107         transformer.transform(domSource, new StreamResult(sw));
    108         return sw.toString();
    109     }
     117   
    110118}
Note: See TracChangeset for help on using the changeset viewer.