[RFC][Icedtea-Web]: Ensure all ports entered are numeric values

Andrew Su asu at redhat.com
Wed Apr 6 06:25:29 PDT 2011


--snip--

> > @@ -254,4 +262,29 @@
> >                   enablePanel(panel, false);
> >           }
> >       }
> > +
> > + /**
> > + * Creates a PlainDocument that only take numbers if it will create
> > a valid port number.
> > + * @return PlainDocument which will ensure numeric values only and
> > is a valid port number.
> > + */
> > + public static PlainDocument getNumberDocument(final Component c){
> 
> Hm... what is c? Is it used in this method? If it's something left
> over
> from a previous patch, it might be best just to delete it. I would
> also
> prefer it if the method name indicated that it's meant for port
> numbers,
> not general numbers.
> 
> > + return new PlainDocument(){
> > + public void insertString(int offs, String str, AttributeSet a)
> > throws BadLocationException {
> > + if (str != null) {
> > + try {
> > + Integer.valueOf(str);
> > + int val = Integer.valueOf(this.getText(0, this.getLength()) +
> > str);
> > + if (val< 1 || val> 65535) { // Invalid port number if true
> > + throw new NumberFormatException("Invalid port number");
> > + }
> > + super.insertString(offs, str, a);
> > + } catch (Exception e) {
> > + JOptionPane.showMessageDialog(null, Translator.R("CPInvalidPort"),
> > Translator.R("CPInvalidPortTitle")
> > + , JOptionPane.WARNING_MESSAGE);
> > + }
> > + }
> > + return;
> > + }
> > + };
> > + }
> >   }
> > diff -r eea730466b87
> > netx/net/sourceforge/jnlp/resources/Messages.properties
> > --- a/netx/net/sourceforge/jnlp/resources/Messages.properties Tue
> > Apr 05 14:38:22 2011 -0400
> > +++ b/netx/net/sourceforge/jnlp/resources/Messages.properties Tue
> > Apr 05 16:26:59 2011 -0400
> > @@ -407,6 +407,8 @@
> >
> >   # Control Panel - Misc.
> >   CPJRESupport=IcedTea-Web currently does not support the use of
> >   multiple JREs.
> > +CPInvalidPort=Invalid port number given.\n[Valid port numbers are
> > 1-65535]
> > +CPInvalidPortTitle=Error on input.
> >
> >   # command line control panel
> >   CLNoInfo=No information avaiable (is this a valid option?).
> 
> Everything else looks fine.

Thanks for looking it over, I've attached a version with the extra parameter removed and renamed it to getPortNumberDocument.

Cheers,
 Andrew



More information about the distro-pkg-dev mailing list