From adffaces-commits-return-449-apmail-incubator-adffaces-commits-archive=incubator.apache.org@incubator.apache.org Sat Jul 29 21:12:44 2006 Return-Path: Delivered-To: apmail-incubator-adffaces-commits-archive@locus.apache.org Received: (qmail 95108 invoked from network); 29 Jul 2006 21:12:43 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 29 Jul 2006 21:12:43 -0000 Received: (qmail 92972 invoked by uid 500); 29 Jul 2006 21:12:43 -0000 Delivered-To: apmail-incubator-adffaces-commits-archive@incubator.apache.org Received: (qmail 92952 invoked by uid 500); 29 Jul 2006 21:12:43 -0000 Mailing-List: contact adffaces-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: adffaces-dev@incubator.apache.org Delivered-To: mailing list adffaces-commits@incubator.apache.org Received: (qmail 92936 invoked by uid 99); 29 Jul 2006 21:12:43 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 29 Jul 2006 14:12:43 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 29 Jul 2006 14:12:42 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 3E8901A981A; Sat, 29 Jul 2006 14:12:22 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r426838 - /incubator/adffaces/branches/matzew-component-renaming/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/webapp/SourceCodeServlet.java Date: Sat, 29 Jul 2006 21:12:21 -0000 To: adffaces-commits@incubator.apache.org From: matzew@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060729211222.3E8901A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: matzew Date: Sat Jul 29 14:12:21 2006 New Revision: 426838 URL: http://svn.apache.org/viewvc?rev=426838&view=rev Log: Added source code servlet Added: incubator/adffaces/branches/matzew-component-renaming/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/webapp/SourceCodeServlet.java (with props) Added: incubator/adffaces/branches/matzew-component-renaming/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/webapp/SourceCodeServlet.java URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-component-renaming/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/webapp/SourceCodeServlet.java?rev=426838&view=auto ============================================================================== --- incubator/adffaces/branches/matzew-component-renaming/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/webapp/SourceCodeServlet.java (added) +++ incubator/adffaces/branches/matzew-component-renaming/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/webapp/SourceCodeServlet.java Sat Jul 29 14:12:21 2006 @@ -0,0 +1,69 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache 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.apache.org/licenses/LICENSE-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.apache.myfaces.trinidaddemo.webapp; + +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; + +public class SourceCodeServlet extends HttpServlet +{ + public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException + { + String webPage = req.getServletPath(); + + // remove the '*.source' suffix that maps to this servlet + int source = webPage.indexOf(".source"); + webPage = webPage.substring(0, source); + + //remove "/faces" mapping + webPage = StringUtils.remove(webPage, "/faces"); + + // get the actual file location of the requested resource + String realPath = getServletConfig().getServletContext().getRealPath(webPage); + + // output an HTML page + res.setContentType("text/plain"); + + // print some html + ServletOutputStream out = res.getOutputStream(); + + // print the file + InputStream in = null; + try + { + in = new BufferedInputStream(new FileInputStream(realPath)); + int ch; + while ((ch = in.read()) !=-1) + { + out.print((char)ch); + } + } + finally { + if (in != null) in.close(); // very important + } +} + +} \ No newline at end of file Propchange: incubator/adffaces/branches/matzew-component-renaming/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/webapp/SourceCodeServlet.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/adffaces/branches/matzew-component-renaming/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/webapp/SourceCodeServlet.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL