Author: ptw
Date: 2007-01-23 14:10:32 -0800 (Tue, 23 Jan 2007)
New Revision: 3494
Modified:
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/css/CSSHandler.java
openlaszlo/trunk/test/style/names/main_underscore.lzx
Log:
Change 20070108-ptw-q by [EMAIL PROTECTED] on 2007-01-08 22:59:33 EST
in /Users/ptw/OpenLaszlo/trunk/test/style/names
Summary: Process CSS escapes
Bugs Fixed:
LPP-3391 'CSS: Selector names cannot include underscore'
Technical Reviewer: ben (Message-Id: <[EMAIL PROTECTED]>)
QA Reviewer: frisco (pending)
Doc Reviewer: n/a
Release Notes:
CSS parsing now correctly processes escapes. An underscore can be
included in a selector or identifier by using `\` to escape the
underscore (additionally, any unicode character can be expressed
as its hexadecimal value in compliance with the w3c CSS
specification.
Details:
CSSHandler: The batik parser accepts escapes according to the CSS
spec, but returns them as written. In the handlers, escapes need
to be converted to the equivalent Javascript.
Tests:
Changing `lzx_bgcolor` to `lzx\_bgcolor` in
test/style/names/main_underscore.lzx makes the test work.
Modified:
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/css/CSSHandler.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/css/CSSHandler.java
2007-01-23 21:39:20 UTC (rev 3493)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/css/CSSHandler.java
2007-01-23 22:10:32 UTC (rev 3494)
@@ -11,6 +11,7 @@
import java.io.*;
import java.util.*;
+import java.util.regex.*;
import org.w3c.css.sac.*;
import org.apache.log4j.*;
import org.jdom.*;
@@ -180,9 +181,36 @@
}
}
+ // Unicode characters
+ Pattern hexEscapePattern = Pattern.compile("\\\\([0-9a-fA-F]{1,6})(\r\n|[
\t\r\n\f])?");
+ // The only characters that need to be escaped in javascript
+ Pattern charEscapePattern = Pattern.compile("\\\\([^\r\n\f0-9a-fA-F])");
+
+ // Convert CSS escapes to Javascript
+ protected String processEscapes (String input) {
+ // Convert unicode escapes to Javascript equivalent (which
+ // means parse the hex escape and insert the corresponding
+ // unicode character in it's place).
+ Matcher m = hexEscapePattern.matcher(input);
+ StringBuffer sb = new StringBuffer();
+ while (m.find()) {
+ // Have I told you how much Java sucks lately?
+ CharArrayWriter u = new CharArrayWriter();
+ u.write(Integer.parseInt(m.group(1), 16));
+ m.appendReplacement(sb, u.toString());
+ }
+ m.appendTail(sb);
+ input = sb.toString();
+ // Convert character escapes to Javascript (which means just
+ // remove the escape, since none of those chars need escaping
+ // in Javascript).
+ input = charEscapePattern.matcher(input).replaceAll("$1");
+ return input;
+ }
+
public void property(String name, LexicalUnit value, boolean important)
throws CSSException {
- mStyleMap.put(name, new StyleProperty(luToString(value), important));
+ mStyleMap.put(processEscapes(name), new
StyleProperty(luToString(value), important));
}
public void importStyle(String uri, SACMediaList media,
@@ -270,15 +298,15 @@
switch (lu.getLexicalUnitType()) {
case LexicalUnit.SAC_ATTR:
- str = "function () { return this['" + lu.getStringValue() + "']; }";
+ str = "function () { return this['" +
processEscapes(lu.getStringValue()) + "']; }";
break;
case LexicalUnit.SAC_IDENT:
- str = "function () { return global['" + lu.getStringValue() + "'];
}";
+ str = "function () { return global['" +
processEscapes(lu.getStringValue()) + "']; }";
break;
case LexicalUnit.SAC_STRING_VALUE:
- str = "\"" + lu.getStringValue() + "\"";
+ str = "\"" + processEscapes(lu.getStringValue()) + "\"";
break;
case LexicalUnit.SAC_URI:
Modified: openlaszlo/trunk/test/style/names/main_underscore.lzx
===================================================================
--- openlaszlo/trunk/test/style/names/main_underscore.lzx 2007-01-23
21:39:20 UTC (rev 3493)
+++ openlaszlo/trunk/test/style/names/main_underscore.lzx 2007-01-23
22:10:32 UTC (rev 3494)
@@ -6,21 +6,25 @@
</script>
<stylesheet>
- #gMax {
- lzx_bgcolor: #00FF00;
+ #brown {
+ lzx\_bgcolor: #00FF00;
+ lzx\5f content: "now is the time...";
}
</stylesheet>
<debug/>
- <class name="B" width="50" height="50" bgcolor="$style{'lzx_bgcolor'}"/>
+ <class name="B" width="50" height="50" bgcolor="$style{'lzx_bgcolor'}">
+ <text name='text' text="$style{'lzx_content'}" />
+ </class>
-<B id="gMax" />
+<B id="brown" />
<TestSuite>
<TestCase>
<method name="testnamesuite">
- assertEquals('0x00FF00', gMax.bgcolor);
+ assertEquals('0x00FF00', brown.bgcolor);
+ assertEquals("now is the time...", brown.text.text)
</method>
</TestCase>
</TestSuite>
_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins