PATCH: Bug 98: loadTemplate(ByteStream, String
Matt Mullens <[email protected]> Sat, 5 Apr 2003 18:58:06 -0800 (PST)
| Newsgroups | gmane.comp.java.xwt.general |
|---|---|
| Message-ID | <[email protected]> |
(Hope this comes through without line wraps or other
goofyness - as I have to send it through yahoo at the
moment.)
This is the submission of patches for bug 98:
LoadTemplate(ByteStream, String)
The second parameter, the template name, is a fully
qualified template
a.b.c
It is allowed to end in .xwt (a.b.c.xwt) or not,
loadTemplate will ignore the suffix.
let me know if you like...
tested in Linux [version 2.4.2-2]
Index: Resources.java
===================================================================
RCS file: /cvs/xwt/src/org/xwt/Resources.java,v
retrieving revision 1.10
diff -u -r1.10 Resources.java
--- Resources.java12 Feb 2003 06:40:22 -00001.10
+++ Resources.java6 Apr 2003 02:27:14 -0000
@@ -131,6 +131,29 @@
if (Log.verbose) Log.log(Resources.class,
"done loading
archive");
}
+
+ /** Load a bytestream */
+ public static synchronized void
loadTemplate(InputStream is,
String name) throws IOException {
+
+ String templateName = new String(name);
+
+ if (templateName.endsWith(".xwt")){
+ templateName =
templateName.substring(0,
templateName.length() - 4);
+ }
+ String packageName =
JSObject.nodeNameToPackageName(templateName);
+ String shortName =
templateName.substring(templateName.lastIndexOf(".")+1);
+ if (!validResourceName(shortName)) return;
+
+ Object user =
usedPackages.get(packageName);
+ if (user != null){
+ if (Log.on) Log.log(Resources.class,
"templates have
already been loaded into " + packageName + "; refusing
to load " +
templateName);
+ }else{
+ Static.createStatic(templateName,
false);
+ usedPackages.put(packageName, new
Object());
+ bytes.put(templateName + ".xwt",
isToByteArray(is));
+ }
+ }
+
/** holds the current theme mappings */
static Vector mapFrom = new Vector();
Index: XWT.java
===================================================================
RCS file: /cvs/xwt/src/org/xwt/XWT.java,v
retrieving revision 1.18
diff -u -r1.18 XWT.java
--- XWT.java3 Oct 2002 22:45:58 -00001.18
+++ XWT.java6 Apr 2003 02:27:15 -0000
@@ -64,6 +64,7 @@
else if (name.equals("println")) return
println;
else if (name.equals("math")) return
org.xwt.util.JSObject.defaultObjects.get("Math",
null);
else if (name.equals("loadArchive")) return
loadArchive;
+ else if (name.equals("loadTemplate")) return
loadTemplate;
else if (name.equals("prefetchImage")) return
prefetchImage;
else if (name.equals("prefs")) return
prefs;
else if (name.equals("encodeURI")) return
JSObject.defaultObjects.get("encodeURI", null);
@@ -508,6 +509,30 @@
return null;
}
};
+
+ private static final JSObject.JSFunction
loadTemplate = new
JSObject.JSFunction() {
+ public Object call(Context cx, Scriptable
thisObj,
Scriptable ctorObj, Object[] args) throws
JavaScriptException {
+ if (!ThreadMessage.suspendThread())
return null;
+
+ try {
+ if (args == null || args.length <
2 || args[0] ==
null || args[1] == null) return null;
+ InputStream is =
((ByteStream)(args[0])).getInputStream();
+ String name = (String)args[1];
+ Resources.loadTemplate(is,
name);
+ } catch (IOException ioe) {
+ if (Log.on) Log.log(this,
"IOException while
loading Template:");
+ if (Log.on) Log.log(this, ioe);
+ throw new
JavaScriptException(ioe.toString());
+
+ } finally {
+ ThreadMessage.resumeThread();
+
+ }
+ return null;
+ }
+ };
+
+
private static final JSObject.JSFunction
prefetchImage = new
JSObject.JSFunction() {
public Object call(Context cx, Scriptable
thisObj,
Scriptable ctorObj, Object[] args) throws
JavaScriptException {
__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online, calculators, forms, and more
http://tax.yahoo.com
_______________________________________________
http://lists.xwt.org/listinfo/dev