Revision: 12041
http://zk1.svn.sourceforge.net/zk1/?rev=12041&view=rev
Author: tomyeh
Date: 2009-07-09 07:52:46 +0000 (Thu, 09 Jul 2009)
Log Message:
-----------
ZK Lighter works with WCS
Modified Paths:
--------------
branches/5.0/zk/src/org/zkoss/zk/ui/http/WcsExtendlet.java
branches/5.0/zk/src/org/zkoss/zk/ui/http/WpdExtendlet.java
branches/5.0/zklighter/src/org/zkoss/zklighter/Lighter.java
branches/5.0/zklighter/zklighter.xml
branches/5.0/zul/src/archive/web/js/zul/wnd/css/window.css.dsp
Added Paths:
-----------
branches/5.0/zk/src/org/zkoss/zk/ui/http/FileWcsExtendlet.java
branches/5.0/zk/src/org/zkoss/zk/ui/http/FileWpdExtendlet.java
Added: branches/5.0/zk/src/org/zkoss/zk/ui/http/FileWcsExtendlet.java
===================================================================
--- branches/5.0/zk/src/org/zkoss/zk/ui/http/FileWcsExtendlet.java (rev 0)
+++ branches/5.0/zk/src/org/zkoss/zk/ui/http/FileWcsExtendlet.java 2009-07-09 07:52:46 UTC (rev 12041)
@@ -0,0 +1,74 @@
+/* FileWcsExtendlet.java
+
+ Purpose:
+
+ Description:
+
+ History:
+ Thu Jul 9 14:11:25 2009, Created by tomyeh
+
+Copyright (C) 2009 Potix Corporation. All Rights Reserved.
+
+This program is distributed under GPL Version 3.0 in the hope that
+it will be useful, but WITHOUT ANY WARRANTY.
+*/
+package org.zkoss.zk.ui.http;
+
+import java.lang.reflect.Method;
+import java.util.Iterator;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.io.FileInputStream;
+import java.io.File;
+
+/**
+ * Used by ZK Lighter to generate the CSS content of a WCS file.
+ * Unlike {@link WcsExtendlet}, it is based on the file system.
+ *
+ * @author tomyeh
+ * @since 5.0.0
+ */
+public class FileWcsExtendlet extends WcsExtendlet{
+ /** Parses and return the content of the specified WCS file.
+ */
+ public String service(File fl, Includer includer) throws Exception {
+ setProvider(new FileProvider(fl, isDebugJS()));
+ try {
+ final WcsInfo wi = (WcsInfo)parse(new FileInputStream(fl), fl.getPath());
+ final StringWriter sw = new StringWriter();
+ for (int j = 0; j < wi.items.length; ++j) {
+ final Object o = wi.items[j];
+ if (o instanceof String) {
+ try {
+ includer.include((String)o, sw);
+ } catch (Throwable ex) {
+ log.realCauseBriefly("Unable to load "+wi.items[j], ex);
+ }
+ } else { //static method
+ sw.write(invoke((Method)o));
+ }
+ sw.write('\n');
+ }
+ for (Iterator it = wi.langdef.getCSSURIs().iterator(); it.hasNext();) {
+ final String uri = (String)it.next();
+ try {
+ includer.include(uri, sw);
+ } catch (Throwable ex) {
+ log.realCauseBriefly("Unable to load "+uri, ex);
+ }
+ }
+ return sw.getBuffer().toString();
+ } finally {
+ setProvider(null);
+ }
+ }
+ /** Work with {@link #service} to inlcude a resource. */
+ public interface Includer {
+ /** Includes the specified resource.
+ * @param uri the URI to include. The format of uri is <code>~./xxx</code>.
+ * @param out the writer to write the content of the resouce to.
+ */
+ public void include(String uri, Writer out)
+ throws java.io.IOException;
+ }
+}
Added: branches/5.0/zk/src/org/zkoss/zk/ui/http/FileWpdExtendlet.java
===================================================================
--- branches/5.0/zk/src/org/zkoss/zk/ui/http/FileWpdExtendlet.java (rev 0)
+++ branches/5.0/zk/src/org/zkoss/zk/ui/http/FileWpdExtendlet.java 2009-07-09 07:52:46 UTC (rev 12041)
@@ -0,0 +1,39 @@
+/* FileWpdExtendlet.java
+
+ Purpose:
+
+ Description:
+
+ History:
+ Thu Jul 9 14:12:42 2009, Created by tomyeh
+
+Copyright (C) 2009 Potix Corporation. All Rights Reserved.
+
+This program is distributed under GPL Version 3.0 in the hope that
+it will be useful, but WITHOUT ANY WARRANTY.
+*/
+package org.zkoss.zk.ui.http;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+/**
+ * Used by ZK Lighter to generate the JavaScript content of a WPD file.
+ * Unlike {@link WpdExtendlet}, it is based on the file system.
+ *
+ * @author tomyeh
+ */
+public class FileWpdExtendlet extends WpdExtendlet {
+ /** Parses and return the content of the specified WPD file.
+ */
+ public byte[] service(File fl) throws Exception {
+ setProvider(new FileProvider(fl, isDebugJS()));
+ try {
+ final Object rawdata = parse(new FileInputStream(fl), fl.getPath());
+ return rawdata instanceof byte[] ? (byte[])rawdata:
+ ((WpdContent)rawdata).toByteArray();
+ } finally {
+ setProvider(null);
+ }
+ }
+}
Modified: branches/5.0/zk/src/org/zkoss/zk/ui/http/WcsExtendlet.java
===================================================================
--- branches/5.0/zk/src/org/zkoss/zk/ui/http/WcsExtendlet.java 2009-07-09 07:43:50 UTC (rev 12040)
+++ branches/5.0/zk/src/org/zkoss/zk/ui/http/WcsExtendlet.java 2009-07-09 07:52:46 UTC (rev 12041)
@@ -98,7 +98,7 @@
response.flushBuffer();
}
- private Object parse(InputStream is, String path) throws Exception {
+ /*package*/ Object parse(InputStream is, String path) throws Exception {
final Element root = new SAXBuilder(true, false, true).build(is).getRootElement();
final String lang = IDOMs.getRequiredAttributeValue(root, "language");
if (lang.length() == 0)
@@ -135,10 +135,10 @@
return _webctx;
}
}
- private static class WcsInfo {
- private final LanguageDefinition langdef;
+ /*package*/ static class WcsInfo {
+ /*package*/ final LanguageDefinition langdef;
/** A list of URI or static method. */
- private final Object[] items;
+ /*package*/ final Object[] items;
private WcsInfo(String lang, List items) {
this.langdef = LanguageDefinition.lookup(lang);
this.items = (Object[])items.toArray(new Object[items.size()]);
Modified: branches/5.0/zk/src/org/zkoss/zk/ui/http/WpdExtendlet.java
===================================================================
--- branches/5.0/zk/src/org/zkoss/zk/ui/http/WpdExtendlet.java 2009-07-09 07:43:50 UTC (rev 12040)
+++ branches/5.0/zk/src/org/zkoss/zk/ui/http/WpdExtendlet.java 2009-07-09 07:52:46 UTC (rev 12041)
@@ -22,7 +22,6 @@
import java.util.Map;
import java.util.HashMap;
import java.io.File;
-import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.ByteArrayOutputStream;
@@ -95,20 +94,8 @@
response.getOutputStream().write(data);
response.flushBuffer();
}
- /** Parses and return the specified file.
- * It is used by ZK Lighter to generate JavaScript files.
- */
- public byte[] service(File fl) throws Exception {
- setProvider(new FileProvider(fl, isDebugJS()));
- try {
- final Object rawdata = parse(new FileInputStream(fl), fl.getPath());
- return rawdata instanceof byte[] ? (byte[])rawdata:
- ((WpdContent)rawdata).toByteArray();
- } finally {
- setProvider(null);
- }
- }
- private Object parse(InputStream is, String path) throws Exception {
+ /*package*/
+ Object parse(InputStream is, String path) throws Exception {
final Element root = new SAXBuilder(true, false, true).build(is).getRootElement();
final String name = IDOMs.getRequiredAttributeValue(root, "name");
if (name.length() == 0)
@@ -404,7 +391,7 @@
return _webctx;
}
}
- private class WpdContent {
+ /*package*/ class WpdContent {
private final String _dir;
private final List _cnt = new LinkedList();
private WpdContent(String dir) {
@@ -419,7 +406,7 @@
private void add(String jspath, String browser) {
_cnt.add(new String[] {jspath, browser});
}
- private byte[] toByteArray() throws ServletException, IOException {
+ /*package*/ byte[] toByteArray() throws ServletException, IOException {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
for (Iterator it = _cnt.iterator(); it.hasNext();) {
final Object o = it.next();
Modified: branches/5.0/zklighter/src/org/zkoss/zklighter/Lighter.java
===================================================================
--- branches/5.0/zklighter/src/org/zkoss/zklighter/Lighter.java 2009-07-09 07:43:50 UTC (rev 12040)
+++ branches/5.0/zklighter/src/org/zkoss/zklighter/Lighter.java 2009-07-09 07:52:46 UTC (rev 12041)
@@ -27,7 +27,8 @@
import org.zkoss.idom.input.SAXBuilder;
import org.zkoss.idom.util.IDOMs;
-import org.zkoss.zk.ui.http.WpdExtendlet;
+import org.zkoss.zk.ui.http.FileWpdExtendlet;
+import org.zkoss.zk.ui.http.FileWcsExtendlet;
/**
* The entry of ZK Lighter
@@ -46,13 +47,14 @@
+"Usage:\n\tjava -classpath $CP org.zkoss.zklighter.Lighter zklighter.xml\n");
System.exit(-1);
}
- final WpdExtendlet wpd = new WpdExtendlet();
+ final FileWpdExtendlet wpd = new FileWpdExtendlet();
+ final FileWcsExtendlet wcs = new FileWcsExtendlet();
for (Iterator it = new SAXBuilder(true, false, true).build(args[0])
.getRootElement().getElements().iterator(); it.hasNext();) {
final Element el = (Element)it.next();
final String nm = el.getName();
if ("javascript".equals(nm)) genJS(wpd, el);
- else if ("css".equals(nm)) genCSS(el);
+ else if ("css".equals(nm)) genCSS(wcs, el);
else if ("copy".equals(nm)) copy(el);
else throw new IOException("Unknown "+nm+", "+el.getLocator());
}
@@ -73,7 +75,7 @@
}
//JS//
- private static void genJS(WpdExtendlet wpd, Element el) throws IOException {
+ private static void genJS(FileWpdExtendlet wpd, Element el) throws IOException {
final File dst = new File(IDOMs.getRequiredElementValue(el, "destination"));
final List srcs = new LinkedList();
for (Iterator it = el.getElements("source").iterator(); it.hasNext();) {
@@ -99,7 +101,7 @@
outJS(wpd, dst, srcs, null, true);
}
}
- private static void outJS(WpdExtendlet wpd, File dst, List srcs,
+ private static void outJS(FileWpdExtendlet wpd, File dst, List srcs,
String locale, boolean debugJS) throws IOException {
wpd.setDebugJS(debugJS);
if (debugJS || locale != null) {
@@ -124,14 +126,15 @@
for (Iterator it = srcs.iterator(); it.hasNext();)
out.write(wpd.service((File)it.next()));
} catch (Throwable ex) {
- out.close();
if (ex instanceof IOException) throw (IOException)ex;
throw SystemException.Aide.wrap(ex);
+ } finally {
+ out.close();
}
}
//CSS//
- private static void genCSS(Element el) throws IOException {
+ private static void genCSS(FileWcsExtendlet wcs, Element el) throws IOException {
final File dst = new File(IDOMs.getRequiredElementValue(el, "destination"));
final List srcs = new LinkedList();
for (Iterator it = el.getElements("source").iterator(); it.hasNext();) {
@@ -139,62 +142,34 @@
final File fl = new File(e.getText(true));
if (!fl.exists())
throw new FileNotFoundException("Not found: "+fl+", "+e.getLocator());
- srcs.add(fl);
+ srcs.add(new Object[] {
+ fl, IDOMs.getRequiredAttributeValue(e, "class-web-path")});
}
- final CSSInfo ci = new CSSInfo(el);
- ci.pure = false;
- final List browsers = new LinkedList();
- for (Iterator it = el.getElements("browser").iterator(); it.hasNext();) {
- browsers.add(((Element)it.next()).getText(true));
- }
-
//merge all browser CSS into one
- ci.pure = true;
- outCombinedCSS(dst, srcs, browsers, ci);
+ outCSS(wcs, new CSSInfo(el), dst, srcs);
}
private static
- void outCombinedCSS(File dst, List srcs, List browsers, CSSInfo ci)
+ void outCSS(FileWcsExtendlet wcs, CSSInfo ci, File dst, List srcs)
throws IOException {
++_cnt;
Writer out = new FileWriter(dst, "UTF-8");
try {
- boolean ignoreInclude = false;
- for (Iterator ito = browsers.iterator(); ito.hasNext();) {
- final String browser = (String)ito.next();
- for (Iterator it = srcs.iterator(); it.hasNext();) {
- File src = (File)it.next();
- outCSS(out, renByBrowser(src, browser), ci, ignoreInclude);
- }
- ignoreInclude = true;
- }
- } finally {
- out.close();
- }
- }
- private static void outCSS(File dst, List srcs, String browser, CSSInfo ci)
- throws IOException {
- ++_cnt;
- dst = renByBrowser(dst, browser);
- Writer out = new FileWriter(dst, "UTF-8");
- try {
for (Iterator it = srcs.iterator(); it.hasNext();) {
- File src = (File)it.next();
- outCSS(out, renByBrowser(src, browser), ci, false);
+ final Object[] inf = (Object[])it.next();
+ ci.source = (File)inf[0];
+ ci.classWebPath = (String)inf[1];
+ out.write(wcs.service(ci.source, new Includer(ci)));
}
+ } catch (Throwable ex) {
+ if (ex instanceof IOException) throw (IOException)ex;
+ throw SystemException.Aide.wrap(ex);
} finally {
out.close();
}
}
- private static File renByBrowser(File fl, String browser) {
- final String nm = fl.getName();
- final int j = nm.indexOf('.', nm.lastIndexOf('/') +1);
- return new File(fl.getParent(),
- j >= 0 ? nm.substring(0, j) + browser + nm.substring(j):
- nm + browser);
- }
private static
- void outCSS(Writer out, File src, CSSInfo ci, boolean ignoreInclude)
+ void outCSS(Writer out, CSSInfo ci, File src)
throws IOException {
ci.source = src;
ci.lineno = 1;
@@ -214,7 +189,7 @@
throw new IOException(ci.message("Non-terminated <"));
if (cc == 'c' && in.charAt(j++) == ':') { //restrict but safer
- outDirective(out, in.substring(j, k), ci, ignoreInclude);
+ outDirective(out, ci, in.substring(j, k));
} else if (cc != '/' && cc != '%')
throw new IOException(ci.message("Unknown <"+cc));
j = k;
@@ -228,23 +203,13 @@
throws IOException {
int j = cnt.indexOf("encodeURL");
if (j < 0) {
- if (ci.pure) {
- String s = (String)ci.vars.get(cnt);
- if (s != null)
- out.write(s);
- else if (isFormula(cnt)) //formula
- out.write('?'); //mark error
- else
- throw new IOException(ci.message("Unknown EL, ${"+ cnt+"}"));
- } else {
- if (isFormula(cnt)) //formula
- out.write('?'); //mark error
- else {
- out.write("${");
- out.write(cnt);
- out.write('}');
- }
- }
+ String s = (String)ci.vars.get(cnt);
+ if (s != null)
+ out.write(s);
+ else if (isFormula(cnt)) //formula
+ out.write('?'); //mark error
+ else
+ throw new IOException(ci.message("Unknown EL, ${"+ cnt+"}"));
return;
}
@@ -274,46 +239,17 @@
}
return false;
}
- private static void outDirective(Writer out, String cnt, CSSInfo ci,
- boolean ignoreInclude)
+ private static void outDirective(Writer out, CSSInfo ci, String cnt)
throws IOException {
int j = cnt.indexOf(' ');
if (j < 0) j = cnt.length();
String nm = cnt.substring(0, j);
if ("include".equals(nm)) {
- if (ignoreInclude) return; //nothing to do
-
j = cnt.indexOf("page=\"", j);
if (j < 0)
throw new IOException(ci.message("The page attribute not found"));
- nm = cnt.substring(j += 6, cnt.indexOf('"', j));
- if (!nm.startsWith("~./"))
- throw new IOException(ci.message("Unknown URI: "+nm));
- nm = nm.substring(2);
- j = nm.length();
-
- for (String path = ci.source.getPath().replace('\\', '/');;) {
- int k = nm.lastIndexOf('/', j);
- if (k < 0)
- throw new IOException(ci.message("Unmatched URI: "+nm));
- final String s = nm.substring(0, k + 1);
- j = path.indexOf(s);
- if (j >= 0) { //found
- nm = path.substring(0, j + s.length()) + nm.substring(k + 1);
- break;
- }
- j = k - 1;
- }
-
- int oldln = ci.lineno;
- File oldsrc = ci.source;
- try {
- outCSS(out, new File(nm), ci, false);
- } finally {
- ci.lineno = oldln;
- ci.source = oldsrc;
- }
+ include(out, ci, cnt.substring(j += 6, cnt.indexOf('"', j)));
} else if ("choose".equals(nm) || "when".equals(nm) || "otherwise".equals(nm)
|| "if".equals(nm) || "set".equals(nm)) {
out.write("//?");
@@ -321,15 +257,38 @@
} else
throw new IOException(ci.message("Unknown <c:"+nm));
}
+ private static void include(Writer out, CSSInfo ci, String uri)
+ throws IOException {
+ if (!uri.startsWith("~./"))
+ throw new IOException(ci.message("Unknown URI: "+uri));
+
+ int oldln = ci.lineno;
+ File oldsrc = ci.source;
+ try {
+ outCSS(out, ci, new File(ci.classWebPath + uri.substring(2)));
+ } finally {
+ ci.lineno = oldln;
+ ci.source = oldsrc;
+ }
+ }
+
+ private static class Includer implements FileWcsExtendlet.Includer {
+ private final CSSInfo _ci;
+ private Includer(CSSInfo ci) {
+ _ci = ci;
+ }
+ public void include(String uri, Writer out) throws IOException {
+ Lighter.include(out, _ci, uri);
+ }
+ }
private static class CSSInfo {
private final Map vars = new HashMap();
private final Map translates = new LinkedHashMap();
- /** Whether to generate pure CSS, i.e., containing no ${xxx}. */
- private boolean pure;
/** The current line number in {@link #source}. */
private int lineno;
/** The source file to parse. */
private File source;
+ private String classWebPath;
private CSSInfo(Element el) {
for (Iterator it = el.getElements("variable").iterator(); it.hasNext();) {
Modified: branches/5.0/zklighter/zklighter.xml
===================================================================
--- branches/5.0/zklighter/zklighter.xml 2009-07-09 07:43:50 UTC (rev 12040)
+++ branches/5.0/zklighter/zklighter.xml 2009-07-09 07:52:46 UTC (rev 12041)
@@ -21,6 +21,7 @@
<locale>id</locale>
<locale>it</locale>
<locale>ja</locale>
+ <locale>kr</locale>
<locale>nl</locale>
<locale>pt</locale>
<locale>ro</locale>
@@ -38,6 +39,10 @@
<source>../zul/codegen/archive/web/js/zul/box/zk.wpd</source>
</javascript>
<javascript>
+ <destination>lib/js/db.js</destination>
+ <source>../zul/codegen/archive/web/js/zul/db/zk.wpd</source>
+ </javascript>
+ <javascript>
<destination>lib/js/grid.js</destination>
<source>../zul/codegen/archive/web/js/zul/grid/zk.wpd</source>
</javascript>
@@ -90,9 +95,10 @@
<source>../zul/codegen/archive/web/js/zul/wgt/zk.wpd</source>
<source>../zul/codegen/archive/web/js/zul/box/zk.wpd</source>
<source>../zul/codegen/archive/web/js/zul/mesh/zk.wpd</source>
+ <source>../zul/codegen/archive/web/js/zul/menu/zk.wpd</source>
<source>../zul/codegen/archive/web/js/zul/grid/zk.wpd</source>
<source>../zul/codegen/archive/web/js/zul/inp/zk.wpd</source>
- <source>../zul/codegen/archive/web/js/zul/menu/zk.wpd</source>
+ <source>../zul/codegen/archive/web/js/zul/db/zk.wpd</source>
<source>../zul/codegen/archive/web/js/zul/utl/zklt.wpd</source>
<source>../zul/codegen/archive/web/js/zul/sel/zk.wpd</source>
<source>../zul/codegen/archive/web/js/zul/wnd/zk.wpd</source>
@@ -111,13 +117,9 @@
<css>
<destination>lib/css/norm.css</destination>
- <source>../zul/src/archive/web/zul/css/norm.css.dsp</source>
+ <source class-web-path="../zul/src/archive/web">../zul/src/archive/web/zul/css/zk.wcs</source>
+ <!-- class-web-path: used to convert ~./ -->
- <browser>ie</browser>
- <browser>moz</browser>
- <browser>saf</browser>
- <browser>opr</browser>
-
<encodeURL prefix="">
<translate from="~./zk/img" to="zkrc"/>
<translate from="~./zul/img" to="zkrc"/>
Modified: branches/5.0/zul/src/archive/web/js/zul/wnd/css/window.css.dsp
===================================================================
--- branches/5.0/zul/src/archive/web/js/zul/wnd/css/window.css.dsp 2009-07-09 07:43:50 UTC (rev 12040)
+++ branches/5.0/zul/src/archive/web/js/zul/wnd/css/window.css.dsp 2009-07-09 07:52:46 UTC (rev 12041)
@@ -361,7 +361,7 @@
background-image: url(${c:encodeURL('~./zul/img/msgbox/stop-btn.png')});
}
-<!-- IE -->
+<%-- IE --%>
<c:if test="${c:isExplorer()}">
.z-messagebox-btn {
width: 47pt;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|