stylesheets are what we call a 'special form', meaning they have their own compiler. If you want to extend how a stylesheet works, you will have to edit that compiler:

  
http://svn.openlaszlo.org/openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/StyleSheetCompiler.java

Ideally, we want our stylesheet compiler to obey the w3c standard for determining character encoding:

  http://www.w3.org/TR/CSS2/syndata.html#charset

What I think this means is that StyleSheetCompiler needs to open the file in a mode where it can peek at the first few bytes of the file and determine the encoding according to the w3c spec, then reopen it with the correct encoding.

**At the very least: 1) we should default to reading the style sheet as UTF-8, not whatever the local machine's default encoding is, and 2) we should use the existing file utility to skip over any byte-order- mark before we start parsing.

I would not be surprised if there is already a jar around that does this for you. We're using the batik libraries to parse the CSS file, so maybe there is another library that does encoding detection?

This code was originally written by Pablo and Ben (cc-ed), maybe they want to help out as OL community contributors?

On 2009-05-07, at 05:01EDT, Raju Bitter wrote:

Hi all,

I'm working on LPP-8045 right now, encoding support for external CSS stylesheets.
http://jira.openlaszlo.org/jira/browse/LPP-8045

Here's what I want to do:

add an @encoding attribute to the stylesheet tag, found the classes
  
http://svn.openlaszlo.org/openlaszlo/trunk/WEB-INF/lps/lfc/services/LzStyleSheet.lzs
  
http://svn.openlaszlo.org/openlaszlo/trunk/WEB-INF/lps/lfc/services/LzCSSStyleSheet.lzs

The idea is to add an encoding attribute to LzStyleSheet. Based on that the file loader in org.openlaszlo.compiler.StyleSheetCompiler.java would take the attribute value on pass it on to the CSSHandler:

               // Actually parse and compile the stylesheet! W00t!
CSSHandler fileHandler = CSSHandler.parse( resolvedFile, encoding);

In CSSHandler.parse() the encoding would be passed on to the handler.getInputSource() method

   public static CSSHandler parse(File file, String encoding)
          throws CSSException {
      try {
          mLogger.info("creating CSSHandler");
          ....
          parser.parseStyleSheet(handler.getInputSource(encoding));

And then modify getInputSource to:

  /** @return InputSource object pointing to the CSS file. */
   InputSource getInputSource(encoding) throws FileNotFoundException {
mLogger.info("Trying to open CSS file " + mFile + " with encoding " + encoding);
       InputSource is = null;
       try {
is = new InputSource(new InputStreamReader(new FileInputStream(mFile), encoding));
       } catch (UnsupportedEncodingException e) {
mLogger.error("Unsupported encoding in file: " + mFile + ", " + e.getMessage());
       }
       return is;
   }

I need help!!!
I added a new attribute to LzStyleSheet.lzs, but it seems like the LZX compiler doesn't complain if there are unkown attributes on a stylesheet tag. Is that a bug? And how can I check if the attribute value will be set inside the debugger? I can't access the stylesheet object through an @id or @name in the debug console.

Thanks,
Raju

Reply via email to