I was expanding the usefullness of the echo tags in JSSI. I have implemented the changes to mirror what I see when I compare the following tags in a .jhtml file versus a .shtml file on Apache Win32(NT4sp5) 1.3.9 JServ 1.0. ================================================================= SERVER_SOFTWARE=<!--#ECHO VAR="SERVER_SOFTWARE" --><br> SERVER_NAME=<!--#ECHO VAR="SERVER_NAME" --><br> GATEWAY_INTERFACE=<!--#ECHO VAR="GATEWAY_INTERFACE" --><br> SERVER_PROTOCOL=<!--#ECHO VAR="SERVER_PROTOCOL" --><br> SERVER_PORT=<!--#ECHO VAR="SERVER_PORT" --><br> REQUEST_METHOD=<!--#ECHO VAR="REQUEST_METHOD" --><br> PATH_INFO=<!--#ECHO VAR="PATH_INFO" --><br> PATH_TRANSLATED=<!--#ECHO VAR="PATH_TRANSLATED" --><br> SCRIPT_NAME=<!--#ECHO VAR="SCRIPT_NAME" --><br> QUERY_STRING=<!--#ECHO VAR="QUERY_STRING" --><br> REMOTE_HOST=<!--#ECHO VAR="REMOTE_HOST" --><br> REMOTE_ADDR=<!--#ECHO VAR="REMOTE_ADDR" --><br> AUTH_TYPE=<!--#ECHO VAR="AUTH_TYPE" --><br> REMOTE_USER=<!--#ECHO VAR="REMOTE_USER" --><br> CONTENT_TYPE=<!--#ECHO VAR="CONTENT_TYPE" --><br> CONTENT_LENGTH=<!--#ECHO VAR="CONTENT_LENGTH" --><br> HTTP_ACCEPT=<!--#ECHO VAR="HTTP_ACCEPT" --><br> HTTP_USER=<!--#ECHO VAR="HTTP_USER_AGENT" --><br> HTTP_REFERER=<!--#ECHO VAR="HTTP_REFERER" --><br> REQUEST_URI=<!--#ECHO VAR="REQUEST_URI" --><br> DOCUMENT_ROOT=<!--#ECHO VAR="DOCUMENT_ROOT" --><br> DOCUMENT_NAME=<!--#ECHO VAR="DOCUMENT_NAME" --><br> LAST_MODIFIED=<!--#ECHO VAR="LAST_MODIFIED" --><br> DATE_GMT=<!--#ECHO VAR="DATE_GMT" --><br> DATE_LOCAL=<!--#ECHO VAR="DATE_LOCAL" --><br> ================================================================= I also fixed a bug with DATE_GMT where it displayed the local time, not the time in GMT. This is my first contribution to an OSS project, so please be kind on my code, and please give me feedback on the quality of code(i.e. this sucks, great, etc.). I have yet to implement, SERVER_SOFTWARE GATEWAY_INTERFACE PATH_INFO PATH_TRANSLATED As I see it, you can't use PATH_INFO or PATH_TRANSLATED while using JSSI because you are using the path info to get the file to parse. I don't know how to access ServletContext from EchoTagHandler, so I can't grab getServerInfo(), and I don't know what defines GATEWAY_INTERFACE, but other than that I think that it is complete. I also have the dates formating to the default that apache sets(in Win32 at least). This format is: EEEE, dd-MMM-yyyy HH:mm:ss zzzz Tuesday, 14-Sep-1999 13:16:36 Central Daylight Time There is a "bug" in how apache handles GMT, so to follow apache, GMT is formated as such. EEEE, dd-MMM-yyyy HH:mm:ss zzzz Tuesday, 14-Sep-1999 18:16:36 GMT Also I formated the code to the Sun Java Code Conventions. Is there a published Apache Code Conventions for Java? I look forward to hearing comments. Thanks. Noah Nordrum [EMAIL PROTECTED] Carpe Diem. A fish a day keeps the doctor away. ===EchoTagHandler.java============================================= /* * Copyright (c) 1997-1999 The Java Apache Project. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by the Java Apache * Project for use in the Apache JServ servlet engine project * (http://java.apache.org/)." * * 4. The names "Apache JServ", "Apache JServ Servlet Engine" and * "Java Apache Project" must not be used to endorse or promote products * derived from this software without prior written permission. * * 5. Products derived from this software may not be called "Apache JServ" * nor may "Apache" nor "Apache JServ" appear in their names without * prior written permission of the Java Apache Project. * * 6. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by the Java Apache * Project for use in the Apache JServ servlet engine project * (http://java.apache.org/)." * * THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "AS IS" AND ANY * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JAVA APACHE PROJECT OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * This software consists of voluntary contributions made by many * individuals on behalf of the Java Apache Group. For more information * on the Java Apache Project and the Apache JServ Servlet Engine project, * please see <http://java.apache.org/>. * */ /* * $Id: EchoTagHandler.java,v 1.2 1999/06/09 22:41:25 hzeller Exp $ */ package org.apache.servlet.ssi; import java.io.IOException; import java.text.SimpleDateFormat; import java.text.DateFormat; import java.util.Date; import javax.servlet.*; import javax.servlet.http.*; import org.apache.java.util.SGMLTag; import org.apache.java.io.PositionReader; /** * A minimalist implementation of the SSI * <code>echo</code> command. * It supports the following variables:<ul> * <li><code>SERVER_SOFTWARE</code> Not yet. * <li><code>SERVER_NAME</code> * <li><code>GATEWAY_INTERFACE</code> Not yet. * <li><code>SERVER_PROTOCOL</code> * <li><code>SERVER_PORT</code> * <li><code>REQUEST_METHOD</code> * <li><code>PATH_INFO</code> * <li><code>PATH_TRANSLATED</code> * <li><code>SCRIPT_NAME</code> * <li><code>QUERY_STRING</code> * <li><code>REMOTE_HOST</code> * <li><code>REMOTE_ADDR</code> * <li><code>AUTH_TYPE</code> * <li><code>REMOTE_USER</code> * <li><code>CONTENT_TYPE</code> * <li><code>CONTENT_LENGTH</code> * <li><code>HTTP_ACCEPT</code> * <li><code>HTTP_USER</code> * <li><code>HTTP_REFERER</code> * <li><code>REQUEST_URI</code> * <li><code>DOCUMENT_ROOT</code> * <li><code>DOCUMENT_NAME</code> * <li><code>LAST_MODIFIED</code> * <li><code>DATE_GMT</code> * <li><code>DATE_LOCAL</code> * </ul> * @author Matthias Wiesmann * @version $Revision: 1.2 $ $Date: 1999/06/09 22:41:25 $ * @author Noah Nordrum * @version $Revision: 1.3 $ $Date: 1999/09/14 14:35:24 $ */ public class EchoTagHandler extends SSITagHandler { protected final static String VAR_PARAM = "VAR"; protected final static String ABOUT_MSG = "Java SSI Implementation by Matthias Wiesmann"; public EchoTagHandler() } protected String echo (SSIContext context, String var) { if (var.equals("ABOUT_SSI")) { return ABOUT_MSG ; } else if (var.equals("SERVER_SOFTWARE")) { return "(none)"; } else if (var.equals("SERVER_NAME")) { return context.getServletRequest().getServerName(); } else if (var.equals("GATEWAY_INTERFACE")) { return "(none)"; } else if (var.equals("SERVER_PROTOCOL")) { return context.getServletRequest().getProtocol(); } else if (var.equals("SERVER_PORT")) { return String.valueOf(context.getServletRequest().getServerPort()); } else if (var.equals("REQUEST_METHOD")) { return context.getServletRequest().getMethod(); } else if (var.equals("PATH_INFO")) { return "(none)"; } else if (var.equals("PATH_TRANSLATED")) { return "(none)"; } else if (var.equals("SCRIPT_NAME")) { return context.getServletRequest().getPathInfo(); } else if (var.equals("QUERY_STRING")) { return context.getServletRequest().getQueryString(); } else if (var.equals("REMOTE_HOST")) { String r = context.getServletRequest().getRemoteHost(); return (r != null) ? r : "(none)"; } else if (var.equals("REMOTE_ADDR")) { String r = context.getServletRequest().getRemoteAddr(); return (r != null) ? r : "(none)"; } else if (var.equals("AUTH_TYPE")) { String r = context.getServletRequest().getAuthType(); return (r != null) ? r : "(none)"; } else if (var.equals("REMOTE_USER")) { String r = context.getServletRequest().getRemoteUser(); return (r != null) ? r : "(none)"; } else if (var.equals("CONTENT_TYPE")) { String r = context.getServletRequest().getContentType(); return (r != null) ? r : "(none)"; } else if (var.equals("CONTENT_LENGTH")) { int r = context.getServletRequest().getContentLength(); return (r != -1) ? String.valueOf(r) : "(none)"; } else if (var.equals("HTTP_ACCEPT")) { return context.getServletRequest().getHeader("Accept"); } else if (var.equals("HTTP_USER_AGENT")) { return context.getServletRequest().getHeader("User-Agent"); } else if (var.equals("HTTP_REFERER")) { String r = context.getServletRequest().getHeader("Referer"); return (r != null) ? r : "(none)"; } else if (var.equals("REQUEST_URI")) { return context.getServletRequest().getRequestURI() + "?" + context.getServletRequest().getQueryString(); } else if (var.equals("DOCUMENT_ROOT")) { String r = context.getServletRequest().getRealPath("/"); if (r.endsWith("/")) { r = r.substring(0,r.length()-1); } return r; } else if (var.equals("DOCUMENT_NAME")) { return context.file.getName(); } else if (var.equals("LAST_MODIFIED")) { return FLastModTagHandler.lastModified(context, context.file); } else if (var.equals("DATE_GMT")) { return context.format(new Date(), "GMT"); } else if (var.equals("DATE_LOCAL")) { return context.format(new Date()); } else { return "(none)"; } } // echo /** * actually perform the action associated with this tag. */ public void executeTag (ParseContext context) throws IOException { final String var = parameters.value(VAR_PARAM, null); if (var == null) { throw new IOException("no VAR parameter!"); } ServletOutputStream out = context.getServletResponse().getOutputStream(); out.print(echo((SSIContext) context, var)); } // executeTag } ===SSIContext.java============================================= /* * Copyright (c) 1997-1999 The Java Apache Project. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by the Java Apache * Project for use in the Apache JServ servlet engine project * (http://java.apache.org/)." * * 4. The names "Apache JServ", "Apache JServ Servlet Engine" and * "Java Apache Project" must not be used to endorse or promote products * derived from this software without prior written permission. * * 5. Products derived from this software may not be called "Apache JServ" * nor may "Apache" nor "Apache JServ" appear in their names without * prior written permission of the Java Apache Project. * * 6. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by the Java Apache * Project for use in the Apache JServ servlet engine project * (http://java.apache.org/)." * * THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "AS IS" AND ANY * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JAVA APACHE PROJECT OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * This software consists of voluntary contributions made by many * individuals on behalf of the Java Apache Group. For more information * on the Java Apache Project and the Apache JServ Servlet Engine project, * please see <http://java.apache.org/>. * */ package org.apache.servlet.ssi; import java.util.Date; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.io.File; import java.util.Vector; import javax.servlet.http.*; /** * This class represents an SSI context. * Its lifetime is one interpretation of a given page. * <br> * An SSI context contains different settings * associated with a file: date and size formats. * The context is used by most instructions * and is set by the <code>config</code> * SSI instruction.<br> * Additional data should be handled here. * @author Matthias Wiesmann * @version $Revision: 1.2 $ $Date: 1999/06/09 22:41:28 $ * @see org.apache.servlet.ssi.SSI */ public class SSIContext extends AbstractParseContext { public SSIContext(File file, HttpServletRequest req, HttpServletResponse res, PageParser parser) { super (req, res); this.file = file; this.parser = parser; } /** The default <code>DateFormat</code> */ public DateFormat date_format = null; /** The default <code>SimpleDateFormat</code> */ public SimpleDateFormat sdf = null; /** The file that is being handled */ public File file ; /** Whether size should be truncated to bytes */ public boolean abbrev = false ; /** The page Parser */ public PageParser parser; /** Formats a Date according to the current context * @param date the date to format * @return a string containing the formated date */ public String format(Date date) { return format(date, System.getProperty("user.timezone")); } // format /** Formats a Date according to the current context and time zone * @param date the date to format * @param zone the time zone to format to * @param style the <CODE>DateFormat</CODE> style to format to * @return a string containing the formated date */ public String format(Date date, String zone) { if (zone.equals("GMT")) { sdf = new SimpleDateFormat("EEEE, dd-MMM-yyyy HH:mm:ss z"); } else { sdf = new SimpleDateFormat("EEEE, dd-MMM-yyyy HH:mm:ss zzzz"); } sdf.setTimeZone(java.util.TimeZone.getTimeZone(zone)); return sdf.format(date); } // format } // SSIContext ------------------------------------------------------------ To subscribe: [EMAIL PROTECTED] To unsubscribe: [EMAIL PROTECTED] Problems?: [EMAIL PROTECTED]
