commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tcu...@apache.org
Subject svn commit: r522301 - in /jakarta/commons/sandbox/jci/trunk: ./ core/src/main/java/org/apache/commons/jci/compilers/ core/src/main/java/org/apache/commons/jci/listeners/ examples/src/main/java/org/apache/commons/jci/examples/configuration/ examples/src...
Date Sun, 25 Mar 2007 16:49:17 GMT
Author: tcurdt
Date: Sun Mar 25 09:49:14 2007
New Revision: 522301

URL: http://svn.apache.org/viewvc?view=rev&rev=522301
Log:
fixed up the jsp example,
implemented the configuration reloading example


Added:
    jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/Configurable.java
  (with props)
    jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/ConfigurationException.java
  (with props)
    jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/Something.java
  (with props)
    jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspGenerator.java
  (with props)
Modified:
    jakarta/commons/sandbox/jci/trunk/TODO.txt
    jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java
    jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/CompilingListener.java
    jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/ConfigurationReloading.java
    jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspReader.java
    jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/ServerPageServlet.java
    jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/Test.jsp
    jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/org/vafer/Test.jsp

Modified: jakarta/commons/sandbox/jci/trunk/TODO.txt
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/TODO.txt?view=diff&rev=522301&r1=522300&r2=522301
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/TODO.txt (original)
+++ jakarta/commons/sandbox/jci/trunk/TODO.txt Sun Mar 25 09:49:14 2007
@@ -8,8 +8,8 @@
 o documentation
 o dependency analysis for proper re-try after errors
 o removing of anonymous classes if parent class is being removed
-o refactore store interface to provide package information
 o ability to add (contents of) jars to the store ...and be able to remove them again
 o maven plugin to compile with any of the compilers -> codehaus.org/mojo
 o compiler discovery via META-INF
 o common compiler configuration
+o build javac classpath from provided classloader
\ No newline at end of file

Modified: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java?view=diff&rev=522301&r1=522300&r2=522301
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java
Sun Mar 25 09:49:14 2007
@@ -23,7 +23,7 @@
  * 
  * If you need more specific settings you have to provide
  * the native compiler configurations to the compilers.
- * Writing of custom factory is suggested. 
+ * Writing of a custom factory is suggested. 
  * 
  * @author tcurdt
  */

Modified: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/CompilingListener.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/CompilingListener.java?view=diff&rev=522301&r1=522300&r2=522301
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/CompilingListener.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/CompilingListener.java
Sun Mar 25 09:49:14 2007
@@ -96,6 +96,31 @@
         transactionalStore.onStart();
     }
 
+    public String[] getResourcesToCompile( final FilesystemAlterationObserver pObserver )
{
+        final Collection created = getCreatedFiles();
+        final Collection changed = getChangedFiles();
+
+        final Collection resourceNames = new ArrayList();
+        
+        for (final Iterator it = created.iterator(); it.hasNext();) {
+            final File createdFile = (File) it.next();
+            if (createdFile.getName().endsWith(getSourceFileExtension())) {
+            	resourceNames.add(getSourceNameFromFile(pObserver, createdFile));
+            }
+        }
+        
+        for (final Iterator it = changed.iterator(); it.hasNext();) {
+            final File changedFile = (File) it.next();
+            if (changedFile.getName().endsWith(getSourceFileExtension())) {
+            	resourceNames.add(getSourceNameFromFile(pObserver, changedFile));
+            }
+        }
+    	
+        final String[] result = new String[resourceNames.size()];
+        resourceNames.toArray(result);
+        return result;
+    }
+    
     public boolean isReloadRequired( final FilesystemAlterationObserver pObserver ) {
     	boolean reload = false;
     	
@@ -112,53 +137,26 @@
                 final String resourceName = ConversionUtils.getResourceNameFromFileName(ConversionUtils.relative(pObserver.getRootDirectory(),
deletedFile));
                 
                 if (resourceName.endsWith(getSourceFileExtension())) {
+                	// if source resource got removed delete the corresponding class 
                     transactionalStore.remove(ConversionUtils.stripExtension(resourceName)
+ ".class");
                 } else {
+                	// ordinary resource to be removed
                     transactionalStore.remove(resourceName);                	
                 }
-
                 
                 // FIXME: does not remove nested classes
                 
             }
             reload = true;
         }
-                        
-        final Collection compileables = new ArrayList();
-        
-        for (final Iterator it = created.iterator(); it.hasNext();) {
-            final File createdFile = (File) it.next();
-            if (createdFile.getName().endsWith(getSourceFileExtension())) {
-                compileables.add(createdFile);
-            }
-        }
-        
-        for (final Iterator it = changed.iterator(); it.hasNext();) {
-            final File changedFile = (File) it.next();
-            if (changedFile.getName().endsWith(getSourceFileExtension())) {
-                compileables.add(changedFile);
-            }
-        }
-
-        if (compileables.size() > 0) {
+                                
+        final String[] resourcesToCompile = getResourcesToCompile(pObserver);
 
-            log.debug(compileables.size() + " classes to compile");
+        if (resourcesToCompile.length > 0) {
 
-            int i = 0;
-            final String[] sourceFiles = new String[compileables.size()];            
-            for (Iterator it = compileables.iterator(); it.hasNext();) {
-                final File file = (File) it.next();
-                final String resourceName = getSourceNameFromFile(pObserver, file);
-                sourceFiles[i] = resourceName;
-                i++;
-            }
+            log.debug(resourcesToCompile.length + " classes to compile");
             
-            final CompilationResult result =
-                compiler.compile(
-                    sourceFiles,
-                    reader,
-                    transactionalStore
-                    );
+            final CompilationResult result = compiler.compile(resourcesToCompile, reader,
transactionalStore);
             
             synchronized(this) {
                 lastResult = result;
@@ -167,16 +165,13 @@
             final CompilationProblem[] errors = result.getErrors();
             final CompilationProblem[] warnings = result.getWarnings();
             
-            log.debug(
-                    errors.length + " errors, " +
-                    warnings.length + " warnings"
-                    );
+            log.debug(errors.length + " errors, " + warnings.length + " warnings");
         
             if (errors.length > 0) {
                 // FIXME: they need to be marked for re-compilation
                 // and then added as compileables again
-                for (int j = 0; j < sourceFiles.length; j++) {
-                    transactionalStore.remove(sourceFiles[j]);
+                for (int j = 0; j < resourcesToCompile.length; j++) {
+                    transactionalStore.remove(resourcesToCompile[j]);
                 }
             }
             

Added: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/Configurable.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/Configurable.java?view=auto&rev=522301
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/Configurable.java
(added)
+++ jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/Configurable.java
Sun Mar 25 09:49:14 2007
@@ -0,0 +1,9 @@
+package org.apache.commons.jci.examples.configuration;
+
+import java.util.Properties;
+
+public interface Configurable {
+	
+	void configure( Properties properties ) throws ConfigurationException;
+
+}

Propchange: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/Configurable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/Configurable.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/Configurable.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/ConfigurationException.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/ConfigurationException.java?view=auto&rev=522301
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/ConfigurationException.java
(added)
+++ jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/ConfigurationException.java
Sun Mar 25 09:49:14 2007
@@ -0,0 +1,7 @@
+package org.apache.commons.jci.examples.configuration;
+
+public class ConfigurationException extends Exception {
+
+	private static final long serialVersionUID = 1L;
+
+}

Propchange: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/ConfigurationException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/ConfigurationException.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/ConfigurationException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/ConfigurationReloading.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/ConfigurationReloading.java?view=diff&rev=522301&r1=522300&r2=522301
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/ConfigurationReloading.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/ConfigurationReloading.java
Sun Mar 25 09:49:14 2007
@@ -17,10 +17,75 @@
 
 package org.apache.commons.jci.examples.configuration;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Properties;
+
+import org.apache.commons.jci.listeners.FileChangeListener;
+import org.apache.commons.jci.monitor.FilesystemAlterationListener;
+import org.apache.commons.jci.monitor.FilesystemAlterationMonitor;
+import org.apache.commons.jci.monitor.FilesystemAlterationObserver;
+
 /**
  * 
  * @author tcurdt
  */
 public final class ConfigurationReloading {
 
+	private final FilesystemAlterationMonitor fam = new FilesystemAlterationMonitor();
+	
+	private void run(String[] args) {
+		
+		final File configFile = new File("some.properties");
+
+		System.out.println("Watching " + configFile.getAbsolutePath());
+		
+		final Collection configurables = new ArrayList();
+		
+		final FilesystemAlterationListener listener = new FileChangeListener() {
+			public void onStop(FilesystemAlterationObserver pObserver) {
+				super.onStop(pObserver);
+				
+				if (hasChanged()) {
+					System.out.println("Configuration change detected " + configFile);
+
+					final Properties props = new Properties();
+					try {
+						
+						props.load(new FileInputStream(configFile));
+
+						System.out.println("Notifying about configuration change " + configFile);
+
+						for (Iterator it = configurables.iterator(); it.hasNext();) {
+							final Configurable configurable = (Configurable) it.next();
+							configurable.configure(props);
+						}
+						
+					} catch (Exception e) {
+						System.err.println("Failed to load configuration " + configFile);
+					}
+
+				}
+			}			
+		};
+		
+		fam.addListener(configFile, listener);			
+		fam.start();
+
+		configurables.add(new Something());
+		
+		while(true) {
+			try {
+				Thread.sleep(1000);
+			} catch (InterruptedException e) {
+			}
+		}
+	}
+	
+	public static void main(String[] args) {
+		new ConfigurationReloading().run(args);
+	}
 }

Added: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/Something.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/Something.java?view=auto&rev=522301
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/Something.java
(added)
+++ jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/Something.java
Sun Mar 25 09:49:14 2007
@@ -0,0 +1,11 @@
+package org.apache.commons.jci.examples.configuration;
+
+import java.util.Properties;
+
+public class Something implements Configurable {
+
+	public void configure( Properties properties ) throws ConfigurationException {
+		System.out.println("Configuration changed");
+	}
+
+}

Propchange: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/Something.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/Something.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/Something.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspGenerator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspGenerator.java?view=auto&rev=522301
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspGenerator.java
(added)
+++ jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspGenerator.java
Sun Mar 25 09:49:14 2007
@@ -0,0 +1,146 @@
+package org.apache.commons.jci.examples.serverpages;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.Writer;
+
+import org.apache.commons.jci.utils.ConversionUtils;
+
+public final class JspGenerator {
+
+	private String quote( final String s ) {
+		
+		final StringBuffer sb = new StringBuffer();
+		final char[] input = s.toCharArray();
+		
+		for (int i = 0; i < input.length; i++) {
+			final char c = input[i];
+			if (c == '"') {
+				sb.append('\\');
+			}
+			if (c == '\\') {
+				sb.append('\\');
+			}
+			
+			if (c == '\n') {
+				sb.append("\");\n").append("    out.write(\"");
+				continue;
+			}
+			sb.append(c);
+		}
+		
+		return sb.toString();
+	}
+	
+	private void wrap( final StringBuffer pInput, final Writer pOutput ) throws IOException
{
+		
+		pOutput.append("    out.write(\"");
+		
+		pOutput.append(quote(pInput.toString()));
+
+		pOutput.append("\");").append('\n');
+	}
+	
+	public byte[] generateJavaSource( final  String pResourceName, final File pFile ) {
+
+		try {
+			final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+			final Reader input = new InputStreamReader(new FileInputStream(pFile));
+			final Writer output = new OutputStreamWriter(outputStream);
+			
+			final int p = pResourceName.lastIndexOf('/');
+
+			final String className;
+			final String packageName;
+
+			if (p < 0) {
+				className = ConversionUtils.stripExtension(pResourceName);
+				packageName = "";
+			} else {
+				className = ConversionUtils.stripExtension(pResourceName.substring(p+1));
+				packageName = pResourceName.substring(0, p).replace('/', '.');
+				output.append("package ").append(packageName).append(";").append('\n');				
+			}
+			
+			
+			output.append("import java.io.PrintWriter;").append('\n');
+			output.append("import java.io.IOException;").append('\n');
+			output.append("import javax.servlet.http.HttpServlet;").append('\n');
+			output.append("import javax.servlet.http.HttpServletRequest;").append('\n');
+			output.append("import javax.servlet.http.HttpServletResponse;").append('\n');
+			output.append("import javax.servlet.ServletException;").append('\n');
+			output.append("public class ").append(className).append(" extends HttpServlet {").append('\n');
+			output.append("  protected void service(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {").append('\n');
+			output.append("    final PrintWriter out = response.getWriter();").append('\n');
+			
+			
+			final char[] open = "<?".toCharArray();
+			final char[] close = "?>".toCharArray();
+
+			StringBuffer sb = new StringBuffer();
+			char[] watch = open;
+			int w = 0;
+			while(true) {
+				int c = input.read();
+				
+				if (c < 0) {
+					break;
+				}
+
+				if (c == watch[w]) {
+					w++;
+					if (watch.length == w) {
+						if (watch == open) {
+							// found open
+							
+							wrap(sb, output);
+
+							sb = new StringBuffer();
+							watch = close;
+						} else if (watch == close) {
+							// found close
+
+							// <? ... ?> is java
+							output.append(sb.toString());
+							
+							sb = new StringBuffer();
+							watch = open;
+						}
+						w = 0;
+					}
+				} else {
+					if (w > 0) {
+						sb.append(watch, 0, w);
+					}
+
+					sb.append((char)c);
+
+					w = 0;
+				}
+			}
+
+			if (watch == open) {
+				wrap(sb, output);
+			}
+
+			
+			output.append("    out.close();").append('\n');
+			output.append("    out.flush();").append('\n');
+			output.append("  }").append('\n');
+			output.append("}").append('\n');
+			
+			
+			output.close();
+			
+			return outputStream.toByteArray();
+		} catch (IOException e) {
+			return null;
+		}
+	}
+
+}

Propchange: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspGenerator.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspGenerator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspReader.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspReader.java?view=diff&rev=522301&r1=522300&r2=522301
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspReader.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspReader.java
Sun Mar 25 09:49:14 2007
@@ -1,178 +1,39 @@
 package org.apache.commons.jci.examples.serverpages;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.Reader;
-import java.io.Writer;
+import java.util.Map;
 
 import org.apache.commons.jci.readers.ResourceReader;
-import org.apache.commons.jci.utils.ConversionUtils;
 
 public final class JspReader implements ResourceReader {
 
+	private final Map sources;
 	private final ResourceReader reader;
 	
 	
-	public JspReader( final ResourceReader pReader ) {
+	public JspReader( final Map pSources, final ResourceReader pReader ) {
 		reader = pReader;
+		sources = pSources;
 	}
 	
-	private String quote( final String s ) {
-		
-		final StringBuffer sb = new StringBuffer();
-		final char[] input = s.toCharArray();
-		
-		for (int i = 0; i < input.length; i++) {
-			final char c = input[i];
-			if (c == '"') {
-				sb.append('\\');
-			}
-			if (c == '\\') {
-				sb.append('\\');
-			}
-			
-			if (c == '\n') {
-				sb.append("\");\n").append("    out.write(\"");
-				continue;
-			}
-			sb.append(c);
-		}
-		
-		return sb.toString();
-	}
-	
-	private void generateJavaCodeFor( final StringBuffer pInput, final Writer pOutput ) throws
IOException {
-		
-		pOutput.append("    out.write(\"");
-		
-		pOutput.append(quote(pInput.toString()));
-
-		pOutput.append("\");").append('\n');
-	}
 	
-	private byte[] transform( String pResourceName, byte[] pBytes ) {
+	public byte[] getBytes( String pResourceName ) {
 
-		try {
-			final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
-			final Reader input = new InputStreamReader(new ByteArrayInputStream(pBytes));
-			final Writer output = new OutputStreamWriter(outputStream);
-			
-			final int p = pResourceName.lastIndexOf('/');
-
-			final String className;
-			final String packageName;
-
-			if (p < 0) {
-				className = ConversionUtils.stripExtension(pResourceName);
-				packageName = "";
-			} else {
-				className = ConversionUtils.stripExtension(pResourceName.substring(p+1));
-				packageName = pResourceName.substring(0, p).replace('/', '.');
-				output.append("package ").append(packageName).append(";").append('\n');				
-			}
-			
-			
-			output.append("import java.io.PrintWriter;").append('\n');
-			output.append("import java.io.IOException;").append('\n');
-			output.append("import javax.servlet.http.HttpServlet;").append('\n');
-			output.append("import javax.servlet.http.HttpServletRequest;").append('\n');
-			output.append("import javax.servlet.http.HttpServletResponse;").append('\n');
-			output.append("import javax.servlet.ServletException;").append('\n');
-			output.append("public class ").append(className).append(" extends HttpServlet {").append('\n');
-			output.append("  protected void service(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {").append('\n');
-			output.append("    final PrintWriter out = response.getWriter();").append('\n');
-			
-			
-			final char[] open = "<?".toCharArray();
-			final char[] close = "?>".toCharArray();
-
-			StringBuffer sb = new StringBuffer();
-			char[] watch = open;
-			int w = 0;
-			while(true) {
-				int c = input.read();
-				
-				if (c < 0) {
-					break;
-				}
-
-				if (c == watch[w]) {
-					w++;
-					if (watch.length == w) {
-						if (watch == open) {
-							// found open
-							
-							generateJavaCodeFor(sb, output);
-
-							sb = new StringBuffer();
-							watch = close;
-						} else if (watch == close) {
-							// found close
-
-							// <? ... ?> is java
-							output.append(sb.toString());
-							
-							sb = new StringBuffer();
-							watch = open;
-						}
-						w = 0;
-					}
-				} else {
-					if (w > 0) {
-						sb.append(watch, 0, w);
-					}
-
-					sb.append((char)c);
-
-					w = 0;
-				}
-			}
-
-			if (watch == open) {
-				generateJavaCodeFor(sb, output);
-			}
-
-			
-			output.append("    out.close();").append('\n');
-			output.append("    out.flush();").append('\n');
-			output.append("  }").append('\n');
-			output.append("}").append('\n');
-			
-			
-			output.close();
-			
-			return outputStream.toByteArray();
-		} catch (IOException e) {
-			return null;
+		final byte[] bytes = (byte[]) sources.get(pResourceName);
+		
+		if (bytes != null) {
+			return bytes;
 		}
+
+		return reader.getBytes(pResourceName);		
 	}
-	
-	public byte[] getBytes( String pResourceName ) {
-		
-		if (pResourceName.endsWith(".java")) {
-			
-			final String jspResourceName = ConversionUtils.stripExtension(pResourceName) + ".jsp";
-			final byte[] resourceBytes = reader.getBytes(jspResourceName);
-			
-			if (resourceBytes == null) {
-				return null;
-			}
-						
-			final byte[] jspServletCode = transform(jspResourceName, resourceBytes);
 
-			System.out.println(new String(jspServletCode));
+	public boolean isAvailable( String pResourceName ) {
 
-			return jspServletCode;
+		if (sources.containsKey(pResourceName)) {
+			return true;
 		}
 		
-		return reader.getBytes(pResourceName);
-	}
-
-	public boolean isAvailable( String pResourceName ) {
-		return reader.isAvailable(pResourceName) || reader.isAvailable(ConversionUtils.stripExtension(pResourceName)
+ ".jsp");
+		return reader.isAvailable(pResourceName);
 	}
 
 }

Modified: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/ServerPageServlet.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/ServerPageServlet.java?view=diff&rev=522301&r1=522300&r2=522301
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/ServerPageServlet.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/ServerPageServlet.java
Sun Mar 25 09:49:14 2007
@@ -62,7 +62,7 @@
 		
 		final File serverpagesDir = new File(getServletContext().getRealPath("/") + getInitParameter("serverpagesDir"));
 		
-		log("monitoring serverpages in " + serverpagesDir);
+		log("Monitoring serverpages in " + serverpagesDir);
 		
 		final TransactionalResourceStore store = new TransactionalResourceStore(new MemoryResourceStore())
{
 
@@ -86,10 +86,10 @@
 					try {
 						final Class clazz = classloader.loadClass(clazzName);
 
-//						if (!clazz.isAssignableFrom(HttpServlet.class)) {
-//							log(clazzName + " is not a servlet");
-//							continue;
-//						}
+						if (!HttpServlet.class.isAssignableFrom(clazz)) {
+							log(clazzName + " is not a servlet");
+							continue;
+						}
 
 						final HttpServlet servlet = (HttpServlet) clazz.newInstance();
 						newServletsByClassname.put(clazzName, servlet);
@@ -100,7 +100,7 @@
 				}
 
 				if (reload) {
-					log("activating new map of servlets "+ newServletsByClassname);
+					log("Activating new map of servlets "+ newServletsByClassname);
 					servletsByClassname = newServletsByClassname;					
 				}
 			}
@@ -117,16 +117,54 @@
 		
 		jspListener = new CompilingListener(new JavaCompilerFactory().createCompiler("eclipse"),
store) {
 
-			public String getSourceFileExtension() {
-				return ".jsp";
+			private final JspGenerator transformer = new JspGenerator();
+			private final Map sources = new HashMap();
+			private final Set resourceToCompile = new HashSet();
+
+			public void onStart(FilesystemAlterationObserver pObserver) {
+				super.onStart(pObserver);
+
+				resourceToCompile.clear();
 			}
 
-			public String getSourceNameFromFile( final FilesystemAlterationObserver pObserver, final
File pFile ) {
-		    	return ConversionUtils.stripExtension(ConversionUtils.getResourceNameFromFileName(ConversionUtils.relative(pObserver.getRootDirectory(),
pFile))) + ".java";
-		    }
-			
+
+			public void onFileChange(File pFile) {
+				if (pFile.getName().endsWith(".jsp")) {
+					final String resourceName = ConversionUtils.stripExtension(getSourceNameFromFile(observer,
pFile)) + ".java";
+					
+					log("Updating " + resourceName);
+					
+					sources.put(resourceName, transformer.generateJavaSource(resourceName, pFile));
+
+					resourceToCompile.add(resourceName);
+				}
+				super.onFileChange(pFile);
+			}
+
+
+			public void onFileCreate(File pFile) {
+				if (pFile.getName().endsWith(".jsp")) {
+					final String resourceName = ConversionUtils.stripExtension(getSourceNameFromFile(observer,
pFile)) + ".java";
+
+					log("Creating " + resourceName);
+
+					sources.put(resourceName, transformer.generateJavaSource(resourceName, pFile));				

+
+					resourceToCompile.add(resourceName);
+				}
+				super.onFileCreate(pFile);
+			}
+
+
+			public String[] getResourcesToCompile(FilesystemAlterationObserver pObserver) {
+				final String[] resourceNames = new String[resourceToCompile.size()];
+				resourceToCompile.toArray(resourceNames);
+				return resourceNames;
+			}
+
+
 			public ResourceReader getReader( final FilesystemAlterationObserver pObserver ) {
-				return new JspReader(super.getReader(pObserver));
+				return new JspReader(sources, super.getReader(pObserver));
 			}
         };
         jspListener.addReloadNotificationListener(classloader);
@@ -147,7 +185,8 @@
 	}
 	
 	protected void service(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
-		log("request " + request.getRequestURI());
+
+		log("Request " + request.getRequestURI());
 		
 		final CompilationResult result = jspListener.getCompilationResult();
 		final CompilationProblem[] errors = result.getErrors();
@@ -171,17 +210,17 @@
 		
 		final String servletClassname = convertRequestToServletClassname(request);
 
-		log("checking for serverpage " + servletClassname);
+		log("Checking for serverpage " + servletClassname);
 		
 		final HttpServlet servlet = (HttpServlet) servletsByClassname.get(servletClassname);
 		
 		if (servlet == null) {
-			log("no servlet  for " + request.getRequestURI());
+			log("No servlet  for " + request.getRequestURI());
 			response.sendError(404);
 			return;
 		}
 
-		log("delegating request to " + servletClassname);
+		log("Delegating request to " + servletClassname);
 		
 		servlet.service(request, response);
 	}

Modified: jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/Test.jsp
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/Test.jsp?view=diff&rev=522301&r1=522300&r2=522301
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/Test.jsp (original)
+++ jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/Test.jsp Sun Mar
25 09:49:14 2007
@@ -1,6 +1,6 @@
 <html><body>
-    TEST
-    <?
-    System.out.println("TEST");
-    ?>
+    
+<? for(int i=0; i<3; i++) { ?>
+   line <br/>      
+<? } ?>
 </body></html>

Modified: jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/org/vafer/Test.jsp
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/org/vafer/Test.jsp?view=diff&rev=522301&r1=522300&r2=522301
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/org/vafer/Test.jsp
(original)
+++ jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/org/vafer/Test.jsp
Sun Mar 25 09:49:14 2007
@@ -0,0 +1 @@
+<html><body>org.vafer.Test</body></html>
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message