From: <hei...@us...> - 2008-09-17 16:31:51
|
Revision: 1506 http://geonetwork.svn.sourceforge.net/geonetwork/?rev=1506&view=rev Author: heikkidoeleman Date: 2008-09-17 16:32:01 +0000 (Wed, 17 Sep 2008) Log Message: ----------- Instruct the XML parser to accept encodings like "UTF8" (not only "UTF-8"), by setting "allow-java-encodings". Modified Paths: -------------- trunk/src/org/fao/geonet/csw/common/util/Xml.java Modified: trunk/src/org/fao/geonet/csw/common/util/Xml.java =================================================================== --- trunk/src/org/fao/geonet/csw/common/util/Xml.java 2008-09-16 06:54:20 UTC (rev 1505) +++ trunk/src/org/fao/geonet/csw/common/util/Xml.java 2008-09-17 16:32:01 UTC (rev 1506) @@ -1,93 +1,97 @@ -//============================================================================= -//=== Copyright (C) 2001-2007 Food and Agriculture Organization of the -//=== United Nations (FAO-UN), United Nations World Food Programme (WFP) -//=== and United Nations Environment Programme (UNEP) -//=== -//=== This program is free software; you can redistribute it and/or modify -//=== it under the terms of the GNU General Public License as published by -//=== the Free Software Foundation; either version 2 of the License, or (at -//=== your option) any later version. -//=== -//=== This program is distributed in the hope that it will be useful, but -//=== WITHOUT ANY WARRANTY; without even the implied warranty of -//=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -//=== General Public License for more details. -//=== -//=== You should have received a copy of the GNU General Public License -//=== along with this program; if not, write to the Free Software -//=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA -//=== -//=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, -//=== Rome - Italy. email: geo...@os... -//============================================================================== - -package org.fao.geonet.csw.common.util; - -import java.io.IOException; -import java.io.InputStream; -import java.io.StringReader; -import org.jdom.Document; -import org.jdom.Element; -import org.jdom.JDOMException; -import org.jdom.input.SAXBuilder; -import org.jdom.output.Format; -import org.jdom.output.XMLOutputter; - -//============================================================================= - -/** This is a portion of the jeeves.utils.Xml class and is replicated here just - * to avoid the jeeves jar - */ - -public class Xml -{ - //--------------------------------------------------------------------------- - //--- - //--- API methods - //--- - //--------------------------------------------------------------------------- - - /** Loads an xml file and returns its root node (validates the xml with a dtd) */ - - public static Element loadString(String data, boolean validate) - throws IOException, JDOMException - { - SAXBuilder builder = new SAXBuilder(validate); - Document jdoc = builder.build(new StringReader(data)); - - return (Element) jdoc.getRootElement().detach(); - } - - //-------------------------------------------------------------------------- - /** Loads an xml stream and returns its root node (validates the xml with a dtd) */ - - public static Element loadStream(InputStream input) throws IOException, JDOMException - { - SAXBuilder builder = new SAXBuilder(); - Document jdoc = builder.build(input); - - return (Element) jdoc.getRootElement().detach(); - } - - //--------------------------------------------------------------------------- - /** Converts an xml element to a string */ - - public static String getString(Element data) - { - XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); - - return outputter.outputString(data); - } - - //--------------------------------------------------------------------------- - - public static String getString(Document data) - { - XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); - - return outputter.outputString(data); - } -} - -//============================================================================= - +//============================================================================= +//=== Copyright (C) 2001-2007 Food and Agriculture Organization of the +//=== United Nations (FAO-UN), United Nations World Food Programme (WFP) +//=== and United Nations Environment Programme (UNEP) +//=== +//=== This program is free software; you can redistribute it and/or modify +//=== it under the terms of the GNU General Public License as published by +//=== the Free Software Foundation; either version 2 of the License, or (at +//=== your option) any later version. +//=== +//=== This program is distributed in the hope that it will be useful, but +//=== WITHOUT ANY WARRANTY; without even the implied warranty of +//=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +//=== General Public License for more details. +//=== +//=== You should have received a copy of the GNU General Public License +//=== along with this program; if not, write to the Free Software +//=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA +//=== +//=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, +//=== Rome - Italy. email: geo...@os... +//============================================================================== + +package org.fao.geonet.csw.common.util; + +import java.io.IOException; +import java.io.InputStream; +import java.io.StringReader; +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.JDOMException; +import org.jdom.input.SAXBuilder; +import org.jdom.output.Format; +import org.jdom.output.XMLOutputter; + +//============================================================================= + +/** This is a portion of the jeeves.utils.Xml class and is replicated here just + * to avoid the jeeves jar + */ + +public class Xml +{ + //--------------------------------------------------------------------------- + //--- + //--- API methods + //--- + //--------------------------------------------------------------------------- + + /** Loads an xml file and returns its root node (validates the xml with a dtd) */ + + public static Element loadString(String data, boolean validate) + throws IOException, JDOMException + { + SAXBuilder builder = new SAXBuilder(validate); + builder.setFeature("http://apache.org/xml/features/allow-java-encodings", true); + + + Document jdoc = builder.build(new StringReader(data)); + + return (Element) jdoc.getRootElement().detach(); + } + + //-------------------------------------------------------------------------- + /** Loads an xml stream and returns its root node (validates the xml with a dtd) */ + + public static Element loadStream(InputStream input) throws IOException, JDOMException + { + SAXBuilder builder = new SAXBuilder(); + builder.setFeature("http://apache.org/xml/features/allow-java-encodings", true); + Document jdoc = builder.build(input); + + return (Element) jdoc.getRootElement().detach(); + } + + //--------------------------------------------------------------------------- + /** Converts an xml element to a string */ + + public static String getString(Element data) + { + XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); + + return outputter.outputString(data); + } + + //--------------------------------------------------------------------------- + + public static String getString(Document data) + { + XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); + + return outputter.outputString(data); + } +} + +//============================================================================= + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |