cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject cvs commit: cocoon-2.1/src/java/org/apache/cocoon/components/notification Notifier.java
Date Sun, 16 Mar 2003 16:44:02 GMT
vgritsenko    2003/03/16 08:44:02

  Modified:    src/java/org/apache/cocoon/components/notification
                        Notifier.java
  Log:
  format code
  
  Revision  Changes    Path
  1.3       +131 -140  cocoon-2.1/src/java/org/apache/cocoon/components/notification/Notifier.java
  
  Index: Notifier.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/notification/Notifier.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Notifier.java	16 Mar 2003 11:20:54 -0000	1.2
  +++ Notifier.java	16 Mar 2003 16:44:02 -0000	1.3
  @@ -68,154 +68,145 @@
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
    * @version CVS $Id$
    */
  -
   public class Notifier {
   
  -  /*
  -   * Generate notification information as a response.
  -   * The notification is directly written to the OutputStream.
  -   * @param  n The <code>Notifying</code> object
  -   * @param outputStream The output stream the notification is written to
  -   *        This could be <code>null</code>.
  -   * @deprecated There is no way in which this method could understand what mime/type to
use. Instead use void notify(Notifying n, OutputStream outputStream, String mimetype), where
the mime/type is requested.
  -   * @see #notify(Notifying n, OutputStream, String)
  -
  -  public static String notify(Notifying n, OutputStream outputStream) throws IOException
{
  -    notify(n, outputStream, "text/html") ;
  -    return "text/html";
  -  }
  -   */
  -   
  -  /**
  -   * Generate notification information as a response.
  -   * The notification is directly written to the OutputStream.
  -   * @param  n The <code>Notifying</code> object
  -   * @param outputStream The output stream the notification is written to
  -   *        This could be <code>null</code>.
  -   */
  -  public static void notify(Notifying n, OutputStream outputStream, String mimetype) throws
IOException {
  -    //(NKB) FIXME should use error page templates, one per mime-type
  -    // currently uses hardcoded html, should be used only as last resort.
  -    notifyHTML(n, outputStream);
  -  }
  -
  -  /**
  -   * Generate notification information as html.
  -   * The notification is directly written to the OutputStream.
  -   * @param  n The <code>Notifying</code> object
  -   * @param outputStream The output stream the notification is written to
  -   *        This could be <code>null</code>.
  -   */
  -  private static void notifyHTML(Notifying n, OutputStream outputStream) throws IOException
{
  -
  -    StringBuffer sb = new StringBuffer();
  -
  -    sb.append("<html><head><title>").append(n.getTitle()).append("</title>");
  -    sb.append("<style><!--");
  -	sb.append("body { background-color: white; color: black; font-family: verdana, helvetica,
sanf serif;}");
  -	sb.append("h1 {color: #336699; margin: 0px 0px 20px 0px; border-width: 0px 0px 1px 0px;
border-style: solid; border-color: #336699;}");
  -	sb.append("p.footer { color: #336699; border-width: 1px 0px 0px 0px; border-style: solid;
border-color: #336699; }");
  -	sb.append("span {color: #336699;}");
  -	sb.append("pre {padding-left: 20px;}");
  -	sb.append("a:link {font-weight: bold; color: #336699;}");
  -	sb.append("a:visited {color: #336699; }");
  -	sb.append("a:hover {color: #800000; background-color: #ffff80;}");
  -	sb.append("a:active {color: #006666;}");
  -    sb.append("--></style>");
  -    sb.append("</head><body>");
  -    sb.append("<h1>").append(n.getTitle()).append("</h1>");
  -    sb.append("<p><span>Message:</span> ").append(n.getMessage()).append("</p>");
  -    sb.append("<p><span>Description:</span> ").append(n.getDescription()).append("</p>");
  -    sb.append("<p><span>Sender:</span> ").append(n.getSender()).append("</p>");
  -    sb.append("<p><span>Source:</span> ").append(n.getSource()).append("</p>");
  -
  -    Map extraDescriptions = n.getExtraDescriptions();
  -    Iterator keyIter = extraDescriptions.keySet().iterator();
  -
  -    while (keyIter.hasNext()) {
  -      String key = (String) keyIter.next();
  +    /*
  +     * Generate notification information as a response.
  +     * The notification is directly written to the OutputStream.
  +     * @param  n The <code>Notifying</code> object
  +     * @param outputStream The output stream the notification is written to
  +     *        This could be <code>null</code>.
  +     * @deprecated There is no way in which this method could understand what mime/type
to use. Instead use void notify(Notifying n, OutputStream outputStream, String mimetype),
where the mime/type is requested.
  +     * @see #notify(Notifying n, OutputStream, String)
  +
  +    public static String notify(Notifying n, OutputStream outputStream) throws IOException
{
  +      notify(n, outputStream, "text/html") ;
  +      return "text/html";
  +    }
  +     */
   
  -      sb.append("<p><span>").append(key).append("</span><pre>").append(
  -              extraDescriptions.get(key)).append("</pre></p>");
  +    /**
  +     * Generate notification information as a response.
  +     * The notification is directly written to the OutputStream.
  +     * @param  n The <code>Notifying</code> object
  +     * @param outputStream The output stream the notification is written to
  +     *        This could be <code>null</code>.
  +     */
  +    public static void notify(Notifying n, OutputStream outputStream, String mimetype)
throws IOException {
  +        //(NKB) FIXME should use error page templates, one per mime-type
  +        // currently uses hardcoded html, should be used only as last resort.
  +        notifyHTML(n, outputStream);
       }
   
  -    sb.append("<p class='footer'><a href='http://cocoon.apache.org/'>").append(Constants.COMPLETE_NAME).append("</p>");
  -    sb.append("</body></html>");
  +    /**
  +     * Generate notification information as html.
  +     * The notification is directly written to the OutputStream.
  +     * @param  n The <code>Notifying</code> object
  +     * @param outputStream The output stream the notification is written to
  +     *        This could be <code>null</code>.
  +     */
  +    private static void notifyHTML(Notifying n, OutputStream outputStream) throws IOException
{
  +        StringBuffer sb = new StringBuffer();
  +
  +        sb.append("<html><head><title>").append(n.getTitle()).append("</title>");
  +        sb.append("<style><!--");
  +        sb.append("body { background-color: white; color: black; font-family: verdana,
helvetica, sanf serif;}");
  +        sb.append("h1 {color: #336699; margin: 0px 0px 20px 0px; border-width: 0px 0px
1px 0px; border-style: solid; border-color: #336699;}");
  +        sb.append("p.footer { color: #336699; border-width: 1px 0px 0px 0px; border-style:
solid; border-color: #336699; }");
  +        sb.append("span {color: #336699;}");
  +        sb.append("pre {padding-left: 20px;}");
  +        sb.append("a:link {font-weight: bold; color: #336699;}");
  +        sb.append("a:visited {color: #336699; }");
  +        sb.append("a:hover {color: #800000; background-color: #ffff80;}");
  +        sb.append("a:active {color: #006666;}");
  +        sb.append("--></style>");
  +        sb.append("</head><body>");
  +        sb.append("<h1>").append(n.getTitle()).append("</h1>");
  +        sb.append("<p><span>Message:</span> ").append(n.getMessage()).append("</p>");
  +        sb.append("<p><span>Description:</span> ").append(n.getDescription()).append("</p>");
  +        sb.append("<p><span>Sender:</span> ").append(n.getSender()).append("</p>");
  +        sb.append("<p><span>Source:</span> ").append(n.getSource()).append("</p>");
  +
  +        Map extraDescriptions = n.getExtraDescriptions();
  +        Iterator keyIter = extraDescriptions.keySet().iterator();
  +
  +        while (keyIter.hasNext()) {
  +            String key = (String) keyIter.next();
  +
  +            sb.append("<p><span>").append(key).append("</span><pre>").append(
  +                    extraDescriptions.get(key)).append("</pre></p>");
  +        }
   
  -    if (outputStream != null)
  -      outputStream.write(sb.toString().getBytes());
  -  }
  -
  -  /*
  -   * Generate notification information in XML format.
  -   * @deprecated Using a ContentHandler doesn't mean that a mimetype cannot be specified;
it could be svg or
  -   * @see #notify(Notifying, ContentHandler, String)
  -
  -  public static void notify(Notifying n, ContentHandler ch) throws SAXException {
  -    notify(n, ch, "text/xml");
  -  }
  -   */
  -   
  -  /**
  -   * Generate notification information in XML format.
  -   */
  -  public static void notify(Notifying n, ContentHandler ch, String mimetype) throws SAXException
{
  -
  -    final String PREFIX = Constants.ERROR_NAMESPACE_PREFIX;
  -    final String URI = Constants.ERROR_NAMESPACE_URI;
  -
  -    // Start the document
  -    ch.startDocument();
  -    ch.startPrefixMapping(PREFIX, URI);
  -
  -    // Root element.
  -    AttributesImpl atts = new AttributesImpl();
  -
  -    atts.addAttribute(URI, "type", PREFIX + ":type", "CDATA", n.getType());
  -    atts.addAttribute(URI, "sender", PREFIX + ":sender", "CDATA", n.getSender());
  -    ch.startElement(URI, "notify", PREFIX + ":notify", atts);
  -    ch.startElement(URI, "title", PREFIX + ":title", new AttributesImpl());
  -    ch.characters(n.getTitle().toCharArray(), 0, n.getTitle().length());
  -    ch.endElement(URI, "title", PREFIX + ":title");
  -    ch.startElement(URI, "source", PREFIX + ":source", new AttributesImpl());
  -    ch.characters(n.getSource().toCharArray(), 0, n.getSource().length());
  -    ch.endElement(URI, "source", PREFIX + ":source");
  -    ch.startElement(URI, "message", PREFIX + ":message", new AttributesImpl());
  +        sb.append("<p class='footer'><a href='http://cocoon.apache.org/'>").append(Constants.COMPLETE_NAME).append("</p>");
  +        sb.append("</body></html>");
   
  -    if (n.getMessage() != null) {
  -      ch.characters(n.getMessage().toCharArray(), 0, n.getMessage().length());
  +        if (outputStream != null)
  +            outputStream.write(sb.toString().getBytes());
       }
   
  -    ch.endElement(URI, "message", PREFIX + ":message");
  -    ch.startElement(URI, "description", PREFIX + ":description",
  -            new AttributesImpl());
  -    ch.characters(n.getDescription().toCharArray(), 0, n.getDescription().length());
  -    ch.endElement(URI, "description", PREFIX + ":description");
  -
  -    Map extraDescriptions = n.getExtraDescriptions();
  -    Iterator keyIter = extraDescriptions.keySet().iterator();
  -    while (keyIter.hasNext()) {
  -      String key = (String) keyIter.next();
  -      String value = String.valueOf(extraDescriptions.get(key));
  -      atts = new AttributesImpl();
  -
  -      atts.addAttribute(URI, "description", PREFIX + ":description", "CDATA", key);
  -      ch.startElement(URI, "extra", PREFIX + ":extra", atts);
  -      ch.characters(value.toCharArray(), 0, value.length());
  -      ch.endElement(URI, "extra", PREFIX + ":extra");
  -    }
  +    /*
  +     * Generate notification information in XML format.
  +     * @deprecated Using a ContentHandler doesn't mean that a mimetype cannot be specified;
it could be svg or
  +     * @see #notify(Notifying, ContentHandler, String)
   
  -    // End root element.
  -    ch.endElement(URI, "notify", PREFIX + ":notify");
  +    public static void notify(Notifying n, ContentHandler ch) throws SAXException {
  +      notify(n, ch, "text/xml");
  +    }
  +     */
   
  -    // End the document.
  -    ch.endPrefixMapping(PREFIX);
  -    ch.endDocument();
  -  }
  +    /**
  +     * Generate notification information in XML format.
  +     */
  +    public static void notify(Notifying n, ContentHandler ch, String mimetype) throws SAXException
{
  +        final String PREFIX = Constants.ERROR_NAMESPACE_PREFIX;
  +        final String URI = Constants.ERROR_NAMESPACE_URI;
  +
  +        // Start the document
  +        ch.startDocument();
  +        ch.startPrefixMapping(PREFIX, URI);
  +
  +        // Root element.
  +        AttributesImpl atts = new AttributesImpl();
  +
  +        atts.addAttribute(URI, "type", PREFIX + ":type", "CDATA", n.getType());
  +        atts.addAttribute(URI, "sender", PREFIX + ":sender", "CDATA", n.getSender());
  +        ch.startElement(URI, "notify", PREFIX + ":notify", atts);
  +        ch.startElement(URI, "title", PREFIX + ":title", new AttributesImpl());
  +        ch.characters(n.getTitle().toCharArray(), 0, n.getTitle().length());
  +        ch.endElement(URI, "title", PREFIX + ":title");
  +        ch.startElement(URI, "source", PREFIX + ":source", new AttributesImpl());
  +        ch.characters(n.getSource().toCharArray(), 0, n.getSource().length());
  +        ch.endElement(URI, "source", PREFIX + ":source");
  +        ch.startElement(URI, "message", PREFIX + ":message", new AttributesImpl());
  +
  +        if (n.getMessage() != null) {
  +            ch.characters(n.getMessage().toCharArray(), 0, n.getMessage().length());
  +        }
  +
  +        ch.endElement(URI, "message", PREFIX + ":message");
  +        ch.startElement(URI, "description", PREFIX + ":description",
  +                        new AttributesImpl());
  +        ch.characters(n.getDescription().toCharArray(), 0, n.getDescription().length());
  +        ch.endElement(URI, "description", PREFIX + ":description");
  +
  +        Map extraDescriptions = n.getExtraDescriptions();
  +        Iterator keyIter = extraDescriptions.keySet().iterator();
  +        while (keyIter.hasNext()) {
  +            String key = (String) keyIter.next();
  +            String value = String.valueOf(extraDescriptions.get(key));
  +            atts = new AttributesImpl();
  +
  +            atts.addAttribute(URI, "description", PREFIX + ":description", "CDATA", key);
  +            ch.startElement(URI, "extra", PREFIX + ":extra", atts);
  +            ch.characters(value.toCharArray(), 0, value.length());
  +            ch.endElement(URI, "extra", PREFIX + ":extra");
  +        }
  +
  +        // End root element.
  +        ch.endElement(URI, "notify", PREFIX + ":notify");
  +
  +        // End the document.
  +        ch.endPrefixMapping(PREFIX);
  +        ch.endDocument();
  +    }
   }
  -
  -
  -
  -
  -
  -
  
  
  

Mime
View raw message