001: /**
002: * $Id: JSPRenderingProvider.java,v 1.10 2005/09/21 10:49:12 dg154973 Exp $
003: * Copyright 2003 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and iPlanet
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.wireless.providers.rendering;
014:
015: import com.sun.portal.providers.jsp.JSPProvider;
016: import com.sun.portal.providers.context.ProviderContext;
017: import com.sun.portal.providers.context.ContainerProviderContext;
018: import com.sun.portal.providers.ProviderException;
019: import com.sun.portal.providers.context.ProviderContextException;
020: import com.sun.portal.log.common.PortalLogger;
021:
022: import javax.servlet.http.HttpServletRequest;
023: import javax.servlet.http.HttpServletResponse;
024: import java.io.File;
025: import java.util.logging.Level;
026: import java.util.logging.Logger;
027:
028: /**
029: * The <code>JSPRenderingProvider</code> class extends from the
030: * <code>JSPProvider</code> and overrides the <code>getContent,
031: * getEdit</code> and <code>getMostSpecificPath</code>
032: * methods of <code>JSPProvider</code>. This is a public class and
033: * can be extended to add more functionality to the provider if needed.
034: * It gets the AML content from JSP templates for the provider and based on a
035: * few checks, it decides whether to pass the AML content back to the
036: * container or call the RenderingEngine
037: * itself and pass back device specific markup to the container.
038: * <p>Rendering Channels created using this
039: * JSPRenderingProvider can be a part of either RenderingContainers or
040: * NativeContainers. While creating channels using
041: * <code>JSPRenderingProvider</code>, the channel developer
042: * has to write a contentPage.jsp and editPage.jsp (if channel is editable)
043: * which would get the content from AML JSPs it has.<p>
044: * All JSPs created for the channel should be valid AML documents.
045: */
046:
047: public class JSPRenderingProvider extends JSPProvider {
048:
049: private static Logger logger = PortalLogger
050: .getLogger(JSPRenderingProvider.class);
051:
052: public void init(String name, HttpServletRequest req)
053: throws ProviderException {
054: super .init(name, req);
055: }
056:
057: /**
058: * This method overrides <code>JSPProvider.getContent()</code> method. It
059: * gets the JSP content from <code>JSPProvider</code> and pass it to
060: * <code>renderContent()</code> method.
061: * Based on a few check, it will either return device specfic markup or AML.
062: *
063: * @return StringBuffer holding the channel content that is markup specific
064: * or AML.
065: * @exception ProviderException If there was an error generating the content.
066: *
067: * @param request An HttpServletRequest that contains information related to
068: * this request for content.
069: * @param response An HttpServletResponse that allows the provider to
070: * influence overall response for the desktop page.
071: * @see com.sun.portal.providers.jsp.JSPProvider#getContent
072: **/
073:
074: public StringBuffer getContent(HttpServletRequest req,
075: HttpServletResponse res) throws ProviderException {
076: StringBuffer sb = super .getContent(req, res);
077: return renderContent(req, sb);
078: }
079:
080: /**
081: * This method overrides <code>JSPProvider.getEdit()</code> method. It gets
082: * the JSP edit page content from <code>JSPProvider</code> and pass it to
083: * <code>renderContent()</code> method.
084: * Based on a few check, it will either return device specfic markup or AML.
085: *
086: * @return StringBuffer holding the channel edit page that is markup
087: * specific or AML.
088: * @exception ProviderException If there was an error generating the content.
089: *
090: * @param request An HttpServletRequest that contains information related x
091: * to this request for content.
092: * @param response An HttpServletResponse that allows the provider to
093: * influence overall response for the desktop page.
094: * @see com.sun.portal.providers.jsp.JSPProvider#getEdit
095: *
096: **/
097: public StringBuffer getEdit(HttpServletRequest req,
098: HttpServletResponse res) throws ProviderException {
099: StringBuffer sb = super .getEdit(req, res);
100: return renderEditContent(req, sb);
101: }
102:
103: /**
104: * This method is expected to be called from the Provider's
105: * <code>getContent()</code> methods after it creates its content
106: * StringBuffer. It calls <code>RenderingUtil.renderContent()</code>
107: * to render the content. The return buffer can contain device specific
108: * markup (rendered) or remain as AML document (not rendered).
109: *
110: * @param req An HttpServletRequest that contains information related to this
111: * request for content.
112: * @param sb The StringBuffer representing the content obtained
113: * from the JSPs.
114: *
115: * @return StringBuffer The return content can be rendered or not rendered.
116: * @see com.sun.portal.wireless.providers.rendering.
117: * RenderingUtil#renderContent
118: */
119:
120: protected StringBuffer renderContent(HttpServletRequest req,
121: StringBuffer sb) throws ProviderException {
122: ContainerProviderContext cpc = (ContainerProviderContext) getProviderContext();
123: return RenderingUtil.renderContent(req, cpc, getName(), sb);
124: }
125:
126: /**
127: * This method is expected to be called from the Provider's <code>getEdit()
128: * </code> methods after it creates its content StringBuffer. It calls
129: * <code>RenderingUtil.renderEditContent()</code> to render the content.
130: * The return buffer can contain device specific markup (rendered) or
131: * remain as AML document (not rendered).
132: *
133: * @param req An HttpServletRequest that contains information related to this
134: * request for content.
135: * @param sb The StringBuffer representing the content obtained
136: * from the JSPs.
137: *
138: * @return StringBuffer The return content can be rendered or not rendered.
139: * @see com.sun.portal.wireless.providers.rendering.
140: * RenderingUtil#renderContent
141: */
142:
143: protected StringBuffer renderEditContent(HttpServletRequest req,
144: StringBuffer sb) throws ProviderException {
145: ContainerProviderContext cpc = (ContainerProviderContext) getProviderContext();
146: return RenderingUtil.renderEditContent(req, cpc, getName(), sb);
147: }
148:
149: /**
150: * Get the most specific JSP path for the given channel name and
151: * file name. This method overrides the <code>JSPProvider.
152: * getMostSpecificJSPPath()</code>
153: * method and calls <code>RenderingUtils.getTemplateMostSpecificPath</code>
154: * to get the real path.
155: *
156: * @param pc The ProviderContext.
157: * @param name The channel name.
158: * @param file The jsp file name.
159: *
160: * @return
161: *
162: * @exception ProviderException if an error occurs in getting the path.
163: * @see com.sun.portal.providers.jsp.JSPProvider#getMostSpecificJSPPath
164: * @see com.sun.portal.wireless.providers.rendering.
165: * RenderingUtil#getTemplateMostSpecificPath
166: **/
167:
168: protected File getMostSpecificJSPPath(ProviderContext pc,
169: String name, String file) throws ProviderException {
170: File jspPath = null;
171: try {
172: jspPath = RenderingUtil.getTemplateMostSpecificPath(
173: (ContainerProviderContext) pc, name, file);
174: } catch (ProviderContextException e) {
175: if (logger.isLoggable(Level.SEVERE))
176: logger.log(Level.SEVERE, "PSMA_CSPWPR0008", e);
177:
178: throw new ProviderException(e.getMessage());
179: }
180:
181: return jspPath;
182: }
183:
184: /**
185: * Get the most specific JSP path for the given channel name and
186: * file name. This method overrides the <code>JSPProvider.
187: * getExistingJSPPath()</code>
188: * method and calls <code>RenderingUtils.getTemplatePath</code> to get
189: * the real path.
190: *
191: * @param pc The ProviderContext.
192: * @param name The channel name.
193: * @param file The jsp file name.
194: *
195: * @return
196: *
197: * @exception ProviderException if an error occurs in getting the path.
198: * @see com.sun.portal.providers.jsp.JSPProvider#getExistingJSPPath
199: * @see com.sun.portal.wireless.providers.rendering.
200: * RenderingUtil#getTemplatePath
201: **/
202: public File getExistingJSPPath(ProviderContext pc, String name,
203: String file) throws ProviderException {
204: File jspPath = null;
205: try {
206: jspPath = RenderingUtil.getTemplatePath(
207: (ContainerProviderContext) pc, name, file);
208: } catch (ProviderContextException e) {
209: if (logger.isLoggable(Level.SEVERE))
210: logger.log(Level.SEVERE, "PSMA_CSPWPR0008", e);
211: throw new ProviderException(e.getMessage());
212: }
213:
214: return jspPath;
215: }
216: }
|