1 32 33 package com.knowgate.scheduler.jobs; 34 35 import java.lang.ref.SoftReference ; 36 37 import java.util.HashMap ; 38 39 import java.io.IOException ; 40 import java.io.FileReader ; 41 import java.io.FileWriter ; 42 import java.io.File ; 43 44 import com.knowgate.debug.DebugFile; 45 import com.knowgate.dataobjs.DB; 46 import com.knowgate.scheduler.Atom; 47 import com.knowgate.scheduler.Job; 48 import com.knowgate.dataxslt.FastStreamReplacer; 49 50 55 56 public class FileDumper extends Job { 57 58 private boolean bHasReplacements; 65 66 private SoftReference oFileStr; 70 71 private FastStreamReplacer oReplacer; 74 75 77 public FileDumper() { 78 bHasReplacements = true; 79 oFileStr = null; 80 oReplacer = new FastStreamReplacer(); 81 } 82 83 85 public void free() {} 86 87 89 103 104 public Object process(Atom oAtm) throws IOException { 105 106 File oFile; FileReader oFileRead; String sPathHTML; char cBuffer[]; Object oReplaced; 112 final String sSep = System.getProperty("file.separator"); 114 if (DebugFile.trace) { 115 DebugFile.writeln("Begin FileDumper.process([Job:" + getStringNull(DB.gu_job,"") + ", Atom:" + String.valueOf(oAtm.getInt(DB.pg_atom)) + "])"); 116 DebugFile.incIdent(); 117 } 118 119 if (bHasReplacements) { 121 124 sPathHTML = getProperty("workareasput"); 126 if (!sPathHTML.endsWith(sSep)) sPathHTML += sSep; 127 128 sPathHTML += getParameter("gu_workarea") + sSep + "apps" + sSep + "Mailwire" + sSep + "html" + sSep + getParameter("gu_pageset") + sSep; 130 131 sPathHTML += getParameter("nm_pageset").replace(' ','_') + ".html"; 133 134 if (DebugFile.trace) DebugFile.writeln("PathHTML = " + sPathHTML); 135 136 139 oReplaced = oReplacer.replace(sPathHTML, oAtm.getItemMap()); 140 141 bHasReplacements = (oReplacer.lastReplacements()>0); 143 } 144 145 else { 146 147 oReplaced = null; 148 149 if (null!=oFileStr) 150 oReplaced = oFileStr.get(); 151 152 if (null==oReplaced) { 153 154 157 sPathHTML = getProperty("workareasput"); 159 if (!sPathHTML.endsWith(sSep)) sPathHTML += sSep; 160 sPathHTML += getParameter("gu_workarea") + sSep + "apps" + sSep + "Mailwire" + sSep + "html" + sSep + getParameter("gu_pageset") + sSep + getParameter("nm_pageset").replace(' ','_') + ".html"; 161 162 if (DebugFile.trace) DebugFile.writeln("PathHTML = " + sPathHTML); 163 164 167 oFile = new File (sPathHTML); 168 169 cBuffer = new char[new Long (oFile.length()).intValue()]; 170 171 oFileRead = new FileReader (oFile); 172 oFileRead.read(cBuffer); 173 oFileRead.close(); 174 175 if (DebugFile.trace) DebugFile.writeln(String.valueOf(cBuffer.length) + " characters readed"); 176 177 180 oReplaced = new String (cBuffer); 181 oFileStr = new SoftReference (oReplaced); 182 183 } 185 } 187 190 String sPathJobDir = getProperty("storage"); 192 if (!sPathJobDir.endsWith(sSep)) sPathJobDir += sSep; 193 sPathJobDir += "jobs" + sSep + getParameter("gu_workarea") + sSep + getString(DB.gu_job) + sSep; 194 195 FileWriter oFileWrite = new FileWriter (sPathJobDir + getString(DB.gu_job) + "_" + String.valueOf(oAtm.getInt(DB.pg_atom)) + ".html", true); 197 oFileWrite.write((String ) oReplaced); 198 oFileWrite.close(); 199 200 iPendingAtoms--; 202 203 if (DebugFile.trace) { 204 DebugFile.writeln("End FileDumper.process([Job:" + getStringNull(DB.gu_job,"") + ", Atom:" + String.valueOf(oAtm.getInt(DB.pg_atom)) + "])"); 205 DebugFile.decIdent(); 206 } 207 208 return oReplaced; 209 } 211 } | Popular Tags |