You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2013/09/03 13:44:37 UTC

svn commit: r1519656 - in /myfaces/tobago/trunk/tobago-core/src: main/java/org/apache/myfaces/tobago/internal/config/ test/java/org/apache/myfaces/tobago/internal/config/ test/resources/

Author: lofwyr
Date: Tue Sep  3 11:44:37 2013
New Revision: 1519656

URL: http://svn.apache.org/r1519656
Log:
TOBAGO-1298: Re-implement TobagoConfigParser
- Fix: now ignoring white spaces and comments

Added:
    myfaces/tobago/trunk/tobago-core/src/test/resources/tobago-config-untidy-2.0.xml
      - copied, changed from r1519596, myfaces/tobago/trunk/tobago-core/src/test/resources/tobago-config-2.0.xml
Modified:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParser.java
    myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParserUnitTest.java

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParser.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParser.java?rev=1519656&r1=1519655&r2=1519656&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParser.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParser.java Tue Sep  3 11:44:37 2013
@@ -81,7 +81,7 @@ public class TobagoConfigParser extends 
   private RendererConfig currentRenderer;
   private ThemeImpl currentTheme;
   private Boolean production;
-  private String text;
+  private StringBuilder buffer;
 
   private Stack<String> stack;
 
@@ -119,7 +119,14 @@ public class TobagoConfigParser extends 
   }
 
   @Override
+  public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
+    super.ignorableWhitespace(ch, start, length);
+  }
+
+  @Override
   public void startDocument() throws SAXException {
+
+    buffer = new StringBuilder();
     stack = new Stack<String>();
   }
 
@@ -132,6 +139,10 @@ public class TobagoConfigParser extends 
   @Override
   public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
 
+    // No unused content should be collected, specially text mixed with tags.
+    assert buffer.toString().trim().length() == 0;
+
+    buffer.setLength(0);
     stack.add(qName);
 
     switch (qName.hashCode()) {
@@ -214,13 +225,16 @@ public class TobagoConfigParser extends 
 
   @Override
   public void characters(char[] ch, int start, int length) throws SAXException {
-    text = new String(ch, start, length);
+    buffer.append(ch, start, length);
   }
 
   @Override
   public void endElement(String uri, String localName, String qName) throws SAXException {
     assert qName.equals(stack.peek());
 
+    final String text = buffer.toString().trim();
+    buffer.setLength(0);
+
     switch (qName.hashCode()) {
 
       case NAME:

Modified: myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParserUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParserUnitTest.java?rev=1519656&r1=1519655&r2=1519656&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParserUnitTest.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParserUnitTest.java Tue Sep  3 11:44:37 2013
@@ -24,7 +24,10 @@ import org.apache.myfaces.tobago.context
 import org.junit.Test;
 import org.xml.sax.SAXException;
 
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.IOException;
 import java.lang.reflect.Field;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.HashSet;
@@ -35,8 +38,17 @@ public class TobagoConfigParserUnitTest 
 
   @Test
   public void testParser() throws Exception {
+    generalTest("tobago-config-2.0.xml");
+  }
+
+  @Test
+  public void testParserUntidy() throws Exception {
+    generalTest("tobago-config-untidy-2.0.xml");
+  }
 
-    final URL url = getClass().getClassLoader().getResource("tobago-config-2.0.xml");
+  private void generalTest(String name)
+      throws IOException, SAXException, ParserConfigurationException, URISyntaxException {
+    final URL url = getClass().getClassLoader().getResource(name);
     final TobagoConfigParser parser = new TobagoConfigParser();
 
     final TobagoConfigFragment fragment = parser.parse(url);

Copied: myfaces/tobago/trunk/tobago-core/src/test/resources/tobago-config-untidy-2.0.xml (from r1519596, myfaces/tobago/trunk/tobago-core/src/test/resources/tobago-config-2.0.xml)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/test/resources/tobago-config-untidy-2.0.xml?p2=myfaces/tobago/trunk/tobago-core/src/test/resources/tobago-config-untidy-2.0.xml&p1=myfaces/tobago/trunk/tobago-core/src/test/resources/tobago-config-2.0.xml&r1=1519596&r2=1519656&rev=1519656&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/test/resources/tobago-config-2.0.xml (original)
+++ myfaces/tobago/trunk/tobago-core/src/test/resources/tobago-config-untidy-2.0.xml Tue Sep  3 11:44:37 2013
@@ -23,64 +23,140 @@
     xsi:schemaLocation="http://myfaces.apache.org/tobago/tobago-config http://myfaces.apache.org/tobago/tobago-config-2.0.xsd"
     version="2.0">
 
-  <name>my-name</name>
+  <name>
+    <!-- comment -->
+    <!-- comment -->
+    my-name
+    <!-- comment -->
+    <!-- comment -->
+  </name>
+
+  <!-- comment -->
 
   <ordering>
     <after>
-      <name>my-after</name>
+      <name>
+        <!-- comment -->
+        my-after
+        <!-- comment -->
+      </name>
+      <!-- comment -->
     </after>
+    <!-- comment -->
     <before>
-      <name>my-before-1</name>
+      <!-- comment -->
+      <name>
+        my-before-1
+      </name>
       <name>my-before-2</name>
     </before>
   </ordering>
 
   <theme-config>
-    <default-theme>speyside</default-theme>
-    <supported-theme>scarborough</supported-theme>
-    <supported-theme>standard</supported-theme>
+    <!-- comment -->
+    <default-theme>
+      <!-- comment -->
+      speyside
+      <!-- comment -->
+    </default-theme>
+    <!-- comment -->
+    <supported-theme>
+      scarborough
+    </supported-theme>
+    <supported-theme>
+      standard
+    </supported-theme>
   </theme-config>
 
-  <resource-dir>my-resource-1</resource-dir>
-  <resource-dir>my-resource-2</resource-dir>
-
-  <create-session-secret>false</create-session-secret>
-  <check-session-secret>false</check-session-secret>
-  <prevent-frame-attacks>false</prevent-frame-attacks>
-
-  <content-security-policy extension-mode="replace">
-    <directive>default-src 'self'</directive>
-    <directive>frame-src http://apache.org</directive>
+  <resource-dir
+      >my-resource-1
+  </resource-dir>
+  <resource-dir>
+    my-resource-2
+  </resource-dir>
+
+  <create-session-secret>
+    false
+  </create-session-secret>
+  <check-session-secret>
+    false
+  </check-session-secret>
+  <prevent-frame-attacks>
+    false
+  </prevent-frame-attacks>
+
+  <content-security-policy
+      extension-mode="replace">
+    <directive>
+      default-src 'self'
+    </directive>
+    <directive>
+      frame-src http://apache.org
+    </directive>
   </content-security-policy>
 
   <renderers>
     <renderer>
-      <name>MyRenderer-1</name>
+      <name>
+        MyRenderer-1
+      </name>
       <supported-markup>
-        <markup>my-markup-1</markup>
+        <markup>
+          my-markup-1
+        </markup>
       </supported-markup>
     </renderer>
     <renderer>
-      <name>MyRenderer-2</name>
+      <name>
+        MyRenderer-2
+      </name>
       <supported-markup>
-        <markup>my-markup-2-1</markup>
-        <markup>my-markup-2-2</markup>
+        <markup>
+          my-markup-2-1
+        </markup>
+        <markup>
+          my-markup-2-2
+        </markup>
       </supported-markup>
     </renderer>
   </renderers>
 
   <theme-definitions>
     <theme-definition>
-      <name>my-theme-1</name>
-      <display-name>My Theme 1</display-name>
-      <resource-path>/my/path-1</resource-path>
-      <versioned>true</versioned>
+      <name>
+        <!-- comment -->
+        my-theme-1
+        <!-- comment -->
+      </name>
+      <!-- comment -->
+      <display-name>
+        <!-- comment -->
+        <!-- comment -->
+        <!-- comment -->
+        My Theme 1
+        <!-- comment -->
+      </display-name>
+      <resource-path>
+        /my/path-1
+      </resource-path>
+      <versioned>
+        true
+      </versioned>
       <renderers>
         <renderer>
-          <name>ThemeRenderer</name>
+          <name>
+            ThemeRenderer
+          </name>
           <supported-markup>
-            <markup>theme-markup</markup>
+            <!-- comment -->
+            <markup>
+              <!-- comment -->
+              theme-markup
+              <!-- comment -->
+            </markup>
+            <!-- comment -->
           </supported-markup>
+          <!-- comment -->
         </renderer>
       </renderers>
       <resources production="true">
@@ -90,9 +166,17 @@
     </theme-definition>
 
     <theme-definition>
-      <name>my-theme-2</name>
-      <resource-path>/my/path-2</resource-path>
-      <fallback>my-theme-1</fallback>
+      <name>
+        <!-- comment -->
+        my-theme-2
+        <!-- comment -->
+      </name>
+      <resource-path>
+        /my/path-2
+      </resource-path>
+      <fallback>
+        my-theme-1
+      </fallback>
       <resources production="false"/>
     </theme-definition>