HTMLReportTemplatepublic class HTMLReportTemplate extends Object
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
this.config = config;
this.target = config.getTarget();
this.targetName = target.getName();
this.reportDir = target.getIntermediateReportDir();
this.dataObjTraverser = new DataTraverser(dataObj);
initialize();
|
Methods Summary |
---|
private void | addBugIds()
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 void | addChecksumSection()
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 void | addComponentDetails()
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 void | addCustomerInformation()
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 void | addDescSection()
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 void | addDocHeading()
Element h1Element = new HTMLElement(HTMLReportConstants.H1);
h1Element.addAttribute(HTMLReportConstants.ALIGN,
HTMLReportConstants.CENTER);
h1Element.addText(HTMLReportConstants.report_heading);
bodyElement.add(h1Element);
| private void | addDocTitle()
Element titleElement = new HTMLElement(HTMLReportConstants.TITLE);
titleElement.addText(HTMLReportConstants.report_heading);
doc.getHead().add(titleElement);
| protected void | addElement(Element element)
bodyElement.add(element);
bodyElement.add(new HTMLElement(HTMLReportConstants.BR));
| private void | addInstallationLogSection(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 void | addInstanceSpecificSection(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 void | addLink(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 void | addLink(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 void | addMiscellaneousInfo()
// Do nothing for PE
| protected void | addMonitoringInfo(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 void | addTOCSection()
toc = new Table();
bodyElement.add(toc);
| protected void | addTitle(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 void | copyFromFile(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 boolean | exists(java.lang.String parent, java.lang.String folder)
File file = new File(parent + File.separator +
folder);
return file.exists();
| protected java.lang.String | getNextTocNo()
return String.valueOf(++tocNo);
| private java.lang.String | getText(java.lang.String str, java.lang.Object[] args)
MessageFormat form = new MessageFormat(str);
return form.format(str,args);
| protected java.lang.String | getTocNo()
return String.valueOf(tocNo);
| private java.lang.String | indentText(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 void | initialize()
doc = new HTMLDocument();
bodyElement = doc.getBody();
addDocTitle();
addDocHeading();
addTOCSection();
addDescSection();
addCustomerInformation();
addBugIds();
addChecksumSection();
addComponentDetails();
addMiscellaneousInfo();
| public void | write()
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
}
|
|