KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jsf > application > JspViewHandler


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2
11  * as published by the Free Software Foundation.
12  *
13  * Resin Open Source is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
16  * of NON-INFRINGEMENT. See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with Resin Open Source; if not, write to the
21  *
22  * Free Software Foundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.jsf.application;
30
31 import java.io.*;
32 import java.util.*;
33
34 import javax.faces.*;
35 import javax.faces.application.*;
36 import javax.faces.component.*;
37 import javax.faces.context.*;
38 import javax.faces.render.*;
39
40 import javax.servlet.*;
41
42 public class JspViewHandler extends ViewHandler
43 {
44   public Locale calculateLocale(FacesContext context)
45   {
46     throw new UnsupportedOperationException JavaDoc();
47   }
48
49   public String JavaDoc calculateRenderKitId(FacesContext context)
50   {
51     return RenderKitFactory.HTML_BASIC_RENDER_KIT;
52   }
53
54   public UIViewRoot createView(FacesContext context,
55                    String JavaDoc viewId)
56   {
57     if (viewId == null) {
58       ExternalContext extContext = context.getExternalContext();
59
60       String JavaDoc servletPath = extContext.getRequestServletPath();
61       String JavaDoc pathInfo = extContext.getRequestPathInfo();
62
63       String JavaDoc path;
64       int dot;
65
66       if (servletPath != null
67       && (dot = servletPath.lastIndexOf('.')) > 0
68       && servletPath.lastIndexOf('/') < dot) {
69     // /test/foo.jsp
70

71     viewId = servletPath.substring(0, dot) + ".jsp";
72       }
73       else if (pathInfo != null) {
74     dot = pathInfo.lastIndexOf('.');
75
76     if (dot > 0)
77       viewId = pathInfo.substring(0, dot) + ".jsp";
78     else
79       viewId = pathInfo + ".jsp";
80       }
81       else
82     viewId = "";
83     }
84     
85     UIViewRoot viewRoot = new UIViewRoot();
86
87     viewRoot.setViewId(viewId);
88     viewRoot.setRenderKitId(calculateRenderKitId(context));
89
90     return viewRoot;
91   }
92
93   public String JavaDoc getActionURL(FacesContext context,
94                  String JavaDoc viewId)
95   {
96     throw new UnsupportedOperationException JavaDoc();
97   }
98
99   public String JavaDoc getResourceURL(FacesContext context,
100                    String JavaDoc path)
101   {
102     throw new UnsupportedOperationException JavaDoc();
103   }
104
105   public void renderView(FacesContext context,
106              UIViewRoot viewToRender)
107     throws IOException, FacesException
108   {
109     String JavaDoc viewId = viewToRender.getViewId();
110
111     ExternalContext extContext = context.getExternalContext();
112
113     ((javax.servlet.http.HttpServletResponse JavaDoc) extContext.getResponse()).setContentType("text/html");
114
115     extContext.dispatch(viewId);
116
117     /*
118     UIViewRoot viewRoot = context.getViewRoot();
119
120     if (viewRoot != null) {
121       viewRoot.setRendered(true); // XXX:
122       
123       viewRoot.encodeAll(context);
124     }
125     */

126   }
127
128   public UIViewRoot restoreView(FacesContext context,
129                 String JavaDoc viewId)
130     throws FacesException
131   {
132     return null;
133   }
134
135   public void writeState(FacesContext context)
136     throws IOException
137   {
138   }
139
140   public String JavaDoc toString()
141   {
142     return "JspViewHandler[]";
143   }
144 }
145
Popular Tags