| 1 |
|
package com.ccg.macros; |
| 2 |
|
|
| 3 |
|
import com.ccg.io.*; |
| 4 |
|
|
| 5 |
|
import java.io.*; |
| 6 |
|
import java.util.*; |
| 7 |
|
|
| 8 |
|
|
| 9 |
|
class TableInsert extends TableProcessor implements MacroHandler { |
| 10 |
|
|
| 11 |
|
private AtMacros _AtMacros; |
| 12 |
|
private String _Source; |
| 13 |
|
private String _Name; |
| 14 |
|
private String _Format; |
| 15 |
|
private Output _Out; |
| 16 |
|
|
| 17 |
|
TableInsert(AtMacros am, String name, String source) { |
| 18 |
0 |
super(null); |
| 19 |
0 |
_AtMacros = am; |
| 20 |
0 |
_Name = name; |
| 21 |
0 |
_Source = source; |
| 22 |
0 |
_Format = ""; |
| 23 |
|
|
| 24 |
0 |
} |
| 25 |
|
|
| 26 |
|
|
| 27 |
|
public boolean processData() { |
| 28 |
|
try { |
| 29 |
0 |
_Out.write(_AtMacros.interpretCheck(_Format)); |
| 30 |
0 |
} catch (Exception ioe) { |
| 31 |
0 |
setDataException(ioe); |
| 32 |
0 |
return false; |
| 33 |
0 |
} |
| 34 |
0 |
return true; |
| 35 |
|
} |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
public void process(Output out, Vector args) |
| 39 |
|
throws IOException, InterpretException { |
| 40 |
|
|
| 41 |
0 |
_Format = ""; |
| 42 |
0 |
if (args.size() >= 1) _Format = args.elementAt(0).toString(); |
| 43 |
|
|
| 44 |
0 |
if (_Format.length() == 0) |
| 45 |
0 |
throw new InterpretException("Error: no FORMAT specified to @"+ |
| 46 |
|
_Name+"(FORMAT)"); |
| 47 |
|
|
| 48 |
0 |
LineNumberReader lnr = |
| 49 |
|
new LineNumberReader(com.ccg.io.Utility.getReader(_Source)); |
| 50 |
|
|
| 51 |
0 |
setTable(new TextTable()); |
| 52 |
|
|
| 53 |
0 |
String fmac = _Name+"F"; |
| 54 |
|
|
| 55 |
0 |
_AtMacros.addMacro(fmac,new TableField(_AtMacros,fmac,this)); |
| 56 |
|
|
| 57 |
0 |
_Out = out; |
| 58 |
|
|
| 59 |
0 |
process(lnr); |
| 60 |
|
|
| 61 |
0 |
_AtMacros.addMacro(fmac,(MacroHandler) null); |
| 62 |
|
|
| 63 |
0 |
Exception re = getDataException(); |
| 64 |
0 |
if (re == null) re = getHeaderException(); |
| 65 |
|
|
| 66 |
|
try { |
| 67 |
0 |
lnr.close(); |
| 68 |
0 |
} catch (IOException ioe) { |
| 69 |
0 |
re = ioe; |
| 70 |
0 |
} |
| 71 |
|
|
| 72 |
0 |
if (re != null) { |
| 73 |
0 |
if (re instanceof IOException) throw (IOException) re; |
| 74 |
0 |
else throw (InterpretException) re; |
| 75 |
|
} |
| 76 |
0 |
} |
| 77 |
|
|
| 78 |
|
} |