You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-commits@xmlgraphics.apache.org by ca...@apache.org on 2007/09/11 10:37:35 UTC

svn commit: r574507 - /xmlgraphics/batik/trunk/sources/org/apache/batik/css/engine/sac/CSSLangCondition.java

Author: cam
Date: Tue Sep 11 01:37:34 2007
New Revision: 574507

URL: http://svn.apache.org/viewvc?rev=574507&view=rev
Log:
Fix :lang() pseudo-element matching so that they match:
  * case-insensitively,
  * using xml:attr="" as well as lang="", and
  * using proper hyphen-separated tokens.

Modified:
    xmlgraphics/batik/trunk/sources/org/apache/batik/css/engine/sac/CSSLangCondition.java

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/css/engine/sac/CSSLangCondition.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/css/engine/sac/CSSLangCondition.java?rev=574507&r1=574506&r2=574507&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/css/engine/sac/CSSLangCondition.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/css/engine/sac/CSSLangCondition.java Tue Sep 11 01:37:34 2007
@@ -20,6 +20,8 @@
 
 import java.util.Set;
 
+import org.apache.batik.util.XMLConstants;
+
 import org.w3c.css.sac.LangCondition;
 import org.w3c.dom.Element;
 
@@ -40,10 +42,16 @@
     protected String lang;
 
     /**
+     * The language with a hyphen suffixed.
+     */
+    protected String langHyphen;
+
+    /**
      * Creates a new LangCondition object.
      */
     public CSSLangCondition(String lang) {
-        this.lang = lang;
+        this.lang = lang.toLowerCase();
+        this.langHyphen = lang + '-';
     }
 
     /**
@@ -84,7 +92,13 @@
      * Tests whether this condition matches the given element.
      */
     public boolean match(Element e, String pseudoE) {
-        return e.getAttribute("lang").startsWith(getLang());
+        String s = e.getAttribute("lang").toLowerCase();
+        if (s.equals(lang) || s.startsWith(langHyphen)) {
+            return true;
+        }
+        s = e.getAttributeNS(XMLConstants.XML_NAMESPACE_URI,
+                             XMLConstants.XML_LANG_ATTRIBUTE).toLowerCase();
+        return s.equals(lang) || s.startsWith(langHyphen);
     }
 
     /**