incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r635585 - in /incubator/sling/trunk/scripting/javascript/src: main/java/org/apache/sling/scripting/javascript/helper/EspReader.java test/java/org/apache/sling/scripting/javascript/helper/EspReaderTest.java
Date Mon, 10 Mar 2008 15:51:25 GMT
Author: fmeschbe
Date: Mon Mar 10 08:51:23 2008
New Revision: 635585

URL: http://svn.apache.org/viewvc?rev=635585&view=rev
Log:
SLING-142, SLING-253 Allow compact expression syntax ${..} everywhere
as a drop-in replacement for <%=...%>.

Modified:
    incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/EspReader.java
    incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/javascript/helper/EspReaderTest.java

Modified: incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/EspReader.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/EspReader.java?rev=635585&r1=635584&r2=635585&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/EspReader.java
(original)
+++ incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/EspReader.java
Mon Mar 10 08:51:23 2008
@@ -78,7 +78,7 @@
      * the {@link #PARSE_STATE_QUOTE} state and ECMA slash slash comments are
      * handled in {@link #PARSE_STATE_ECMA_COMMENTL} state.
      */
-    private static final byte PARSE_STATE_ECMA = 3;
+    private static final byte PARSE_STATE_ECMA = 2;
 
     /**
      * ECMA script expression reading state. This state works exactly the same
@@ -87,7 +87,12 @@
      * is itself wrapped with a <code>out.write()</code> statement
      * verbatim.
      */
-    private static final byte PARSE_STATE_ECMA_EXPR = 4;
+    private static final byte PARSE_STATE_ECMA_EXPR = 3;
+
+    /**
+     * Compact ESP expression syntax similar to JSP Expression Language notation 
+     */
+    private static final byte PARSE_STATE_ECMA_EXPR_COMPACT = 4;
 
     /**
      * JSP comment reading state. When in this state everything upto the closing
@@ -109,38 +114,21 @@
      * mainly used to (re-)inject static text into the output without further
      * processing.
      */
-    private static final byte PARSE_STATE_VERBATIM = 8;
+    private static final byte PARSE_STATE_VERBATIM = 7;
 
     /**
      * ECMA Comment reading state. When in this state, an ECMA slash star
      * comment is read (and completely returned).
      */
-    private static final byte PARSE_STATE_ECMA_COMMENT = 9;
+    private static final byte PARSE_STATE_ECMA_COMMENT = 8;
 
     /**
      * ECMA Comment reading state. When in this state, an ECMA slash slash
      * comment is read (and completely returned).
      */
-    private static final byte PARSE_STATE_ECMA_COMMENTL = 10;
-    
-    /**
-     * Attribute value (single quote) reading state. This is needed for identifying the compact
-     * syntax which is only allowed in attributes.
-     */
-    private static final byte PARSE_STATE_ATTRIBUTE_SINGLE = 11;
+    private static final byte PARSE_STATE_ECMA_COMMENTL = 9;
     
     /**
-     * Attribute value (double quote) reading state. This is needed for identifying the compact
-     * syntax which is only allowed in attributes.
-     */
-    private static final byte PARSE_STATE_ATTRIBUTE_DOUBLE = 12;
-    
-    /**
-     * Compact JSP expression syntax to be used in attributes.
-     */
-    private static final byte PARSE_STATE_COMPACT_ATTRIBUTE = 13;
-
-    /**
      * To work with lookahead and character insertion, we use a PushbackReader.
      */
     private PushbackReader input;
@@ -433,21 +421,20 @@
 
                 // Template text state - text is wrapped in out.write()
                 case PARSE_STATE_ESP:
-                    if (c == '=') { //might start HTML attribute definition
+                    if (c == '$') { // might start EL-like ECMA expr
                     	int c2 = input.read();
-                    	if (c2 == '"') {
-                    		pushState(PARSE_STATE_ATTRIBUTE_DOUBLE);
-                    		//input.unread(c2);
-                    		doVerbatim("=\\\"");
-                    		continue;
-                    	} else if (c2 == '\'') {
-                    		pushState(PARSE_STATE_ATTRIBUTE_SINGLE);
-                    		doVerbatim("='");
-                    		continue;
-                    	} else {
-                    		input.unread(c2);
-                    		continue;
+                    	if (c2 == '{') {
+                            // ECMA expression ${ ... }
+                            pushState(PARSE_STATE_ECMA_EXPR_COMPACT);
+                            startWrite(null);
+                            if (!lineStart) {
+                                doVerbatim("\");");
+                            }
+                            continue;
                     	}
+                    	 
+                    	input.unread(c2);
+
                     } else  if (c == '<') { // might start ECMA code/expr, ESP comment
or JSP comment
                         int c2 = input.read();
                         int c3 = input.read();
@@ -594,6 +581,21 @@
                     }
                     break;
 
+                // reading compact (EL-like) ECMA Expression
+                case PARSE_STATE_ECMA_EXPR_COMPACT:
+                    if (c == '}') { //might be the end of a compact expression
+                        // An expression is wrapped in out.write()
+                        popState();
+                        doVerbatim(");");
+
+                        // next ESP needs out.write(
+                        lineStart = true;
+
+                        continue;
+
+                    }
+                    break;
+
                 // Reading a JSP comment, only returning line endings
                 case PARSE_STATE_JSP_COMMENT:
 
@@ -692,64 +694,6 @@
 
                     break;
                     
-                case PARSE_STATE_ATTRIBUTE_DOUBLE:
-                	if (c == '"') {
-                		input.unread(c);
-                		popState();
-                		continue;
-                	} else if (c == '$') {
-                		int c2 = input.read();
-                		if (c2 == '{') {
-	                		// ECMA expression attribute="bla${1+1}"
-	                        pushState(PARSE_STATE_COMPACT_ATTRIBUTE);
-	                        startWrite(null);
-	                        if (!lineStart) {
-	                            doVerbatim("\");");
-	                        }
-	                        continue;
-                		} else {
-                			//false alarm
-                			input.unread(c2);
-                		}
-                	}
-                	break;
-                	
-                case PARSE_STATE_ATTRIBUTE_SINGLE:
-                	if (c == '\'') {
-                		input.unread(c);
-                		popState();
-                		continue;
-                	} else if (c == '$') {
-                		int c2 = input.read();
-                		if (c2 == '{') {
-	                		// ECMA expression attribute="bla${1+1}"
-	                        pushState(PARSE_STATE_COMPACT_ATTRIBUTE);
-	                        startWrite(null);
-	                        if (!lineStart) {
-	                            doVerbatim("\");");
-	                        }
-	                        continue;
-                		} else {
-                			//false alarm
-                			input.unread(c2);
-                		}
-                	}
-                	break;
-            	
-                case PARSE_STATE_COMPACT_ATTRIBUTE:
-                	if (c == '}') { //might be the end of a compact expression
-                        // An expression is wrapped in out.write()
-            			popState();
-                        doVerbatim(");");
-
-                        // next ESP needs out.write(
-                        lineStart = true;
-
-                        continue;
-
-                    }
-                	break;
-
                 // What ???!!!
                 default:
 

Modified: incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/javascript/helper/EspReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/javascript/helper/EspReaderTest.java?rev=635585&r1=635584&r2=635585&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/javascript/helper/EspReaderTest.java
(original)
+++ incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/javascript/helper/EspReaderTest.java
Mon Mar 10 08:51:23 2008
@@ -245,12 +245,36 @@
         assertEquals(expected, actual);
     }
     
-    public void DISABLED_SEE_SLING_253_testEqualSigns() throws IOException {
+    public void testEqualSigns() throws IOException {
         final String input = "currentNode.text=<%= currentNode.text %>";
         final String expected = 
             "out=response.writer;" 
             + "out.write(\"currentNode.text=\");"
             + "out.write( currentNode.text );"
+            ;
+        final String actual = parse(input);
+        assertEquals(expected, actual);
+    }
+    
+    public void testSingleQuoted() throws IOException {
+        final String input = "currentNode.text='<%= currentNode.text %>'";
+        final String expected = 
+            "out=response.writer;" 
+            + "out.write(\"currentNode.text='\");"
+            + "out.write( currentNode.text );"
+            + "out.write(\"'\");"
+            ;
+        final String actual = parse(input);
+        assertEquals(expected, actual);
+    }
+    
+    public void testDoubleQuoted() throws IOException {
+        final String input = "currentNode.text=\"<%= currentNode.text %>\"";
+        final String expected = 
+            "out=response.writer;" 
+            + "out.write(\"currentNode.text=\\\"\");"
+            + "out.write( currentNode.text );"
+            + "out.write(\"\\\"\");"
             ;
         final String actual = parse(input);
         assertEquals(expected, actual);



Mime
View raw message