Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
$URL: https://source.sakaiproject.org/svn/jsf/tags/sakai-10.0/jsf-widgets/src/java/org/sakaiproject/jsf/renderer/AppletRenderer.java $ $Id: AppletRenderer.java 105077 2012-02-24 22:54:29Z ottenhoff@longsight.com $ Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008 The Sakai Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.opensource.org/licenses/ECL-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 
 
 
 package org.sakaiproject.jsf.renderer;
 
 
 import java.util.Map;

Description:

Render an applet in a browser-indepemdent way

Copyright: Copyright (c) 2005

Organization: Sakai Project

Author(s):
Ed Smiley
Version:
$Id: AppletRenderer.java 105077 2012-02-24 22:54:29Z ottenhoff@longsight.com $
 
 
 public class AppletRenderer
   extends Renderer
 {
   private static final String IE_CODEBASE =
     "http://java.sun.com/products/plugin/1.4/jinstall-14-win32.cab#Version=1,4,0,mn";
   private static final String NS_PLUGINSPAGE =
     "http://java.sun.com/products/plugin/1.4/plugin-install.html";
   private static final String VERSION = "1.4";
   private static final String DEFAULT_WIDTH = "200";
   private static final String DEFAULT_HEIGHT = "200";
   private static final String DEFAULT_VSPACE = "0";
   private static final String DEFAULT_HSPACE = "0";
 
   public boolean supportsComponentType(UIComponent component)
   {
     return (component instanceof UIOutput);
   }


  

Parameters:
context FacesContext for the current request
component UIComponent being rendered
Throws:
java.io.IOException if an input/output error occurs
Todo:
apply attributes

Faces render output method .

Method Generator: org.sakaiproject.jsf.devtool.RenderMaker

 
   public void encodeBegin(FacesContext contextUIComponent component)
     throws IOException
   {
     if (!component.isRendered())
     {
       return;
     }
 
     String width = (String) RendererUtil.getDefaultedAttribute(contextcomponent"width");
     String height = (String) RendererUtil.getDefaultedAttribute(contextcomponent"height");
     String vspace = (String) RendererUtil.getDefaultedAttribute(contextcomponent"vspace");
     String hspace = (String) RendererUtil.getDefaultedAttribute(contextcomponent"hspace");
 
     String javaClass = (String) RendererUtil.getAttribute(contextcomponent"javaClass");
     String javaArchive = (String) RendererUtil.getAttribute(contextcomponent"javaArchive");
     String codebase = (String) RendererUtil.getAttribute(contextcomponent"codebase");
     String paramList = (String) RendererUtil.getAttribute(contextcomponent"paramList");
 
     String name = (String) RendererUtil.getAttribute(contextcomponent"name");
     Map appParamMap = makeAppletParameters(paramList);
     
     if(null!=codebaseappParamMap.put("codebase"codebase);
    if(null!=javaArchiveappParamMap.put("archive"javaArchive);
    //if(null!=name) appParamMap.put("id", name);
    appParamMap.put("code"javaClass);
    ResponseWriter writer = context.getResponseWriter();
    renderApplet(widthheightvspacehspacecodebasejavaClass,
      javaArchive
      name
      appParamMapwriter);
  }

    
Accept a comma separated list of name value pairs.

Parameters:
paramList
Returns:
Todo:
quotations to escape out "," and "=". Usage: <sakai:applet ... paramList="param1=value1,param2=value2,..."...
  private Map makeAppletParameters(String paramList)
  {
    Map appParamMap = new HashMap();
    if (paramList != null){
      StringTokenizer paramsTokenizer = new StringTokenizer(paramList","false);
      while (paramsTokenizer.hasMoreTokens())
      {
        StringTokenizer nameValueTokenizer =
          new StringTokenizer(paramsTokenizer.nextToken(), "="false);
        if (nameValueTokenizer.countTokens()<2) continue;
        String name = nameValueTokenizer.nextToken();
        String value = nameValueTokenizer.nextToken();
        appParamMap.put(namevalue);
      }
    }
    return appParamMap;
  }

  
Render applet in browser independent way.

Parameters:
width value of the corresponding tag attribute
height value of the corresponding tag attribute
vspace value of the corresponding tag attribute
hspace value of the corresponding tag attribute
codebase value of the corresponding tag attribute
javaClass value of the corresponding tag attribute
javaArchive value of the corresponding tag attribute
version value of the corresponding tag attribute
appParamMap comma separated list of name value pairs from paramList tag attribute
writer ResponseWriter
Throws:
java.io.IOException
//   <OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
//    width="200" height="200" align="baseline"
//    codebase="http://java.sun.com/products/plugin/1.4/jinstall-14-win32.cab#Version=1,4,0,mn">
//    <PARAM NAME="code" VALUE="XYZApp.class">
//    <PARAM NAME="codebase" VALUE="html/">
//    <PARAM NAME="type" VALUE="application/x-java-applet;jpi-version=1.4">
//    <PARAM NAME="model" VALUE="models/HyaluronicAcid.xyz">
//    <PARAM NAME="scriptable" VALUE="true">
//    <COMMENT>
//        <EMBED type="application/x-java-applet;jpi-version=1.4" width="200"
//           height="200" align="baseline" code="XYZApp.class"
//           codebase="html/" model="models/HyaluronicAcid.xyz"
//           pluginspage="http://java.sun.com/j2se/1.4/download.html">
//            <NOEMBED>
//                No Java 2 SDK, Standard Edition v 1.4 support for APPLET!!
//            </NOEMBED>
//        </EMBED>
//    </COMMENT>
//</OBJECT>
  private void renderApplet(String widthString heightString vspace,
    String hspaceString codebaseString javaClassString javaArchive,
    String name,
    Map appParamMapResponseWriter writer)
    throws IOException
  {
    writer.write("");
    writer.write("<OBJECT ");
    writer.write("    classid=\"clsid:8AD9C840-044E-11D1-B3E9-00805F499D93\" ");
    writer.write("    width=\"" + width + "\" ");
    writer.write("    height=\"" + height + "\" ");
    writer.write("    hspace=\"" + hspace + "\" ");
    writer.write("    vspace=\"" + vspace + "\" ");
    writer.write("    codebase=\"" +  + "\"");
    writer.write("    archive=\"" + javaArchive + "\"");
    writer.write("    id=\"" + name + "\"");
    writer.write(">");
//    writer.write("    <PARAM name=\"java_code\" value=\"" + javaClass + "\">");
//    writer.write("    <PARAM name=\"java_archive\" value=\"" + javaArchive +
//      ">");
    writer.write(
      "    <PARAM name=\"type\" value=\"application/x-java-applet;version=" +
       + "\">");
    renderObjectParams(writerappParamMap);
    writer.write("<COMMENT>");
    writer.write("<EMBED ");
    writer.write("    type=\"application/x-java-applet;version=" +  +
      "\" ");
    writer.write("    width=\"" + width + "\" ");
    writer.write("    height=\"" + height + "\" ");
    writer.write("    hspace=\"" + hspace + "\" ");
    writer.write("    vspace=\"" + vspace + "\" ");
    writer.write("    pluginspage=\"" +  + "\" ");
//    writer.write("    java_code=\"" + javaClass + "\"");
//    writer.write("    java_archive=\"" + javaArchive + "");
    // if the name is not null duplicate it to the id param
    if(null!=name) {
    	appParamMap.put("id"name);
    	appParamMap.put("name"name);
    }
    renderEmbedParams(writerappParamMap);
    writer.write("/>");
    writer.write("");
    writer.write("<NOEMBED>");
    writer.write("    <font color=\"red\">");
    writer.write("    Note: Requires Java Plug-in " +  + ".");
    writer.write("    </b></font><br/>");
    writer.write("</NOEMBED>");
    writer.write("</COMMENT>");
    writer.write("</OBJECT>");
  }

    
Render Map of Embed tag params,

Parameters:
writer
appParamMap
Throws:
java.io.IOException
  private void renderEmbedParams(ResponseWriter writerMap appParamMap)
    throws IOException
  {
	  Iterator paramIter = appParamMap.entrySet().iterator();
	  while (paramIter.hasNext())
	  {
		  Entry entrySet = (EntryparamIter.next();
		  String name = (StringentrySet.getKey();
		  String value = (StringentrySet.getValue();
		  writer.write("    " + name + "=\"" + value + "\" ");
	  }
  }

  
Render Map of Object PARAMs.

Parameters:
writer
appParamMap
Throws:
java.io.IOException
  private void renderObjectParams(ResponseWriter writerMap appParamMap)
    throws IOException
  {
    Iterator iter = appParamMap.entrySet().iterator();
    while (iter.hasNext())
    {
      Entry entrySet = (Entryiter.next();
      String name = (StringentrySet.getKey();
      String value = (StringentrySet.getValue();
      writer.write("    <PARAM name=\"" +
        name +
        "\" value=\"" +
        value + "\">");
    }
  }
New to GrepCode? Check out our FAQ X