9.1 Fix XML Defaults

<..xtpipes fields..>+
 private static String [] ml2xml = null;
 static Class<?> ml2xmlClassObj = null;
 -_-_-

<..scan ml2xml argument..>
 if( args[n].substring(2).equals("") ){
    if( ml2xml == null ){ ml2xml = new String[0]; }
 } else {
    if( ml2xml == null ){
       ml2xml = new String[1];
    } else {
       String [] m2x = new String [ml2xml.length + 1];
       for(int cnt=0; cnt < ml2xml.length; cnt++){
         m2x[cnt] = ml2xml[cnt];
       }
       ml2xml = m2x;
    }
    ml2xml[ ml2xml.length - 1 ] = args[n].substring(2);
 }
 -_-_-

<..inputStream := (InputStream) new Ml2xml(filename, "foo.m2x")..>
 try{
    ml2xmlClassObj = Class.forName( "ml2xml.Ml2xml" );
 } catch (java.lang.ClassNotFoundException cnf ){
    instructionErr( null, "Class not found: ml2xml.Ml2xml", 25 );
 }
 Class<?> [] argTyp = { String.class, String[].class };
 Constructor<?> con = ml2xmlClassObj.getConstructor( argTyp );
 try{
    <.trace call to ml2xml.>
    inputStream = (InputStream) con.newInstance(
          new Object[]{xml, ml2xml}
       );
 } catch(java.lang.reflect.InvocationTargetException ite){
    String s = "Problem at: ml2xml.Ml2xml(" + xml + ","
               + "new String[]{" ;
    for(int i=0; i < Xtpipes.ml2xml.length; i++){
       s += ((i==0)? "\"" : ", \"") + Xtpipes.ml2xml[i] + "\"";
    }
    s += "})";
    instructionErr( null, s + "; " + ite.getCause(), 38);
 }
 -_-_-

ite.getTargetException().printStackTrace();

<..Ml2xml close files..>
 if( Xtpipes.ml2xml != null ){
    Class<?> [] argTyp = {};
    Method m = ml2xmlClassObj . getMethod( "closeFiles", argTyp );
    m.invoke( null, new Object[0] );
 }
 -_-_-

<..trace call to ml2xml..>
 if( Xtpipes.trace ){
    String s = "Calling: ml2xml.Ml2xml(inputStream,"
               + "new String[]{" ;
    for(int i=0; i < Xtpipes.ml2xml.length; i++){
       s += ((i==0)? "\"" : ", \"") + Xtpipes.ml2xml[i] + "\"";
    }
    s += "})";
    Xtpipes.logWriter.println( s );
 }
 -_-_-

<..close ml2xml files..>
 if( ml2xmlClassObj != null ){
   Class<?> [] argTypes = { };
   Method m = ml2xmlClassObj.getMethod( "closeFiles", argTypes );
   Object parmValues[] = new Object[0];
   m.invoke( null, parmValues );
 }
 -_-_-

<..xtpipes imports..>+
 import java.lang.reflect.Constructor;
 -_-_-

Ml2xml is referenced through reflection instead of directly so that xtpipes can be delivered also without that utility, e.g., for tex4ht where no treatment of faulty XML file is to be done. In fact, this approach can be generalized to offer arbitrary filter for the input.