User: rinkrank
  Date: 02/04/21 13:40:15

  Modified:    core/src/xdoclet/util XmlValidator.java
  Log:
  -handled classloading issues in xjavadoc in stead of xdoclet
  -some loader/module bugfixes
  
  Revision  Changes    Path
  1.12      +52 -40    xdoclet/core/src/xdoclet/util/XmlValidator.java
  
  Index: XmlValidator.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/util/XmlValidator.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -w -r1.11 -r1.12
  --- XmlValidator.java 12 Apr 2002 21:01:58 -0000      1.11
  +++ XmlValidator.java 21 Apr 2002 20:40:14 -0000      1.12
  @@ -9,6 +9,9 @@
   import org.xml.sax.*;
   import org.xml.sax.helpers.DefaultHandler;
   import org.xml.sax.helpers.ParserAdapter;
  +
  +import javax.xml.parsers.*;
  +
   import xdoclet.XDocletException;
   
   import java.io.File;
  @@ -24,7 +27,7 @@
    *
    * @author    <a href="mailto:[EMAIL PROTECTED]";>Aslak Helles�y</a>
    * @created   September 18, 2001
  - * @version   $Revision: 1.11 $
  + * @version   $Revision: 1.12 $
    * @todo      Deal with Translator.getString()'s exception better in
    *      resolveEntity(String, String)
    */
  @@ -38,7 +41,7 @@
        /**
         * @todo-javadoc   Describe the field
         */
  -     private static XmlValidator instance;
  +     private static XmlValidator instance = new XmlValidator( null );
   
        /**
         * @todo-javadoc   Describe the field
  @@ -46,7 +49,7 @@
        protected ClassLoader classLoader;
   
        /**
  -      * XMLReader used to validation process
  +      * XMLReader used for validation
         */
        protected XMLReader xmlReader = null;
   
  @@ -186,7 +189,7 @@
        public void warning( SAXParseException e )
                 throws SAXParseException
        {
  -             throw e;
  +//           throw e;
        }
   
        /**
  @@ -200,40 +203,17 @@
         */
        public void validate( File xmlFile ) throws XDocletException
        {
  +             if( classLoader == null )
  +             {
  +                     // we're running in forked mode. no need to use ant 
classloader hack
  +                     // Get strange  org.xml.sax.SAXParseException: Declared 
encoding "UTF-8" does not match actual one "Cp1252"; this might not be an error.
                initValidator();
  +             }
  +             else
  +             {
  +                     initValidatorHack();
  +             }
                doValidate( xmlFile );
  -
  -//      try
  -//      {
  -//         SAXParser parser = factory.newSAXParser();
  -//
  -//         cat.debug( "Parsing " + xmlFile.getAbsolutePath() );
  -//         parser.parse( xmlFile, this );
  -//         cat.debug( "Parsing OK" );
  -//      }
  -//      catch( SAXParseException e )
  -//      {
  -//         String message = Translator.getString( "generated_xml_invalid",
  -//               new String[]{e.getSystemId(), Integer.toString( e.getLineNumber() 
), e.getMessage()} );
  -//
  -//         throw new XDocletException( e, message );
  -//      }
  -//      catch( SAXException e )
  -//      {
  -//         throw new XDocletException( e, Translator.getString( 
"couldnt_init_xml_parser" ) );
  -//      }
  -//      catch( IOException e )
  -//      {
  -//         throw new XDocletException( e, Translator.getString( 
"couldnt_load_xml_file" ) );
  -//      }
  -//      catch( ParserConfigurationException e )
  -//      {
  -//         throw new XDocletException( e, Translator.getString( 
"couldnt_conf_xml_parser" ) );
  -//      }
  -//      catch( NullPointerException e )
  -//      {
  -//         throw new XDocletException( e, Translator.getString( "couldnt_load_dtd" 
) );
  -//      }
        }
   
        /*
  @@ -275,12 +255,12 @@
                catch( SAXException e )
                {
                        e.printStackTrace();
  -                     throw new XDocletException( "Could'nt validate document " + 
xml_file );
  +                     throw new XDocletException( "Couldn't validate document " + 
xml_file );
                }
                catch( IOException e )
                {
                        e.printStackTrace();
  -                     throw new XDocletException( e, "Could'nt validate document " + 
xml_file );
  +                     throw new XDocletException( e, "Couldn't validate document " + 
xml_file );
                }
   
   //      if( errorHandler.getFailure() )
  @@ -299,7 +279,7 @@
         * @todo-javadoc                Write javadocs for method
         * @todo-javadoc                Write javadocs for exception
         */
  -     private void initValidator() throws XDocletException
  +     private void initValidatorHack() throws XDocletException
        {
                Category cat = Log.getCategory( XmlValidator.class, "initValidator" );
   
  @@ -396,6 +376,38 @@
                        {
                                e.printStackTrace();
                        }
  +             }
  +     }
  +
  +     private void initValidator() throws XDocletException
  +     {
  +             try
  +             {
  +                     SAXParserFactory factory = SAXParserFactory.newInstance();
  +
  +                     factory.setValidating( true );
  +                     xmlReader = factory.newSAXParser().getXMLReader();
  +                     xmlReader.setEntityResolver( this );
  +                     xmlReader.setErrorHandler( this );
  +             }
  +             catch( SAXParseException e )
  +             {
  +                     String message = Translator.getString( "generated_xml_invalid",
  +                             new String[]{e.getSystemId(), Integer.toString( 
e.getLineNumber() ), e.getMessage()} );
  +
  +                     throw new XDocletException( e, message );
  +             }
  +             catch( SAXException e )
  +             {
  +                     throw new XDocletException( e, Translator.getString( 
"couldnt_init_xml_parser" ) );
  +             }
  +             catch( ParserConfigurationException e )
  +             {
  +                     throw new XDocletException( e, Translator.getString( 
"couldnt_conf_xml_parser" ) );
  +             }
  +             catch( NullPointerException e )
  +             {
  +                     throw new XDocletException( e, Translator.getString( 
"couldnt_load_dtd" ) );
                }
        }
   }
  
  
  

_______________________________________________
Xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel

Reply via email to