Changeset 2235

Show
Ignore:
Timestamp:
06/12/08 16:31:40 (4 months ago)
Author:
apatel
Message:

Fixed input checking logic of the Network Shape wizard dialog. I think it works as expected except that I need to update the ip_addr pattern that I had added in earlier commit to fix the bug in alphanumeric IP address acceptance.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/framework-plugin/src/com/tresys/framework/plugin/wizards/shape/NetworkResourceShapePropertyPage.java

    r2234 r2235  
    202202                                String value = (String)selection.getFirstElement (); 
    203203                                modifyValue (value); 
    204                                 updateStatus (); 
    205 
     204                                checkInput (); 
     205                       
    206206 
    207207                } 
     
    221221 
    222222                        modifyValue (s); 
    223                         updateStatus (); 
     223                        checkInput (); 
    224224                } 
    225225 
     
    241241 
    242242                        modifyValue (s); 
    243                          
    244                         if (s.trim ().length () == 0) 
    245                                         updateStatus (this.errorMessage, false); 
    246                          
    247                         else 
    248                                 updateStatus(); 
     243                        checkInput (); 
    249244                }                
    250245        } 
     
    267262 
    268263                        modifyValue (s); 
    269                          
    270                         if (!this.required && s.trim().length () == 0) 
    271                         { 
    272                                 updateStatus();                  
    273                         } 
    274                         else 
    275                         { 
    276                                 boolean match = Pattern.matches(NetworkResourceShape.NetworkResource_ip_address_pattern, s); 
    277                                 boolean ip4 = Pattern.matches (NetworkResourceShape.NetworkResource_ipv4_address_pattern, s); 
    278                                 boolean ip6 = Pattern.matches(NetworkResourceShape.NetworkResource_ipv6_address_pattern, s);  
    279                                  
    280                                 if( ip4 || ip6 || match ) 
    281                                         updateStatus (); 
    282                                 else 
    283                                 { 
    284                                         String msg = getErrorMessage (); 
    285                                         if (msg == null || !msg.equals (this.errorMessage)) 
    286                                                 updateStatus (this.errorMessage, false); 
    287                                 } 
    288                         } 
     264                        checkInput (); 
    289265                } 
    290266        } 
     
    305281                         
    306282                        modifyValue (s); 
    307                          
    308                         if (s.trim ().length () > 0 && !Pattern.matches (NetworkResourceShape.NetworkResource_ip_ports_pattern, s)) 
    309                                 updateStatus(this.errorMessage, false); 
    310                         else 
    311                                 updateStatus(); 
     283                        checkInput (); 
    312284                } 
    313285        } 
     
    441413                                        GridData sysData = new GridData(GridData.FILL_HORIZONTAL| GridData.GRAB_HORIZONTAL); 
    442414                                        device.setLayoutData(sysData); 
     415                                        device.setText (this.localDevice); 
    443416                                } 
    444417                                 
     
    498471                                        GridData sysData = new GridData(GridData.FILL_HORIZONTAL| GridData.GRAB_HORIZONTAL); 
    499472                                        device.setLayoutData(sysData); 
     473                                        device.setText (this.remoteDevice); 
    500474                                } 
    501475 
     
    569543        } 
    570544         
    571         /* 
    572          * Verify that a BaseDomain was selected 
     545         
     546        protected void checkInput() 
     547        { 
     548                StructuredSelection sel = (StructuredSelection)m_combo.getSelection (); 
     549                Rdef networkType = (Rdef)sel.getFirstElement (); 
     550 
     551                if (networkType != null && 
     552                        (networkType.GetSysResourceState (SystemResourceTypes.ipsec) == SysResourceState.Yes || networkType.GetSysResourceState (SystemResourceTypes.ipsec) == SysResourceState.Optional)) 
     553                { 
     554                        // required value 
     555                        if ( localIPAddress.length () == 0 ) 
     556                        { 
     557                                updateStatus ("Enter valid local IP address", false); 
     558                                return; 
     559                        } 
     560                         
     561                        // this is optional value check only if it has any valid characters. 
     562                        if( localIPPorts.trim ().length () > 0 && 
     563                                (!Pattern.matches (NetworkResourceShape.NetworkResource_ip_ports_pattern, localIPPorts.trim ())) 
     564                                ) 
     565                        { 
     566                                updateStatus("Enter valid local port, multiple ports seperated by space", false); 
     567                                return; 
     568                        } 
     569 
     570                        { 
     571                                // all the required value check is complete 
     572                                // lets make sure that the value matches the requirement 
     573                                boolean match = Pattern.matches(NetworkResourceShape.NetworkResource_ip_address_pattern, localIPAddress.trim ()); 
     574                                boolean ip4 = Pattern.matches (NetworkResourceShape.NetworkResource_ipv4_address_pattern, localIPAddress.trim ()); 
     575                                boolean ip6 = Pattern.matches(NetworkResourceShape.NetworkResource_ipv6_address_pattern, localIPAddress.trim ());  
     576                                 
     577                                if( ! (ip4 || ip6 || match) ) 
     578                                { 
     579                                        updateStatus ("Enter valid local IP address", false); 
     580                                        return; 
     581                                } 
     582                        } 
     583                } 
     584                else if (networkType != null && 
     585                        (networkType.GetSysResourceState (SystemResourceTypes.secmark) == SysResourceState.Yes || networkType.GetSysResourceState (SystemResourceTypes.secmark) == SysResourceState.Optional)) 
     586                { 
     587                         
     588                        if( localDevice.trim ().length () == 0 ) 
     589                        { 
     590                                updateStatus ("Enter valid local Device", false); 
     591                                return; 
     592                        } 
     593                        // local information 
     594                        if ( localIPAddress.trim ().length () == 0 ) 
     595                        { 
     596                                updateStatus ("Enter valid local IP address", false); 
     597                                return; 
     598                        } 
     599                        if ( localMask.trim ().length () > 0  
     600                                                && !Pattern.matches (NetworkResourceShape.NetworkResource_ipv4_address_pattern, localMask.trim ()) 
     601                                                && !Pattern.matches(NetworkResourceShape.NetworkResource_ipv6_address_pattern, localMask.trim ()) 
     602                                                ) 
     603                        { 
     604                                updateStatus ("Enter valid local Mask value", false); 
     605                                return; 
     606                        } 
     607                        if( localIPPorts.trim ().length () > 0 && 
     608                                (!Pattern.matches (NetworkResourceShape.NetworkResource_ip_ports_pattern, localIPPorts.trim ())) 
     609                                ) 
     610                        { 
     611                                updateStatus("Enter valid local ports, multiple ports seperated by space", false); 
     612                                return; 
     613                        } 
     614                         
     615                        { 
     616                                boolean match = Pattern.matches(NetworkResourceShape.NetworkResource_ip_address_pattern, localIPAddress.trim ()); 
     617                                boolean ip4 = Pattern.matches (NetworkResourceShape.NetworkResource_ipv4_address_pattern, localIPAddress.trim ()); 
     618                                boolean ip6 = Pattern.matches(NetworkResourceShape.NetworkResource_ipv6_address_pattern, localIPAddress.trim ());  
     619                                 
     620                                if( ! (ip4 || ip6 || match) ) 
     621                                { 
     622                                        updateStatus ("Enter valid local IP address", false); 
     623                                        return; 
     624                                } 
     625                        } 
     626                         
     627                         
     628                        // remote infomration all of them are optional 
     629                        if( remoteDevice.trim ().length () > 0  && remoteIPAddress.trim ().length () == 0) 
     630                        { 
     631                                updateStatus ("Enter valid remote IP Address", false); 
     632                                return; 
     633                        } 
     634                        if ( remoteIPAddress.trim ().length () > 0  && remoteDevice.trim ().length () == 0 ) 
     635                        { 
     636                                updateStatus ("Enter valid remote Device", false); 
     637                                return; 
     638                        } 
     639                        if ( remoteIPAddress.trim ().length () > 0 ) 
     640                        { 
     641                                boolean match = Pattern.matches(NetworkResourceShape.NetworkResource_ip_address_pattern, remoteIPAddress.trim ()); 
     642                                boolean ip4 = Pattern.matches (NetworkResourceShape.NetworkResource_ipv4_address_pattern, remoteIPAddress.trim ()); 
     643                                boolean ip6 = Pattern.matches(NetworkResourceShape.NetworkResource_ipv6_address_pattern, remoteIPAddress.trim ());  
     644                                 
     645                                if( ! (ip4 || ip6 || match) ) 
     646                                { 
     647                                        updateStatus ("Enter Valid remote IP address", false); 
     648                                        return; 
     649                                } 
     650                        } 
     651                        if ( remoteMask.trim ().length () > 0  
     652                                                && !Pattern.matches (NetworkResourceShape.NetworkResource_ipv4_address_pattern, remoteMask.trim ()) 
     653                                                && !Pattern.matches(NetworkResourceShape.NetworkResource_ipv6_address_pattern, remoteMask.trim ()) 
     654                                                ) 
     655                        { 
     656                                updateStatus ("Enter valid remote Mask value", false); 
     657                                return; 
     658                        } 
     659                        if( remoteIPPorts.trim ().length () > 0 && 
     660                                (!Pattern.matches (NetworkResourceShape.NetworkResource_ip_ports_pattern, remoteIPPorts.trim ())) 
     661                                ) 
     662                        { 
     663                                updateStatus("Enter valid remote ports, multiple ports seperated by space", false); 
     664                                return; 
     665                        } 
     666                         
     667                } 
     668                 
     669                // no error go ahead and allow user to complete 
     670                updateStatus (null, true); 
     671        } 
     672 
     673        /** 
     674         * I had to copy stuff from the parent. 
     675         * Never call super.DialogChanged(). That is not appropriate for this 
     676         * wizard. 
    573677         */ 
    574678        public void DialogChanged() 
    575679        {                
    576                 updateStatus(); 
    577         } 
    578          
    579         protected void updateStatus() 
    580         {                
    581                 super.DialogChanged (); 
    582  
    583                 if (this.getErrorMessage () == null) 
    584                 { 
    585                         if ((getNetworkType().GetSysResourceState (SystemResourceTypes.ipsec) == SysResourceState.Yes || getNetworkType().GetSysResourceState (SystemResourceTypes.ipsec) == SysResourceState.Optional)) 
    586                         { 
    587                                 if (localIPAddress.trim ().length () == 0) 
    588                                         super.updateStatus (Messages.NetworkResourcePropertyPage_bad_local_ip_address, false); 
    589                         } 
    590                          
    591                         else if ((getNetworkType().GetSysResourceState (SystemResourceTypes.secmark) == SysResourceState.Yes || getNetworkType().GetSysResourceState (SystemResourceTypes.secmark) == SysResourceState.Optional)) 
    592                         { 
    593                                 if (localDevice.trim ().length () == 0 && localIPAddress.trim ().length () == 0) 
    594                                         super.updateStatus (Messages.NetworkResourcePropertyPage_err_local_device_or_ip, false); 
    595                         }                
    596                 } 
     680                String name = getShapeName(); 
     681                 
     682                if (name == null || name.length() == 0) 
     683                { 
     684                        m_errorMessage = NLS.bind (Messages.ShapePropertyPage_err1, getShape ().getType()); 
     685                        updateStatus(m_errorMessage, false); 
     686                        return; 
     687                } 
     688                 
     689                //Need to test if name is valid 
     690                m_errorMessage = getShape ().testValidity(name); 
     691                 
     692                if (m_errorMessage != null) 
     693                { 
     694                        updateStatus(m_errorMessage, false); 
     695                        return; 
     696                } 
     697                 
     698                // check all the fields. 
     699                checkInput (); 
    597700        } 
    598701