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 2017/03/29 12:17:00 UTC

svn commit: r1789348 - /myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/DebugResponseWriterWrapper.java

Author: lofwyr
Date: Wed Mar 29 12:17:00 2017
New Revision: 1789348

URL: http://svn.apache.org/viewvc?rev=1789348&view=rev
Log:
log in error, when writing same attribute in one element twice (only in development mode)

Modified:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/DebugResponseWriterWrapper.java

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/DebugResponseWriterWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/DebugResponseWriterWrapper.java?rev=1789348&r1=1789347&r2=1789348&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/DebugResponseWriterWrapper.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/DebugResponseWriterWrapper.java Wed Mar 29 12:17:00 2017
@@ -32,11 +32,14 @@ import javax.faces.context.ResponseWrite
 import java.io.IOException;
 import java.io.Writer;
 import java.util.EmptyStackException;
+import java.util.HashSet;
+import java.util.Set;
 import java.util.Stack;
 
 public class DebugResponseWriterWrapper extends TobagoResponseWriter {
 
   private Stack<Object> stack = new Stack<Object>();
+  private Set<MarkupLanguageAttributes> usedAttributes = new HashSet<MarkupLanguageAttributes>();
 
   private static final Logger LOG = LoggerFactory.getLogger(DebugResponseWriterWrapper.class);
 
@@ -89,16 +92,31 @@ public class DebugResponseWriterWrapper
   public void writeAttribute(final MarkupLanguageAttributes name, final String value, final boolean escape)
       throws IOException {
     responseWriter.writeAttribute(name, value, escape);
+    if (usedAttributes.contains(name)) {
+      LOG.error("Duplicate attribute '" + name + "' in element <" + stack.peek() + ">!", new IllegalStateException());
+    } else {
+      usedAttributes.add(name);
+    }
   }
 
   @Override
   public void writeAttribute(final MarkupLanguageAttributes name, final HtmlTypes types) throws IOException {
     responseWriter.writeAttribute(name, types);
+    if (usedAttributes.contains(name)) {
+      LOG.error("Duplicate attribute '" + name + "' in element <" + stack.peek() + ">!", new IllegalStateException());
+    } else {
+      usedAttributes.add(name);
+    }
   }
 
   @Override
   public void writeURIAttribute(MarkupLanguageAttributes name, String string) throws IOException {
     responseWriter.writeURIAttribute(name, string);
+    if (usedAttributes.contains(name)) {
+      LOG.error("Duplicate attribute '" + name + "' in element <" + stack.peek() + ">!", new IllegalStateException());
+    } else {
+      usedAttributes.add(name);
+    }
   }
 
   @Override
@@ -175,6 +193,8 @@ public class DebugResponseWriterWrapper
     }
     stack.push(name);
     responseWriter.startElement(name, currentComponent);
+
+    usedAttributes.clear();
   }
 
   @Override
@@ -184,6 +204,8 @@ public class DebugResponseWriterWrapper
     }
     stack.push(name);
     responseWriter.startElement(name);
+
+    usedAttributes.clear();
   }
 
   @Override