1 4 package com.openedit.generators; 5 6 import java.io.EOFException ; 7 8 import com.openedit.Generator; 9 import com.openedit.WebPageRequest; 10 import com.openedit.util.OutputFiller; 11 12 16 public abstract class BaseGenerator implements Generator, Cloneable 17 { 18 protected String fieldName; 19 private OutputFiller fieldOutputFiller; 20 21 protected OutputFiller getOutputFiller() 22 { 23 if ( fieldOutputFiller == null ) 24 { 25 fieldOutputFiller = new OutputFiller(); 26 } 27 return fieldOutputFiller; 28 } 29 30 31 public String getName() 32 { 33 return fieldName; 34 } 35 public void setName(String inName) 36 { 37 fieldName = inName; 38 } 39 public boolean canGenerate(WebPageRequest inReq) 41 { 42 return !inReq.getPage().isBinary(); 43 } 44 public Object clone() 45 { 46 try 47 { 48 return super.clone(); 49 } 50 catch (CloneNotSupportedException ex) 51 { 52 return null; 54 } 55 } 56 public boolean hasGenerator(Generator inChild) 57 { 58 return inChild == this; 59 } 60 61 62 protected boolean ignoreError(Throwable inWrapped) 63 { 64 if( inWrapped == null ) 65 { 66 return false; 67 } 68 if( inWrapped instanceof EOFException ) 69 { 70 return true; 71 } 72 String message = inWrapped.toString() + inWrapped.getMessage(); 73 74 if ( message.indexOf("Broken pipe") > -1 || 75 message.indexOf("socket write error") > -1 || 76 message.indexOf("Connection reset") > -1 ) { 78 return true; 79 } 80 81 return ignoreError( inWrapped.getCause() ); 82 } 83 84 } 85 | Popular Tags |