Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Logback: the reliable, generic, fast and flexible logging framework. Copyright (C) 1999-2011, QOS.ch. All rights reserved. This program and the accompanying materials are dual-licensed under either the terms of the Eclipse Public License v1.0 as published by the Eclipse Foundation or (per the licensee's choosing) under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation.
 
 package ch.qos.logback.core.html;
 
 import java.util.Map;
 
 import static ch.qos.logback.core.CoreConstants.LINE_SEPARATOR;
This class is a base class for HTMLLayout classes part of other logback modules such as logback-classic and logback-access.

Author(s):
S├ębastien Pennec
 
 public abstract class HTMLLayoutBase<E> extends LayoutBase<E> {
 
   protected String pattern;
 
   protected Converter<E> head;
 
   protected String title = "Logback Log Messages";
 
   //It is the responsibility of derived classes to set
   //this variable in their constructor to a default value.
   protected CssBuilder cssBuilder;
 
    // counter keeping track of the rows output
   protected long counter = 0;
  
  
Set the ConversionPattern option. This is the string which controls formatting and consists of a mix of literal content and conversion specifiers.
 
   public void setPattern(String conversionPattern) {
      = conversionPattern;
   }

  
Returns the value of the ConversionPattern option.
 
   public String getPattern() {
     return ;
   }
 
   public CssBuilder getCssBuilder() {
     return ;
   }
 
   public void setCssBuilder(CssBuilder cssBuilder) {
     this. = cssBuilder;
   }

  
Parses the pattern and creates the Converter linked list.
 
   @Override
   public void start() {
     int errorCount = 0;
     
     try {
       Parser<E> p = new Parser<E>();
       p.setContext(getContext());
       Node t = p.parse();
       this. = p.compile(tgetEffectiveConverterMap());
       ConverterUtil.startConverters(this.);
     } catch (ScanException ex) {
       addError("Incorrect pattern found"ex);
       errorCount++;
     }
 
     if (errorCount == 0) {
       super. = true;
     }
   }
   
   protected abstract Map<StringStringgetDefaultConverterMap();

  
  
Returns a map where the default converter map is merged with the map contained in the context.
    Map<StringStringeffectiveMap = new HashMap<StringString>();
    // add the least specific map fist
    Map<StringStringdefaultMap = getDefaultConverterMap();
    if (defaultMap != null) {
      effectiveMap.putAll(defaultMap);
    }
    // contextMap is more specific than the default map
    Context context = getContext();
    if (context != null) {
      @SuppressWarnings("unchecked")
      Map<StringStringcontextMap = (Map<StringString>) context
      if (contextMap != null) {
        effectiveMap.putAll(contextMap);
      }
    }
    return effectiveMap;
  }
  
  
The Title option takes a String value. This option sets the document title of the generated HTML document.

Defaults to 'Logback Log Messages'.

  public void setTitle(String title) {
    this. = title;
  }

  
Returns the current value of the Title option.
  public String getTitle() {
    return ;
  }

  
Returns the content type output by this layout, i.e "text/html".
  public String getContentType() {
    return "text/html";
  }

  
Returns appropriate HTML headers.
  public String getFileHeader() {
    StringBuilder sbuf = new StringBuilder();
    sbuf.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"");
    sbuf.append(" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
    sbuf.append();
    sbuf.append("<html>");
    sbuf.append();
    sbuf.append("  <head>");
    sbuf.append();
    sbuf.append("    <title>");
    sbuf.append();
    sbuf.append("</title>");
    sbuf.append();
    
    .addCss(sbuf);
    sbuf.append();
    sbuf.append("  </head>");
    sbuf.append();
    sbuf.append("<body>");
    sbuf.append();
    return sbuf.toString();
  }
  
    StringBuilder sbuf = new StringBuilder();
    sbuf.append("<hr/>");
    sbuf.append();
    sbuf.append("<p>Log session start time ");
    sbuf.append(new java.util.Date());
    sbuf.append("</p><p></p>");
    sbuf.append();
    sbuf.append();
    sbuf.append("<table cellspacing=\"0\">");
    sbuf.append();
    
    return sbuf.toString();
  }
  private void buildHeaderRowForTable(StringBuilder sbuf) {
    Converter c = ;
    String name;
    sbuf.append("<tr class=\"header\">");
    sbuf.append();
    while (c != null) {
      name = computeConverterName(c);
      if (name == null) {
        c = c.getNext();
        continue;
      }
      sbuf.append("<td class=\"");
      sbuf.append(computeConverterName(c));
      sbuf.append("\">");
      sbuf.append(computeConverterName(c));
      sbuf.append("</td>");
      sbuf.append();
      c = c.getNext();
    }
    sbuf.append("</tr>");
    sbuf.append();
  }
  
    StringBuilder sbuf = new StringBuilder();
    sbuf.append("</table>");
    return sbuf.toString();    
  }

  
Returns the appropriate HTML footers.
  public String getFileFooter() {
    StringBuilder sbuf = new StringBuilder();
    sbuf.append();
    sbuf.append("</body></html>");
    return sbuf.toString();
  }
  
  protected void startNewTableIfLimitReached(StringBuilder sbuf) {
    if (this. >= .) {
       = 0;
      sbuf.append("</table>");
      sbuf.append();
      sbuf.append("<p></p>");
      sbuf.append("<table cellspacing=\"0\">");
      sbuf.append();
      buildHeaderRowForTable(sbuf);
    }
  }
    String className = c.getClass().getSimpleName();
    int index = className.indexOf("Converter");
    if (index == -1) {
      return className;
    } else {
      return className.substring(0, index);
    }
  }
New to GrepCode? Check out our FAQ X