1 28 29 package com.idaremedia.antx.print; 30 31 import java.io.ByteArrayOutputStream ; 32 import java.io.IOException ; 33 34 import org.apache.tools.ant.BuildException; 35 import org.apache.tools.ant.Project; 36 37 import com.idaremedia.antx.FlexString; 38 import com.idaremedia.antx.Stringifier; 39 import com.idaremedia.antx.helpers.Tk; 40 41 42 55 56 public final class DiagnosticsValue extends FlexString 57 { 58 61 public DiagnosticsValue() 62 { 63 super(); 64 } 65 66 67 71 public DiagnosticsValue(boolean lenient) 72 { 73 super(); 74 setLenient(lenient); 75 } 76 77 78 83 protected String stringFrom(Object o, Project P) 84 { 85 String s = Stringifier.get(false).stringFrom(o,P); 86 if (s==null) { 87 PrinterRegistry registry = PrinterRegistryContext.getPrinterRegistryNoNull(); 88 if (registry==PrinterRegistryContext.getEmptyPrinterRegistry()) { 89 s = Tk.stringFrom(o,P); 90 } else { 91 ByteArrayOutputStream os = new ByteArrayOutputStream (100); 92 DisplayRequest r = new DisplayRequest(o); 93 try { 94 registry.getPrinterForNoNull(o).print(r,os); 95 } catch (IOException iox) { 96 if (!isLenient()) { 97 throw new BuildException(iox); 98 } 99 iox.printStackTrace(System.err); return Tk.stringFrom(o,P); 101 } 102 r = null; 103 s = os.toString(); 104 os = null; 105 } 106 } 107 return s; 108 } 109 } 110 111 112 | Popular Tags |