Changeset 25604

Show
Ignore:
Timestamp:
16.05.2012 09:35:37 (7 years ago)
Author:
sjm84
Message:

Recommiting Anu's changes without the print statements

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/XMLTransformer.java

    r25603 r25604  
    130130        try 
    131131        { 
    132             TransformErrorListener transformerErrorListener = (TransformErrorListener)this.t_factory.getErrorListener(); 
    133             transformerErrorListener.setStylesheet(stylesheet);          
     132            TransformErrorListener transformerErrorListener = (TransformErrorListener) this.t_factory.getErrorListener(); 
     133            transformerErrorListener.setStylesheet(stylesheet); 
    134134            // Use the TransformerFactory to process the stylesheet Source and generate a Transformer. 
    135135            Transformer transformer = this.t_factory.newTransformer(new StreamSource(stylesheet)); 
     
    165165        try 
    166166        { 
    167             TransformErrorListener transformerErrorListener = (TransformErrorListener)this.t_factory.getErrorListener(); 
     167            TransformErrorListener transformerErrorListener = (TransformErrorListener) this.t_factory.getErrorListener(); 
    168168            transformerErrorListener.setStylesheet(stylesheet); 
    169169            // Use the TransformerFactory to process the stylesheet Source and generate a Transformer. 
     
    223223    public Node transform(Document stylesheet, Document source, HashMap parameters, Document docDocType) 
    224224    { 
    225         System.err.println("1"); 
    226225        return transform(stylesheet, source, parameters, docDocType, null); 
    227226    } 
     
    231230        try 
    232231        { 
    233             System.err.println("1.1"); 
    234232            // Use the TransformerFactory to process the stylesheet Source and generate a Transformer. 
    235             TransformErrorListener transformerErrorListener = (TransformErrorListener)this.t_factory.getErrorListener(); 
     233            TransformErrorListener transformerErrorListener = (TransformErrorListener) this.t_factory.getErrorListener(); 
    236234            transformerErrorListener.setStylesheet(stylesheet); 
    237             Transformer transformer = this.t_factory.newTransformer(new DOMSource(stylesheet));          
    238  
    239             System.err.println("1.2"); 
     235            Transformer transformer = this.t_factory.newTransformer(new DOMSource(stylesheet)); 
     236 
    240237            //logger.info("XMLTransformer transformer is " + transformer); //done in ErrorListener 
    241238            if (parameters != null) 
     
    249246                } 
    250247            } 
    251             System.err.println("1.3"); 
     248 
    252249            // When we transform the DOMResult, we need to make sure the result of 
    253250            // the transformation has a DocType. For that to happen, we need to create 
     
    261258            } 
    262259            DOMSource domSource = new DOMSource(source); 
    263             System.err.println("2"); 
    264260            transformer.setErrorListener(new TransformErrorListener(stylesheet, domSource)); 
    265             System.err.println("4"); 
    266261            transformer.transform(domSource, result); 
    267             System.err.println("5"); 
    268262            return result.getNode(); // pass the entire document 
    269263        } 
     
    292286        try 
    293287        { 
    294             TransformErrorListener transformerErrorListener = (TransformErrorListener)this.t_factory.getErrorListener(); 
     288            TransformErrorListener transformerErrorListener = (TransformErrorListener) this.t_factory.getErrorListener(); 
    295289            transformerErrorListener.setStylesheet(stylesheet); 
    296290            Transformer transformer = this.t_factory.newTransformer(new StreamSource(stylesheet)); 
     
    403397        protected Source source = null; // can be DOMSource or StreamSource 
    404398        protected boolean debugAsFile = true; // true if xslt or source are not real physical files 
    405          
     399 
    406400        // *********** METHODS TO BE CALLED WHEN SETTING AN ERROR LISTENER ON TRANSFORMERFACTORY OBJECTS 
    407401        // The default constructor is only for when setting an ErrorListener on TransformerFactory objects 
    408         public TransformErrorListener() { 
     402        public TransformErrorListener() 
     403        { 
    409404            this.stylesheet = null; 
    410405            this.source = null; 
    411406            XMLTransformer.debugFileCount++; 
    412407        } 
    413          
    414         public void setStylesheet(Document xslt)  
     408 
     409        public void setStylesheet(Document xslt) 
    415410        { 
    416411            this.debugAsFile = true; 
     
    418413            this.source = null; 
    419414        } 
    420          
    421         public void setStylesheet(String xslt)  
     415 
     416        public void setStylesheet(String xslt) 
    422417        { 
    423418            this.debugAsFile = true; 
     
    425420            this.source = null; 
    426421        } 
    427          
    428         public void setStylesheet(File xslt)  
     422 
     423        public void setStylesheet(File xslt) 
    429424        { 
    430425            this.debugAsFile = false; // if this constructor is called, we're dealing with physical files for both xslt and source           
     
    458453 
    459454        // *********** METHODS CALLED AUTOMATICALLY ON ERROR 
    460          
     455 
    461456        //  Receive notification of a recoverable error. 
    462457        public void error(TransformerException exception) 
     
    532527                // since !debugAsFile, we are dealing with physical files,  
    533528                // variable stylesheet would have stored the filename instead of contents 
    534                 this.errorMessage = this.errorMessage + "\nstylesheet filename: " + stylesheet;              
    535                  
     529                this.errorMessage = this.errorMessage + "\nstylesheet filename: " + stylesheet; 
     530 
    536531                this.errorMessage += "\nException CAUSE:\n" + exception.getCause(); 
    537532                System.err.println("\n****Error transforming xml:\n" + this.errorMessage + "\n****\n"); 
     
    544539            } 
    545540        } 
    546          
     541 
    547542        // This method will redo the transformation that went wrong with *real* files:  
    548543        // it writes out the stylesheet and source XML to files first, then performs the transformation 
     
    557552            File styleFile = new File(webLogsTmpFolder + File.separator + "stylesheet" + XMLTransformer.debugFileCount + ".xml"); 
    558553            File sourceFile = new File(webLogsTmpFolder + File.separator + "source" + XMLTransformer.debugFileCount + ".xml"); 
    559                  
    560554 
    561555            try 
     
    572566            } 
    573567 
    574             if(this.source != null) { // ErrorListener was set on a Transformer object 
     568            if (this.source != null) 
     569            { // ErrorListener was set on a Transformer object 
    575570                try 
    576571                { 
     
    606601            System.err.println("*****************************************"); 
    607602            System.err.println("Look for stylesheet in: " + styleFile.getAbsolutePath()); 
    608             if(this.source != null) { // ErrorListener was set on a Transformer object 
     603            if (this.source != null) 
     604            { // ErrorListener was set on a Transformer object 
    609605                System.err.println("Look for source XML in: " + sourceFile.getAbsolutePath()); 
    610             }    
     606            } 
    611607 
    612608            // now perform the transform again, which will assign another TransformErrorListener 
    613609            // but since debuggingAsFile is turned off, we won't recurse into this section of 
    614610            // handling the error again 
    615             if(this.source != null) { // ErrorListener was set on a Transformer object 
     611            if (this.source != null) 
     612            { // ErrorListener was set on a Transformer object 
    616613                XMLTransformer.this.transform(styleFile, sourceFile); // calls the File, File version, so debugAsFile will be false 
    617             }  
    618              
    619             else { // ErrorListener was set on a TransformerFactory object 
    620                  
     614            } 
     615 
     616            else 
     617            { // ErrorListener was set on a TransformerFactory object 
     618 
    621619                // The recursive step in this case is to perform the instantiation  
    622620                // of the Transformer object again. 
     
    627625                // Therefore, the debugAsFile state for the single TransformerFactory's  
    628626                // TransformerHandler changes each time also. 
    629                  
    630                 try { 
     627 
     628                try 
     629                { 
    631630                    debugAsFile = false; 
    632                     this.stylesheet = styleFile.getAbsolutePath();                   
     631                    this.stylesheet = styleFile.getAbsolutePath(); 
    633632                    //TransformErrorListener transformerErrorListener = (TransformErrorListener)XMLTransformer.this.t_factory.getErrorListener(); 
    634633                    //transformerErrorListener.setStylesheet(styleFile); 
    635634                    Transformer transformer = XMLTransformer.this.t_factory.newTransformer(new StreamSource(styleFile)); 
    636                     if(transformer == null) { 
     635                    if (transformer == null) 
     636                    { 
    637637                        String msg = "XMLTransformer transformer is " + transformer; 
    638638                        logger.info(msg); 
    639639                        System.out.println(msg + "\n****\n"); 
    640640                    } 
    641                 } catch (TransformerConfigurationException e) 
     641                } 
     642                catch (TransformerConfigurationException e) 
    642643                { 
    643                     String message = "Couldn't create transformer object: " + e.getMessageAndLocation();                     
     644                    String message = "Couldn't create transformer object: " + e.getMessageAndLocation(); 
    644645                    logger.error(message); 
    645646                    logger.error(e.getLocationAsString()); 
     
    648649                catch (TransformerException e) 
    649650                { 
    650                     String message = "Couldn't transform the source: " + e.getMessageAndLocation();  
     651                    String message = "Couldn't transform the source: " + e.getMessageAndLocation(); 
    651652                    logger.error(message); 
    652653                    System.out.println(message); 
    653654                } 
    654             }  
     655            } 
    655656 
    656657        }