FileDocCategorySizeDatePackage
HTMLReportTemplate.javaAPI DocGlassfish v2 API15805Fri May 04 22:34:48 BST 2007com.sun.enterprise.diagnostics.report.html

HTMLReportTemplate

public class HTMLReportTemplate extends Object
author
Manisha Umbarje

Fields Summary
private static final String
REPORT_NAME
private Table
toc
private Document
doc
protected Element
bodyElement
private Element
descElement
private int
tocNo
protected ReportConfig
config
protected ReportTarget
target
private String
targetName
private String
reportDir
protected DataTraverser
dataObjTraverser
private static String
report_description
private static final String
description
private static final String
customer_information
private static final String
bug_ids
private static String
component_details
private static final String
checksum_details
protected static final String
monitoring_information
private static final String
system_information
private static final String
installation_log
private static final String
domain_xml_validation_details
private static Logger
logger
Constructors Summary
public HTMLReportTemplate(ReportConfig config, Data dataObj)
Creates a new instance of HTMLReportTemplate

targetName
name of the target for which HTML report is being generated
reportDir
directory which contains data to generate HTML report summary


                                       
         
            this.config = config;
            this.target = config.getTarget();
            this.targetName = target.getName();
            this.reportDir = target.getIntermediateReportDir();
            this.dataObjTraverser = new DataTraverser(dataObj);
            initialize();
    
Methods Summary
private voidaddBugIds()

        if(config.getCLIOptions().getBugIds() != null &&
                config.getCLIOptions().getBugIds().trim().length() > 0) {
            addTitle(bug_ids, true, true, 0,0);
            HTMLElement bugIdElement = new HTMLElement(bug_ids);
            bugIdElement.addText(config.getCLIOptions().getBugIds());
            addElement(bugIdElement);
        }
    
private voidaddChecksumSection()

        Iterator<Data> iterator = dataObjTraverser.getData(DataType.CHECKSUM);
        if(iterator.hasNext()) {
            ArrayList elements= new ArrayList();
            Element link = new Link(checksum_details,
                    "#"+getNextTocNo());
            elements.add(link);
            toc.addRow(elements,null);
            Element bodyLink = new Link(null,null,getTocNo());
            bodyElement.add(bodyLink);
        }
        while(iterator.hasNext()) {
            Data checksumData = iterator.next();
            Iterator<Iterator<String>> details = checksumData.getTable();

            Table table = new Table(1,0);
            Element h2 = new HTMLElement("h2");
            h2.addText(checksumData.getSource() + " " + checksum_details);
            bodyElement.add(h2);
            table.addRow(details.next(), true, null);

            while(details.hasNext()) {
                table.addRow(details.next(), false, null);
            }
            bodyElement.add(table);
        }

    
private voidaddComponentDetails()

        String componentDetailsTitle = getText(component_details,
                new Object[] {target.getName()});
        addTitle(componentDetailsTitle, true, true, 0,0);
        Element element = new HTMLElement("component_details");
        addInstanceSpecificSection(element);
        addElement(element);
     
private voidaddCustomerInformation()

        Iterator<Data> iterator = dataObjTraverser.getData(DataType.CUSTOMER_INFO);

        if (iterator.hasNext()) {
            Data dataObj = iterator.next();
            addTitle(customer_information, true, true, 0,0);
            HTMLElement element = new HTMLElement("customer_information");
            if(dataObj instanceof FileData) {
                copyFromFile(element, dataObj.getSource());
            }
            element.addText(dataObj.getValues());
            addElement(element);
        }
    
private voidaddDescSection()

        addTitle(description, true, true, 0,0);
        descElement = new HTMLElement("desc");
        String description = getText(report_description,
                new Object[] {targetName, new Date()});
        descElement.addText(description);
        addElement(descElement);
   
private voidaddDocHeading()

        Element h1Element = new HTMLElement(HTMLReportConstants.H1);
        h1Element.addAttribute(HTMLReportConstants.ALIGN,
                HTMLReportConstants.CENTER);
        h1Element.addText(HTMLReportConstants.report_heading);
        bodyElement.add(h1Element);
    
private voidaddDocTitle()

        Element titleElement = new HTMLElement(HTMLReportConstants.TITLE);
        titleElement.addText(HTMLReportConstants.report_heading);
        doc.getHead().add(titleElement);
    
protected voidaddElement(Element element)

        bodyElement.add(element);
        bodyElement.add(new HTMLElement(HTMLReportConstants.BR));
    
private voidaddInstallationLogSection(boolean enabled, Element element, int indentation)

        List<String> files = new ArrayList(2);
        if(enabled) {
            String[] logFiles =
                    new File(
                    target.getIntermediateReportDir()).list(new FilenameFilter() {
               public boolean accept(File folder, String name)  {
                   if( (name.contains(Constants.INSTALLATION_LOG_PREFIX)) ||
                           (name.contains(Constants.SJSAS_INSTALLATION_LOG_PREFIX)))
                       return true;
                   return false;
               }
            });
            files.addAll(Arrays.asList(logFiles));
        }

        for(String fileName : files) {
            addLink(element,  fileName, fileName,  indentation);
        }
    
protected voidaddInstanceSpecificSection(Element element)

         if(element != null) {
            Iterator<ServiceConfig > configurations = config.getInstanceConfigurations();

            while(configurations.hasNext()) {
                ServiceConfig config = configurations.next();
                String instanceName = config.getInstanceName();
                int indentation = 1;
                String linkPrefix = "." + File.separator ;
                String instanceFolder = reportDir;
                if(!(instanceName.equals(TargetType.DAS.getType()))) {
                    linkPrefix = instanceName + File.separator ;
                    instanceFolder = instanceFolder + File.separator + instanceName;
                    addLink(element, instanceName, instanceName, indentation++);
                }

                addLink(element, "config", linkPrefix + "config",
                        indentation);

                //add generated and applications only if directories exist
                if(exists(instanceFolder, Constants.GENERATED))
                    addLink(element, Constants.GENERATED,
                            linkPrefix + Constants.GENERATED, indentation);
                if(exists(instanceFolder, Constants.APPLICATIONS))
                    addLink(element, Constants.APPLICATIONS,
                            linkPrefix + Constants.APPLICATIONS, indentation);
                if(exists(instanceFolder, Defaults.LOGS))
                    addLink(element,  Defaults.LOGS, linkPrefix + Defaults.LOGS,
                            indentation);
                if(exists(instanceFolder,Defaults.DOMAIN_XML_VERIFICATION_OUTPUT))
                    addLink(element, domain_xml_validation_details,
                            linkPrefix + Defaults.DOMAIN_XML_VERIFICATION_OUTPUT,
                            indentation);
                addInstallationLogSection(config.isCaptureInstallLogEnabled(),
                        element, indentation);
                addLink(config.isCaptureSystemInfoEnabled(),
                        element, DataType.SYSTEM_INFO, system_information,
                        indentation);

                addMonitoringInfo(element, instanceName, indentation);

            }//while
        }
    
private voidaddLink(boolean enabled, Element element, java.lang.String dataType, java.lang.String text, int indentation)

        if(enabled) {
            Iterator<Data> iterator = dataObjTraverser.getData(dataType);
            while(iterator.hasNext()){
                Data data = iterator.next();
                addLink(element, text, data.getSource(), indentation);
            }
        }
    
protected voidaddLink(Element element, java.lang.String text, java.lang.String link, int textIndent)

        String indentation = indentText("", textIndent);

        if(text!=null){
            if(link==null)
                link="#";
            Link detail = new Link(text,link);
            Element span = new HTMLElement(HTMLReportConstants.SPAN);
            span.addText(indentation);
            span.add(detail);
            element.add(span);
            element.add(new HTMLElement(HTMLReportConstants.BR));
        }
    
protected voidaddMiscellaneousInfo()

        // Do nothing for PE
    
protected voidaddMonitoringInfo(Element element, java.lang.String instanceName, int indentation)

        if (!config.getCLIOptions().isLocal()) {
             addLink(element, monitoring_information,
                     instanceName +
                     File.separator + Defaults.MONITORING_INFO_FILE,
                     indentation);
        }
    
private voidaddTOCSection()

         toc = new Table();
         bodyElement.add(toc);
    
protected voidaddTitle(java.lang.String title, boolean add2TOC, boolean showTitleInBody, int titleIndent, int textIndent)


        String tocTitle = indentText("", titleIndent);

         if(add2TOC){
            ArrayList elements= new ArrayList();
            Element p = new HTMLElement(HTMLReportConstants.PARA);
            p.addText(tocTitle);

            Element link = new Link(title,"#"+getNextTocNo());
            p.add(link);
            elements.add(p);
            toc.addRow(elements,null);
        }


        Element bodyLink = new Link(null,null,getTocNo());
        bodyElement.add(bodyLink);

        if(showTitleInBody){
            Element h2 = new HTMLElement(HTMLReportConstants.H2);
            h2.addText(title);
            bodyElement.add(h2);
        }
    
private voidcopyFromFile(Element element, java.lang.String fileName)

        if ((element != null) && (fileName != null)) {
            logger.log(Level.FINE,"fileName : " + fileName);
            BufferedReader reader = null;
            try {
                reader =
                    new BufferedReader(new FileReader(fileName));

                String entry ;
                while((entry = reader.readLine()) != null) {
                    logger.log(Level.FINE, "entry : " + entry);
                    element.addText(entry);
                    element.add(new HTMLElement("br"));
                }
                reader.close();

            } catch(IOException e) {
                logger.log(Level.WARNING,"diagnostic-service.copy_failed",
                        new Object[]{fileName,e.getMessage()});
            } finally {

            }
        }
    
protected booleanexists(java.lang.String parent, java.lang.String folder)

        File file = new File(parent + File.separator +
                folder);
        return file.exists();
    
protected java.lang.StringgetNextTocNo()

      return String.valueOf(++tocNo);
    
private java.lang.StringgetText(java.lang.String str, java.lang.Object[] args)

        MessageFormat form = new MessageFormat(str);
        return form.format(str,args);
    
protected java.lang.StringgetTocNo()

      return String.valueOf(tocNo);
    
private java.lang.StringindentText(java.lang.String text, int indentIndex)
Indent a text

        String indentedText = text;
        for(int i=1; i <=indentIndex; i++){
            indentedText =  (Escape.getInstance().
             decodeEntities("     " +
             "   ")) + indentedText;
        }
        return indentedText;

    
private voidinitialize()

        doc = new HTMLDocument();
        bodyElement = doc.getBody();

        addDocTitle();
        addDocHeading();
        addTOCSection();
        addDescSection();
        addCustomerInformation();
        addBugIds();
        addChecksumSection();
        addComponentDetails();
        addMiscellaneousInfo();
    
public voidwrite()

        try {
            String reportFile = reportDir + REPORT_NAME;
            //System.out.println("Report Summary File Name : " + reportFile);
            File file = new File(reportFile);
            //System.out.println("DOC : " + doc.toString());
            BufferedWriter writer = new BufferedWriter(
                    new FileWriter(file));

            writer.write(doc.toString());
            writer.flush();
        } catch (Exception e) {
            e.printStackTrace();
            //@todo handle exception intelligently
        }