You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by so...@apache.org on 2008/01/31 08:44:36 UTC

svn commit: r617035 [17/22] - in /lenya/branches/revolution/1.3.x: ./ src/java/org/apache/lenya/ac/ src/java/org/apache/lenya/ac/cache/ src/java/org/apache/lenya/ac/cifs/ src/java/org/apache/lenya/ac/file/ src/java/org/apache/lenya/ac/impl/ src/java/or...

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/index/IndexInformation.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/index/IndexInformation.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/index/IndexInformation.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/index/IndexInformation.java Wed Jan 30 23:44:03 2008
@@ -14,11 +14,8 @@
  *  limitations under the License.
  *
  */
-
 /* $Id$  */
-
 package org.apache.lenya.lucene.index;
-
 import java.io.File;
 import java.io.FileFilter;
 import java.text.DateFormat;
@@ -26,184 +23,155 @@
 import java.util.Calendar;
 import java.util.Date;
 import java.util.GregorianCalendar;
-
-import org.apache.log4j.Category;
+import org.apache.log4j.Logger;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
-
 /**
  * Helper class to hold indexing information
  */
 public class IndexInformation {
-    
-    private static Category log = Category.getInstance(IndexInformation.class);
-    
-    /**
-     * Creates a new IndexInformation object.
-     * @param index DOCUMENT ME!
-     * @param dumpDirectory DOCUMENT ME!
-     * @param filter DOCUMENT ME!
-     * @param create DOCUMENT ME!
-     */
-    public IndexInformation(String index, File dumpDirectory, FileFilter filter, boolean create) {
-        log.info("Collecting index information for index '" + index + "'...");
-
-        this.creating = create;
-        this.index = index;
-        collectFiles(dumpDirectory, filter, index);
-        this.startTime = new GregorianCalendar();
-
-        log.info(this.length + " files to index");
-        //log.info(getFileNumber() + " files to index");
-    }
-
-    private String index;
-
-    protected String getIndex() {
-        return this.index;
-    }
-
-    private boolean creating;
-
-    protected boolean isCreating() {
-        return this.creating;
-    }
-
-    //private List files = new ArrayList();
-    private int length = 0;
-
-    /**
-     *
-     */
-    protected void addFile(File file) {
-        //files.add(file);
-	this.length++;
-    }
-
-    /**
-     * DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     */
-/*
-    public File[] getFiles() {
-        Collections.sort(files);
-
-        return (File[]) files.toArray(new File[files.size()]);
-    }
-*/
-
-    private int currentFile = 0;
-
-    /**
-     * DOCUMENT ME!
-     */
-    public void increase() {
-        this.currentFile++;
-    }
-
-    /**
-     * DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     */
-    public int getCurrentFile() {
-        return currentFile;
-    }
-
-    /**
-     * Get number of files to index
-     *
-     * @return number of files to index
-     */
-/*
-    public int getFileNumber() {
-        return files.size();
-    }
-*/
-
-    private Calendar startTime;
-
-    /**
-     * DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     */
-    public Calendar getStartTime() {
-        return this.startTime;
-    }
-
-    /**
-     * Generate string which tells about the indexing progress
-     *
-     * @return indexing progress
-     */
-    public String printProgress() {
-        double percent = (double) this.currentFile / (double) this.length;
-        //double percent = (double) currentFile / (double) getFileNumber();
-        DateFormat format = new SimpleDateFormat("HH:mm:ss");
-
-        //return "added document " + getCurrentFile() + " of " + getFileNumber() + " (" +
-        return "added document " + getCurrentFile() + " of " + this.length + " (" +
-        (int) (percent * 100) + "%" + ", remaining time: " +
-        format.format(getEstimatedTime().getTime()) + ")";
-    }
-
-    /**
-     *
-     */
-    protected Calendar getEstimatedTime() {
-        long elapsedMillis = new Date().getTime() - getStartTime().getTime().getTime();
-
-        double millisPerFile = (double) elapsedMillis / (double) this.currentFile;
-        long estimatedMillis = (long) (millisPerFile * this.length) - elapsedMillis;
-        //long estimatedMillis = (long) (millisPerFile * getFileNumber()) - elapsedMillis;
-
-        GregorianCalendar estimatedCalendar = new GregorianCalendar();
-        estimatedCalendar.setTimeInMillis(estimatedMillis);
-        estimatedCalendar.roll(Calendar.HOUR, false);
-
-        return estimatedCalendar;
-    }
-
-    /**
-     * Collect files
-     */
-    protected void collectFiles(File dumpDirectory, FileFilter filter, String _index) {
-        IndexIterator iterator = new IndexIterator(_index, filter);
-        IndexIteratorHandler handler;
-
-        if (isCreating()) {
-            handler = new CreateHandler();
-        } else {
-            handler = new UpdateHandler();
-        }
-
-        iterator.addHandler(handler);
-        iterator.iterate(dumpDirectory);
-    }
-
-    /**
-     * DOCUMENT ME!
-     */
-    public class CreateHandler extends AbstractIndexIteratorHandler {
-        /** Handles a file.
-         *
-         */
-        public void handleFile(IndexReader reader, File file) {
-            IndexInformation.this.addFile(file);
-        }
-    }
-
-    /**
-     * DOCUMENT ME!
-     */
-    public class UpdateHandler extends AbstractIndexIteratorHandler {
-        /** Handles a new document.
-         *
-         */
-        public void handleNewDocument(IndexReader reader, Term term, File file) {
-            IndexInformation.this.addFile(file);
-        }
-    }
+   private static Logger log = Logger.getLogger(IndexInformation.class);
+   /**
+    * Creates a new IndexInformation object.
+    * 
+    * @param index
+    *           DOCUMENT ME!
+    * @param dumpDirectory
+    *           DOCUMENT ME!
+    * @param filter
+    *           DOCUMENT ME!
+    * @param create
+    *           DOCUMENT ME!
+    */
+   public IndexInformation(String index, File dumpDirectory, FileFilter filter, boolean create) {
+      log.info("Collecting index information for index '" + index + "'...");
+      this.creating = create;
+      this.index = index;
+      collectFiles(dumpDirectory, filter, index);
+      this.startTime = new GregorianCalendar();
+      log.info(this.length + " files to index");
+      // log.info(getFileNumber() + " files to index");
+   }
+   private String index;
+   protected String getIndex() {
+      return this.index;
+   }
+   private boolean creating;
+   protected boolean isCreating() {
+      return this.creating;
+   }
+   // private List files = new ArrayList();
+   private int length = 0;
+   /**
+    * 
+    */
+   protected void addFile(File file) {
+      // files.add(file);
+      this.length++;
+   }
+   /**
+    * DOCUMENT ME!
+    * 
+    * @return DOCUMENT ME!
+    */
+   /*
+    * public File[] getFiles() { Collections.sort(files);
+    * 
+    * return (File[]) files.toArray(new File[files.size()]); }
+    */
+   private int currentFile = 0;
+   /**
+    * DOCUMENT ME!
+    */
+   public void increase() {
+      this.currentFile++;
+   }
+   /**
+    * DOCUMENT ME!
+    * 
+    * @return DOCUMENT ME!
+    */
+   public int getCurrentFile() {
+      return currentFile;
+   }
+   /**
+    * Get number of files to index
+    * 
+    * @return number of files to index
+    */
+   /*
+    * public int getFileNumber() { return files.size(); }
+    */
+   private Calendar startTime;
+   /**
+    * DOCUMENT ME!
+    * 
+    * @return DOCUMENT ME!
+    */
+   public Calendar getStartTime() {
+      return this.startTime;
+   }
+   /**
+    * Generate string which tells about the indexing progress
+    * 
+    * @return indexing progress
+    */
+   public String printProgress() {
+      double percent = (double) this.currentFile / (double) this.length;
+      // double percent = (double) currentFile / (double) getFileNumber();
+      DateFormat format = new SimpleDateFormat("HH:mm:ss");
+      // return "added document " + getCurrentFile() + " of " + getFileNumber() + " (" +
+      return "added document " + getCurrentFile() + " of " + this.length + " (" + (int) (percent * 100) + "%" + ", remaining time: " + format.format(getEstimatedTime().getTime()) + ")";
+   }
+   /**
+    * 
+    */
+   protected Calendar getEstimatedTime() {
+      long elapsedMillis = new Date().getTime() - getStartTime().getTime().getTime();
+      double millisPerFile = (double) elapsedMillis / (double) this.currentFile;
+      long estimatedMillis = (long) (millisPerFile * this.length) - elapsedMillis;
+      // long estimatedMillis = (long) (millisPerFile * getFileNumber()) - elapsedMillis;
+      GregorianCalendar estimatedCalendar = new GregorianCalendar();
+      estimatedCalendar.setTimeInMillis(estimatedMillis);
+      estimatedCalendar.roll(Calendar.HOUR, false);
+      return estimatedCalendar;
+   }
+   /**
+    * Collect files
+    */
+   protected void collectFiles(File dumpDirectory, FileFilter filter, String _index) {
+      IndexIterator iterator = new IndexIterator(_index, filter);
+      IndexIteratorHandler handler;
+      if(isCreating()){
+         handler = new CreateHandler();
+      }else{
+         handler = new UpdateHandler();
+      }
+      iterator.addHandler(handler);
+      iterator.iterate(dumpDirectory);
+   }
+   /**
+    * DOCUMENT ME!
+    */
+   public class CreateHandler extends AbstractIndexIteratorHandler {
+      /**
+       * Handles a file.
+       * 
+       */
+      public void handleFile(IndexReader reader, File file) {
+         IndexInformation.this.addFile(file);
+      }
+   }
+   /**
+    * DOCUMENT ME!
+    */
+   public class UpdateHandler extends AbstractIndexIteratorHandler {
+      /**
+       * Handles a new document.
+       * 
+       */
+      public void handleNewDocument(IndexReader reader, Term term, File file) {
+         IndexInformation.this.addFile(file);
+      }
+   }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/index/IndexIterator.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/index/IndexIterator.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/index/IndexIterator.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/index/IndexIterator.java Wed Jan 30 23:44:03 2008
@@ -14,11 +14,8 @@
  *  limitations under the License.
  *
  */
-
 /* $Id$  */
-
 package org.apache.lenya.lucene.index;
-
 import java.io.File;
 import java.io.FileFilter;
 import java.io.IOException;
@@ -32,307 +29,256 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-
-import org.apache.log4j.Category;
+import org.apache.log4j.Logger;
 import org.apache.lucene.document.DateField;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermEnum;
-
 public class IndexIterator {
-    
-    private static Category log = Category.getInstance(IndexIterator.class);
-    
-    /**
-     * Creates a new instance of IndexItertor
-     */
-    public IndexIterator(String index, FileFilter filter) {
-        this.filter = filter;
-        this.index = index;
-    }
-
-    private String index;
-
-    protected String getIndex() {
-        return index;
-    }
-
-    private FileFilter filter;
-
-    /**
-     * @return FileFilter
-     */
-    protected FileFilter getFilter() {
-        return filter;
-    }
-
-    private List handlers = new ArrayList();
-
-    /**
-     * DOCUMENT ME!
-     *
-     * @param handler DOCUMENT ME!
-     */
-    public void addHandler(IndexIteratorHandler handler) {
-        if (!handlers.contains(handler)) {
-            handlers.add(handler);
-        }
-    }
-
-    protected void handleFile(File file) {
-        for (Iterator i = handlers.iterator(); i.hasNext();) {
-            IndexIteratorHandler handler = (IndexIteratorHandler) i.next();
-            handler.handleFile(getReader(), file);
-        }
-    }
-
-    protected void handleStaleDocument(Term term) {
-        for (Iterator i = handlers.iterator(); i.hasNext();) {
-            IndexIteratorHandler handler = (IndexIteratorHandler) i.next();
-            handler.handleStaleDocument(getReader(), term);
-        }
-    }
-
-    protected void handleUnmodifiedDocument(Term term, File file) {
-        for (Iterator i = handlers.iterator(); i.hasNext();) {
-            IndexIteratorHandler handler = (IndexIteratorHandler) i.next();
-            handler.handleUnmodifiedDocument(getReader(), term, file);
-        }
-    }
-
-    protected void handleNewDocument(Term term, File file) {
-        for (Iterator i = handlers.iterator(); i.hasNext();) {
-            IndexIteratorHandler handler = (IndexIteratorHandler) i.next();
-            handler.handleNewDocument(getReader(), term, file);
-        }
-    }
-
-    private IndexReader reader;
-
-    protected IndexReader getReader() {
-        return reader;
-    }
-
-    /**
-     * Iterate over all files within directory
-     *
-     * @param dumpDirectory Directory over which shall be iterated
-     */
-    public void iterate(File dumpDirectory) {
-        log.info("Iterating files (" + dumpDirectory + ")");
-
-        try {
-            reader = IndexReader.open(getIndex());
-
-            TermEnum iterator = enumerateUIDs(getReader());
-
-	    // TODO: Should be configurable
-	    boolean sort = false;
-
-	    if (sort) {
-                File[] files = getFiles(dumpDirectory);
-
-                for (int i = 0; i < files.length; i++) {
-                    iterateFiles(iterator, files[i], dumpDirectory);
-                }
-            } else {
-                log.debug("Do not sort files ...");
-                traverse(iterator, dumpDirectory, dumpDirectory);
+   private static Logger log = Logger.getLogger(IndexIterator.class);
+   /**
+    * Creates a new instance of IndexItertor
+    */
+   public IndexIterator(String index, FileFilter filter) {
+      this.filter = filter;
+      this.index = index;
+   }
+   private String index;
+   protected String getIndex() {
+      return index;
+   }
+   private FileFilter filter;
+   /**
+    * @return FileFilter
+    */
+   protected FileFilter getFilter() {
+      return filter;
+   }
+   private List handlers = new ArrayList();
+   /**
+    * DOCUMENT ME!
+    * 
+    * @param handler
+    *           DOCUMENT ME!
+    */
+   public void addHandler(IndexIteratorHandler handler) {
+      if(!handlers.contains(handler)){
+         handlers.add(handler);
+      }
+   }
+   protected void handleFile(File file) {
+      for(Iterator i = handlers.iterator(); i.hasNext();){
+         IndexIteratorHandler handler = (IndexIteratorHandler) i.next();
+         handler.handleFile(getReader(), file);
+      }
+   }
+   protected void handleStaleDocument(Term term) {
+      for(Iterator i = handlers.iterator(); i.hasNext();){
+         IndexIteratorHandler handler = (IndexIteratorHandler) i.next();
+         handler.handleStaleDocument(getReader(), term);
+      }
+   }
+   protected void handleUnmodifiedDocument(Term term, File file) {
+      for(Iterator i = handlers.iterator(); i.hasNext();){
+         IndexIteratorHandler handler = (IndexIteratorHandler) i.next();
+         handler.handleUnmodifiedDocument(getReader(), term, file);
+      }
+   }
+   protected void handleNewDocument(Term term, File file) {
+      for(Iterator i = handlers.iterator(); i.hasNext();){
+         IndexIteratorHandler handler = (IndexIteratorHandler) i.next();
+         handler.handleNewDocument(getReader(), term, file);
+      }
+   }
+   private IndexReader reader;
+   protected IndexReader getReader() {
+      return reader;
+   }
+   /**
+    * Iterate over all files within directory
+    * 
+    * @param dumpDirectory
+    *           Directory over which shall be iterated
+    */
+   public void iterate(File dumpDirectory) {
+      log.info("Iterating files (" + dumpDirectory + ")");
+      try{
+         reader = IndexReader.open(getIndex());
+         TermEnum iterator = enumerateUIDs(getReader());
+         // TODO: Should be configurable
+         boolean sort = false;
+         if(sort){
+            File[] files = getFiles(dumpDirectory);
+            for(int i = 0; i < files.length; i++){
+               iterateFiles(iterator, files[i], dumpDirectory);
             }
-
-            // iterate the rest of stale documents
-            while ((iterator.term() != null) && iterator.term().field().equals("uid")) {
-                handleStaleDocument(iterator.term());
-                iterator.next();
-            }
-
-            iterator.close();
-            reader.close();
-        } catch (IOException e) {
-            log.error(e);
-        }
-    }
-
-    /**
-     *
-     */
-    protected void iterateFiles(TermEnum iterator, File file, File dumpDirectory)
-        throws IOException {
-        String uid = createUID(file, dumpDirectory);
-        log.debug("-----------------------------------------------------");
-        log.debug("[file]  file uid: " + uid2url(uid));
-
-        handleFile(file);
-
-        // handle all terms with a smaller uid than the modified file and delete their documents
-        while (isStale(iterator.term(), uid)) {
-            log.debug("[stale] term uid: " + uid2url(iterator.term().text()));
+         }else{
+            log.debug("Do not sort files ...");
+            traverse(iterator, dumpDirectory, dumpDirectory);
+         }
+         // iterate the rest of stale documents
+         while((iterator.term() != null) && iterator.term().field().equals("uid")){
             handleStaleDocument(iterator.term());
             iterator.next();
-        }
-
-        // handle un-modified file
-        if (hasEqualUID(iterator.term(), uid)) {
-            log.debug("[unmod] term uid: " + uid2url(iterator.term().text()));
-            handleUnmodifiedDocument(iterator.term(), file);
-            iterator.next();
-        }
-        // handle new file
-        else {
-            if (iterator.term() != null) {
-                log.debug("[new]   term uid: " + uid2url(iterator.term().text()));
-                handleNewDocument(iterator.term(), file);
-            }
-        }
-    }
-
-    /**
-     * Returns an term enumerator beginning with the first term that represents a UID field.
-     */
-    protected TermEnum enumerateUIDs(IndexReader reader) {
-        TermEnum tEnum = null;
-
-        try {
-            tEnum = reader.terms(new Term("uid", ""));
-        } catch (IOException e) {
-            log.error("Term enumeration failed: ", e);
-        }
-            
-        return tEnum;
-    }
-
-    /**
-     * Returns if the term is not null and decribes a UID field.
-     */
-    protected static boolean isUIDTerm(Term term) {
-        return (term != null) && term.field().equals("uid");
-    }
-
-    /**
-     * Returns <code>true</code> if the file described by uid has a bigger UID than the
-     * file described by the existing UID term.
-     */
-    protected static boolean isStale(Term term, String uid) {
-        return isUIDTerm(term) && (term.text().compareTo(uid) < 0);
-    }
-
-    /**
-     * Returns <code>true</code> if the file described by uid has the same UID as the
-     * file described by the existing UID term.
-     */
-    protected static boolean hasEqualUID(Term term, String uid) {
-        return isUIDTerm(term) && term.text().equals(uid);
-    }
-
-    /**
-     * Create a unique id
-     *
-     * @param file file to index
-     * @param dumpDir dump directory
-     *
-     * @return id
-     */
-    public static String createID(File file, File dumpDir) {
-        if (dumpDir.getPath().length() <= file.getPath().length()) {
-            String id = file.getPath().substring(dumpDir.getPath().length());
-            //id = id.replace(File.separatorChar, '\u0000'));
-            return id;
-        } else {
-            log.warn("Length of dumping directory is less than length of file name! Absolute path is being returned as id.");
-            return file.getAbsolutePath();
-        }
-    }
-
-    /**
-     * Append path and date into a string in such a way that lexicographic sorting gives the same
-     * results as a walk of the file hierarchy.  Thus null (\u0000) is used both to separate
-     * directory components and to separate the path from the date.
-     *
-     * @param file DOCUMENT ME!
-     * @param htdocsDumpDir DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     */
-    public static String createUID(File file, File htdocsDumpDir) {
-        String requestURI = file.getPath().substring(htdocsDumpDir.getPath().length());
-        String uid = requestURI.replace(File.separatorChar, '\u0000') + "\u0000" +
-            DateField.timeToString(file.lastModified());
-
-        return uid;
-    }
-
-    /**
-     * Converts a UID to a URL string.
-     */
-    public static String uid2url(String uid) {
-        String url = uid.replace('\u0000', '/'); // replace nulls with slashes
-        String timeString = uid.substring(uid.lastIndexOf("\u0000") + 1);
-        Date date = DateField.stringToDate(timeString);
-        DateFormat format = new SimpleDateFormat("yyyy.MM.dd  HH:mm:ss");
-
-        return url.substring(0, url.lastIndexOf('/')) + " " + format.format(date);
-    }
-
-    /**
-     * Get Files and sorts by alphabet?
-     */
-    public File[] getFiles(File dumpDirectory) {
-        List files = new ArrayList();
-        collectFiles(dumpDirectory, files);
-        Collections.sort(files);
-
-        Map uidToFile = new HashMap();
-
-        String[] uids = new String[files.size()];
-
-        for (int i = 0; i < uids.length; i++) {
-            uids[i] = createUID((File) files.get(i), dumpDirectory);
-            uidToFile.put(uids[i], files.get(i));
-        }
-
-        Arrays.sort(uids);
-
-        File[] fileArray = new File[uids.length];
-
-        for (int i = 0; i < uids.length; i++) {
-            File file = (File) uidToFile.get(uids[i]);
-            log.debug(file);
-            fileArray[i] = file;
-        }
-
-        return fileArray;
-    }
-
-    /**
-     * Collect files
-     */
-    protected void collectFiles(File file, List files) {
-        if (file.isDirectory()) {
-            log.debug("Apply filter " + getFilter().getClass().getName() + " to: " + file);
-            File[] fileArray = file.listFiles(getFilter());
-
-            for (int i = 0; i < fileArray.length; i++) {
-                collectFiles(fileArray[i], files);
-            }
-        } else {
-            files.add(file);
-        }
-    }
-
-    /**
-     * Traverse directory
-     */
-    protected void traverse(TermEnum iterator, File file, File dumpDirectory) throws IOException {
-        if (file.isDirectory()) {
-            log.debug("Apply filter " + getFilter().getClass().getName() + " to: " + file);
-            File[] fileArray = file.listFiles(getFilter());
-
-            for (int i = 0; i < fileArray.length; i++) {
-                traverse(iterator, fileArray[i], dumpDirectory);
-            }
-        } else {
-            log.debug(file);
-            iterateFiles(iterator, file, dumpDirectory);
-        }
-    }
+         }
+         iterator.close();
+         reader.close();
+      }catch(IOException e){
+         log.error(e);
+      }
+   }
+   /**
+    * 
+    */
+   protected void iterateFiles(TermEnum iterator, File file, File dumpDirectory) throws IOException {
+      String uid = createUID(file, dumpDirectory);
+      log.debug("-----------------------------------------------------");
+      log.debug("[file]  file uid: " + uid2url(uid));
+      handleFile(file);
+      // handle all terms with a smaller uid than the modified file and delete their documents
+      while(isStale(iterator.term(), uid)){
+         log.debug("[stale] term uid: " + uid2url(iterator.term().text()));
+         handleStaleDocument(iterator.term());
+         iterator.next();
+      }
+      // handle un-modified file
+      if(hasEqualUID(iterator.term(), uid)){
+         log.debug("[unmod] term uid: " + uid2url(iterator.term().text()));
+         handleUnmodifiedDocument(iterator.term(), file);
+         iterator.next();
+      }
+      // handle new file
+      else{
+         if(iterator.term() != null){
+            log.debug("[new]   term uid: " + uid2url(iterator.term().text()));
+            handleNewDocument(iterator.term(), file);
+         }
+      }
+   }
+   /**
+    * Returns an term enumerator beginning with the first term that represents a UID field.
+    */
+   protected TermEnum enumerateUIDs(IndexReader reader) {
+      TermEnum tEnum = null;
+      try{
+         tEnum = reader.terms(new Term("uid", ""));
+      }catch(IOException e){
+         log.error("Term enumeration failed: ", e);
+      }
+      return tEnum;
+   }
+   /**
+    * Returns if the term is not null and decribes a UID field.
+    */
+   protected static boolean isUIDTerm(Term term) {
+      return (term != null) && term.field().equals("uid");
+   }
+   /**
+    * Returns <code>true</code> if the file described by uid has a bigger UID than the file described by the existing UID term.
+    */
+   protected static boolean isStale(Term term, String uid) {
+      return isUIDTerm(term) && (term.text().compareTo(uid) < 0);
+   }
+   /**
+    * Returns <code>true</code> if the file described by uid has the same UID as the file described by the existing UID term.
+    */
+   protected static boolean hasEqualUID(Term term, String uid) {
+      return isUIDTerm(term) && term.text().equals(uid);
+   }
+   /**
+    * Create a unique id
+    * 
+    * @param file
+    *           file to index
+    * @param dumpDir
+    *           dump directory
+    * 
+    * @return id
+    */
+   public static String createID(File file, File dumpDir) {
+      if(dumpDir.getPath().length() <= file.getPath().length()){
+         String id = file.getPath().substring(dumpDir.getPath().length());
+         // id = id.replace(File.separatorChar, '\u0000'));
+         return id;
+      }else{
+         log.warn("Length of dumping directory is less than length of file name! Absolute path is being returned as id.");
+         return file.getAbsolutePath();
+      }
+   }
+   /**
+    * Append path and date into a string in such a way that lexicographic sorting gives the same results as a walk of the file hierarchy. Thus null (\u0000) is used both to separate directory components and to separate the path from the date.
+    * 
+    * @param file
+    *           DOCUMENT ME!
+    * @param htdocsDumpDir
+    *           DOCUMENT ME!
+    * 
+    * @return DOCUMENT ME!
+    */
+   public static String createUID(File file, File htdocsDumpDir) {
+      String requestURI = file.getPath().substring(htdocsDumpDir.getPath().length());
+      String uid = requestURI.replace(File.separatorChar, '\u0000') + "\u0000" + DateField.timeToString(file.lastModified());
+      return uid;
+   }
+   /**
+    * Converts a UID to a URL string.
+    */
+   public static String uid2url(String uid) {
+      String url = uid.replace('\u0000', '/'); // replace nulls with slashes
+      String timeString = uid.substring(uid.lastIndexOf("\u0000") + 1);
+      Date date = DateField.stringToDate(timeString);
+      DateFormat format = new SimpleDateFormat("yyyy.MM.dd  HH:mm:ss");
+      return url.substring(0, url.lastIndexOf('/')) + " " + format.format(date);
+   }
+   /**
+    * Get Files and sorts by alphabet?
+    */
+   public File[] getFiles(File dumpDirectory) {
+      List files = new ArrayList();
+      collectFiles(dumpDirectory, files);
+      Collections.sort(files);
+      Map uidToFile = new HashMap();
+      String[] uids = new String[files.size()];
+      for(int i = 0; i < uids.length; i++){
+         uids[i] = createUID((File) files.get(i), dumpDirectory);
+         uidToFile.put(uids[i], files.get(i));
+      }
+      Arrays.sort(uids);
+      File[] fileArray = new File[uids.length];
+      for(int i = 0; i < uids.length; i++){
+         File file = (File) uidToFile.get(uids[i]);
+         log.debug(file);
+         fileArray[i] = file;
+      }
+      return fileArray;
+   }
+   /**
+    * Collect files
+    */
+   protected void collectFiles(File file, List files) {
+      if(file.isDirectory()){
+         log.debug("Apply filter " + getFilter().getClass().getName() + " to: " + file);
+         File[] fileArray = file.listFiles(getFilter());
+         for(int i = 0; i < fileArray.length; i++){
+            collectFiles(fileArray[i], files);
+         }
+      }else{
+         files.add(file);
+      }
+   }
+   /**
+    * Traverse directory
+    */
+   protected void traverse(TermEnum iterator, File file, File dumpDirectory) throws IOException {
+      if(file.isDirectory()){
+         log.debug("Apply filter " + getFilter().getClass().getName() + " to: " + file);
+         File[] fileArray = file.listFiles(getFilter());
+         for(int i = 0; i < fileArray.length; i++){
+            traverse(iterator, fileArray[i], dumpDirectory);
+         }
+      }else{
+         log.debug(file);
+         iterateFiles(iterator, file, dumpDirectory);
+      }
+   }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/parser/HTMLParserFactory.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/parser/HTMLParserFactory.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/parser/HTMLParserFactory.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/parser/HTMLParserFactory.java Wed Jan 30 23:44:03 2008
@@ -14,42 +14,32 @@
  *  limitations under the License.
  *
  */
-
 /* $Id$  */
-
 package org.apache.lenya.lucene.parser;
-
 import java.io.File;
-
-import org.apache.log4j.Category;
-
+import org.apache.log4j.Logger;
 /**
  * Factory to create HTML parsers that are used for indexing HTML.
  */
 public class HTMLParserFactory {
-    
-    public static Category log = Category.getInstance(HTMLParserFactory.class);
-    
-    /**
-     * Returns an HTMLParser.
-     */
-    public static HTMLParser newInstance(File file) {
-        HTMLParser parser = null;
-
-        // HTML files
-        if (file.getName().endsWith(".html")) {
-            parser = new SwingHTMLParser();
-        }
-        // PDF files
-        else if (file.getName().endsWith(".txt")) {
-            parser = new PDFParserWrapper();
-        } else {
-            parser = new SwingHTMLParser();
-            log.debug(".newInstance(): WARNING: Suffix did no match (" + file.getName()  + "). SwingHTMLParser as default parser selected!");
-        }
-
-        log.debug("returning a " + parser.getClass().getName() + " for " + file.getName());
-
-        return parser;
-    }
+   private static Logger log = Logger.getLogger(HTMLParserFactory.class);
+   /**
+    * Returns an HTMLParser.
+    */
+   public static HTMLParser newInstance(File file) {
+      HTMLParser parser = null;
+      // HTML files
+      if(file.getName().endsWith(".html")){
+         parser = new SwingHTMLParser();
+      }
+      // PDF files
+      else if(file.getName().endsWith(".txt")){
+         parser = new PDFParserWrapper();
+      }else{
+         parser = new SwingHTMLParser();
+         log.debug(".newInstance(): WARNING: Suffix did no match (" + file.getName() + "). SwingHTMLParser as default parser selected!");
+      }
+      log.debug("returning a " + parser.getClass().getName() + " for " + file.getName());
+      return parser;
+   }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/parser/ParseException.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/parser/ParseException.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/parser/ParseException.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/parser/ParseException.java Wed Jan 30 23:44:03 2008
@@ -14,41 +14,40 @@
  *  limitations under the License.
  *
  */
-
 /* $Id$  */
-
 package org.apache.lenya.lucene.parser;
-
 public class ParseException extends Exception {
-    /** Creates a new instance of ParseException */
-    public ParseException() {
-    }
-
-    /**
-     * Creates a new ParseException object.
-     *
-     * @param message the error message
-     * @param cause the cause of the exception
-     */
-    public ParseException(String message, Throwable cause) {
-        super(message, cause);
-    }
-
-    /**
-     * Creates a new ParseException object.
-     *
-     * @param message the error message
-     */
-    public ParseException(String message) {
-        super(message);
-    }
-
-    /**
-     * Creates a new ParseException object.
-     *
-     * @param cause the cause of the exception
-     */
-    public ParseException(Throwable cause) {
-        super(cause);
-    }
+   private static final long serialVersionUID = 1L;
+   /** Creates a new instance of ParseException */
+   public ParseException() {
+   }
+   /**
+    * Creates a new ParseException object.
+    * 
+    * @param message
+    *           the error message
+    * @param cause
+    *           the cause of the exception
+    */
+   public ParseException(String message, Throwable cause) {
+      super(message, cause);
+   }
+   /**
+    * Creates a new ParseException object.
+    * 
+    * @param message
+    *           the error message
+    */
+   public ParseException(String message) {
+      super(message);
+   }
+   /**
+    * Creates a new ParseException object.
+    * 
+    * @param cause
+    *           the cause of the exception
+    */
+   public ParseException(Throwable cause) {
+      super(cause);
+   }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/parser/PreParser.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/parser/PreParser.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/parser/PreParser.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/parser/PreParser.java Wed Jan 30 23:44:03 2008
@@ -14,49 +14,35 @@
  *  limitations under the License.
  *
  */
-
 /* $Id$  */
-
 package org.apache.lenya.lucene.parser;
-
 import java.io.IOException;
 import java.io.Reader;
 import java.io.StringReader;
-
-import org.apache.log4j.Category;
-
+import org.apache.log4j.Logger;
 /**
- * The Java HTML parser cannot handle self-closing text.
- * This class converts all "/>" strings to ">" to avoid this problem.
+ * The Java HTML parser cannot handle self-closing text. This class converts all "/>" strings to ">" to avoid this problem.
  */
 public class PreParser {
-    
-    private static Category log = Category.getInstance(PreParser.class);
-    
-    /** Creates a new instance of PreParser */
-    public PreParser() {
-        log.debug("creating new object");
-    }
-
-    /**
-     * Parses HTML from a reader.
-     */
-    public Reader parse(Reader reader) throws IOException {
-        StringBuffer buffer = new StringBuffer();
-        boolean pending = false;
-
-        char[] chars = new char[1];
-
-        while (reader.read(chars) != -1) {
-            int lastPosition = buffer.length() - 1;
-
-            if ((chars[0] == '>') && (buffer.charAt(lastPosition) == '/')) {
-                buffer.deleteCharAt(lastPosition);
-            }
-
-            buffer.append(chars[0]);
-        }
-
-        return new StringReader(buffer.toString());
-    }
+   private static Logger log = Logger.getLogger(PreParser.class);
+   /** Creates a new instance of PreParser */
+   public PreParser() {
+      log.debug("creating new object");
+   }
+   /**
+    * Parses HTML from a reader.
+    */
+   public Reader parse(Reader reader) throws IOException {
+      StringBuffer buffer = new StringBuffer();
+      // boolean pending = false;
+      char[] chars = new char[1];
+      while(reader.read(chars) != -1){
+         int lastPosition = buffer.length() - 1;
+         if((chars[0] == '>') && (buffer.charAt(lastPosition) == '/')){
+            buffer.deleteCharAt(lastPosition);
+         }
+         buffer.append(chars[0]);
+      }
+      return new StringReader(buffer.toString());
+   }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/parser/SwingHTMLHandler.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/parser/SwingHTMLHandler.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/parser/SwingHTMLHandler.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/parser/SwingHTMLHandler.java Wed Jan 30 23:44:03 2008
@@ -14,457 +14,378 @@
  *  limitations under the License.
  *
  */
-
 /* $Id$  */
-
 package org.apache.lenya.lucene.parser;
-
 import java.io.Reader;
 import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
-
 import javax.swing.text.MutableAttributeSet;
 import javax.swing.text.html.HTML;
 import javax.swing.text.html.HTML.Tag;
 import javax.swing.text.html.HTMLEditorKit.ParserCallback;
-
-import org.apache.log4j.Category;
-
+import org.apache.log4j.Logger;
 public class SwingHTMLHandler extends ParserCallback {
-    Category log = Category.getInstance(SwingHTMLHandler.class);
-
-    /** 
-     * Creates a new instance of SwingHTMLHandler
-     */
-    public SwingHTMLHandler() {
-        debug("\n\n\n\n\nCreating " + getClass().getName());
-
-        // index everything by default
-        startIndexing();
-    }
-
-    private TagStack tagStack = new TagStack();
-
-    protected TagStack getStack() {
-        return tagStack;
-    }
-
-    private StringBuffer titleBuffer = new StringBuffer();
-    private StringBuffer keywordsBuffer = new StringBuffer();
-
-    /**
-     *
-     */
-    protected void appendToTitle(char[] data) {
-        titleBuffer.append(data);
-    }
-
-    /**
-     * Get title
-     *
-     * @return DOCUMENT ME!
-     */
-    public String getTitle() {
-        debug("\n\nTitle: " + titleBuffer.toString());
-
-        return titleBuffer.toString();
-    }
-
-    /**
-     * Get keywords
-     *
-     * @return DOCUMENT ME!
-     */
-    public String getKeywords() {
-        log.debug("Keywords: " + keywordsBuffer.toString());
-
-        return keywordsBuffer.toString();
-    }
-
-    private StringBuffer contentsBuffer = new StringBuffer();
-
-    protected void appendToContents(char[] data) {
-        contentsBuffer.append(data);
-    }
-
-    /**
-     * DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     */
-    public Reader getReader() {
-        debug("\nContents: " + contentsBuffer.toString());
-
-        return new StringReader(contentsBuffer.toString());
-    }
-
-    private boolean indexing;
-
-    protected boolean isIndexing() {
-        return indexing;
-    }
-
-    protected void startIndexing() {
-        indexing = true;
-    }
-
-    protected void stopIndexing() {
-        indexing = false;
-    }
-
-    //-------------------------------------------------------------------------
-    // Tag handling
-    //-------------------------------------------------------------------------
-
-    /**
-     * Handles a start tag.
-     */
-    public void handleStartTag(Tag tag, MutableAttributeSet attributes, int pos) {
-        getStack().push(tag);
-
-        // append whitespace
-        if (!contentsBuffer.toString().endsWith(" ")) {
-            contentsBuffer.append(" ");
-        }
-
-        if (tag.equals(HTML.Tag.META)) {
-            handleMetaTag(attributes);
-        }
-
-        if (tag.equals(HTML.Tag.TITLE)) {
-            handleTitleStartTag();
-        }
-
-        if (isTagInitialized() && tag.equals(getLuceneTag())) {
-            handleLuceneStartTag(tag, attributes);
-        }
-    }
-
-    /**
-     * Handles an end tag.
-     */
-    public void handleEndTag(Tag tag, int pos) {
-        // append whitespace
-        if (!contentsBuffer.toString().endsWith(" ")) {
-            contentsBuffer.append(" ");
-        }
-
-        if (isTagInitialized() && tag.equals(getLuceneTag())) {
-            handleLuceneEndTag();
-        }
-
-        if (tag.equals(HTML.Tag.TITLE)) {
-            handleTitleEndTag();
-        }
-
-        try {
-            getStack().pop();
-        } catch (TagStack.UnderflowException e) {
-            log(e);
-        }
-    }
-
-    //-------------------------------------------------------------------------
-    // Title
-    //-------------------------------------------------------------------------
-    private boolean titleParsing;
-
-    protected boolean isTitleParsing() {
-        return titleParsing;
-    }
-
-    protected void startTitleParsing() {
-        titleParsing = true;
-    }
-
-    protected void stopTitleParsing() {
-        titleParsing = false;
-    }
-
-    protected void handleTitleStartTag() {
-        startTitleParsing();
-    }
-
-    protected void handleTitleEndTag() {
-        stopTitleParsing();
-    }
-
-    //-------------------------------------------------------------------------
-    // Lucene metag tags
-    //-------------------------------------------------------------------------
-    public static final String LUCENE_TAG_NAME = "lucene-tag-name";
-    public static final String LUCENE_CLASS_VALUE = "lucene-class-value";
-    private HTML.Tag luceneTag = null;
-
-    /**
-     * Sets the tag name used to avoid indexing.
-     */
-    protected void setLuceneTag(HTML.Tag tag) {
-        debug("Lucene tag:         " + tag);
-        luceneTag = tag;
-    }
-
-    /**
-     * Returns the tag name used to avoid indexing.
-     */
-    protected HTML.Tag getLuceneTag() {
-        return luceneTag;
-    }
-
-    private String luceneClassValue = null;
-
-    /**
-     * Sets the value for the <code>class</code> attribute used to avoid indexing.
-     */
-    protected void setLuceneClassValue(String value) {
-        debug("Lucene class value: " + value);
-        luceneClassValue = value;
-    }
-
-    /**
-     * Returns the value for the <code>class</code> attribute used to avoid indexing.
-     */
-    protected String getLuceneClassValue() {
-        return luceneClassValue;
-    }
-
-    /**
-     * Returns if the Lucene META tags are provided.
-     */
-    protected boolean isTagInitialized() {
-        return (getLuceneTag() != null) && (getLuceneClassValue() != null);
-    }
-
-    /**
-     * Handles a META tag. This method checks for the Lucene configuration tags.
-     */
-    protected void handleMetaTag(MutableAttributeSet attributes) {
-        Object nameObject = attributes.getAttribute(HTML.Attribute.NAME);
-        Object valueObject = attributes.getAttribute(HTML.Attribute.VALUE);
-
-        if ((nameObject != null) && (valueObject != null)) {
-            String name = (String) nameObject;
-            log.debug("Meta tag found: name = " + name);
-
-            if (name.equals(LUCENE_TAG_NAME)) {
-                String tagName = (String) valueObject;
-                HTML.Tag tag = HTML.getTag(tagName.toLowerCase());
-                setLuceneTag(tag);
+   private static Logger log = Logger.getLogger(SwingHTMLHandler.class);
+   /**
+    * Creates a new instance of SwingHTMLHandler
+    */
+   public SwingHTMLHandler() {
+      debug("\n\n\n\n\nCreating " + getClass().getName());
+      // index everything by default
+      startIndexing();
+   }
+   private TagStack tagStack = new TagStack();
+   protected TagStack getStack() {
+      return tagStack;
+   }
+   private StringBuffer titleBuffer = new StringBuffer();
+   private StringBuffer keywordsBuffer = new StringBuffer();
+   /**
+    * 
+    */
+   protected void appendToTitle(char[] data) {
+      titleBuffer.append(data);
+   }
+   /**
+    * Get title
+    * 
+    * @return DOCUMENT ME!
+    */
+   public String getTitle() {
+      debug("\n\nTitle: " + titleBuffer.toString());
+      return titleBuffer.toString();
+   }
+   /**
+    * Get keywords
+    * 
+    * @return DOCUMENT ME!
+    */
+   public String getKeywords() {
+      log.debug("Keywords: " + keywordsBuffer.toString());
+      return keywordsBuffer.toString();
+   }
+   private StringBuffer contentsBuffer = new StringBuffer();
+   protected void appendToContents(char[] data) {
+      contentsBuffer.append(data);
+   }
+   /**
+    * DOCUMENT ME!
+    * 
+    * @return DOCUMENT ME!
+    */
+   public Reader getReader() {
+      debug("\nContents: " + contentsBuffer.toString());
+      return new StringReader(contentsBuffer.toString());
+   }
+   private boolean indexing;
+   protected boolean isIndexing() {
+      return indexing;
+   }
+   protected void startIndexing() {
+      indexing = true;
+   }
+   protected void stopIndexing() {
+      indexing = false;
+   }
+   // -------------------------------------------------------------------------
+   // Tag handling
+   // -------------------------------------------------------------------------
+   /**
+    * Handles a start tag.
+    */
+   public void handleStartTag(Tag tag, MutableAttributeSet attributes, int pos) {
+      getStack().push(tag);
+      // append whitespace
+      if(!contentsBuffer.toString().endsWith(" ")){
+         contentsBuffer.append(" ");
+      }
+      if(tag.equals(HTML.Tag.META)){
+         handleMetaTag(attributes);
+      }
+      if(tag.equals(HTML.Tag.TITLE)){
+         handleTitleStartTag();
+      }
+      if(isTagInitialized() && tag.equals(getLuceneTag())){
+         handleLuceneStartTag(tag, attributes);
+      }
+   }
+   /**
+    * Handles an end tag.
+    */
+   public void handleEndTag(Tag tag, int pos) {
+      // append whitespace
+      if(!contentsBuffer.toString().endsWith(" ")){
+         contentsBuffer.append(" ");
+      }
+      if(isTagInitialized() && tag.equals(getLuceneTag())){
+         handleLuceneEndTag();
+      }
+      if(tag.equals(HTML.Tag.TITLE)){
+         handleTitleEndTag();
+      }
+      try{
+         getStack().pop();
+      }catch(TagStack.UnderflowException e){
+         log(e);
+      }
+   }
+   // -------------------------------------------------------------------------
+   // Title
+   // -------------------------------------------------------------------------
+   private boolean titleParsing;
+   protected boolean isTitleParsing() {
+      return titleParsing;
+   }
+   protected void startTitleParsing() {
+      titleParsing = true;
+   }
+   protected void stopTitleParsing() {
+      titleParsing = false;
+   }
+   protected void handleTitleStartTag() {
+      startTitleParsing();
+   }
+   protected void handleTitleEndTag() {
+      stopTitleParsing();
+   }
+   // -------------------------------------------------------------------------
+   // Lucene metag tags
+   // -------------------------------------------------------------------------
+   public static final String LUCENE_TAG_NAME = "lucene-tag-name";
+   public static final String LUCENE_CLASS_VALUE = "lucene-class-value";
+   private HTML.Tag luceneTag = null;
+   /**
+    * Sets the tag name used to avoid indexing.
+    */
+   protected void setLuceneTag(HTML.Tag tag) {
+      debug("Lucene tag:         " + tag);
+      luceneTag = tag;
+   }
+   /**
+    * Returns the tag name used to avoid indexing.
+    */
+   protected HTML.Tag getLuceneTag() {
+      return luceneTag;
+   }
+   private String luceneClassValue = null;
+   /**
+    * Sets the value for the <code>class</code> attribute used to avoid indexing.
+    */
+   protected void setLuceneClassValue(String value) {
+      debug("Lucene class value: " + value);
+      luceneClassValue = value;
+   }
+   /**
+    * Returns the value for the <code>class</code> attribute used to avoid indexing.
+    */
+   protected String getLuceneClassValue() {
+      return luceneClassValue;
+   }
+   /**
+    * Returns if the Lucene META tags are provided.
+    */
+   protected boolean isTagInitialized() {
+      return (getLuceneTag() != null) && (getLuceneClassValue() != null);
+   }
+   /**
+    * Handles a META tag. This method checks for the Lucene configuration tags.
+    */
+   protected void handleMetaTag(MutableAttributeSet attributes) {
+      Object nameObject = attributes.getAttribute(HTML.Attribute.NAME);
+      Object valueObject = attributes.getAttribute(HTML.Attribute.VALUE);
+      if((nameObject != null) && (valueObject != null)){
+         String name = (String) nameObject;
+         log.debug("Meta tag found: name = " + name);
+         if(name.equals(LUCENE_TAG_NAME)){
+            String tagName = (String) valueObject;
+            HTML.Tag tag = HTML.getTag(tagName.toLowerCase());
+            setLuceneTag(tag);
+         }
+         if(name.equals(LUCENE_CLASS_VALUE)){
+            setLuceneClassValue((String) valueObject);
+         }
+      }
+      Object contentObject = attributes.getAttribute(HTML.Attribute.CONTENT);
+      if((nameObject != null) && (contentObject != null)){
+         String name = (String) nameObject;
+         log.debug("Meta tag found: name = " + name);
+         if(name.equals("keywords")){
+            log.debug("Keywords found ...");
+            keywordsBuffer = new StringBuffer((String) contentObject);
+         }
+      }
+      // do not index everything if tags are provided
+      if(isTagInitialized()){
+         stopIndexing();
+      }
+   }
+   // -------------------------------------------------------------------------
+   // Lucene index control tags
+   // -------------------------------------------------------------------------
+   private TagStack luceneStack = new TagStack();
+   protected TagStack getLuceneStack() {
+      return luceneStack;
+   }
+   /**
+    * Handles a Lucene index control start tag.
+    */
+   protected void handleLuceneStartTag(HTML.Tag tag, MutableAttributeSet attributes) {
+      Object valueObject = attributes.getAttribute(HTML.Attribute.CLASS);
+      if(valueObject != null){
+         String value = (String) valueObject;
+         if(value.equals(getLuceneClassValue())){
+            getLuceneStack().push(tag);
+            debug("");
+            debug("---------- Starting indexing ----------");
+            startIndexing();
+         }
+      }
+   }
+   /**
+    * Handles a Lucene index control end tag.
+    */
+   protected void handleLuceneEndTag() {
+      try{
+         HTML.Tag stackTag = getStack().top();
+         if(!getLuceneStack().isEmpty()){
+            HTML.Tag luceneTag = getLuceneStack().top();
+            if(stackTag == luceneTag){
+               debug("");
+               debug("---------- Stopping indexing ----------");
+               getLuceneStack().pop();
+               stopIndexing();
             }
-
-            if (name.equals(LUCENE_CLASS_VALUE)) {
-                setLuceneClassValue((String) valueObject);
-            }
-        }
-
-        Object contentObject = attributes.getAttribute(HTML.Attribute.CONTENT);
-        if ((nameObject != null) && (contentObject != null)) {
-            String name = (String) nameObject;
-            log.debug("Meta tag found: name = " + name);
-            if (name.equals("keywords")) {
-                log.debug("Keywords found ...");
-                keywordsBuffer = new StringBuffer((String) contentObject);
-            }
-        }
-
-        // do not index everything if tags are provided
-        if (isTagInitialized()) {
-            stopIndexing();
-        }
-    }
-
-    //-------------------------------------------------------------------------
-    // Lucene index control tags
-    //-------------------------------------------------------------------------
-    private TagStack luceneStack = new TagStack();
-
-    protected TagStack getLuceneStack() {
-        return luceneStack;
-    }
-
-    /**
-     * Handles a Lucene index control start tag.
-     */
-    protected void handleLuceneStartTag(HTML.Tag tag, MutableAttributeSet attributes) {
-        Object valueObject = attributes.getAttribute(HTML.Attribute.CLASS);
-
-        if (valueObject != null) {
-            String value = (String) valueObject;
-
-            if (value.equals(getLuceneClassValue())) {
-                getLuceneStack().push(tag);
-                debug("");
-                debug("---------- Starting indexing ----------");
-                startIndexing();
-            }
-        }
-    }
-
-    /**
-     * Handles a Lucene index control end tag.
-     */
-    protected void handleLuceneEndTag() {
-        try {
-            HTML.Tag stackTag = getStack().top();
-
-            if (!getLuceneStack().isEmpty()) {
-                HTML.Tag luceneTag = getLuceneStack().top();
-
-                if (stackTag == luceneTag) {
-                    debug("");
-                    debug("---------- Stopping indexing ----------");
-                    getLuceneStack().pop();
-                    stopIndexing();
-                }
-            }
-        } catch (TagStack.UnderflowException e) {
-            log("Lucene index control tag not closed!", e);
-        }
-    }
-
-    /**
-     * Handles an end tag.
-     */
-    public void handleSimpleTag(Tag tag, MutableAttributeSet attributes, int pos) {
-        handleStartTag(tag, attributes, pos);
-        handleEndTag(tag, pos);
-    }
-
-    //-------------------------------------------------------------------------
-    // Text handling
-    //-------------------------------------------------------------------------
-    public void handleText(char[] data, int pos) {
-        //String string = new String(data);
-        //System.out.println(indent + string.substring(0, Math.min(20, string.length())) + " ...");
-        if (isDebug) {
-            System.out.println(".handleText(): data: " + new String(data));
-        }
-
-        /*
-                if (data[0] == '>') {
-                   throw new IllegalStateException();
-                   }
-        */
-        if (isIndexing() || isTitleParsing()) {
-            appendToContents(data);
-        }
-
-        if (isTitleParsing()) {
-            appendToTitle(data);
-        }
-    }
-
-    //-------------------------------------------------------------------------
-    // Logging
-    //-------------------------------------------------------------------------
-    private boolean isDebug = false;
-
-    /**
-     * Logs a message.
-     */
-    protected void debug(String message) {
-        if (isDebug) {
-            System.out.println(message);
-        }
-    }
-
-    /**
-     * Logs an exception.
-     */
-    protected void log(Exception e) {
-        log("", e);
-    }
-
-    /**
-     * Logs an exception with a message.
-     */
-    protected void log(String message, Exception e) {
-        System.out.print(getClass().getName() + ": " + message + " ");
-        e.printStackTrace(System.out);
-    }
-
-    /**
-     * DOCUMENT ME!
-     */
-    public class TagStack {
-        private List tags = new ArrayList();
-
-        /**
-         * DOCUMENT ME!
-         *
-         * @param tag DOCUMENT ME!
-         */
-        public void push(HTML.Tag tag) {
-            tags.add(0, tag);
-        }
-
-        /**
-         * DOCUMENT ME!
-         *
-         * @return DOCUMENT ME!
-         *
-         * @throws UnderflowException DOCUMENT ME!
-         */
-        public HTML.Tag pop() throws UnderflowException {
-            HTML.Tag tag = top();
-            tags.remove(tag);
-
-            return tag;
-        }
-
-        /**
-         * DOCUMENT ME!
-         *
-         * @return DOCUMENT ME!
-         *
-         * @throws UnderflowException DOCUMENT ME!
-         */
-        public HTML.Tag top() throws UnderflowException {
-            HTML.Tag tag = null;
-
-            if (!tags.isEmpty()) {
-                tag = (HTML.Tag) tags.get(0);
-            } else {
-                throw new UnderflowException();
-            }
-
-            return tag;
-        }
-
-        /**
-         * DOCUMENT ME!
-         *
-         * @return DOCUMENT ME!
-         */
-        public boolean isEmpty() {
-            return tags.isEmpty();
-        }
-
-        /**
-         * DOCUMENT ME!
-         */
-        public void dump() {
-            System.out.print("stack: ");
-
-            for (Iterator i = tags.iterator(); i.hasNext();) {
-                System.out.print(i.next() + ", ");
-            }
-
-            System.out.println("");
-        }
-
-        /**
-         * DOCUMENT ME!
-         */
-        public class UnderflowException extends Exception {
-            /**
-             * Creates a new UnderflowException object.
-             */
-            public UnderflowException() {
-                super("Stack underflow");
-            }
-        }
-    }
+         }
+      }catch(TagStack.UnderflowException e){
+         log("Lucene index control tag not closed!", e);
+      }
+   }
+   /**
+    * Handles an end tag.
+    */
+   public void handleSimpleTag(Tag tag, MutableAttributeSet attributes, int pos) {
+      handleStartTag(tag, attributes, pos);
+      handleEndTag(tag, pos);
+   }
+   // -------------------------------------------------------------------------
+   // Text handling
+   // -------------------------------------------------------------------------
+   public void handleText(char[] data, int pos) {
+      // String string = new String(data);
+      // System.out.println(indent + string.substring(0, Math.min(20, string.length())) + " ...");
+      if(isDebug){
+         System.out.println(".handleText(): data: " + new String(data));
+      }
+      /*
+       * if (data[0] == '>') { throw new IllegalStateException(); }
+       */
+      if(isIndexing() || isTitleParsing()){
+         appendToContents(data);
+      }
+      if(isTitleParsing()){
+         appendToTitle(data);
+      }
+   }
+   // -------------------------------------------------------------------------
+   // Logging
+   // -------------------------------------------------------------------------
+   private boolean isDebug = false;
+   /**
+    * Logs a message.
+    */
+   protected void debug(String message) {
+      if(isDebug){
+         System.out.println(message);
+      }
+   }
+   /**
+    * Logs an exception.
+    */
+   protected void log(Exception e) {
+      log("", e);
+   }
+   /**
+    * Logs an exception with a message.
+    */
+   protected void log(String message, Exception e) {
+      System.out.print(getClass().getName() + ": " + message + " ");
+      e.printStackTrace(System.out);
+   }
+   /**
+    * DOCUMENT ME!
+    */
+   public class TagStack {
+      private List tags = new ArrayList();
+      /**
+       * DOCUMENT ME!
+       * 
+       * @param tag
+       *           DOCUMENT ME!
+       */
+      public void push(HTML.Tag tag) {
+         tags.add(0, tag);
+      }
+      /**
+       * DOCUMENT ME!
+       * 
+       * @return DOCUMENT ME!
+       * 
+       * @throws UnderflowException
+       *            DOCUMENT ME!
+       */
+      public HTML.Tag pop() throws UnderflowException {
+         HTML.Tag tag = top();
+         tags.remove(tag);
+         return tag;
+      }
+      /**
+       * DOCUMENT ME!
+       * 
+       * @return DOCUMENT ME!
+       * 
+       * @throws UnderflowException
+       *            DOCUMENT ME!
+       */
+      public HTML.Tag top() throws UnderflowException {
+         HTML.Tag tag = null;
+         if(!tags.isEmpty()){
+            tag = (HTML.Tag) tags.get(0);
+         }else{
+            throw new UnderflowException();
+         }
+         return tag;
+      }
+      /**
+       * DOCUMENT ME!
+       * 
+       * @return DOCUMENT ME!
+       */
+      public boolean isEmpty() {
+         return tags.isEmpty();
+      }
+      /**
+       * DOCUMENT ME!
+       */
+      public void dump() {
+         System.out.print("stack: ");
+         for(Iterator i = tags.iterator(); i.hasNext();){
+            System.out.print(i.next() + ", ");
+         }
+         System.out.println("");
+      }
+      /**
+       * DOCUMENT ME!
+       */
+      public class UnderflowException extends Exception {
+         private static final long serialVersionUID = 1L;
+         /**
+          * Creates a new UnderflowException object.
+          */
+         public UnderflowException() {
+            super("Stack underflow");
+         }
+      }
+   }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/parser/SwingHTMLParser.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/parser/SwingHTMLParser.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/parser/SwingHTMLParser.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/parser/SwingHTMLParser.java Wed Jan 30 23:44:03 2008
@@ -14,11 +14,8 @@
  *  limitations under the License.
  *
  */
-
 /* $Id$  */
-
 package org.apache.lenya.lucene.parser;
-
 import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
@@ -27,73 +24,56 @@
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URLConnection;
-
 import javax.swing.text.html.parser.ParserDelegator;
-
 public class SwingHTMLParser extends AbstractHTMLParser {
-    /** Creates a new instance of SwingHTMLParser */
-    public SwingHTMLParser() {
-    }
-
-    /**
-     * Parses a URI.
-     */
-    public void parse(URI uri) throws ParseException {
-        try {
-            ParserDelegator delagator = new ParserDelegator();
-            handler = new SwingHTMLHandler();
-
-            Reader reader = new PreParser().parse(getReader(uri));
-            delagator.parse(reader, handler, true);
-        } catch (IOException e) {
-            throw new ParseException(e);
-        }
-    }
-
-    private SwingHTMLHandler handler;
-
-    protected SwingHTMLHandler getHandler() {
-        return handler;
-    }
-
-    /**
-     * Get title
-     *
-     * @return DOCUMENT ME!
-     */
-    public String getTitle() {
-        return getHandler().getTitle();
-    }
-
-    /**
-     * Get keywords
-     *
-     * @return DOCUMENT ME!
-     */
-    public String getKeywords() {
-        return getHandler().getKeywords();
-    }
-
-    private Reader reader;
-
-    /**
-     * DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     */
-    public Reader getReader() {
-        return getHandler().getReader();
-    }
-
-    protected Reader getReader(URI uri) throws IOException, MalformedURLException {
-        if (uri.toString().startsWith("http:")) {
-            // uri is url
-            URLConnection connection = uri.toURL().openConnection();
-
-            return new InputStreamReader(connection.getInputStream());
-        } else {
-            // uri is file
-            return new FileReader(new File(uri));
-        }
-    }
+   /** Creates a new instance of SwingHTMLParser */
+   public SwingHTMLParser() {
+   }
+   /**
+    * Parses a URI.
+    */
+   public void parse(URI uri) throws ParseException {
+      try{
+         ParserDelegator delagator = new ParserDelegator();
+         handler = new SwingHTMLHandler();
+         Reader reader = new PreParser().parse(getReader(uri));
+         delagator.parse(reader, handler, true);
+      }catch(IOException e){
+         throw new ParseException(e);
+      }
+   }
+   private SwingHTMLHandler handler;
+   protected SwingHTMLHandler getHandler() {
+      return handler;
+   }
+   /**
+    * Get title
+    * 
+    * @return DOCUMENT ME!
+    */
+   public String getTitle() {
+      return getHandler().getTitle();
+   }
+   /**
+    * Get keywords
+    * 
+    * @return DOCUMENT ME!
+    */
+   public String getKeywords() {
+      return getHandler().getKeywords();
+   }
+   // private Reader reader;
+   public Reader getReader() {
+      return getHandler().getReader();
+   }
+   protected Reader getReader(URI uri) throws IOException, MalformedURLException {
+      if(uri.toString().startsWith("http:")){
+         // uri is url
+         URLConnection connection = uri.toURL().openConnection();
+         return new InputStreamReader(connection.getInputStream());
+      }else{
+         // uri is file
+         return new FileReader(new File(uri));
+      }
+   }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/net/Configuration.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/net/Configuration.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/net/Configuration.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/net/Configuration.java Wed Jan 30 23:44:03 2008
@@ -14,126 +14,105 @@
  *  limitations under the License.
  *
  */
-
 /* $Id$  */
-
 package org.apache.lenya.net;
-
 import java.net.URL;
 import java.util.Properties;
-
-import org.apache.log4j.Category;
-
-
+import org.apache.log4j.Logger;
 /**
  * Read configuration
  */
 public class Configuration {
-    static Category log = Category.getInstance(Configuration.class);
-    public static final String DEFAULT_CONFIGURATION_FILE = "org/apache/lenya/net/conf.properties";
-    public static final String DEFAULT_CONFIGURATION_KEY = "lenya.configuration";
-    public static final String OVERRIDE_DEFAULT_CONFIGURATION_KEY = "override.lenya.configuration";
-    public String configurationPath = null;
-    public String smtpHost = null;
-    public String smtpPort = null;
-    public String smtpDomain = null;
-
-    /**
-     * Creates a new Configuration object.
-     */
-    public Configuration() {
-        getProperties(load());
-    }
-
-    /**
-     * http://www.artima.com/java/answers/Mar2001/messages/164.html export
-     * CLASSPATH=/home/lenya/src/xps/build/properties:... java
-     * -Doverride.lenya.configuration=org/apache/lenya/altconf.properties org.apache.lenya.net.Configuration
-     *
-     * @param args DOCUMENT ME!
-     */
-    public static void main(String[] args) {
-        Configuration conf = new Configuration();
-
-        System.out.println("Proxy Manager Configuration Path: " + conf.configurationPath);
-        System.out.println("SMTP Host: " + conf.smtpHost);
-        System.out.println("SMTP Port: " + conf.smtpPort);
-        System.out.println("SMTP Domain: " + conf.smtpDomain);
-    }
-
-    /**
-     * DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     */
-    public static Properties load() {
-        String resourcePathRelativeToClasspath = System.getProperty(OVERRIDE_DEFAULT_CONFIGURATION_KEY);
-
-        if (resourcePathRelativeToClasspath == null) {
-            resourcePathRelativeToClasspath = System.getProperty(DEFAULT_CONFIGURATION_KEY, DEFAULT_CONFIGURATION_FILE);
-            log.debug(DEFAULT_CONFIGURATION_KEY + "=" + resourcePathRelativeToClasspath);
-        } else {
-            log.debug(OVERRIDE_DEFAULT_CONFIGURATION_KEY + "=" + resourcePathRelativeToClasspath);
-        }
-
-        URL url = Configuration.class.getClassLoader().getResource(resourcePathRelativeToClasspath);
-
-        if (url == null) {
-            log.error(".load(): Could not find resource on classpath: " + resourcePathRelativeToClasspath);
-        }
-
-	log.debug(url);
-
-        Properties properties = new Properties();
-
-        try {
-            properties.load(Configuration.class.getResourceAsStream("conf.properties"));
-        } catch (Exception e) {
-            log.error(e);
-        }
-
-        return properties;
-    }
-
-    /**
-     * DOCUMENT ME!
-     *
-     * @param properties DOCUMENT ME!
-     */
-    public void getProperties(Properties properties) {
-        if (properties != null) {
-            configurationPath = getProperty(properties, "org.apache.lenya.net.ProxyManager.configurationPath");
-            smtpHost = getProperty(properties, "org.apache.lenya.net.SMTP.host");
-            smtpPort = getProperty(properties, "org.apache.lenya.net.SMTP.port");
-            smtpDomain = getProperty(properties, "org.apache.lenya.net.SMTP.domain");
-        }
-    }
-
-    /**
-     * DOCUMENT ME!
-     *
-     * @param properties DOCUMENT ME!
-     * @param key DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     */
-    public String getProperty(Properties properties, String key) {
-        String value = properties.getProperty(key);
-
-        if (value != null) {
-            log.debug(key + "=" + value);
-
-            return value;
-        } else {
-            log.error("No such property: " + key);
-        }
-
-        return null;
-    }
-
-    /**
-     * DOCUMENT ME!
-     */
-    public static void register() {
-    }
+   private static Logger log = Logger.getLogger(Configuration.class);
+   public static final String DEFAULT_CONFIGURATION_FILE = "org/apache/lenya/net/conf.properties";
+   public static final String DEFAULT_CONFIGURATION_KEY = "lenya.configuration";
+   public static final String OVERRIDE_DEFAULT_CONFIGURATION_KEY = "override.lenya.configuration";
+   public String configurationPath = null;
+   public String smtpHost = null;
+   public String smtpPort = null;
+   public String smtpDomain = null;
+   /**
+    * Creates a new Configuration object.
+    */
+   public Configuration() {
+      getProperties(load());
+   }
+   /**
+    * http://www.artima.com/java/answers/Mar2001/messages/164.html export CLASSPATH=/home/lenya/src/xps/build/properties:... java -Doverride.lenya.configuration=org/apache/lenya/altconf.properties org.apache.lenya.net.Configuration
+    * 
+    * @param args
+    *           DOCUMENT ME!
+    */
+   public static void main(String[] args) {
+      Configuration conf = new Configuration();
+      System.out.println("Proxy Manager Configuration Path: " + conf.configurationPath);
+      System.out.println("SMTP Host: " + conf.smtpHost);
+      System.out.println("SMTP Port: " + conf.smtpPort);
+      System.out.println("SMTP Domain: " + conf.smtpDomain);
+   }
+   /**
+    * DOCUMENT ME!
+    * 
+    * @return DOCUMENT ME!
+    */
+   public static Properties load() {
+      String resourcePathRelativeToClasspath = System.getProperty(OVERRIDE_DEFAULT_CONFIGURATION_KEY);
+      if(resourcePathRelativeToClasspath == null){
+         resourcePathRelativeToClasspath = System.getProperty(DEFAULT_CONFIGURATION_KEY, DEFAULT_CONFIGURATION_FILE);
+         log.debug(DEFAULT_CONFIGURATION_KEY + "=" + resourcePathRelativeToClasspath);
+      }else{
+         log.debug(OVERRIDE_DEFAULT_CONFIGURATION_KEY + "=" + resourcePathRelativeToClasspath);
+      }
+      URL url = Configuration.class.getClassLoader().getResource(resourcePathRelativeToClasspath);
+      if(url == null){
+         log.error(".load(): Could not find resource on classpath: " + resourcePathRelativeToClasspath);
+      }
+      log.debug(url);
+      Properties properties = new Properties();
+      try{
+         properties.load(Configuration.class.getResourceAsStream("conf.properties"));
+      }catch(Exception e){
+         log.error(e);
+      }
+      return properties;
+   }
+   /**
+    * DOCUMENT ME!
+    * 
+    * @param properties
+    *           DOCUMENT ME!
+    */
+   public void getProperties(Properties properties) {
+      if(properties != null){
+         configurationPath = getProperty(properties, "org.apache.lenya.net.ProxyManager.configurationPath");
+         smtpHost = getProperty(properties, "org.apache.lenya.net.SMTP.host");
+         smtpPort = getProperty(properties, "org.apache.lenya.net.SMTP.port");
+         smtpDomain = getProperty(properties, "org.apache.lenya.net.SMTP.domain");
+      }
+   }
+   /**
+    * DOCUMENT ME!
+    * 
+    * @param properties
+    *           DOCUMENT ME!
+    * @param key
+    *           DOCUMENT ME!
+    * 
+    * @return DOCUMENT ME!
+    */
+   public String getProperty(Properties properties, String key) {
+      String value = properties.getProperty(key);
+      if(value != null){
+         log.debug(key + "=" + value);
+         return value;
+      }else{
+         log.error("No such property: " + key);
+      }
+      return null;
+   }
+   /**
+    * DOCUMENT ME!
+    */
+   public static void register() {
+   }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/net/InetAddressUtil.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/net/InetAddressUtil.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/net/InetAddressUtil.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/net/InetAddressUtil.java Wed Jan 30 23:44:03 2008
@@ -14,186 +14,145 @@
  *  limitations under the License.
  *
  */
-
 /* $Id$  */
-
 package org.apache.lenya.net;
-
 import java.net.InetAddress;
 import java.net.UnknownHostException;
-
-import org.apache.log4j.Category;
-
+import org.apache.log4j.Logger;
 /**
  * A utility class for InetAddress. Also see http://jodies.de/ipcalc
  */
 public class InetAddressUtil {
-
-    private static final Category log = Category.getInstance(InetAddressUtil.class);
-
-    /**
-     * Ctor.
-     */
-    private InetAddressUtil() {
-    }
-
-    /**
-     * Checks if a subnet contains a specific IP address.
-     * 
-     * @param network The network address.
-     * @param netmask The subnet mask.
-     * @param ip The IP address to check.
-     * @return A boolean value.
-     */
-    public static boolean contains(InetAddress network, InetAddress netmask, InetAddress ip) {
-        if(log.isDebugEnabled()) {
+   private static Logger log = Logger.getLogger(InetAddressUtil.class);
+   /**
+    * Ctor.
+    */
+   private InetAddressUtil() {
+   }
+   /**
+    * Checks if a subnet contains a specific IP address.
+    * 
+    * @param network
+    *           The network address.
+    * @param netmask
+    *           The subnet mask.
+    * @param ip
+    *           The IP address to check.
+    * @return A boolean value.
+    */
+   public static boolean contains(InetAddress network, InetAddress netmask, InetAddress ip) {
+      if(log.isDebugEnabled()){
+         log.debug("=======================================");
+         log.debug("Checking IP address: " + ip + " in " + network + " / " + netmask);
+      }
+      byte[] networkBytes = network.getAddress();
+      byte[] netmaskBytes = netmask.getAddress();
+      byte[] ipBytes = ip.getAddress();
+      /* check IPv4/v6-compatibility or parameters: */
+      if(networkBytes.length != netmaskBytes.length || netmaskBytes.length != ipBytes.length){
+         /*
+          * FIXME: If network and netmask have the same size should already be checked whenever org.apache.lenya.ac.(impl.Abstract)IPRange is set. In that case the user should be notified of this configuration-error instead of silently accepting the buggy IPRange as one not matching any host! (Note that changes to the public API of IPRange and other classes would be necessary to fix this problem. This method and therefore this whole class would probably be obsolete in that case.)
+          */
+         if(log.isDebugEnabled()){
+            log.debug("Network address " + network + ", subnet mask " + netmask + " and/or host address " + ip + " have different sizes! (return false ...)");
             log.debug("=======================================");
-            log.debug("Checking IP address: " + ip + " in " + network + " / " + netmask);
-        }
-        
-        byte[] networkBytes = network.getAddress();
-        byte[] netmaskBytes = netmask.getAddress();
-        byte[] ipBytes = ip.getAddress();
-        
-        /* check IPv4/v6-compatibility or parameters: */
-        if(networkBytes.length != netmaskBytes.length
-            || netmaskBytes.length != ipBytes.length)
-        {
-            /*
-             * FIXME: If network and netmask have the same size
-             * should already be checked whenever
-             * org.apache.lenya.ac.(impl.Abstract)IPRange
-             * is set. In that case the user should be notified
-             * of this configuration-error instead of silently
-             * accepting the buggy IPRange as one not matching
-             * any host!
-             * (Note that changes to the public API of IPRange
-             * and other classes would be necessary to fix this
-             * problem. This method and therefore this whole
-             * class would probably be obsolete in that case.)
-             */
-            if(log.isDebugEnabled()) {
-                log.debug
-                    ("Network address " + network + ", subnet mask "
-                     + netmask + " and/or host address " + ip
-                     + " have different sizes! (return false ...)");
-                log.debug("=======================================");
+         }
+         return false;
+      }
+      /* Check if the masked network and ip addresses match: */
+      for(int i = 0; i < netmaskBytes.length; i++){
+         int mask = netmaskBytes[i] & 0xff;
+         if((networkBytes[i] & mask) != (ipBytes[i] & mask)){
+            if(log.isDebugEnabled()){
+               log.debug(ip + " is not in " + network + " / " + netmask);
+               log.debug("=======================================");
             }
             return false;
-        }
-        
-        /* Check if the masked network and ip addresses match: */
-        for(int i=0; i<netmaskBytes.length; i++) {
-            int mask = netmaskBytes[i] & 0xff;
-            if((networkBytes[i] & mask) != (ipBytes[i] & mask)) {
-                if(log.isDebugEnabled()) {
-                    log.debug
-                        (ip + " is not in " + network + " / " + netmask);
-                    log.debug("=======================================");
-                }
-                return false;
+         }
+      }
+      if(log.isDebugEnabled()){
+         log.debug(ip + " is in " + network + " / " + netmask);
+         log.debug("=======================================");
+      }
+      return true;
+   }
+   /**
+    * Returns the n-th part of an InetAddress.
+    * 
+    * @param ip
+    *           The address.
+    * @param partNumber
+    *           The number of the part.
+    * @return An integer value.
+    * 
+    * @deprecated This was an internal implementation detail of the method {@link #contains} and should never have been made public. (And it's inefficient and unnecessary too, as well as broken for IPv6. ;-) Use <code>ip.getAddress()[partNumber]</code> instead.
+    */
+   public static int getClassPart(InetAddress ip, int partNumber) {
+      String[] parts = ip.getHostAddress().split("\\.");
+      String part = parts[partNumber];
+      return new Integer(part).intValue();
+   }
+   /**
+    * Check netmask, e.g. 255.255.255.240 is fine, 255.255.240.16 is illegal (needs to be 255.255.240.0)
+    * 
+    * @param netmask
+    *           The netmask address.
+    * @return An integer value. -1 if illegal netmask, otherwise 0, 1, 2, 3
+    * 
+    * @deprecated This was an internal implementation detail of the method {@link #contains} and should never have been made public. Furthermore it's broken for IPv6. (However, there is no real replacement. If you need this functionality, you should rewrite it yourself.)
+    */
+   public static int checkNetmask(InetAddress netmask) {
+      String[] parts = netmask.getHostAddress().split("\\.");
+      Integer[] numbers = new Integer[4];
+      for(int i = 0; i < 4; i++){
+         numbers[i] = new Integer(parts[i]);
+      }
+      for(int i = 0; i < 4; i++){
+         log.debug(".checkNetmask(): Check part: " + numbers[i]);
+         if(0 <= numbers[i].intValue() && numbers[i].intValue() <= 255){
+            if(numbers[i].intValue() != 255){
+               for(int k = i + 1; k < 4; k++){
+                  if(numbers[k].intValue() != 0){
+                     log.error(".checkNetmask(): Illegal Netmask: " + netmask);
+                     return -1;
+                  }
+               }
+               return i;
+            }else{
+               continue;
             }
-        }
-        if(log.isDebugEnabled()) {
-            log.debug
-                (ip + " is in " + network + " / " + netmask);
-            log.debug("=======================================");
-        }
-        return true;
-    }
-
-    /**
-     * Returns the n-th part of an InetAddress.
-     * @param ip The address.
-     * @param partNumber The number of the part.
-     * @return An integer value.
-     * 
-     * @deprecated This was an internal implementation detail of the
-     *      method {@link #contains} and should never have been
-     *      made public. (And it's inefficient and unnecessary
-     *      too, as well as broken for IPv6. ;-)
-     *      Use <code>ip.getAddress()[partNumber]</code>
-     *      instead.
-     */
-    public static int getClassPart(InetAddress ip, int partNumber) {
-        String[] parts = ip.getHostAddress().split("\\.");
-        String part = parts[partNumber];
-        return new Integer(part).intValue();
-    }
-
-    /**
-     * Check netmask, e.g. 255.255.255.240 is fine, 255.255.240.16 is illegal (needs to be 255.255.240.0)
-     * @param netmask The netmask address.
-     * @return An integer value. -1 if illegal netmask, otherwise 0, 1, 2, 3
-     * 
-     * @deprecated This was an internal implementation detail of the
-     *      method {@link #contains} and should never have been
-     *      made public. Furthermore it's broken for IPv6.
-     *      (However, there is no real replacement. If you
-     *      need this functionality, you should rewrite it
-     *      yourself.)
-     */
-    public static int checkNetmask(InetAddress netmask) {
-        String[] parts = netmask.getHostAddress().split("\\.");
-        Integer[] numbers = new Integer[4];
-        for (int i = 0; i < 4; i++) {
-            numbers[i] = new Integer(parts[i]);
-        }
-
-        for (int i = 0; i < 4; i++) {
-            log.debug(".checkNetmask(): Check part: " + numbers[i]);
-            if (0 <= numbers[i].intValue() && numbers[i].intValue() <= 255) {
-                if (numbers[i].intValue() != 255) {
-                    for (int k = i + 1; k < 4; k++) {
-                        if (numbers[k].intValue() != 0) {
-                            log.error(".checkNetmask(): Illegal Netmask: " + netmask);
-                            return -1;
-                        }
-                    }
-                    return i;
-                } else {
-                    continue;
-                }
-            } else {
-                // FIXME: This check not really be necessary because java.net.UnknownHostException should be thrown long time before
-                log.error(".checkNetmask(): Illegal Netmask: " + netmask);
-                return -1;
-            }
-        }
-        if (log.isDebugEnabled()) {
-            log.debug("All parts equal 255: " + netmask);
-        }
-        return 3;
-    }
-
-    /**
-     * Converts a string to an IP addres.
-     * @param string The IP address, represented by a string.
-     * @return An InetAddress object.
-     * @throws AccessControlException when something went wrong.
-     * 
-     * @deprecated This was an internal implementation detail of the
-     *      method {@link #contains} and should never have been
-     *      made public. (And it's unnecessary
-     *      too, as well as broken for IPv6. ;-)
-     *      Use <code>InetAddress.getByName(string)</code>
-     *      instead.
-     */
-    public static InetAddress getAddress(String string) throws UnknownHostException {
-        String[] strings = string.split("\\.");
-
-        InetAddress address;
-        byte[] numbers = new byte[strings.length];
-        for (int i = 0; i < strings.length; i++) {
-            int number = Integer.parseInt(strings[i]);
-            if (number > 127) {
-                number = number - 256;
-            }
-            numbers[i] = (byte) number;
-        }
-
-        address = InetAddress.getByAddress(numbers);
-        return address;
-    }
-
+         }else{
+            // FIXME: This check not really be necessary because java.net.UnknownHostException should be thrown long time before
+            log.error(".checkNetmask(): Illegal Netmask: " + netmask);
+            return -1;
+         }
+      }
+      if(log.isDebugEnabled()){
+         log.debug("All parts equal 255: " + netmask);
+      }
+      return 3;
+   }
+   /**
+    * Converts a string to an IP address.
+    * 
+    * @param string
+    *           The IP address, represented by a string.
+    * @return An InetAddress object.
+    * 
+    * @deprecated This was an internal implementation detail of the method {@link #contains} and should never have been made public. (And it's unnecessary too, as well as broken for IPv6. ;-) Use <code>InetAddress.getByName(string)</code> instead.
+    */
+   public static InetAddress getAddress(String string) throws UnknownHostException {
+      String[] strings = string.split("\\.");
+      InetAddress address;
+      byte[] numbers = new byte[strings.length];
+      for(int i = 0; i < strings.length; i++){
+         int number = Integer.parseInt(strings[i]);
+         if(number > 127){
+            number = number - 256;
+         }
+         numbers[i] = (byte) number;
+      }
+      address = InetAddress.getByAddress(numbers);
+      return address;
+   }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org