1 33 34 package com.icesoft.applications.faces.auctionMonitor.beans; 35 36 import org.apache.commons.logging.Log; 37 import org.apache.commons.logging.LogFactory; 38 39 import java.io.IOException ; 40 import java.io.InputStreamReader ; 41 import java.io.Reader ; 42 import java.io.StringWriter ; 43 44 49 public class ReadmeBean { 50 private static Log log = LogFactory.getLog(ReadmeBean.class); 51 private String readmeText = ""; 52 private boolean expanded = false; 53 private String buttonLabel = README; 54 private static final String SUCCESS = "success"; 55 private static final String README = "./images/view-notes-button.gif"; 56 private static final String CLOSEME = "./images/hide-notes-button.gif"; 57 58 public ReadmeBean() { 59 loadDefaultReadmeFile(); 60 } 61 62 public ReadmeBean(String readmeText) { 63 this.readmeText = readmeText; 64 } 65 66 public String getReadmeText() { 67 return readmeText; 68 } 69 70 public String getButtonLabel() { 71 return buttonLabel; 72 } 73 74 public boolean isExpanded() { 75 return expanded; 76 } 77 78 public void setExpanded(boolean expanded) { 79 this.expanded = expanded; 80 } 81 82 public String pressExpandButton() { 83 expanded = !expanded; 84 if (expanded) { 85 this.buttonLabel = CLOSEME; 86 } else { 87 this.buttonLabel = README; 88 } 89 return SUCCESS; 90 } 91 92 98 private boolean loadDefaultReadmeFile() { 99 try { 100 Reader readmeReader = 101 new InputStreamReader (this.getClass().getClassLoader() 102 .getResourceAsStream( 103 "com/icesoft/applications/faces/auctionMonitor/readme.html")); 104 StringWriter readmeWriter = new StringWriter (); 105 106 char[] buf = new char[2000]; 107 int len; 108 try { 109 while ((len = readmeReader.read(buf)) > -1) { 110 readmeWriter.write(buf, 0, len); 111 } 112 } catch (IOException e) { 113 if (log.isErrorEnabled()) { 114 log.error( 115 "Something went wrong while parsing the readme file, likely because of " + 116 e); 117 } 118 } 119 readmeReader.close(); 121 122 this.readmeText = readmeWriter.toString(); 123 124 readmeWriter.close(); 126 127 return true; 128 129 } catch (Exception e) { 130 if (log.isWarnEnabled()) { 131 log.warn( 132 "General error while attempting to load the readme file, cause may be " + 133 e); 134 } 135 } 136 137 return false; 138 } 139 } 140 | Popular Tags |