You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by st...@locus.apache.org on 2000/09/22 22:19:04 UTC

cvs commit: xml-cocoon/src/org/apache/cocoon Notification.java Notifier.java

stefano     00/09/22 13:19:04

  Modified:    src/org/apache/cocoon Tag: xml-cocoon2 Notification.java
                        Notifier.java
  Log:
  removed that unportable (and useless) ASCII art along with (slow) system.out (logs are there for a reason) and cleanup the messy code
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.2   +22 -113   xml-cocoon/src/org/apache/cocoon/Attic/Notification.java
  
  Index: Notification.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Attic/Notification.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- Notification.java	2000/08/31 15:59:51	1.1.2.1
  +++ Notification.java	2000/09/22 20:19:03	1.1.2.2
  @@ -9,26 +9,19 @@
   package org.apache.cocoon;
   
   import java.util.HashMap;
  -import java.util.Set;
  -import java.util.Iterator;
   
  -import java.io.BufferedReader;
  -import java.io.IOException;
  -import java.io.PipedReader;
  -import java.io.PipedWriter;
  +import java.io.StringWriter;
   import java.io.PrintWriter;
   
   import org.xml.sax.SAXException;
  -import org.xml.sax.ContentHandler;
   
  -import org.apache.avalon.ComponentNotAccessibleException;
  -
   /**
    *  Generates an XML representation of the current notification.
    *
    * @author <a href="mailto:nicolaken@supereva.it">Nicola Ken Barozzi</a> Aisa
    * @created 24 August 2000
    */
  + 
   public class Notification implements Notificable {
   
       /**
  @@ -74,94 +67,44 @@
       }
   
       /**
  -     *  Constructor for the Notification object
  +     * Constructor for the Notification object
        *
  -     *@param  t  Description of Parameter
  -     */
  -    public Notification(Object sender, Throwable t) {
  -        this.setThrowable(sender, t);
  -    }
  -
  -    /**
  -     *  Constructor for the Notification object
  -     *
  -     *@param  t  Description of Parameter
  +     * @param  o  Description of Parameter
        */
  -    public Notification(Object sender, SAXException t) {
  -
  -        this.setThrowable(sender, t);
  -        addExtraDescription("SAX-processing-exception",
  -                            ((SAXException) t).getException().toString());
  +    public Notification(Object sender, Object o) {
  +        this(sender);
  +        setType("object");
  +        setTitle("Object notification");
  +        setSource(o.getClass().getName());
  +        setMessage(o.toString());
       }
  -
  +    
       /**
  -     *  Constructor for the Notification object
  +     * Constructor for the Notification object
        *
  -     *@param  t  Description of Parameter
  +     * @param  t  Description of Parameter
        */
  -    public Notification(Object sender, ComponentNotAccessibleException t) {
  -
  -        this.setThrowable(sender, t);
  -        addExtraDescription("SAX-processing-exception",
  -                            ((ComponentNotAccessibleException) t)
  -                                .getException().toString());
  -    }
  -
  -    private void setThrowable(Object sender, Throwable t) {
  -
  +    public Notification(Object sender, Throwable t) {
  +        this(sender);
           setType("error");
           setTitle("Cocoon error");
           setSource(t.getClass().getName());
  -        setSender(sender);
           setMessage(t.getMessage());
           setDescription(t.toString());
  -
  -        StringBuffer stacktrace = new StringBuffer();
  -        String       CurrentString;
   
  -        try {
  -            PipedWriter    CurrentPipedWriter = new PipedWriter();
  -            PrintWriter    CurrentWriter      =
  -                new PrintWriter(CurrentPipedWriter);
  -            PipedReader    CurrentPipedReader =
  -                new PipedReader(CurrentPipedWriter);
  -            BufferedReader CurrentReader      =
  -                new BufferedReader(CurrentPipedReader);
  -            Thread         CurrentReadThread  = new ReadThread(CurrentWriter,
  -                                                    t);
  -
  -            CurrentReadThread.start();
  -
  -            do {
  -                try {
  -                    CurrentString = CurrentReader.readLine();
  -
  -                    stacktrace.append(CurrentString + "\n");
  -                } catch (Throwable x) {
  -                    CurrentString = null;
  -                }
  -            } while (CurrentString != null);
  -        } catch (IOException ioe) {
  -            stacktrace.append("C2: Error in getting StackTrace");
  -            System.err.println(
  -                "\n\nC2:Error in printing error: cannot get stacktrace correctly..");
  -        }
  -
  -        extraDescriptions.put("stacktrace", stacktrace);
  +        StringWriter stackTrace = new StringWriter();
  +        t.printStackTrace(new PrintWriter(stackTrace));
  +        extraDescriptions.put("stacktrace", stackTrace.toString());
       }
   
       /**
        *  Constructor for the Notification object
        *
  -     *@param  o  Description of Parameter
  +     *@param  t  Description of Parameter
        */
  -    public Notification(Object sender, Object o) {
  -
  -        setType("object");
  -        setTitle("Object notification");
  -        setSource(o.getClass().getName());
  -        setSender(sender);
  -        setMessage(o.toString());
  +    public Notification(Object sender, SAXException t) {
  +        this(sender, (Throwable) t);
  +        addExtraDescription("SAX-processing-exception", ((SAXException) t).getException().toString());
       }
   
       /**
  @@ -285,40 +228,6 @@
        */
       public HashMap getExtraDescriptions() {
           return extraDescriptions;
  -    }
  -
  -    /**
  -     *  A thread that prints the stackTrace of a <code>Throwable</code> object to a
  -     *  PrintWriter.
  -     *
  -     * @author <a href="mailto:nicolaken@supereva.it">Nicola Ken Barozzi</a> Aisa
  -     * @created 31 July 2000
  -     */
  -    class ReadThread extends Thread {
  -
  -        PrintWriter CurrentWriter;
  -        Throwable   t;
  -
  -        /**
  -         *  Constructor for the ReadThread object
  -         *
  -         *@param  CurrentWriter  The <code>PrintWriter</code> to print the stacktrace
  -         *      to.
  -         *@param  t              The <code>Throwable</code> object containing the
  -         *      stackTrace.
  -         */
  -        ReadThread(PrintWriter CurrentWriter, Throwable t) {
  -            this.CurrentWriter = CurrentWriter;
  -            this.t             = t;
  -        }
  -
  -        /**
  -         *  Main processing method for the ReadThread object. A thread that prints the
  -         *  stackTrace of a <code>t</code> to <code>CurrentWriter</code> .
  -         */
  -        public void run() {
  -            t.printStackTrace(CurrentWriter);
  -        }
       }
   }
   
  
  
  
  1.1.2.3   +49 -189   xml-cocoon/src/org/apache/cocoon/Attic/Notifier.java
  
  Index: Notifier.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Attic/Notifier.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- Notifier.java	2000/09/03 13:45:37	1.1.2.2
  +++ Notifier.java	2000/09/22 20:19:03	1.1.2.3
  @@ -31,187 +31,82 @@
    * Generates an XML representation of the current notification.
    *
    * @author <a href="mailto:nicolaken@supereva.it">Nicola Ken Barozzi</a> Aisa
  - * @created 24 August 2000
  + * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  + * @version CVS $Revision: 1.1.2.3 $ $Date: 2000/09/22 20:19:03 $
    */
    
   public class Notifier {
   
  -    private static int printStreamNotifications = 0;
  -
  -    /**
  -     * The URI of the namespace of this generator.
  -     */
  -    protected final static String URI = "http://apache.org/cocoon/2.0/error";
  -
       /**
  -     * The namespace prefix for this namespace URI.
  +     * Generate notification information as servlet response
        */
  -    protected final static String PREFIX = "ntf";
  +    public static void notify(Notificable n, HttpServletRequest req, HttpServletResponse res) throws IOException {
   
  -    /**
  -     * Gets the CocoonAsciArt attribute of the Notification object
  -     *
  -     * @return The CocoonAsciArt value
  -     */
  -    public static String getCocoonAsciArt() {
  -
  -        return " ������ ����ͻ ������ ����ͻ ����ͻ ����ͻ  \n"
  -               + " �      �   .� �      �   .� �.   � �    �  \n"
  -               + " ������ ����ͼ ������ ����ͼ ����ͼ �    �";
  -    }
  -
  -    /**
  -     * Generate notification information on PrintStream Out in text.
  -     *
  -     * @param  Out               The PrintStream to use.
  -     */
  -    public static void notify(Notificable n, PrintStream Out) {
  -
  -        printStreamNotifications++;
  -
  -        Out.println("");
  -        Out.println(
  -            "**********************************************************");
  -        Out.println("");
  -        Out.println(getCocoonAsciArt() + " "
  -                    + org.apache.cocoon.Cocoon.VERSION);
  -        Out.println("");
  -        Out.println("--- " + n.getTitle() + " ---");
  -        Out.println("");
  -        Out.println(" " + n.getType() + " - " + n.getMessage());
  -        Out.println("");
  -        Out.println(" description - " + n.getDescription());
  -        Out.println("");
  -        Out.println(" from - " + n.getSender());
  -        Out.println("");
  -        Out.println(" source - " + n.getSource());
  -        Out.println("");
  -
  -        HashMap  extraDescriptions = n.getExtraDescriptions();
  -        Iterator keyIter           = extraDescriptions.keySet().iterator();
  -
  -        while (keyIter.hasNext()) {
  -            String key = (String) keyIter.next();
  -
  -            Out.println(" " + key + " - " + extraDescriptions.get(key));
  -            Out.println("");
  -        }
  -
  -        Out.println("**************** printStream notifications: "
  -                    + String.valueOf(printStreamNotifications)
  -                    + " ***************");
  -        Out.println("");
  -    }
  -
  -    public static void notify(Notificable n, HttpServletRequest req,
  -                              HttpServletResponse res) {
  -
           StringBuffer sb = new StringBuffer();
  -
  -        try {
   
  -            // get the request user agent
  -            String agent = req.getParameter("user-Agent");
  +        String contentType = req.getContentType();
   
  -            if (agent == null) {
  -                agent = req.getHeader("user-Agent");
  -            }
  +        if ("text/html".equals(contentType)) {
  +            res.setContentType("text/html");
  +            sb.append("<html><head><title>" + n.getTitle() + "</title>");
  +            sb.append("<STYLE><!--H1{font-family : sans-serif,Arial,Tahoma;color : white;background-color : #0086b2;} ");
  +            sb.append("BODY{font-family : sans-serif,Arial,Tahoma;color : black;background-color : white;} ");
  +            sb.append("B{color : white;background-color : #0086b2;} ");
  +            sb.append("HR{color : #0086b2;} ");
  +            sb.append("--></STYLE> ");
  +            sb.append("</head><body>");
  +            sb.append("<h1>Cocoon 2 - " + n.getTitle() + "</h1>");
  +            sb.append("<HR size=\"1\" noshade>");
  +            sb.append("<p><b>type</b> " + n.getType() + "</p>");
  +            sb.append("<p><b>message</b> <u>" + n.getMessage() + "</u></p>");
  +            sb.append("<p><b>description</b> <u>" + n.getDescription() + "</u></p>");
  +            sb.append("<p><b>sender</b> " + n.getSender() + "</p>");
  +            sb.append("<p><b>source</b> " + n.getSource() + "</p>");
   
  -            if (agent == null) {
  -                agent = "";
  -            }
  +            HashMap extraDescriptions = n.getExtraDescriptions();
  +            Iterator keyIter = extraDescriptions.keySet().iterator();
   
  -            String ContentType = req.getContentType();
  +            while (keyIter.hasNext()) {
  +                String key = (String) keyIter.next();
   
  -            if (ContentType == null) {
  -                ContentType = "";
  +                sb.append("<p><b>" + key + "</b><pre>" + extraDescriptions.get(key) + "</pre></p>");
               }
   
  -            if (agent.startsWith("Mozilla")
  -                    || ContentType.equals("txt/html")) {
  -                res.setContentType("text/html");
  -                sb.append("<html><head><title>" + n.getTitle() + "</title>");
  -                sb.append(
  -                    "<STYLE><!--H1{font-family : sans-serif,Arial,Tahoma;color : white;background-color : #0086b2;} ");
  -                sb.append(
  -                    "BODY{font-family : sans-serif,Arial,Tahoma;color : black;background-color : white;} ");
  -                sb.append("B{color : white;background-color : #0086b2;} ");
  -                sb.append("HR{color : #0086b2;} ");
  -                sb.append("--></STYLE> ");
  -                sb.append("</head><body>");
  -                sb.append("<h1>Cocoon 2 - " + n.getTitle() + "</h1>");
  -                sb.append("<HR size=\"1\" noshade>");
  -                sb.append("<p><b>type</b> " + n.getType() + "</p>");
  -                sb.append("<p><b>message</b> <u>" + n.getMessage()
  -                          + "</u></p>");
  -                sb.append("<p><b>description</b> <u>" + n.getDescription()
  -                          + "</u></p>");
  -                sb.append("<p><b>sender</b> " + n.getSender() + "</p>");
  -                sb.append("<p><b>source</b> " + n.getSource() + "</p>");
  -
  -                HashMap  extraDescriptions = n.getExtraDescriptions();
  -                Iterator keyIter           =
  -                    extraDescriptions.keySet().iterator();
  -
  -                while (keyIter.hasNext()) {
  -                    String key = (String) keyIter.next();
  -
  -                    sb.append("<p><b>" + key + "</b> <pre> "
  -                              + extraDescriptions.get(key) + "</pre></p>");
  -                }
  -
  -                sb.append("<HR size=\"1\" noshade>");
  -                sb.append("</body></html>");
  -            } else {
  -                res.setContentType("text/xml");
  -                sb.append("<notify type=\"" + n.getType() + "\" sender=\""
  -                          + n.getSender() + "\">");
  -                sb.append("<title>" + n.getTitle() + "</title>");
  -                sb.append("<source>" + n.getSource() + "</source>");
  -                sb.append("<message>" + n.getMessage() + "</message>");
  -                sb.append("<description>" + n.getDescription()
  -                          + "</description>");
  -
  -                HashMap  extraDescriptions = n.getExtraDescriptions();
  -                Iterator keyIter           =
  -                    extraDescriptions.keySet().iterator();
  -
  -                while (keyIter.hasNext()) {
  -                    String key = (String) keyIter.next();
  -
  -                    sb.append("<extra description=\"" + key + "\">"
  -                              + extraDescriptions.get(key) + "</extra>");
  -                }
  +            sb.append("<HR size=\"1\" noshade>");
  +            sb.append("</body></html>");
  +        } else {
  +            res.setContentType("text/xml");
  +            sb.append("<notify type=\"" + n.getType() + "\" sender=\"" + n.getSender() + "\">");
  +            sb.append("<title>" + n.getTitle() + "</title>");
  +            sb.append("<source>" + n.getSource() + "</source>");
  +            sb.append("<message>" + n.getMessage() + "</message>");
  +            sb.append("<description>" + n.getDescription() + "</description>");
   
  -                sb.append("</notify>");
  -            }
  +            HashMap extraDescriptions = n.getExtraDescriptions();
  +            Iterator keyIter = extraDescriptions.keySet().iterator();
   
  -            ServletOutputStream Out = res.getOutputStream();
  +            while (keyIter.hasNext()) {
  +                String key = (String) keyIter.next();
   
  -            Out.print(new String(sb));
  +                sb.append("<extra description=\"" + key + "\">" + extraDescriptions.get(key) + "</extra>");
  +            }
   
  -            //Out.flush();
  -        } catch (IOException ioe) {}
  -        finally {
  -            notify(n, System.out);
  +            sb.append("</notify>");
           }
  +
  +        res.getOutputStream().print(sb.toString());
       }
   
       /**
        * Generate notification information in XML format.
  -     *
  -     * @param  ch                The ContentHandler to use.
  -     * @exception  SAXException  Description of problem there is creating the output
  -     *      SAX events.
        */
  -    public static void notify(Notificable n, ContentHandler ch)
  -            throws SAXException {
  +    public static void notify(Notificable n, ContentHandler ch) throws SAXException {
   
  -        //only for test.
  -        notify(n, System.out);
  +        final String URI = Cocoon.ERROR_NAMESPACE_PREFIX;
  +        final String PREFIX = Cocoon.ERROR_NAMESPACE_PREFIX;
   
           String buf;
  -
  +        
           // Start the document
           ch.startDocument();
           ch.startPrefixMapping(PREFIX, URI);
  @@ -263,42 +158,7 @@
           ch.endElement(URI, "notify", "notify");
   
           // End the document.
  -        ch.endPrefixMapping(PREFIX);
  +        ch.endPrefixMapping(Cocoon.ERROR_NAMESPACE_PREFIX);
           ch.endDocument();
  -    }
  -
  -    /**
  -     *  A thread that prints the stackTrace of a <code>Throwable</code> object to a
  -     *  PrintWriter.
  -     *
  -     *@author     <a href="mailto:nicolaken@supereva.it">Nicola Ken Barozzi</a>
  -     *      Aisa
  -     *@created    31 July 2000
  -     */
  -    class ReadThread extends Thread {
  -
  -        PrintWriter CurrentWriter;
  -        Throwable   t;
  -
  -        /**
  -         *  Constructor for the ReadThread object
  -         *
  -         *@param  CurrentWriter  The <code>PrintWriter</code> to print the stacktrace
  -         *      to.
  -         *@param  t              The <code>Throwable</code> object containing the
  -         *      stackTrace.
  -         */
  -        ReadThread(PrintWriter CurrentWriter, Throwable t) {
  -            this.CurrentWriter = CurrentWriter;
  -            this.t             = t;
  -        }
  -
  -        /**
  -         *  Main processing method for the ReadThread object. A thread that prints the
  -         *  stackTrace of a <code>t</code> to <code>CurrentWriter</code> .
  -         */
  -        public void run() {
  -            t.printStackTrace(CurrentWriter);
  -        }
       }
   }
  
  
  

Re: cvs commit: xml-cocoon/src/org/apache/cocoon Notification.java Notifier.java

Posted by Nicola Ken Barozzi <ni...@supereva.it>.
From: "Pier P. Fumagalli" <pi...@apache.org>
> stefano@locus.apache.org wrote:
> > 
> > Log:
> >   removed that unportable (and useless) ASCII art along with (slow)
> >   system.out (logs are there for a reason) and cleanup the messy code
> 
> Thanks! (this eases stuff!)

I'm sorry that you think my coding is messy, and I would prefer that you tell
me first, being it my code, if it's not too much of a fuss >:-(
Anyway, why is it messy? Would you like it if I go round saying _your_
code is messy? Don't think you are perfect, we _all_ have to learn.
It is important that I get feedback on my code.
I think these remarks are _unfair_. :-(
The " unportable (and useless) ASCII art " was there to make errors more
evident and not pass unnoticed. No problem if it annoys you, I don't care
if you take it away, but it was not put there just for fun.
The "(slow) system.out" is rather important to me and to many other 
programmers IMO, and if it's slow who cares, it should not fire if all
is ok. "(logs are there for a reason)"... yes, I KNOW, I already said
I knew logging had to be kicked in, and the "(slow) system.out" is there
just till C2 gets finished. Alpha 2a? Get real.

I would appreciate you all refer to the author of the code first before
spreading _bullshit_ because:
1. nobody is perfect, this is for the users and the coders.
2. if you didn't write the code maybe you don't understand it. Some things
that seem stupid to you have been thought of. 
3. if the author doesn't get notified he cannot improve.
4. it's not nice to refer to other's people code as sloppy, you are not perfect.
5. if the code is not ok, who wrote it is the first one who has to make it ok.

I am astonished by this lack of sensibility.
I hope it will not happen again.
Nobody would like to contribute if this is done behind their backs.
If you don't trust me, tell me.
If you don't like my code tell me.
If you don't think I'm good enough, don't accept my work.

But please, don't make fun of me.

Nicola Ken Barozzi


Re: cvs commit: xml-cocoon/src/org/apache/cocoon Notification.java Notifier.java

Posted by "Pier P. Fumagalli" <pi...@apache.org>.
stefano@locus.apache.org wrote:
> 
> Log:
>   removed that unportable (and useless) ASCII art along with (slow)
>   system.out (logs are there for a reason) and cleanup the messy code

Thanks! (this eases stuff!)

	Pier