1 32 33 package it.businesslogic.ireport; 34 35 import it.businesslogic.ireport.util.*; 36 import java.util.*; 37 import java.io.*; 38 43 public class ScriptletCode { 44 45 public static final int GLOBAL_DECLARATIONS = 0; 46 public static final int EVENT_AFTER_COLUMN_INIT = 1; 47 public static final int EVENT_AFTER_DETAIL_EVAL = 2; 48 public static final int EVENT_AFTER_GROUP_INIT = 3; 49 public static final int EVENT_AFTER_PAGE_INIT = 4; 50 public static final int EVENT_AFTER_REPORT_INIT = 5; 51 public static final int EVENT_BEFORE_COLUMN_INIT = 6; 52 public static final int EVENT_BEFORE_DETAIL_EVAL = 7; 53 public static final int EVENT_BEFORE_GROUP_INIT = 8; 54 public static final int EVENT_BEFORE_PAGE_INIT = 9; 55 public static final int EVENT_BEFORE_REPORT_INIT = 10; 56 57 public static final int LAST_PORTION = 10; 58 public String [] portion_keywords = null; 59 60 61 protected HashMap code_portions; 62 63 64 public ScriptletCode() { 65 66 code_portions = new HashMap(); 67 portion_keywords = new String [LAST_PORTION+1]; 68 69 portion_keywords[GLOBAL_DECLARATIONS] = "GLOBAL_DECLARATIONS"; 70 portion_keywords[EVENT_AFTER_COLUMN_INIT] = "EVENT_AFTER_COLUMN_INIT"; 71 portion_keywords[EVENT_AFTER_DETAIL_EVAL] = "EVENT_AFTER_DETAIL_EVAL"; 72 portion_keywords[EVENT_AFTER_GROUP_INIT] = "EVENT_AFTER_GROUP_INIT"; 73 portion_keywords[EVENT_AFTER_PAGE_INIT] = "EVENT_AFTER_PAGE_INIT"; 74 portion_keywords[EVENT_AFTER_REPORT_INIT] = "EVENT_AFTER_REPORT_INIT"; 75 portion_keywords[EVENT_BEFORE_COLUMN_INIT]= "EVENT_BEFORE_COLUMN_INIT"; 76 portion_keywords[EVENT_BEFORE_DETAIL_EVAL]= "EVENT_BEFORE_DETAIL_EVAL"; 77 portion_keywords[EVENT_BEFORE_GROUP_INIT] = "EVENT_BEFORE_GROUP_INIT"; 78 portion_keywords[EVENT_BEFORE_PAGE_INIT] = "EVENT_BEFORE_PAGE_INIT"; 79 portion_keywords[EVENT_BEFORE_REPORT_INIT]= "EVENT_BEFORE_REPORT_INIT"; 80 81 } 82 83 86 public String getPortion(int portion) 87 { 88 89 if (code_portions.get(""+portion) == null) 90 { 91 return ""; 92 } 93 return (String )code_portions.get(""+portion); 94 } 95 96 99 public void setPortionCode(int portion, String code) 100 { 101 102 code_portions.put(""+portion, code); 103 } 104 105 108 public StringBuffer getAll() 109 { 110 StringBuffer s = new StringBuffer (); 111 112 String global_portion = getPortion( GLOBAL_DECLARATIONS).trim(); 113 114 int i = global_portion.lastIndexOf("}"); 115 global_portion = global_portion.substring(0,i) + global_portion.substring(i+1); 116 117 s.append( global_portion ); 118 s.append("\n"); 119 for ( int k=1; k< LAST_PORTION+1 ; ++k) 120 { 121 s.append( "/** Begin " + portion_keywords[k] + " This line is generated by iReport. Don't modify or move please! */\n" ); 122 s.append( getPortion(k) ); 123 s.append( "/** End " + portion_keywords[k] + " This line is generated by iReport. Don't modify or move please! */\n" ); 124 } 125 126 s.append("\n}"); 127 128 return s; 129 } 130 131 132 133 public ScriptletCode(String filename) throws FileNotFoundException, IOException 134 { 135 this( new FileReader(filename) ); 136 } 137 138 139 140 public ScriptletCode(java.io.InputStream is) throws IOException 141 { 142 this( new InputStreamReader(is) ); 143 } 144 145 public ScriptletCode(Reader in) throws IOException 146 { 147 this(); 148 LineNumberReader lin = new LineNumberReader(in); 149 String line = ""; 150 151 int actualPortion = GLOBAL_DECLARATIONS; 152 153 while ( (line = lin.readLine()) != null) 154 { 155 if ( line.trim().startsWith("/** Begin EVENT_AFTER_COLUMN_INIT")) 156 { 157 actualPortion = EVENT_AFTER_COLUMN_INIT; 158 continue; 159 } 160 else if ( line.trim().startsWith("/** Begin EVENT_AFTER_DETAIL_EVAL")) 161 { 162 actualPortion = EVENT_AFTER_DETAIL_EVAL; 163 continue; 164 } 165 else if ( line.trim().startsWith("/** Begin EVENT_AFTER_GROUP_INIT")) 166 { 167 actualPortion = EVENT_AFTER_GROUP_INIT; 168 continue; 169 } 170 else if ( line.trim().startsWith("/** Begin EVENT_AFTER_PAGE_INIT")) 171 { 172 actualPortion = EVENT_AFTER_PAGE_INIT; 173 continue; 174 } 175 else if ( line.trim().startsWith("/** Begin EVENT_AFTER_REPORT_INIT")) 176 { 177 actualPortion = EVENT_AFTER_REPORT_INIT; 178 continue; 179 } 180 else if ( line.trim().startsWith("/** Begin EVENT_BEFORE_COLUMN_INIT")) 181 { 182 actualPortion = EVENT_BEFORE_COLUMN_INIT; 183 continue; 184 } 185 else if ( line.trim().startsWith("/** Begin EVENT_BEFORE_DETAIL_EVAL")) 186 { 187 actualPortion = EVENT_BEFORE_DETAIL_EVAL; 188 continue; 189 } 190 else if ( line.trim().startsWith("/** Begin EVENT_BEFORE_GROUP_INIT")) 191 { 192 actualPortion = EVENT_BEFORE_GROUP_INIT; 193 continue; 194 } 195 else if ( line.trim().startsWith("/** Begin EVENT_BEFORE_PAGE_INIT")) 196 { 197 actualPortion = EVENT_BEFORE_PAGE_INIT; 198 continue; 199 } 200 else if ( line.trim().startsWith("/** Begin EVENT_BEFORE_REPORT_INIT")) 201 { 202 actualPortion = EVENT_BEFORE_REPORT_INIT; 203 continue; 204 } 205 else if ( line.trim().startsWith("/** End EVENT_")) 206 { 207 actualPortion = GLOBAL_DECLARATIONS; 208 continue; 209 } 210 211 append(line, actualPortion); 212 } 213 } 214 215 216 public void append(String line, int portion) 217 { 218 String str = Misc.nvl( this.code_portions.get(""+portion),""); 219 str += line + "\n"; 220 this.code_portions.put(""+portion,str); 221 222 } 223 } 224 | Popular Tags |