diff options
author | Saad Mohammad <[email protected]> | 2011-08-03 12:32:22 -0400 |
---|---|---|
committer | Saad Mohammad <[email protected]> | 2011-08-03 12:32:22 -0400 |
commit | 742992d4908c77888f1f132eb8cae0010870abdd (patch) | |
tree | e92d6cb22c5c021740ba94db0e2ab522771dc0bc /netx/net/sourceforge | |
parent | 5f16196b6120cc98d56c3ad00e16e9d84421ace3 (diff) |
Minor changes in algorithm that compares signed JNLP application/template
Diffstat (limited to 'netx/net/sourceforge')
-rw-r--r-- | netx/net/sourceforge/jnlp/JNLPMatcher.java | 97 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/Node.java | 13 |
2 files changed, 56 insertions, 54 deletions
diff --git a/netx/net/sourceforge/jnlp/JNLPMatcher.java b/netx/net/sourceforge/jnlp/JNLPMatcher.java index 7cc2f4f..ed9ce94 100644 --- a/netx/net/sourceforge/jnlp/JNLPMatcher.java +++ b/netx/net/sourceforge/jnlp/JNLPMatcher.java @@ -38,10 +38,11 @@ exception statement from your version. 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 @@ public final class JNLPMatcher { private final Node appTemplateNode; private final Node launchJNLPNode; private final boolean isTemplate; - private Boolean match; /** * Public constructor @@ -78,26 +78,33 @@ public final class JNLPMatcher { 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 @@ public final class JNLPMatcher { 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 @@ public final class JNLPMatcher { * @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 @@ public final class JNLPMatcher { } return false; } - - /** - * Getter for application/template Node - * - * @return the Node of the signed application/template file - */ - public Node getAppTemplateNode() { - return appTemplateNode; - } - - /** - * Getter for launching application Node + + /*** + * Closes an input stream * - * @return the Node of the launching JNLP file + * @param stream + * The input stream that will be closed */ - public Node getLaunchJNLPNode() { - return launchJNLPNode; + private void closeInputStream(InputStream stream) { + if (stream != null) + try { + stream.close(); + } catch (Exception e) { + e.printStackTrace(System.err); + } } - /** - * Getter for isTemplate + /*** + * Closes an output stream * - * @return true if a signed template is being used for matching; otherwise - * false. + * @param stream + * The output stream that will be closed */ - public boolean isTemplate() { - return isTemplate; + private void closeOutputStream(OutputStream stream) { + if (stream != null) + try { + stream.close(); + } catch (Exception e) { + e.printStackTrace(System.err); + } } } diff --git a/netx/net/sourceforge/jnlp/Node.java b/netx/net/sourceforge/jnlp/Node.java index 2c754d7..327d640 100644 --- a/netx/net/sourceforge/jnlp/Node.java +++ b/netx/net/sourceforge/jnlp/Node.java @@ -145,19 +145,6 @@ class Node { 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); } |