System.out.println("SAX HANDLER USED:" + mySAXContentHandlerClassName);
System.out.println("[GenericQueryXML.returnVal] SAX HANDLER USED:" + mySAXContentHandlerClassName);
     public void  returnVal( OutputStream out)     {          System.out.print("[GenericQueryXML.returnVal] called.");          XMLObjectProvider   myObjectProvider = (XMLObjectProvider)this.getParam(this.paramkey_XML_SERVICE);          XSLTInputSource  myXSL = null;          String mySAXContentHandlerClassName = null;          //          // XSL PARAMETER?          //          myXSL=getXSLFromParameter();          //StringBuffer sbuf_xsl = (StringBuffer)preConfiguredParameters.get(this.paramkey_XSL);          //if( sbuf_xsl != null) myXSL =  new XSLTInputSource(new StringReader(sbuf_xsl.toString()));          //System.out.println(" myXSL=" + myXSL);          //          // SAX CONTENTHANDLER PARAMETER?          //          String sbuf_sax = (String)preConfiguredParameters.get(this.paramkey_SAX);          if( sbuf_sax != null) mySAXContentHandlerClassName = sbuf_sax.toString();          if( mySAXContentHandlerClassName != null) {             System.out.println("SAX HANDLER USED:" + mySAXContentHandlerClassName);          }          else {             System.out.println("SAX HANDLER NOT USED." );          }          //#################################          // XSL PROCESSING          // ################################          if( myXSL != null)          {              try {   /**                  File xslf = new File( "../../gldictionary_entries/task.simple.1.xsl");                  System.out.println("XSL FILE ATTEMPTED READ:" + xslf.getAbsolutePath() );                  FileReader fr = new FileReader(xslf);                  XSLTInputSource  xslsource =  new XSLTInputSource(fr);                  myXSL= xslsource;                  **/                 TXDocument doc = null;                 synchronized( myObjectProvider) {                     Object odoc= getDocument(myObjectProvider);                     if( odoc instanceof TXDocument) doc = (TXDocument)odoc;                 }                 //                 // this is TERRIBLE THING TO DO FOR NOW...                 //  converting DOM TO STRING TO APPLY XSL is v. inefficient,                 // but until old ALP XML parser version can be updated, no choice...                 // soon.                 //                 if( (myXSL != null) && ( doc != null) )                 {                    StringWriter sw = new StringWriter();                    doc.print(sw);                    StringBuffer sb = sw.getBuffer();                    //System.err.println("returnVal, sb.toSTring()=" + sb.toString().substring(0,120));                    //System.err.println("returnVal, sbuf.toString()=" + sbuf.toString());                    StringReader sr = new StringReader(sb.toString() );                    applyXSL(sr,myXSL, out);                 } else if( (doc != null)  ) {                     doc.print(new PrintWriter(out));                 }                 // send document to client                 //doc.print(new PrintWriter(out));              } catch (Exception ex ){                    ex.printStackTrace();              }          }          //#################################          // SAX PROCESSING          // ################################          else if ( mySAXContentHandlerClassName != null ) {              //              // Set from mySAXContentHandlerClassName...              //              BContentHandler myContentHandler=null;              try{                 Class klass = Class.forName(mySAXContentHandlerClassName);                 myContentHandler = (BContentHandler)klass.newInstance();              } catch (ClassNotFoundException cex ) {                 System.err.println("[GenericQueryXML.returnVal()]  Class NOT FOUND trying to create new Content Handler instance.");                 System.err.println("[[GenericQueryXML.returnVal()]  Be sure handler is in classpath.");                 cex.printStackTrace();              } catch (ClassCastException cex) {                 System.err.println("[GenericQueryXML.returnVal()]  Class CAST EXCEPTION creating new Content Handler instance.");                 System.err.println("[[GenericQueryXML.returnVal()]  Be sure handler implements interface BContentHandler!");                 cex.printStackTrace();              } catch (Exception ex) {                 ex.printStackTrace();              }              //BContentHandler myContentHandler = new BContentHandler();              if( mySaxParser == null) {                    mySaxParser = new SAXParser();                    try {                         // try to activate validation                         mySaxParser.setFeature("http://xml.org/sax/features/validation", true);                    } catch (SAXException e) {                         System.err.println("Cannot activate validation.");                    }              } // end create SAX parser              if( mySaxParser != null)              {                  mySaxParser.setContentHandler(myContentHandler);                  mySaxParser.setErrorHandler(new BErrorHandler());              }              TXDocument doc = null;              synchronized( myObjectProvider) {                     Object odoc= getDocument(myObjectProvider);                     if( odoc instanceof TXDocument) doc = (TXDocument)odoc;              }              if( ( doc != null) )              {                    StringWriter sw = new StringWriter();                    try{                        doc.print(sw);                    } catch( IOException ex ) {                        ex.printStackTrace();                    }                    StringBuffer sb = sw.getBuffer();                    StringReader str_reader = new StringReader(sb.toString() );                    try {                        InputSource in = new InputSource(str_reader);                        mySaxParser.parse(in);                    } catch (IOException e) {                        System.err.println("I/O exception reading XML document. " + e);                        e.printStackTrace();                    } catch (SAXException e) {                        System.err.println("SAX exception parsing document. " + e);                        e.printStackTrace();                    }                   //-----------------------------------------------------------------                   // Traverse and "write" the tree                   // Start from the root object                   //-----------------------------------------------------------------                   PrintWriter pw = new PrintWriter(out);                   pw.println("<?xml version=\"1.0\"?>");                   Iterator it3 = myContentHandler.getRootElements().iterator();                   while(it3.hasNext()){                      BElement be = (BElement)it3.next();                      be.print(pw);                   }                   pw.flush();                   System.out.println("[GenericQueryXML] pw.toString()=" + pw.toString() );              }          }          // ##############################          // FLUSH! object cache after we've consumed data          // ##############################          synchronized( myObjectProvider ) {              reset(myObjectProvider);          }  }