You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/04/29 04:41:10 UTC
svn commit: r939183 - in /myfaces/tomahawk/trunk/examples/simple20: pom.xml
src/main/java/org/apache/myfaces/examples/webapp/SourceCodeServlet.java
src/main/webapp/META-INF/templates/mbean_source.xhtml
Author: lu4242
Date: Thu Apr 29 02:41:10 2010
New Revision: 939183
URL: http://svn.apache.org/viewvc?rev=939183&view=rev
Log:
fix source code servlet to output bean info
Modified:
myfaces/tomahawk/trunk/examples/simple20/pom.xml
myfaces/tomahawk/trunk/examples/simple20/src/main/java/org/apache/myfaces/examples/webapp/SourceCodeServlet.java
myfaces/tomahawk/trunk/examples/simple20/src/main/webapp/META-INF/templates/mbean_source.xhtml
Modified: myfaces/tomahawk/trunk/examples/simple20/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/examples/simple20/pom.xml?rev=939183&r1=939182&r2=939183&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/examples/simple20/pom.xml (original)
+++ myfaces/tomahawk/trunk/examples/simple20/pom.xml Thu Apr 29 02:41:10 2010
@@ -48,6 +48,9 @@
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
+ <resource>
+ <directory>src/main/java</directory>
+ </resource>
</resources>
<plugins>
Modified: myfaces/tomahawk/trunk/examples/simple20/src/main/java/org/apache/myfaces/examples/webapp/SourceCodeServlet.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/examples/simple20/src/main/java/org/apache/myfaces/examples/webapp/SourceCodeServlet.java?rev=939183&r1=939182&r2=939183&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/examples/simple20/src/main/java/org/apache/myfaces/examples/webapp/SourceCodeServlet.java (original)
+++ myfaces/tomahawk/trunk/examples/simple20/src/main/java/org/apache/myfaces/examples/webapp/SourceCodeServlet.java Thu Apr 29 02:41:10 2010
@@ -20,6 +20,9 @@ package org.apache.myfaces.examples.weba
import javax.servlet.*;
import javax.servlet.http.*;
+
+import org.apache.myfaces.shared_tomahawk.util.ClassUtils;
+
import java.io.*;
public class SourceCodeServlet extends HttpServlet
@@ -32,31 +35,80 @@ public class SourceCodeServlet extends H
// remove the '*.source' suffix that maps to this servlet
int chopPoint = webPage.indexOf(".source");
- webPage = webPage.substring(0, chopPoint - 3);
- webPage += "xhtml"; // replace jsf with xhtml
+ String path = webPage.substring(0, chopPoint);
- // get the actual file location of the requested resource
- String realPath = getServletConfig().getServletContext().getRealPath(webPage);
+ if (path.endsWith(".java"))
+ {
+ path = path.substring(0,path.length()-5);
+
+ if (path.contains("org.apache.myfaces.examples"))
+ {
+ path = path.replace('.', '/') + ".java";
+
+ InputStream is = ClassUtils.getResourceAsStream(path);
+
+ // output an HTML page
+ res.setContentType("text/plain");
+
+ if (is != null)
+ {
+ // print some html
+ ServletOutputStream out = res.getOutputStream();
+
+ // print the file
+ InputStream in = null;
+ try
+ {
+ in = new BufferedInputStream(is);
+ int ch;
+ while ((ch = in.read()) !=-1)
+ {
+ out.print((char)ch);
+ }
+ }
+ finally {
+ if (in != null) in.close(); // very important
+ }
+ }
+ else
+ {
+ res.sendError(HttpServletResponse.SC_NOT_FOUND);
+ }
+ }
+ else
+ {
+ res.sendError(HttpServletResponse.SC_NOT_FOUND);
+ }
+ }
+ else
+ {
+
+ webPage = webPage.substring(0, chopPoint - 3);
+ webPage += "xhtml"; // replace jsf with xhtml
+
+ // get the actual file location of the requested resource
+ String realPath = getServletConfig().getServletContext().getRealPath(webPage);
- // output an HTML page
- res.setContentType("text/plain");
+ // output an HTML page
+ res.setContentType("text/plain");
- // print some html
- ServletOutputStream out = res.getOutputStream();
+ // 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)
+ // print the file
+ InputStream in = null;
+ try
{
- out.print((char)ch);
+ 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
}
- }
- finally {
- if (in != null) in.close(); // very important
}
}
}
Modified: myfaces/tomahawk/trunk/examples/simple20/src/main/webapp/META-INF/templates/mbean_source.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/examples/simple20/src/main/webapp/META-INF/templates/mbean_source.xhtml?rev=939183&r1=939182&r2=939183&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/examples/simple20/src/main/webapp/META-INF/templates/mbean_source.xhtml (original)
+++ myfaces/tomahawk/trunk/examples/simple20/src/main/webapp/META-INF/templates/mbean_source.xhtml Thu Apr 29 02:41:10 2010
@@ -5,6 +5,7 @@
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:t="http://myfaces.apache.org/tomahawk">
<body>
<ui:composition>
@@ -12,10 +13,12 @@
<br/>
<t:dataList value="#{accessedBeans.beanList}" var="accessedBean" layout="unorderedList">
+ <h:outputLink value="#{accessedBean.clazz}.java.source" disabled="#{!fn:startsWith(accessedBean.clazz,'org.apache.myfaces.examples')}">
<h:outputText value="Usage of bean with name : "/>
<h:outputText value="#{accessedBean.name}"/>
<h:outputText value=" and class : "/>
<h:outputText value="#{accessedBean.clazz}"/>
+ </h:outputLink>
</t:dataList>
</ui:composition>
</body>