KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > generators > BaseGenerator


1 /*
2  * Created on Jun 5, 2005
3  */

4 package com.openedit.generators;
5
6 import java.io.EOFException JavaDoc;
7
8 import com.openedit.Generator;
9 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 JavaDoc
17 {
18     protected String JavaDoc 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 JavaDoc getName()
32     {
33         return fieldName;
34     }
35     public void setName(String JavaDoc inName)
36     {
37         fieldName = inName;
38     }
39     //TODO: Should this check for exists? What about isBinary?
40
public boolean canGenerate(WebPageRequest inReq)
41     {
42         return !inReq.getPage().isBinary();
43     }
44     public Object JavaDoc clone()
45     {
46         try
47         {
48             return super.clone();
49         }
50         catch (CloneNotSupportedException JavaDoc ex)
51         {
52             //silent, will never happen
53
return null;
54         }
55     }
56     public boolean hasGenerator(Generator inChild)
57     {
58         return inChild == this;
59     }
60
61
62     protected boolean ignoreError(Throwable JavaDoc inWrapped)
63     {
64         if( inWrapped == null )
65         {
66             return false;
67         }
68         if( inWrapped instanceof EOFException JavaDoc )
69         {
70             return true;
71         }
72         String JavaDoc 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 ) //tomcat
77
{
78             return true;
79         }
80     
81         return ignoreError( inWrapped.getCause() );
82     }
83
84 }
85
Popular Tags