incubator-adffaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mat...@apache.org
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 GMT
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



Mime
View raw message