[RFC][Icedtea-Web]: Ensure all ports entered are numeric values
Omair Majid
omajid at redhat.com
Mon Mar 21 12:04:54 PDT 2011
On 03/21/2011 02:58 PM, Andrew Su wrote:
>> On 03/21/2011 01:51 PM, Andrew Su wrote:
>>
>>> v1 does not alert the user (silently ignore input). v2 alerts the
>>> user via popup.
>>>
>>
>> Only v2 will be applied, right?
>
> only one of the two, was more of asking for an opinion to whether we want to have silent handling of the input. or nag.
> I've fixed up v2 (now v3) assuming you wanted it to display something.
>
Ah, ok. I thought v2 was an improved version of v1 (and I was wondering
why you posted v1 at all). I dont really see a problem with dialogs.
>>
>>> 20110321_number_only_v1.patch
>>>
>>>
>>> @@ -254,4 +262,28 @@
>>> 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){
>>> + 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) {
>>> + // Just don't insert.
>>> + }
>>> + }
>>> + return;
>>> + }
>>> + };
>>> + }
>>
>> What about remove()? How is deleting port numbers handled?
>
> What issues do you see with removing numbers? If you are only allowed to add numeric values..
> Removing them will still leave you with numeric values.
>
I am wondering how a port value of "" will be dealt with.
Cheers,
Omair
More information about the distro-pkg-dev
mailing list