cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From coli...@apache.org
Subject cvs commit: cocoon-2.1/src/scratchpad/src/org/apache/cocoon/generation FlowVelocityGenerator.java
Date Sun, 06 Apr 2003 03:04:27 GMT
coliver     2003/04/05 19:04:27

  Modified:    src/scratchpad/src/org/apache/cocoon/generation
                        FlowVelocityGenerator.java
  Log:
  Attempt to give meaningful error information when generated xml document is invalid
  
  Revision  Changes    Path
  1.3       +37 -2     cocoon-2.1/src/scratchpad/src/org/apache/cocoon/generation/FlowVelocityGenerator.java
  
  Index: FlowVelocityGenerator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/scratchpad/src/org/apache/cocoon/generation/FlowVelocityGenerator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FlowVelocityGenerator.java	27 Mar 2003 19:54:09 -0000	1.2
  +++ FlowVelocityGenerator.java	6 Apr 2003 03:04:27 -0000	1.3
  @@ -77,12 +77,14 @@
   import org.apache.velocity.runtime.log.LogSystem;
   import org.xml.sax.InputSource;
   import org.xml.sax.SAXException;
  +import org.xml.sax.SAXParseException;
   import org.mozilla.javascript.*;
   import org.apache.velocity.util.introspection.*;
   import java.beans.PropertyDescriptor;
   import java.io.IOException;
   import java.io.InputStream;
   import java.io.StringReader;
  +import java.io.BufferedReader;
   import java.io.StringWriter;
   import java.util.ArrayList;
   import java.util.HashMap;
  @@ -812,6 +814,7 @@
           }
   
           SAXParser parser = null;
  +        StringWriter w = new StringWriter();
           try {
               parser = (SAXParser) this.manager.lookup(SAXParser.ROLE);
               if (getLogger().isDebugEnabled()) {
  @@ -819,15 +822,47 @@
               }
   
               /* lets render a template */
  -            StringWriter w = new StringWriter();
               this.tmplEngine.mergeTemplate(super.source, velocityContext, w);
   
               InputSource xmlInput =
                       new InputSource(new StringReader(w.toString()));
  +            xmlInput.setSystemId(super.source);
               parser.parse(xmlInput, this.xmlConsumer);
           } catch (IOException e) {
               getLogger().warn("VelocityGenerator.generate()", e);
               throw new ResourceNotFoundException("Could not get Resource for VelocityGenerator",
e);
  +        } catch (SAXParseException e) {
  +            int line = e.getLineNumber();
  +            int column = e.getColumnNumber();
  +            if (line <= 0) {
  +                line = Integer.MAX_VALUE;
  +            }
  +            BufferedReader reader = 
  +                new BufferedReader(new StringReader(w.toString()));
  +            String message = e.getMessage() +" In generated document:\n";
  +            for (int i = 0; i < line; i++) {
  +                String lineStr = reader.readLine();
  +                if (lineStr == null) {
  +                    break;
  +                }
  +                message += lineStr + "\n";
  +            }
  +            String columnIndicator = "";
  +            if (column > 0) {
  +                for (int i = 1; i < column; i++) {
  +                    columnIndicator += " ";
  +                }
  +                columnIndicator += "^" + "\n";
  +                message += columnIndicator;
  +            }
  +            SAXException pe = new SAXParseException(message, 
  +                                                    e.getPublicId(),
  +                                                    "(Document generated from template
"+e.getSystemId() + ")",
  +                                                    e.getLineNumber(),
  +                                                    e.getColumnNumber(),
  +                                                    null);
  +            getLogger().error("VelocityGenerator.generate()", pe);
  +            throw pe;
           } catch (SAXException e) {
               getLogger().error("VelocityGenerator.generate()", e);
               throw e;
  
  
  

Mime
View raw message