% (1) Adjust the four directory names 



% (2) xhlatex tex4ht-xv4ht "html,3"

% (3) Consider adjusting the entries in \CATALOG (may also be done
%     in \section{Access to DTD's})


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% tex4ht-xv4ht.tex                                       %
% Copyright (C) 2005--            Eitan M. Gurari        %
%                                                        %
% This work may be distributed and/or modified under the %
% conditions of the LaTeX Project Public License, either %
% version 1.3 of this license or (at your option) any    %
% later version. The latest version of this license is   %
% in                                                     %
%   http://www.latex-project.org/lppl.txt                %
% and version 1.3 or later is part of all distributions  %
% of LaTeX version 2003/12/01 or later.                  %
%                                                        %
% This work has the LPPL maintenance status "maintained".%
%                                                        %
% This Current Maintainer of this work                   %
% is Eitan M. Gurari.                                    %
%                                                        %
% If you modify this file your changing the signature    %
% in \message{(signature)} below will be appreciated.    %
%                                                        %
%                             gurari@cse.ohio-state.edu  %
%                 http://www.cse.ohio-state.edu/~gurari  %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
\message{(<signature>)}



\newcount\tmpcnt  \tmpcnt\time  \divide\tmpcnt  60
\edef\temp{\the\tmpcnt}
\multiply\tmpcnt  -60 \advance\tmpcnt  \time

\edef\version{\the\year-\ifnum \month<10 0\fi
  \the\month-\ifnum \day<10 0\fi\the\day
   -\ifnum \temp<10 0\fi \temp
   :\ifnum \tmpcnt<10 0\fi\the\tmpcnt}
\def\CopyYear.#1.{%
   \ifnum #1=\year #1\space\space\space\space\space\space
    \else          #1--\the\year\fi
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass{article}

   \input tex4ht-dir.tex   
   \usepackage{url}

   \Configure{ProTex}{java,title,<<<>>>,list,`}

\begin{document}

\title{A XML Validator for TeX4ht}
\author{Eitan M. Gurari} 
\maketitle

\begin{abstract}
  This is a simple validator. It is offered as a fall
  back for platforms that don't provide alternative validators.
\end{abstract}

%%%%%%%%%%%%%%%%%%%%
\section{The Driver}
%%%%%%%%%%%%%%%%%%%%

\<xv4ht\><<<
`<copyright`>
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Hashtable;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.DefaultHandler;

`<Xv4htContentHandler`>
`<ValErrorHandler`>
public class xv4ht{
  static public void main (String[] args)
     throws SAXException,
            ParserConfigurationException,
            IOException
  {
     SAXParserFactory factory = 
         SAXParserFactory.newInstance();
     factory.setValidating( true );
     factory.setNamespaceAware( true );
     SAXParser saxParser = factory.newSAXParser();
     XMLReader xmlReader = saxParser.getXMLReader();
     `<verify command line`>
     xmlReader.setContentHandler( `<add content handler`> );
     xmlReader.parse ( new File(args[0]).toURL().toString() );
  }
}
>>>

\<verify command line\><<<
if( args.length != 2 ){
  System.out.print( 
       "--- A command line of the following form is required ---" 
     + "\n      java [-cp <path>] xv4ht <filename> <catalog>" 
     + "\nreceived:\n      java"
  );
  for(int i=0; i<args.length; i++ ){
     System.out.print( " " + args[i] );
  }
  System.out.println();
  System.exit( 1 );
}
>>>


%%%%%%%%%%%%%%%%%%%%
\section{The Content Handler}
%%%%%%%%%%%%%%%%%%%%

\<add content handler\><<<
new Xv4htContentHandler(xmlReader, args[1]) 
>>>

\<Xv4htContentHandler\><<<
class Xv4htContentHandler extends DefaultHandler {

   String catalog;
   boolean withinDTD = false;
   Xv4htErrorHandler errHandler;
   Xv4htLexicalHandler lexicalHandler;

   public Xv4htContentHandler(XMLReader xmlReader, String catalog){ 
     super();
     this.catalog = catalog;
     `<add lexical handler`>
     `<add error handler`>
     `<add entity resolver`>
   }

   public void startPrefixMapping(String prefix, String uri){
   }

   public void endPrefixMapping(String prefix)  {
   }

   public void ignorableWhitespace(
                           char[] ch, int start, int length) {
   }

   public void notationDecl(
             String name, String publicId, String systemId) {
   }
   `<Xv4htEntityResolver`>
   `<Xv4htLexicalHandler`>
   `<ValDeclHandler`>
}
>>>





%%%%%%%%%%%%%%%%%%%%
\section{The Lexical Handler}
%%%%%%%%%%%%%%%%%%%%


\<add lexical handler\><<<
lexicalHandler = new Xv4htLexicalHandler();
try {
  xmlReader.setProperty(
     "http://xml.org/sax/properties/lexical-handler", 
     lexicalHandler
  );
}
catch (SAXNotRecognizedException e) {
  System.err.println(
   "err 1");
  return;
} 
catch (SAXNotSupportedException e) {
  System.err.println(
   "err 2");
  return;
} 
>>>     





\<Xv4htLexicalHandler\><<<
class Xv4htLexicalHandler implements LexicalHandler {
  public void startDTD(String name, String publicId, String systemId) 
   throws SAXException {
     withinDTD = true;
     errHandler.errorOff();
  }
  
  public void endDTD() throws SAXException {
     withinDTD = false;
     errHandler.errorOn();
  }
public void comment (char[] text, int start, int length) 
   throws SAXException {
}
  public void startEntity(String name) throws SAXException {}
  public void endEntity(String name) throws SAXException {}
  public void startCDATA() throws SAXException {}
  public void endCDATA() throws SAXException {}
}
>>>




%%%%%%%%%%%%%%%%%%%%
\section{The Entity Resolver}
%%%%%%%%%%%%%%%%%%%%


\<add entity resolver\><<<
xmlReader.setEntityResolver( new Xv4htEntityResolver() );
>>>

\<Xv4htEntityResolver\><<<
public class Xv4htEntityResolver implements EntityResolver {

  private Hashtable entities = new Hashtable();

  public Xv4htEntityResolver() {
     `<load catalog`>
  }

  public InputSource resolveEntity(String publicID,
   String systemID) throws SAXException {
     if( publicID== null ){ return null; }
     if( entities.containsKey(publicID) ){
       String url = (String) entities.get(publicID);
       InputSource local = new InputSource(url);
       return local;
     } 
     return null; 
  }

}
>>>


\<load catalog\><<<
try{
      FileReader myIn  = new FileReader( catalog );
      while( true ){
        int c;
        String publicID = "";
        String systemID = "";

        while( (c = myIn.read()) != '\"' ){ 
           if( c == -1 ){ break; }
        }
        if( c == -1 ){ break; }
        while( (c = myIn.read()) != '\"' ){ 
           publicID += (char) c;
           if( c == -1 ){ break; }
        }
        if( c == -1 ){ break; }

        while( (c = myIn.read()) != '\"' ){ 
           if( c == -1 ){ break; }
        }
        if( c == -1 ){ break; }
        while( (c = myIn.read()) != '\"' ){ 
           systemID += (char) c;
           if( c == -1 ){ break; }
        }
        if( c == -1 ){ break; }

        entities.put(publicID, systemID);
      }
} catch(java.io.IOException e){   }
>>>


%%%%%%%%%%%%%%%%%%%%
\section{The Error Handler}
%%%%%%%%%%%%%%%%%%%%


\<add error handler\><<<
errHandler = new Xv4htErrorHandler();
xmlReader.setErrorHandler( errHandler );
>>>

\<ValErrorHandler\><<<
class Xv4htErrorHandler extends DefaultHandler {
  private boolean errOn = true;

  public void warning(SAXParseException e) {
    showError( e, "Warning" );
  }

  public void error(SAXParseException e) {
    showError( e, "Warning" );
  }

  public void fatalError(SAXParseException e) {
    showError( e, "Warning" );
  }

  public void errorOff() {
     errOn = false;
  }

  public void errorOn() {
     errOn = true;
  }

  private void showError(SAXParseException e, String m){
    if( errOn ){
      int c = e.getColumnNumber();
      System.out.println(
        m + ": " + e.getSystemId() + " " + e.getLineNumber() 
        + ((c==-1)? "" : ("," + c))
        + ": " + e.getMessage()      
      );
  } }
}
>>>

%%%%%%%%%%%%%%%%%%%%
\section{Access to DTD's}
%%%%%%%%%%%%%%%%%%%%

\def\.#1.{\csname #1\endcsname}

 
\<xv4ht.cat\><<<
`<XHTML 1.1 plus MathML 2.0 (private)`>
`<XHTML 1.0 Transitional (private)`>
`<HTML 4.01 Frameset (private)`>
`<MathML 2.0 (private)`>
`<Modified W3C MathML 1.01 (private)`>
`<OfficeDocument 2.0 (private)`>
`<OfficeDocument 1.0 (private)`>
`<DocBook XML V4.2CR1 (private)`>
`<TEI Lite XML ver. 1.3 (private)`>
`<JavaHelp Version 1.0 (private)`>
>>>

\<xv4ht.cat-unix\><<<
`<XHTML 1.1 plus MathML 2.0`>
`<XHTML 1.0 Transitional`>
`<HTML 4.01 Frameset`>
`<MathML 2.0`>
`<Modified W3C MathML 1.01`>
`<OfficeDocument 2.0`>
`<OfficeDocument 1.0`>
`<DocBook XML V4.2CR1`>
`<TEI Lite XML ver. 1.3`>
`<JavaHelp Version 1.0`>
>>>

\<xv4ht.cat-win\><<<
`<XHTML 1.1 plus MathML 2.0`>
`<XHTML 1.0 Transitional`>
`<HTML 4.01 Frameset`>
`<MathML 2.0`>
`<Modified W3C MathML 1.01`>
`<OfficeDocument 2.0`>
`<OfficeDocument 1.0`>
`<DocBook XML V4.2CR1`>
`<TEI Lite XML ver. 1.3`>
`<JavaHelp Version 1.0`>
>>>




\begin{itemize}
\item
\url{http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd}


\<XHTML 1.1 plus MathML 2.0\><<<
"-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
   "http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd >>>



\<XHTML 1.1 plus MathML 2.0 (private)\><<<
"-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
   "`.DTDS.svg.dir/xhtml-math-svg.dtd" >>>


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\item
\url{http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd}


\<XHTML 1.0 Transitional\><<<
"-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd >>>



\<XHTML 1.0 Transitional (private)\><<<
"-//W3C//DTD XHTML 1.0 Transitional//EN"
   "`.DTDS.xhtml/xhtml1-transitional.dtd" >>>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\item
\url{http://www.w3.org/TR/html4/frameset.dtd}

\<HTML 4.01 Frameset\><<<
"-//W3C//DTD HTML 4.01 Frameset//EN"
   "http://www.w3.org/TR/html4/frameset.dtd >>>

\<HTML 4.01 Frameset (private)\><<<
"-//W3C//DTD HTML 4.01 Frameset//EN"
   "`.DTDS.xhtml/xhtml1-frameset.dtd" >>>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\item
% \url{}

\<MathML 2.0 (private)\><<<
"-//W3C//DTD MathML 2.0//EN"
   "`.DTDS.mathml/mathml2.dtd" >>>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\item
 \url{http://www.openoffice.org}



\<OfficeDocument 2.0 (private)\><<<
"-//OpenOffice.org//DTD OfficeDocument 2.0//EN"
   "`.DTDS.openoffice/oo2.dir/office.dtd" >>>

\<OfficeDocument 1.0 (private)\><<<
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN"
   "`.DTDS.openoffice/office.dtd" >>>

\<Modified W3C MathML 1.01 (private)\><<<
"-//OpenOffice.org//DTD Modified W3C MathML 1.01//EN"
   "`.DTDS.openoffice/math.dtd" >>>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\item
\url{http://www.oasis-open.org/docbook/xml/4.2CR1/docbookx.dtd}

\<DocBook XML V4.2CR1\><<<
"-//OASIS//DTD DocBook XML V4.2CR1//EN"
   "http://www.oasis-open.org/docbook/xml/4.2CR1/docbookx.dtd >>>

\<DocBook XML V4.2CR1 (private)\><<<
"-//OASIS//DTD DocBook XML V4.2CR1//EN"
   "`.DTDS.docbook.dir/docbookx.dtd" >>>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\item
% \url{}

\<TEI Lite XML ver. 1.3 (private)\><<<
"-//TEI//DTD TEI Lite XML ver. 1.3//EN"
   "`.DTDS.teixlite.dir/teixlite.dtd" >>>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\item
 \url{http://java.sun.com/products/javahelp/}


\<JavaHelp Version 1.0 (private)\><<<
"-//Sun Microsystems Inc.//DTD JavaHelp HelpSet Version 1.0//EN" 
   "`.DTDS.jh1.1.3/javahelp/lib/dtd/helpset_1_0.dtd"
"-//Sun Microsystems Inc.//DTD JavaHelp Map Version 1.0//EN"
   "`.DTDS.jh1.1.3/javahelp/lib/dtd/map_1_0.dtd" 
"-//Sun Microsystems Inc.//DTD JavaHelp TOC Version 1.0//EN" 
   "`.DTDS.jh1.1.3/javahelp/lib/dtd/toc_1_0.dtd" 
"-//Sun Microsystems Inc.//DTD JavaHelp Index Version 1.0//EN"
   "`.DTDS.jh1.1.3/javahelp/lib/dtd/index_1_0.dtd" >>>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{itemize}


%%%%%%%%%%%%%%%%%%
\section{Copyrignt}
%%%%%%%%%%%%%%%%%%

\<copyright\><<<
/**********************************************************/
/* xv4ht.java                            `version */
/* Copyright (C) `CopyYear.2005.    Eitan M. Gurari            */
/*                                                        */
/* This work may be distributed and/or modified under the */
/* conditions of the LaTeX Project Public License, either */
/* version 1.3 of this license or (at your option) any    */
/* later version. The latest version of this license is   */
/* in                                                     */
/*   http://www.latex-project.org/lppl.txt                */
/* and version 1.3 or later is part of all distributions  */
/* of LaTeX version 2003/12/01 or later.                  */
/*                                                        */
/* This work has the LPPL maintenance status "maintained".*/
/*                                                        */
/* This Current Maintainer of this work                   */
/* is Eitan M. Gurari.                                    */
/*                                                        */
/* If you modify this program your changing its signature */
/* with a directive of the following form will be         */
/* appreciated.                                           */
/*      #define PLATFORM "signature"                      */
/*                                                        */
/*                             gurari@cse.ohio-state.edu  */
/*                 http://www.cse.ohio-state.edu/~gurari  */
/**********************************************************/
>>>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\OutputCode\<xv4ht\>
\OutputCodE\<xv4ht.cat\>
\OutputCodE\<xv4ht.cat-unix\>
\OutputCodE\<xv4ht.cat-win\>

\Needs{"mkdir xv4htmp"}

\Needs{"  cp  xv4ht.java xv4htmp/. 
        ; cd xv4htmp 
        ; javac xv4ht.java
        ; jar -cf xv4ht.jar *.class
        ; mkdir \HOME texmf/tex4ht/bin 
        ; mv xv4ht.jar \HOME texmf/tex4ht/bin/. 
"}

\Needs{"rm -r xv4htmp"}

\Needs{"  mv xv4ht.cat \HOME texmf/tex4ht/base/solaris/. "}





\end{document}






