Class DtdParser


  • public class DtdParser
    extends java.lang.Object
    This class is used to read embedded DTDs from XML files and write them back later. This is neccessary due to the fact, that the transformer of w3c.dom loses any information of embedded DTDs.
    Author:
    pastuschek
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String DOCTYPE  
    • Constructor Summary

      Constructors 
      Constructor Description
      DtdParser()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static Dtd checkForDTD​(java.util.List<java.lang.String> stringList)
      Checks a List of Strings for an embedded DTD.
      static Dtd extractDTD​(java.io.File file)
      Will extract a embedded DTD from an XML file.
      static Dtd extractDTD​(java.io.InputStream in)
      Will extract a embedded DTD from an XML file.
      private static java.util.List<java.lang.String> readFile​(java.io.File file)
      Reads a file and returns a List of Strings with the content.
      private static java.util.List<java.lang.String> readFile​(java.io.InputStream in)
      Reads a from an input stream and returns a List of Strings with the content.
      static void writeDtd​(java.io.File file, Dtd dtd)
      Writes the dtd back into a file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DtdParser

        public DtdParser()
    • Method Detail

      • extractDTD

        public static Dtd extractDTD​(java.io.File file)
                              throws java.io.FileNotFoundException
        Will extract a embedded DTD from an XML file.
        Parameters:
        file - The XML file.
        Returns:
        A List of Strings with the embedded DTD.
        Throws:
        java.io.FileNotFoundException - Thrown if the XML file could not be found.
      • extractDTD

        public static Dtd extractDTD​(java.io.InputStream in)
        Will extract a embedded DTD from an XML file.
        Parameters:
        in - the input stream
        Returns:
        A List of Strings with the embedded DTD.
      • checkForDTD

        private static Dtd checkForDTD​(java.util.List<java.lang.String> stringList)
        Checks a List of Strings for an embedded DTD. If a DTD exists it is returned as a new List of Strings.
        Parameters:
        stringList - List of Strings that are to be checked for DTD.
        Returns:
        A List of Strings with the DTD only (formatting will be maintained).
      • writeDtd

        public static void writeDtd​(java.io.File file,
                                    Dtd dtd)
                             throws java.io.FileNotFoundException
        Writes the dtd back into a file.
        Parameters:
        file - The file to change.
        dtd - The dtd to write into the file.
        Throws:
        java.io.FileNotFoundException - If file was not found.
      • readFile

        private static java.util.List<java.lang.String> readFile​(java.io.File file)
                                                          throws java.io.FileNotFoundException
        Reads a file and returns a List of Strings with the content.
        Parameters:
        file - The file to be read.
        Returns:
        A List of Strings with the content.
        Throws:
        java.io.FileNotFoundException - If File was not found.
      • readFile

        private static java.util.List<java.lang.String> readFile​(java.io.InputStream in)
        Reads a from an input stream and returns a List of Strings with the content.
        Parameters:
        in - the input stream to read
        Returns:
        A List of Strings with the content.