org.cdlib.xtf.dynaXML
Class IpList

Object
  extended by IpList

 class IpList
extends Object

Loads and provides quick access to a map of IP addresses. Reads a file containing IP addresses and ranges, as well as excluded addresses, and provides a way to check if a given IP address matches.


Nested Class Summary
private  class IpList.IpAddr
          Data class to keep track of the four numeric components of an IP address.
private  class IpList.IpRange
          Data structure to keep track of a range of IP addresses and whether they are "positive" or "negative".
 
Field Summary
private  ArrayList<IpList.IpRange> ranges
          List of IpRanges.
 
Constructor Summary
IpList(String path)
          Constructs and loads an IP map from the specified file.
 
Method Summary
 boolean isApproved(String ipAddrStr)
          Parses the given IP address and checks whether it falls within one of the positive ranges of the map, and doesn't fall in one of the excluded ranges.
private  void processEntry(String line, boolean isPositive)
          Used by readMap to parse a single entry in the IP map file.
private  void readRanges(String path)
          Reads the contents the given file into the IP map.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ranges

private ArrayList<IpList.IpRange> ranges
List of IpRanges.

Constructor Detail

IpList

public IpList(String path)
       throws IOException
Constructs and loads an IP map from the specified file.

Parameters:
path - Path to the file to load the IP map from.
Throws:
IOException - If the IP map file couldn't be opened.
Method Detail

isApproved

public boolean isApproved(String ipAddrStr)
Parses the given IP address and checks whether it falls within one of the positive ranges of the map, and doesn't fall in one of the excluded ranges.

Parameters:
ipAddrStr - A string of the form "a.b.c.d" where each component is a decimal number from 0-255.
Returns:
true if and only if the address matches.

readRanges

private void readRanges(String path)
                 throws IOException
Reads the contents the given file into the IP map.

Parameters:
path - Path to the file to load
Throws:
IOException - If the file couldn't be read from.

processEntry

private void processEntry(String line,
                          boolean isPositive)
Used by readMap to parse a single entry in the IP map file.

Parameters:
line - The line of text to parse
isPositive - true if this is an "exclude" line