KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > core > view > ClientType


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: ClientType.java,v 1.9 2004/02/01 05:16:28 christianc Exp $
19  */

20 package org.enhydra.barracuda.core.view;
21
22 import java.util.*;
23 import org.w3c.dom.*;
24 import org.w3c.dom.html.*;
25
26 /**
27  * <p>This class defines all valid ClientTypes.
28  *
29  * <p>We start by defining a series of basic interfaces to define all known client types
30  * and specify how they relate to one another. Please note that these are hierarchical in
31  * nature. Strongly typed ClientType interfaces include:
32  *
33  * <ul>
34  * <li>GenericBrowser<ul>
35  * <li>HtmlBrowser<ul>
36  * <li>HtmlStandardBrowser<ul>
37  * <li>Html32Browser<ul>
38  * <li>IE3x<ul>
39  * <li>IE4x</li>
40  * </ul>
41  * </li>
42  * <li>NN3x<ul>
43  * <li>NN4x</li>
44  * </ul>
45  * </li>
46  * <li>Opera4x</li>
47  * </ul>
48  * </li>
49  * <li>Html40Browser<ul>
50  * <li>IE5x<ul>
51  * <li>IE6x</li>
52  * </ul>
53  * </li>
54  * <li>NN6x</li>
55  * <li>Opera5x</li>
56  * </ul>
57  * </li>
58  * </ul>
59  * </li>
60  * <li>ChtmlBrowser</li>
61  * </ul>
62  * </li>
63  * <li>XmlBrowser<ul>
64  * <li>VxmlBrowser</li>
65  * <li>WmlBrowser</li>
66  * <li>XhtmlBrowser</li>
67  * </ul>
68  * </li>
69  * <li>Unknown</li>
70  * </ul>
71  * </li>
72  * </ul>
73  *
74  * We can reference these interfaces to determine what kind of ClientType we're
75  * actually dealing with. We also define concrete client types to allow us to
76  * actually assign client type values.
77  *
78  * <p>Concrete client types include:
79  * <ul>
80  * <li>ClientType.HTML_BROWSER</li>
81  * <li>ClientType.HTML_3_2_BROWSER</li>
82  * <li>ClientType.IE_3x</li>
83  * <li>ClientType.IE_4x</li>
84  * <li>ClientType.NN_3x</li>
85  * <li>ClientType.NN_4x</li>
86  * <li>ClientType.OPERA_4x</li>
87  * <li>ClientType.HTML_4_0_BROWSER</li>
88  * <li>ClientType.IE_5x</li>
89  * <li>ClientType.IE_6x</li>
90  * <li>ClientType.NN_6x</li>
91  * <li>ClientType.OPERA_5x</li>
92  * <li>ClientType.CHTML_BROWSER</li>
93  * <li>ClientType.WML_BROWSER</li>
94  * <li>ClientType.XML_BROWSER</li>
95  * <li>ClientType.UNKNOWN_BROWSER</li>
96  * </ul>
97  *
98  * <p> This all functions in a manner similar to the FormatType class. For more
99  * details, please refer to those Javadocs.
100  */

101 public abstract class ClientType {
102
103     //concrete instances of client types
104
public static final ClientType HTML_BROWSER = new HtmlBrowserImpl();
105     public static final ClientType HTML_3_2_BROWSER = new Html32BrowserImpl();
106     public static final ClientType IE_3x = new IE3xImpl();
107     public static final ClientType IE_4x = new IE4xImpl();
108     public static final ClientType NN_3x = new NN3xImpl();
109     public static final ClientType NN_4x = new NN4xImpl();
110     public static final ClientType OPERA_4x = new Opera4xImpl();
111     public static final ClientType HTML_4_0_BROWSER = new Html40BrowserImpl();
112     public static final ClientType IE_5x = new IE5xImpl();
113     public static final ClientType IE_6x = new IE6xImpl();
114     public static final ClientType NN_6x = new NN6xImpl();
115     public static final ClientType OPERA_5x = new Opera5xImpl();
116     public static final ClientType CHTML_BROWSER = new ChtmlBrowserImpl();
117     public static final ClientType XML_BROWSER = new XmlBrowserImpl();
118     public static final ClientType VXML_BROWSER = new VxmlBrowserImpl();
119     public static final ClientType WML_BROWSER = new WmlBrowserImpl();
120     public static final ClientType XHTML_BROWSER = new XhtmlBrowserImpl();
121     public static final ClientType UNKNOWN_BROWSER = new UnknownBrowserImpl();
122
123     //base client types (hierarchical defs)
124
public interface GenericBrowser {};
125     public interface HtmlBrowser extends GenericBrowser {};
126     public interface HtmlStandardBrowser extends HtmlBrowser {};
127     public interface Html32Browser extends HtmlStandardBrowser {};
128     public interface IE3x extends Html32Browser {};
129     public interface IE4x extends IE3x {};
130     public interface NN3x extends Html32Browser {};
131     public interface NN4x extends NN3x {};
132     public interface Opera4x extends Html32Browser {};
133     public interface Html40Browser extends Html32Browser {};
134     public interface IE5x extends Html40Browser, IE4x {};
135     public interface IE6x extends Html40Browser, IE5x {};
136     public interface NN6x extends Html40Browser, NN4x {};
137     public interface Opera5x extends Html40Browser, Opera4x {};
138     public interface ChtmlBrowser extends HtmlBrowser {};
139     public interface XmlBrowser extends GenericBrowser {};
140     public interface VxmlBrowser extends XmlBrowser {};
141     public interface WmlBrowser extends XmlBrowser {};
142     public interface XhtmlBrowser extends XmlBrowser {};
143     public interface UnknownBrowser extends GenericBrowser {};
144     
145 //TODO: we really need to flesh out the browser info for CHTML, VXML, WML, & HXTML (both basic and standard)
146

147     //private implementations (while the concrete implementations above are final
148
//so they can't be changed, the specific implementations are left merely protected,
149
//allowing developers to extend for custom types if needed).
150

151     //client types
152
protected static class GenericBrowserImpl extends ClientType implements GenericBrowser {
153         public String JavaDoc toString() {
154             String JavaDoc s = this.getClass().getName();
155             int spos = s.indexOf("$");
156             int epos = s.indexOf("Impl");
157             return s.substring(spos+1, epos);
158         }
159     };
160     protected static class HtmlBrowserImpl extends GenericBrowserImpl implements HtmlBrowser {};
161     protected static class HtmlStandardBrowserImpl extends HtmlBrowserImpl implements HtmlStandardBrowser {};
162     protected static class Html32BrowserImpl extends HtmlStandardBrowserImpl implements Html32Browser {};
163     protected static class IE3xImpl extends Html32BrowserImpl implements IE3x {};
164     protected static class IE4xImpl extends IE3xImpl implements IE4x {};
165     protected static class NN3xImpl extends Html32BrowserImpl implements NN3x {};
166     protected static class NN4xImpl extends NN3xImpl implements NN4x {};
167     protected static class Opera4xImpl extends Html32BrowserImpl implements Opera4x {};
168     protected static class Html40BrowserImpl extends Html32BrowserImpl implements Html40Browser {};
169     protected static class IE5xImpl extends Html40BrowserImpl implements IE5x {};
170     protected static class IE6xImpl extends Html40BrowserImpl implements IE6x {};
171     protected static class NN6xImpl extends Html40BrowserImpl implements NN6x {};
172     protected static class Opera5xImpl extends Html40BrowserImpl implements Opera5x {};
173     protected static class ChtmlBrowserImpl extends HtmlBrowserImpl implements ChtmlBrowser {};
174     protected static class XmlBrowserImpl extends GenericBrowserImpl implements XmlBrowser {};
175     protected static class VxmlBrowserImpl extends XmlBrowserImpl implements VxmlBrowser {};
176     protected static class WmlBrowserImpl extends XmlBrowserImpl implements WmlBrowser {};
177     protected static class XhtmlBrowserImpl extends XmlBrowserImpl implements XhtmlBrowser {};
178     protected static class UnknownBrowserImpl extends GenericBrowserImpl implements UnknownBrowser {};
179
180     /**
181      * Given a target string, find the matching client type
182      *
183      * @param strName the str name that describes this client type
184      * (ie. "ClientType.HTML_BROWSER", etc)
185      * @return the matching client type or null if there is no match
186      */

187     public static ClientType getInstance(String JavaDoc strName) {
188         if (strName.indexOf("HTML_BROWSER")!=-1) return ClientType.HTML_BROWSER;
189         else if (strName.indexOf("HTML_3_2_BROWSER")!=-1) return ClientType.HTML_3_2_BROWSER;
190         else if (strName.indexOf("IE_3x")!=-1) return ClientType.IE_3x;
191         else if (strName.indexOf("IE_4x")!=-1) return ClientType.IE_4x;
192         else if (strName.indexOf("NN_3x")!=-1) return ClientType.NN_3x;
193         else if (strName.indexOf("NN_4x")!=-1) return ClientType.NN_4x;
194         else if (strName.indexOf("OPERA_4x")!=-1) return ClientType.OPERA_4x;
195         else if (strName.indexOf("HTML_4_0_BROWSER")!=-1) return ClientType.HTML_4_0_BROWSER;
196         else if (strName.indexOf("IE_5x")!=-1) return ClientType.IE_5x;
197         else if (strName.indexOf("IE_6x")!=-1) return ClientType.IE_6x;
198         else if (strName.indexOf("NN_6x")!=-1) return ClientType.NN_6x;
199         else if (strName.indexOf("OPERA_5x")!=-1) return ClientType.OPERA_5x;
200         else if (strName.indexOf("CHTML_BROWSER")!=-1) return ClientType.CHTML_BROWSER;
201         else if (strName.indexOf("XML_BROWSER")!=-1) return ClientType.XML_BROWSER;
202         else if (strName.indexOf("VXML_BROWSER")!=-1) return ClientType.VXML_BROWSER;
203         else if (strName.indexOf("WML_BROWSER")!=-1) return ClientType.WML_BROWSER;
204         else if (strName.indexOf("XHTML_BROWSER")!=-1) return ClientType.XHTML_BROWSER;
205         else if (strName.indexOf("UNKNOWN_BROWSER")!=-1) return ClientType.UNKNOWN_BROWSER;
206         else return null;
207     }
208
209     /**
210      * Private constructor to prevent external instantiation
211      */

212     protected ClientType() {}
213
214     public static void main(String JavaDoc args[]) {
215         System.out.println ("Testing...");
216         System.out.println ("IE_5x instanceof ClientType.Html32Browser:"+(ClientType.IE_5x instanceof ClientType.Html32Browser));
217     }
218 }
219
Popular Tags