Mercurial > hg > release > icedtea-web-1.2
changeset 270:f2c80b9ceae1
Minor changes in algorithm that compares signed JNLP application/template
author | Saad Mohammad <smohammad@redhat.com> |
---|---|
date | Wed, 03 Aug 2011 12:32:22 -0400 |
parents | 7668bf410571 |
children | defa7d0051bf |
files | ChangeLog netx/net/sourceforge/jnlp/JNLPMatcher.java netx/net/sourceforge/jnlp/Node.java |
diffstat | 3 files changed, 70 insertions(+), 54 deletions(-) [+] |
line wrap: on
line diff
--- 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@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@redhat.com> *Makefile.am: (stamps/netx-dist-tests-prepare-reproducers.stamp):
--- 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); + } } }
--- 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); }