[Openjnlp-devel] New OpenJNLP User / Some Patches
Brought to you by:
kherr
|
From: Nathan M. <nm...@vi...> - 2002-11-19 12:23:30
|
Hello OpenJNLP Community,
I'm a new user of OpenJNLP. It solves an important problem for me -
thanks for a valuable contribution to the JNLP world!
I'm using OpenJNLP 0.7 in an environment it's never encountered before:
running an application launched with an URL containing query fields. For
example:
http://myhost/myapp?foo=bar&baz=foo
My environment exposed some OpenJNLP bugs - I've attached some patches
to address them. Here's a brief explanation of the problems and patches:
- IconFactory.java contains an extraneous semicolon that causes
compilation to fail with some compilers; it creates an "unreachable
statement".
- JNLPContentHandler fails to set the resource properties when it
builds an ApplicationDescriptor.
- FileCacheEntry does not properly deal with resource names such as
my example URL, above - it creates badly formed XML documents that
do not parse. I've added logic to transform the strings stored in
"entry.xml" into a form safe to use in an attribute field or as element
text: the dangerous characters <>'"& are replaced with character entity
codes that will be properly recognized and parsed by XML compilers
such as NanoXML.
There's one more change I'd like to make. I might not get to it very
quickly, but here's the remaining problem I'd like to fix: the library
should *not* apply the same caching logic to .jnlp files that it applies
to resources specified in the .jnlp files; it should just fetch the URL
once and then use it. As is, it's issuing something like four queries
(GET and HEAD) against the same URL - in my case causing the server to
perform a lot of wasted work. If/when I'm able to fix this one, I'll
send more patches.
Thanks again for the great work!
Nathan Meyers
nm...@vi...
Index: src/org/nanode/app/openjnlp/desktop/IconFactory.java
===================================================================
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- src/org/nanode/app/openjnlp/desktop/IconFactory.java 18 Nov 2002 12:04:16 -0000 1.1.1.1
+++ src/org/nanode/app/openjnlp/desktop/IconFactory.java 18 Nov 2002 13:30:21 -0000 1.2
@@ -150,7 +150,7 @@
* @see #getIcon(Descriptor, String, int)
*/
public static ImageIcon getIcon(Descriptor des, int size) {
- return getIcon(des, Information.ICON_DEFAULT, size);;
+ return getIcon(des, Information.ICON_DEFAULT, size);
}
/**
Index: src/org/nanode/jnlp/JNLPContentHandler.java
===================================================================
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- src/org/nanode/jnlp/JNLPContentHandler.java 18 Nov 2002 12:04:17 -0000 1.1.1.1
+++ src/org/nanode/jnlp/JNLPContentHandler.java 18 Nov 2002 21:52:01 -0000 1.2
@@ -533,6 +533,10 @@
for (Iterator iter = nativelibSet.iterator(); iter.hasNext();) {
resources.addReference((Reference) iter.next());
}
+
+ if (props != null) {
+ resources.setProperties(props);
+ }
descriptor.setContext(jnlpSpec);
descriptor.setInformation(information);
Index: src/org/nanode/launcher/cache/FileCacheEntry.java
===================================================================
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- src/org/nanode/launcher/cache/FileCacheEntry.java 18 Nov 2002 12:04:19 -0000 1.1.1.1
+++ src/org/nanode/launcher/cache/FileCacheEntry.java 18 Nov 2002 18:51:51 -0000 1.2
@@ -510,7 +510,7 @@
fw.write(" <meta name=\"");
fw.write(key);
fw.write("\">");
- fw.write(entryMeta.getProperty(key));
+ fw.write(xmlEncode(entryMeta.getProperty(key)));
fw.write("</meta>\n");
}
@@ -524,7 +524,7 @@
fw.write(" <resource href=\"");
}
- fw.write(rsrc[i].getReference().getURL().toString());
+ fw.write(xmlEncode(rsrc[i].getReference().getURL().toString()));
fw.write("\" modtime=\"");
fw.write(Long.toString(rsrc[i].getLastModified()));
fw.write("\" />\n");
@@ -539,6 +539,27 @@
} catch (Exception e) {
System.err.println(e);
}
+ }
+
+ /**
+ * Render a string safe for use in an attribute or element text
+ * in an XML document. The result should be fully parsable by
+ * an XML parser.
+ */
+ public static String xmlEncode(String xml) {
+ StringBuffer result = new StringBuffer();
+ for (int i = 0; i < xml.length(); i++) {
+ char ch = xml.charAt(i);
+ switch (ch) {
+ case '<': result.append("<"); break;
+ case '>': result.append(">"); break;
+ case '"': result.append("""); break;
+ case '\'': result.append("'"); break;
+ case '&': result.append("&"); break;
+ default: result.append(ch); break;
+ }
+ }
+ return result.toString();
}
/**
|