[jsword-svn] r1255 - trunk/jsword/src/main/java/org/crosswire/jsword/book/sword

dmsmith at www.crosswire.org dmsmith at www.crosswire.org
Tue Mar 20 14:36:45 MST 2007


Author: dmsmith
Date: 2007-03-20 14:36:44 -0700 (Tue, 20 Mar 2007)
New Revision: 1255

Added:
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/TreeKey.java
Modified:
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/GenBookBackend.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/IndexKey.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/TreeKeyIndex.java
Log:
More GenBook work

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/GenBookBackend.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/GenBookBackend.java	2007-03-19 22:07:43 UTC (rev 1254)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/GenBookBackend.java	2007-03-20 21:36:44 UTC (rev 1255)
@@ -48,6 +48,9 @@
     public GenBookBackend(SwordBookMetaData sbmd) throws BookException
     {
         super(sbmd);
+
+        index = new TreeKeyIndex(sbmd);
+
         String path = getExpandedDataPath();
         bdtFile = new File(path + EXTENSION_BDT);
 
@@ -96,6 +99,9 @@
             bdtRaf = null;
         }
         active = false;
+
+        // Also deactivate the index
+        Activator.deactivate(index);
     }
 
     /* (non-Javadoc)
@@ -117,6 +123,17 @@
         SwordBookMetaData bmd = getBookMetaData();
         Key reply = new DefaultKeyList(null, bmd.getName());
 
+        try
+        {
+            TreeNode node = index.getRoot();
+            TreeKey key = new TreeKey(node, null);
+            reply.addAll(key);
+        }
+        catch (IOException e)
+        {
+            log.error("Could not get root of GenBook", e); //$NON-NLS-1$
+        }
+        
         return reply;
     }
 
@@ -156,6 +173,10 @@
     private RandomAccessFile bdtRaf;
 
     /**
+     * The raw index file
+     */
+    private TreeKeyIndex index;
+    /**
      * Are we active
      */
     private boolean active;

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/IndexKey.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/IndexKey.java	2007-03-19 22:07:43 UTC (rev 1254)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/IndexKey.java	2007-03-20 21:36:44 UTC (rev 1255)
@@ -48,10 +48,7 @@
      */
     IndexKey(String text)
     {
-        super(text, text, null);
-
-        this.offset = -1;
-        this.size = -1;
+        this(text, -1, -1, null);
     }
 
     /**

Added: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/TreeKey.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/TreeKey.java	                        (rev 0)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/TreeKey.java	2007-03-20 21:36:44 UTC (rev 1255)
@@ -0,0 +1,102 @@
+package org.crosswire.jsword.book.sword;
+/**
+ * Distribution License:
+ * JSword is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License, version 2.1 as published by
+ * the Free Software Foundation. This program is distributed in the hope
+ * that it will be useful, but WITHOUT ANY WARRANTY; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * The License is available on the internet at:
+ *       http://www.gnu.org/copyleft/lgpl.html
+ * or by writing to:
+ *      Free Software Foundation, Inc.
+ *      59 Temple Place - Suite 330
+ *      Boston, MA 02111-1307, USA
+ *
+ * Copyright: 2005
+ *     The copyright to this program is held by it's authors.
+ *
+ * ID: $Id: LZSSBackend.java 1143 2006-10-04 22:07:23 -0400 (Wed, 04 Oct 2006) dmsmith $
+ */
+import org.crosswire.jsword.passage.DefaultLeafKeyList;
+import org.crosswire.jsword.passage.Key;
+
+/**
+ * A Key that knows where the data is in the real file.
+ * 
+ * @see gnu.lgpl.License for license details.
+ *      The copyright to this program is held by it's authors.
+ * @author Joe Walker [joe at eireneh dot com]
+ */
+class TreeKey extends DefaultLeafKeyList
+{
+    /**
+     * Setup with the key name and positions of data in the file
+     */
+    TreeKey(TreeNode node, Key parent)
+    {
+        super(node.getName(), node.getName(), parent);
+
+        this.node = node;
+    }
+
+    /**
+     * Setup with the key name. Use solely for searching.
+     */
+    TreeKey(String text)
+    {
+        super(text, text, null);
+
+        this.node = null;
+    }
+
+    /**
+     * @return the name
+     */
+    public String getName()
+    {
+        return node.getName();
+    }
+
+    /**
+     * @param newName the offset to set
+     */
+    public void setName(String newName)
+    {
+        node.setName(newName);
+    }
+
+    /**
+     * @return the offset
+     */
+    public int getOffset()
+    {
+        return node.getOffset();
+    }
+
+    /**
+     * @param newOffset the offset to set
+     */
+    public void setOffset(int newOffset)
+    {
+        node.setOffset(newOffset);
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#clone()
+     */
+    public Object clone()
+    {
+        return super.clone();
+    }
+
+    private TreeNode node;
+
+    /**
+     * Serialization ID
+     */
+    private static final long serialVersionUID = -6560408145705717977L;
+
+}

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/TreeKeyIndex.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/TreeKeyIndex.java	2007-03-19 22:07:43 UTC (rev 1254)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/TreeKeyIndex.java	2007-03-20 21:36:44 UTC (rev 1255)
@@ -128,6 +128,7 @@
             return -1;
         }
 
+        checkActive();
         byte[] buffer = SwordUtil.readRAF(idxRaf, index, 4);
         return SwordUtil.decodeLittleEndian32(buffer, 0);
     }
@@ -147,6 +148,7 @@
             return node;
         }
 
+        checkActive();
         byte[] buffer = SwordUtil.readRAF(datRaf, offset, 12);
         node.setParent(SwordUtil.decodeLittleEndian32(buffer, 0));
         node.setNextSibling(SwordUtil.decodeLittleEndian32(buffer, 4));




More information about the jsword-svn mailing list