/hg/icedtea-web: Minor changes in algorithm that compares signed...
smohammad at icedtea.classpath.org
smohammad at icedtea.classpath.org
Wed Aug 3 09:32:46 PDT 2011
changeset f2c80b9ceae1 in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=f2c80b9ceae1
author: Saad Mohammad <smohammad at redhat.com>
date: Wed Aug 03 12:32:22 2011 -0400
Minor changes in algorithm that compares signed JNLP
application/template
diffstat:
ChangeLog | 14 ++++
netx/net/sourceforge/jnlp/JNLPMatcher.java | 97 +++++++++++++++++------------
netx/net/sourceforge/jnlp/Node.java | 13 ----
3 files changed, 70 insertions(+), 54 deletions(-)
diffs (201 lines):
diff -r 7668bf410571 -r f2c80b9ceae1 ChangeLog
--- a/ChangeLog Tue Aug 02 11:05:47 2011 +0200
+++ b/ChangeLog Wed Aug 03 12:32:22 2011 -0400
@@ -1,3 +1,17 @@
+2011-08-03 Saad Mohammad <smohammad at redhat.com>
+
+ * netx/net/sourceforge/jnlp/JNLPMatcher.java:
+ (JNLPMatcher): Removed NullPointerException from being thrown, caught and
+ then thrown again via JNLPMatcherException. This was replaced by throwing
+ a checked exception [JNLPMatcherException] directly.
+ (JNLPMatcher): Removed unused code [getters]
+ (JNLPMatcher): Closed Input/Output streams that were opened.
+ (isMatch): Removed caching of return value
+ (closeInputStream): Added this method to close input streams
+ (closeOutputStream): Added this method to close output streams
+ * netx/net/sourceforge/jnlp/Node.java:
+ Removed getAttributeNames() method from the commented section
+
2011-08-02 Jiri Vanek <jvanek at redhat.com>
*Makefile.am: (stamps/netx-dist-tests-prepare-reproducers.stamp):
diff -r 7668bf410571 -r f2c80b9ceae1 netx/net/sourceforge/jnlp/JNLPMatcher.java
--- a/netx/net/sourceforge/jnlp/JNLPMatcher.java Tue Aug 02 11:05:47 2011 +0200
+++ b/netx/net/sourceforge/jnlp/JNLPMatcher.java Wed Aug 03 12:32:22 2011 -0400
@@ -38,10 +38,11 @@
package net.sourceforge.jnlp;
import java.util.List;
+import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
@@ -59,7 +60,6 @@
private final Node appTemplateNode;
private final Node launchJNLPNode;
private final boolean isTemplate;
- private Boolean match;
/**
* Public constructor
@@ -78,26 +78,33 @@
public JNLPMatcher(InputStreamReader appTemplate, InputStreamReader launchJNLP,
boolean isTemplate) throws JNLPMatcherException {
+ if (appTemplate == null && launchJNLP == null)
+ throw new JNLPMatcherException(
+ "Template JNLP file and Launching JNLP file are both null.");
+ else if (appTemplate == null)
+ throw new JNLPMatcherException("Template JNLP file is null.");
+ else if (launchJNLP == null)
+ throw new JNLPMatcherException("Launching JNLP file is null.");
+
+ //Declare variables for signed JNLP file
+ PipedInputStream pinTemplate= null;
+ PipedOutputStream poutTemplate= null;
+
+ //Declare variables for launching JNLP file
+ PipedInputStream pinJNLPFile = null;
+ PipedOutputStream poutJNLPFile = null;
+
try {
-
- if (appTemplate == null && launchJNLP == null)
- throw new NullPointerException(
- "Template JNLP file and Launching JNLP file are both null.");
- else if (appTemplate == null)
- throw new NullPointerException("Template JNLP file is null.");
- else if (launchJNLP == null)
- throw new NullPointerException("Launching JNLP file is null.");
-
XMLElement appTemplateXML = new XMLElement();
XMLElement launchJNLPXML = new XMLElement();
// Remove the comments and CDATA from the JNLP file
- final PipedInputStream pinTemplate = new PipedInputStream();
- final PipedOutputStream poutTemplate = new PipedOutputStream(pinTemplate);
+ pinTemplate = new PipedInputStream();
+ poutTemplate = new PipedOutputStream(pinTemplate);
appTemplateXML.sanitizeInput(appTemplate, poutTemplate);
- final PipedInputStream pinJNLPFile = new PipedInputStream();
- final PipedOutputStream poutJNLPFile = new PipedOutputStream(pinJNLPFile);
+ pinJNLPFile = new PipedInputStream();
+ poutJNLPFile = new PipedOutputStream(pinJNLPFile);
launchJNLPXML.sanitizeInput(launchJNLP, poutJNLPFile);
// Parse both files
@@ -113,6 +120,14 @@
throw new JNLPMatcherException(
"Failed to create an instance of JNLPVerify with specified InputStreamReader",
e);
+ } finally {
+ // Close all stream
+ closeInputStream(pinTemplate);
+ closeOutputStream(poutTemplate);
+
+ closeInputStream(pinJNLPFile);
+ closeOutputStream(poutJNLPFile);
+
}
}
@@ -122,11 +137,9 @@
* @return true if both JNLP files are 'matched', otherwise false
*/
public boolean isMatch() {
-
- if (match == null)
- match = matchNodes(appTemplateNode, launchJNLPNode);
-
- return match;
+
+ return matchNodes(appTemplateNode, launchJNLPNode);
+
}
/**
@@ -241,32 +254,34 @@
}
return false;
}
-
- /**
- * Getter for application/template Node
+
+ /***
+ * Closes an input stream
*
- * @return the Node of the signed application/template file
+ * @param stream
+ * The input stream that will be closed
*/
- public Node getAppTemplateNode() {
- return appTemplateNode;
+ private void closeInputStream(InputStream stream) {
+ if (stream != null)
+ try {
+ stream.close();
+ } catch (Exception e) {
+ e.printStackTrace(System.err);
+ }
}
- /**
- * Getter for launching application Node
+ /***
+ * Closes an output stream
*
- * @return the Node of the launching JNLP file
+ * @param stream
+ * The output stream that will be closed
*/
- public Node getLaunchJNLPNode() {
- return launchJNLPNode;
- }
-
- /**
- * Getter for isTemplate
- *
- * @return true if a signed template is being used for matching; otherwise
- * false.
- */
- public boolean isTemplate() {
- return isTemplate;
+ private void closeOutputStream(OutputStream stream) {
+ if (stream != null)
+ try {
+ stream.close();
+ } catch (Exception e) {
+ e.printStackTrace(System.err);
+ }
}
}
diff -r 7668bf410571 -r f2c80b9ceae1 netx/net/sourceforge/jnlp/Node.java
--- a/netx/net/sourceforge/jnlp/Node.java Tue Aug 02 11:05:47 2011 +0200
+++ b/netx/net/sourceforge/jnlp/Node.java Wed Aug 03 12:32:22 2011 -0400
@@ -145,19 +145,6 @@
return children;
}
- String[] getAttributeNames() {
- if (attributeNames == null) {
- List<String> list = new ArrayList<String>();
-
- for (Enumeration e = xml.enumerateAttributeNames(); e.hasMoreElements();)
- list.add(new String((String) e.nextElement()));
-
- attributeNames = list.toArray(new String[list.size()]);
-
- }
- return attributeNames;
- }
-
String getAttribute(String name) {
return tinyNode.getAttribute(name);
}
More information about the distro-pkg-dev
mailing list