01: /*
02: * Created on Jun 5, 2005
03: */
04: package com.openedit.generators;
05:
06: import java.io.EOFException;
07:
08: import com.openedit.Generator;
09: import com.openedit.WebPageRequest;
10: import com.openedit.util.OutputFiller;
11:
12: /**
13: * @author cburkey
14: *
15: */
16: public abstract class BaseGenerator implements Generator, Cloneable {
17: protected String fieldName;
18: private OutputFiller fieldOutputFiller;
19:
20: protected OutputFiller getOutputFiller() {
21: if (fieldOutputFiller == null) {
22: fieldOutputFiller = new OutputFiller();
23: }
24: return fieldOutputFiller;
25: }
26:
27: public String getName() {
28: return fieldName;
29: }
30:
31: public void setName(String inName) {
32: fieldName = inName;
33: }
34:
35: //TODO: Should this check for exists? What about isBinary?
36: public boolean canGenerate(WebPageRequest inReq) {
37: return !inReq.getPage().isBinary();
38: }
39:
40: public Object clone() {
41: try {
42: return super .clone();
43: } catch (CloneNotSupportedException ex) {
44: //silent, will never happen
45: return null;
46: }
47: }
48:
49: public boolean hasGenerator(Generator inChild) {
50: return inChild == this ;
51: }
52:
53: protected boolean ignoreError(Throwable inWrapped) {
54: if (inWrapped == null) {
55: return false;
56: }
57: if (inWrapped instanceof EOFException) {
58: return true;
59: }
60: String message = inWrapped.toString() + inWrapped.getMessage();
61:
62: if (message.indexOf("Broken pipe") > -1
63: || message.indexOf("socket write error") > -1
64: || message.indexOf("Connection reset") > -1) //tomcat
65: {
66: return true;
67: }
68:
69: return ignoreError(inWrapped.getCause());
70: }
71:
72: }
|