[jsword-svn] r1113 - in trunk/jsword/src/main/java/org/crosswire/jsword: book book/filter/thml book/sword examples

dmsmith at crosswire.org dmsmith at crosswire.org
Tue Aug 1 05:18:00 MST 2006


Author: dmsmith
Date: 2006-08-01 05:17:46 -0700 (Tue, 01 Aug 2006)
New Revision: 1113

Added:
   trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/AnonymousTag.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/ColTag.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/RowTag.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/SubTag.java
Modified:
   trunk/jsword/src/main/java/org/crosswire/jsword/book/OSISUtil.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/CustomHandler.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/SmallTag.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/SupTag.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/BookType.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/RawLDBackend.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordUtil.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ZLDBackend.java
   trunk/jsword/src/main/java/org/crosswire/jsword/examples/DictToOsis.java
Log:
First pass implementation of zLD. It needs to be cleaned up.

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/OSISUtil.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/OSISUtil.java	2006-07-31 20:03:31 UTC (rev 1112)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/OSISUtil.java	2006-08-01 12:17:46 UTC (rev 1113)
@@ -48,41 +48,79 @@
 public final class OSISUtil
 {
     /**
-     * Constant to help narrow down what we use "hi" for. In this case the bold tag
+     * The following are values for the type attribute on the hi element.
      */
+    /**
+     * Constant for acrostic highlighting
+     */
+    public static final String HI_ACROSTIC = "acrostic"; //$NON-NLS-1$
+
+    /**
+     * Constant for rendering bold text
+     */
     public static final String HI_BOLD = "bold"; //$NON-NLS-1$
 
     /**
-     * Constant to help narrow down what we use "hi" for. In this case the italic tag
+     * Constant for rendering emphatic text
      */
+    public static final String HI_EMPHASIS = "emphasis"; //$NON-NLS-1$
+
+    /**
+     * Constant for rendering illuminated text.
+     */
+    public static final String HI_ILLUMINATED = "illuminated"; //$NON-NLS-1$
+
+    /**
+     * Constant for rendering italic text.
+     */
     public static final String HI_ITALIC = "italic"; //$NON-NLS-1$
 
     /**
-     * Constant to help narrow down what we use "hi" for. In this case the underline tag
+     * Constant for rendering strike-through text
      */
-    public static final String HI_UNDERLINE = "underline"; //$NON-NLS-1$
+    public static final String HI_LINETHROUGH = "line-through"; //$NON-NLS-1$
 
     /**
-     * Constant to help narrow down what we use seg for. In this case the justify right tag
+     * Constant for rendering normal text.
      */
-    public static final String SEG_JUSTIFYRIGHT = "text-align: right;"; //$NON-NLS-1$
+    public static final String HI_NORMAL = "normal"; //$NON-NLS-1$
 
     /**
-     * Constant to help narrow down what we use seg for. In this case the justify right tag
+     * Constant for rendering small caps
      */
-    public static final String SEG_CENTER = "text-align: center;"; //$NON-NLS-1$
+    public static final String HI_SMALL_CAPS = "small-caps"; //$NON-NLS-1$
 
     /**
-     * Constant to help narrow down what we use seg for. In this case the small tag
+     * Constant for rendering subscripts
      */
-    public static final String SEG_SMALL = "font-size: small;"; //$NON-NLS-1$
+    public static final String HI_SUB = "sub"; //$NON-NLS-1$
 
     /**
-     * Constant to help narrow down what we use seg for. In this case the sup tag
+     * Constant for rendering superscripts
      */
-    public static final String SEG_SUPERSCRIPT = "vertical-align: super;"; //$NON-NLS-1$
+    public static final String HI_SUPER = "super"; //$NON-NLS-1$
 
     /**
+     * Constant for rendering underlined text
+     */
+    public static final String HI_UNDERLINE = "underline"; //$NON-NLS-1$
+
+    /**
+     * Constant for rendering uppercase text
+     */
+    public static final String HI_X_CAPS = "x-caps"; //$NON-NLS-1$
+
+    /**
+     * Constant to help narrow down what we use seg for. In this case the justify right tag
+     */
+    public static final String SEG_JUSTIFYRIGHT = "text-align: right;"; //$NON-NLS-1$
+
+    /**
+     * Constant to help narrow down what we use seg for. In this case the justify right tag
+     */
+    public static final String SEG_CENTER = "text-align: center;"; //$NON-NLS-1$
+
+    /**
      * Constant to help narrow down what we use seg for. In this case the color tag
      */
     public static final String SEG_COLORPREFIX = "color: "; //$NON-NLS-1$
@@ -93,6 +131,11 @@
     public static final String SEG_SIZEPREFIX = "font-size: "; //$NON-NLS-1$
 
     /**
+     * Constant for x- types
+     */
+    public static final String TYPE_X_PREFIX = "x-"; //$NON-NLS-1$
+
+    /**
      * Constant for the study note type
      */
     public static final String NOTETYPE_STUDY = "x-StudyNote"; //$NON-NLS-1$
@@ -104,6 +147,16 @@
     public static final String VARIANT_CLASS = "x-class"; //$NON-NLS-1$
 
     /**
+     * Constant for the pos (part of speech) type.
+     */
+    public static final String POS_TYPE = "x-pos"; //$NON-NLS-1$
+
+    /**
+     * Constant for the def (dictionary definition) type
+     */
+    public static final String DEF_TYPE = "x-def"; //$NON-NLS-1$
+
+    /**
      * Constant for a Strongs numbering lemma
      */
     public static final String LEMMA_STRONGS = "strong:"; //$NON-NLS-1$
@@ -130,7 +183,7 @@
     public static final String Q_EMBEDDED = "embedded"; //$NON-NLS-1$
 
     /**
-     * Constant to help narrow down what we use "list" for.
+     * Constant to help narrow down what dvwe use "list" for.
      */
     public static final String LIST_ORDERED = "x-ordered"; //$NON-NLS-1$
     public static final String LIST_UNORDERED = "x-unordered"; //$NON-NLS-1$

Added: trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/AnonymousTag.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/AnonymousTag.java	2006-07-31 20:03:31 UTC (rev 1112)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/AnonymousTag.java	2006-08-01 12:17:46 UTC (rev 1113)
@@ -0,0 +1,66 @@
+/**
+ * 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: DivTag.java 1068 2006-04-08 02:20:41Z dmsmith $
+ */
+package org.crosswire.jsword.book.filter.thml;
+
+import org.crosswire.jsword.book.OSISUtil;
+import org.jdom.Element;
+import org.xml.sax.Attributes;
+
+/**
+ * THML Tag to process the pos element.
+ * (Part of speech)
+ * 
+ * @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]
+ */
+public class AnonymousTag extends AbstractTag
+{
+    public AnonymousTag(String name)
+    {
+        tagName = name;
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.book.filter.thml.Tag#getTagName()
+     */
+    public String getTagName()
+    {
+        return tagName;
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.book.filter.thml.Tag#processTag(org.jdom.Element, org.xml.sax.Attributes)
+     */
+    /* @Override */
+    public Element processTag(Element ele, Attributes attrs)
+    {
+        Element seg = OSISUtil.factory().createSeg();
+        seg.setAttribute(OSISUtil.OSIS_ATTR_TYPE, OSISUtil.TYPE_X_PREFIX + getTagName());
+        ele.addContent(seg);
+        return seg;
+    }
+    /**
+     * The alias that we are using for the other tag
+     */
+    private String tagName;
+}

Added: trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/ColTag.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/ColTag.java	2006-07-31 20:03:31 UTC (rev 1112)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/ColTag.java	2006-08-01 12:17:46 UTC (rev 1113)
@@ -0,0 +1,55 @@
+/**
+ * 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: BTag.java 1068 2006-04-08 02:20:41Z dmsmith $
+ */
+package org.crosswire.jsword.book.filter.thml;
+
+import org.crosswire.jsword.book.OSISUtil;
+import org.jdom.Element;
+import org.xml.sax.Attributes;
+
+/**
+ * THML Tag to process the table column element.
+ * 
+ * @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]
+ */
+public class ColTag extends AbstractTag
+{
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.book.filter.thml.Tag#getTagName()
+     */
+    public String getTagName()
+    {
+        return "col"; //$NON-NLS-1$
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.book.filter.thml.Tag#processTag(org.jdom.Element, org.xml.sax.Attributes)
+     */
+    /* @Override */
+    public Element processTag(Element ele, Attributes attrs)
+    {
+        Element hi = OSISUtil.factory().createCell();
+        ele.addContent(hi);
+        return hi;
+    }
+}

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/CustomHandler.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/CustomHandler.java	2006-07-31 20:03:31 UTC (rev 1112)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/CustomHandler.java	2006-08-01 12:17:46 UTC (rev 1113)
@@ -206,9 +206,12 @@
             new ScriptureTag(),
             new ScripRefTag(),
             new SmallTag(),
+            new SubTag(),
             new SupTag(),
             new SyncTag(),
             new TableTag(),
+            new RowTag(),
+            new ColTag(),
             new TdTag(),
             new TermTag(),
             new ThTag(),
@@ -226,6 +229,91 @@
             new IgnoreTag("span"), //$NON-NLS-1$
             new IgnoreTag("dir"), //$NON-NLS-1$
             new IgnoreTag("pre"), //$NON-NLS-1$
+            // all the following are from Webster's Dict
+            // Don't know what to do with them
+            // They are not ThML!
+            new AnonymousTag("def"), //$NON-NLS-1$
+            new AnonymousTag("pos"), //$NON-NLS-1$
+            new AnonymousTag("hpos"), //$NON-NLS-1$
+            new AnonymousTag("org"), //$NON-NLS-1$
+            new AnonymousTag("wf"), //$NON-NLS-1$
+            new AnonymousTag("cd"), //$NON-NLS-1$
+            new AnonymousTag("sd"), //$NON-NLS-1$
+            new AnonymousTag("tran"), //$NON-NLS-1$
+            new AnonymousTag("itran"), //$NON-NLS-1$
+            new AnonymousTag("qpers"), //$NON-NLS-1$
+            new AnonymousTag("fract"), //$NON-NLS-1$
+            new AnonymousTag("sn"), //$NON-NLS-1$
+            new AnonymousTag("singw"), //$NON-NLS-1$
+            new AnonymousTag("universbold"), //$NON-NLS-1$
+            new AnonymousTag("plw"), //$NON-NLS-1$
+            new AnonymousTag("matrix"), //$NON-NLS-1$
+            new AnonymousTag("ttitle"), //$NON-NLS-1$
+            new AnonymousTag("englishtype"), //$NON-NLS-1$
+            new AnonymousTag("figcap"), //$NON-NLS-1$
+            new AnonymousTag("extendedtype"), //$NON-NLS-1$
+            new AnonymousTag("musfig"), //$NON-NLS-1$
+            new AnonymousTag("stageof"), //$NON-NLS-1$
+            new AnonymousTag("wns"), //$NON-NLS-1$
+            new AnonymousTag("subs"), //$NON-NLS-1$
+            new AnonymousTag("sups"), //$NON-NLS-1$
+            new AnonymousTag("nonpareiltype"), //$NON-NLS-1$
+            new AnonymousTag("gothictype"), //$NON-NLS-1$
+            new AnonymousTag("sanserif"), //$NON-NLS-1$
+            new AnonymousTag("sansserif"), //$NON-NLS-1$
+            new AnonymousTag("headrow"), //$NON-NLS-1$
+            new AnonymousTag("figure"), //$NON-NLS-1$
+            new AnonymousTag("srow"), //$NON-NLS-1$
+            new AnonymousTag("longprimertype"), //$NON-NLS-1$
+            new AnonymousTag("greatprimertype"), //$NON-NLS-1$
+            new AnonymousTag("est"), //$NON-NLS-1$
+            new AnonymousTag("chname"), //$NON-NLS-1$
+            new AnonymousTag("miniontype"), //$NON-NLS-1$
+            new AnonymousTag("supr"), //$NON-NLS-1$
+            new AnonymousTag("sansserif"), //$NON-NLS-1$
+            new AnonymousTag("funct"), //$NON-NLS-1$
+            new AnonymousTag("item"), //$NON-NLS-1$
+            new AnonymousTag("mitem"), //$NON-NLS-1$
+            new AnonymousTag("mtable"), //$NON-NLS-1$
+            new AnonymousTag("figtitle"), //$NON-NLS-1$
+            new AnonymousTag("ct"), //$NON-NLS-1$
+            new AnonymousTag("defwf"), //$NON-NLS-1$
+            new AnonymousTag("umac"), //$NON-NLS-1$
+            new AnonymousTag("pearltype"), //$NON-NLS-1$
+            new AnonymousTag("vertical"), //$NON-NLS-1$
+            new AnonymousTag("title"), //$NON-NLS-1$
+            new AnonymousTag("picatype"), //$NON-NLS-1$
+            new AnonymousTag("point18"), //$NON-NLS-1$
+            new AnonymousTag("matrix2x5"), //$NON-NLS-1$
+            new AnonymousTag("oldenglishtype"), //$NON-NLS-1$
+            new AnonymousTag("oldstyletype"), //$NON-NLS-1$
+            new AnonymousTag("smpicatype"), //$NON-NLS-1$
+            new AnonymousTag("frenchelzevirtype"), //$NON-NLS-1$
+            new AnonymousTag("typewritertype"), //$NON-NLS-1$
+            new AnonymousTag("scripttype"), //$NON-NLS-1$
+            new AnonymousTag("point1"), //$NON-NLS-1$
+            new AnonymousTag("point1.5"), //$NON-NLS-1$
+            new AnonymousTag("point2"), //$NON-NLS-1$
+            new AnonymousTag("point2.5"), //$NON-NLS-1$
+            new AnonymousTag("point3"), //$NON-NLS-1$
+            new AnonymousTag("point3.5"), //$NON-NLS-1$
+            new AnonymousTag("point4"), //$NON-NLS-1$
+            new AnonymousTag("point4.5"), //$NON-NLS-1$
+            new AnonymousTag("point5"), //$NON-NLS-1$
+            new AnonymousTag("point5.5"), //$NON-NLS-1$
+            new AnonymousTag("point6"), //$NON-NLS-1$
+            new AnonymousTag("point7"), //$NON-NLS-1$
+            new AnonymousTag("point8"), //$NON-NLS-1$
+            new AnonymousTag("point9"), //$NON-NLS-1$
+            new AnonymousTag("point10"), //$NON-NLS-1$
+            new AnonymousTag("point11"), //$NON-NLS-1$
+            new AnonymousTag("point12"), //$NON-NLS-1$
+            new AnonymousTag("point14"), //$NON-NLS-1$
+            new AnonymousTag("point16"), //$NON-NLS-1$
+            new AnonymousTag("point18"), //$NON-NLS-1$
+            new AnonymousTag("point20"), //$NON-NLS-1$
+           new AnonymousTag("tt"), //$NON-NLS-1$
+            new AnonymousTag("hw"), //$NON-NLS-1$
         };
         for (int i = 0; i < tags.length; i++)
         {

Added: trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/RowTag.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/RowTag.java	2006-07-31 20:03:31 UTC (rev 1112)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/RowTag.java	2006-08-01 12:17:46 UTC (rev 1113)
@@ -0,0 +1,55 @@
+/**
+ * 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: BTag.java 1068 2006-04-08 02:20:41Z dmsmith $
+ */
+package org.crosswire.jsword.book.filter.thml;
+
+import org.crosswire.jsword.book.OSISUtil;
+import org.jdom.Element;
+import org.xml.sax.Attributes;
+
+/**
+ * THML Tag to process the table row element.
+ * 
+ * @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]
+ */
+public class RowTag extends AbstractTag
+{
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.book.filter.thml.Tag#getTagName()
+     */
+    public String getTagName()
+    {
+        return "row"; //$NON-NLS-1$
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.book.filter.thml.Tag#processTag(org.jdom.Element, org.xml.sax.Attributes)
+     */
+    /* @Override */
+    public Element processTag(Element ele, Attributes attrs)
+    {
+        Element hi = OSISUtil.factory().createRow();
+        ele.addContent(hi);
+        return hi;
+    }
+}

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/SmallTag.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/SmallTag.java	2006-07-31 20:03:31 UTC (rev 1112)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/SmallTag.java	2006-08-01 12:17:46 UTC (rev 1113)
@@ -48,9 +48,9 @@
     /* @Override */
     public Element processTag(Element ele, Attributes attrs)
     {
-        Element seg = OSISUtil.factory().createSeg();
-        seg.setAttribute(OSISUtil.OSIS_ATTR_TYPE, OSISUtil.SEG_SMALL);
-        ele.addContent(seg);
-        return seg;
+        Element hi = OSISUtil.factory().createHI();
+        hi.setAttribute(OSISUtil.OSIS_ATTR_TYPE, OSISUtil.HI_SMALL_CAPS);
+        ele.addContent(hi);
+        return hi;
     }
 }

Added: trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/SubTag.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/SubTag.java	2006-07-31 20:03:31 UTC (rev 1112)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/SubTag.java	2006-08-01 12:17:46 UTC (rev 1113)
@@ -0,0 +1,56 @@
+/**
+ * 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: BTag.java 1068 2006-04-08 02:20:41Z dmsmith $
+ */
+package org.crosswire.jsword.book.filter.thml;
+
+import org.crosswire.jsword.book.OSISUtil;
+import org.jdom.Element;
+import org.xml.sax.Attributes;
+
+/**
+ * THML Tag to process the bold element.
+ * 
+ * @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]
+ */
+public class SubTag extends AbstractTag
+{
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.book.filter.thml.Tag#getTagName()
+     */
+    public String getTagName()
+    {
+        return "sub"; //$NON-NLS-1$
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.book.filter.thml.Tag#processTag(org.jdom.Element, org.xml.sax.Attributes)
+     */
+    /* @Override */
+    public Element processTag(Element ele, Attributes attrs)
+    {
+        Element hi = OSISUtil.factory().createHI();
+        hi.setAttribute(OSISUtil.OSIS_ATTR_TYPE, OSISUtil.HI_SUB);
+        ele.addContent(hi);
+        return hi;
+    }
+}

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/SupTag.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/SupTag.java	2006-07-31 20:03:31 UTC (rev 1112)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/SupTag.java	2006-08-01 12:17:46 UTC (rev 1113)
@@ -48,9 +48,9 @@
     /* @Override */
     public Element processTag(Element ele, Attributes attrs)
     {
-        Element seg = OSISUtil.factory().createSeg();
-        seg.setAttribute(OSISUtil.OSIS_ATTR_TYPE, OSISUtil.SEG_SUPERSCRIPT);
-        ele.addContent(seg);
-        return seg;
+        Element hi = OSISUtil.factory().createHI();
+        hi.setAttribute(OSISUtil.OSIS_ATTR_TYPE, OSISUtil.HI_SUPER);
+        ele.addContent(hi);
+        return hi;
     }
 }

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/BookType.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/BookType.java	2006-07-31 20:03:31 UTC (rev 1112)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/BookType.java	2006-08-01 12:17:46 UTC (rev 1113)
@@ -243,11 +243,6 @@
             return new ZLDBackend(sbmd, rootPath);
         }
 
-        protected boolean isBackendSupported(SwordBookMetaData sbmd)
-        {
-            return false;
-        }
-
         /**
          * Serialization ID
          */

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/RawLDBackend.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/RawLDBackend.java	2006-07-31 20:03:31 UTC (rev 1112)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/RawLDBackend.java	2006-08-01 12:17:46 UTC (rev 1113)
@@ -136,7 +136,8 @@
     {
         checkActive();
 
-        BookMetaData bmd = getBookMetaData();
+        SwordBookMetaData bmd = getBookMetaData();
+        String charset = bmd.getBookCharset();
         Key reply = new DefaultKeyList(null, bmd.getName());
 
         boolean isDailyDevotional = bmd.getBookCategory().equals(BookCategory.DAILY_DEVOTIONS);
@@ -191,7 +192,7 @@
                 byte[] keydata = new byte[keyend];
                 System.arraycopy(data, 0, keydata, 0, keyend);
 
-                String keytitle = new String(keydata).trim();
+                String keytitle = SwordUtil.decode(reply, keydata, charset).trim();
                 // for some wierd reason plain text (i.e. SourceType=0) dicts
                 // all get \ added to the ends of the index entries.
                 if (keytitle.endsWith("\\")) //$NON-NLS-1$
@@ -256,7 +257,7 @@
             byte[] reply = new byte[remainder];
             System.arraycopy(data, keyend + 1, reply, 0, remainder);
 
-            return SwordUtil.decode(key, reply, charset);
+            return SwordUtil.decode(key, reply, charset).trim();
         }
         catch (IOException ex)
         {

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordUtil.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordUtil.java	2006-07-31 20:03:31 UTC (rev 1112)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordUtil.java	2006-08-01 12:17:46 UTC (rev 1113)
@@ -21,11 +21,15 @@
  */
 package org.crosswire.jsword.book.sword;
 
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.RandomAccessFile;
 import java.io.UnsupportedEncodingException;
 import java.util.zip.DataFormatException;
 import java.util.zip.Inflater;
+import java.util.zip.InflaterInputStream;
 
 import org.crosswire.common.util.Logger;
 import org.crosswire.jsword.book.BookException;
@@ -156,6 +160,31 @@
 
         return uncompressed;
     }
+    /**
+     * Uncompress a block of GZIP compressed data
+     * @param compressed The data to uncompress
+     * @param endsize The expected resultant data size
+     * @return The uncompressed data
+     * @throws IOException 
+     */
+    public static byte[] uncompress(byte[] compressed) throws IOException
+    {
+        final int BUFFER = 2048;
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        BufferedOutputStream out = new BufferedOutputStream(bos, BUFFER);
+        ByteArrayInputStream bis = new ByteArrayInputStream(compressed);
+        InflaterInputStream in = new InflaterInputStream(bis, new Inflater(), BUFFER);
+        byte[] buf = new byte[BUFFER];
+        int count;
+        while ((count = in.read(buf)) != -1)
+        {
+            out.write(buf, 0, count);
+        }
+        in.close();
+        out.flush();
+        out.close();
+        return bos.toByteArray();
+    }
 
     /**
      * Transform a byte array into a string given the encoding.

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ZLDBackend.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ZLDBackend.java	2006-07-31 20:03:31 UTC (rev 1112)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ZLDBackend.java	2006-08-01 12:17:46 UTC (rev 1113)
@@ -22,10 +22,28 @@
 package org.crosswire.jsword.book.sword;
 
 import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
 
+import org.crosswire.common.activate.Activator;
 import org.crosswire.common.activate.Lock;
+import org.crosswire.common.util.ClassUtil;
+import org.crosswire.common.util.FileUtil;
+import org.crosswire.common.util.Logger;
+import org.crosswire.common.util.Reporter;
+import org.crosswire.common.util.StringUtil;
+import org.crosswire.jsword.book.BookCategory;
 import org.crosswire.jsword.book.BookException;
+import org.crosswire.jsword.book.BookMetaData;
+import org.crosswire.jsword.book.DataPolice;
+import org.crosswire.jsword.book.sword.RawLDBackend.IndexKey;
 import org.crosswire.jsword.passage.DefaultKeyList;
+import org.crosswire.jsword.passage.DefaultLeafKeyList;
 import org.crosswire.jsword.passage.Key;
 
 /**
@@ -38,12 +56,86 @@
  */
 public class ZLDBackend extends AbstractBackend
 {
+    private static final String EXTENSION_INDEX = ".idx"; //$NON-NLS-1$
+    private static final String EXTENSION_DATA = ".dat"; //$NON-NLS-1$
+    private static final String EXTENSION_Z_INDEX = ".zdx"; //$NON-NLS-1$
+    private static final String EXTENSION_Z_DATA = ".zdt"; //$NON-NLS-1$
+
+    private static final int IDX_ENTRY_SIZE = 8;
+    private static final int ZDX_ENTRY_SIZE = 8;
+    private static final int BLOCK_ENTRY_COUNT = 4;
+    private static final int BLOCK_ENTRY_SIZE = 8;
+
     /**
+     * Used to separate the key name from the key value
+     */
+    private static final byte SEPARATOR = 10; // ^M=CR=13=0x0d=\r ^J=LF=10=0x0a=\n
+
+    /**
+     * The log stream
+     */
+    private static final Logger log = Logger.getLogger(ZLDBackend.class);
+
+    private File idxFile;
+
+    private File datFile;
+
+    /**
+     * The compressed index.
+     */
+    private File zdxFile;
+ 
+    /**
+     * The compressed text.
+     */
+    private File zdtFile;
+
+    private RandomAccessFile idxRaf;
+    private RandomAccessFile datRaf;
+    private RandomAccessFile zdxRaf;
+    private RandomAccessFile zdtRaf;
+    private boolean active;
+    private Key keys;
+    private int lastBlockNum = -1;
+    private static final byte[] emptyBytes = new byte[0];
+    private byte[] lastUncompressed = emptyBytes;
+
+    /**
      * Simple ctor
+     * @throws BookException 
      */
-    public ZLDBackend(SwordBookMetaData sbmd, File rootPath)
+    public ZLDBackend(SwordBookMetaData sbmd, File rootPath) throws BookException
     {
         super(sbmd, rootPath);
+
+        String dataPath = sbmd.getProperty(ConfigEntryType.DATA_PATH);
+        File baseurl = new File(rootPath, dataPath);
+        String path = baseurl.getAbsolutePath();
+
+        idxFile = new File(path + EXTENSION_INDEX);
+        datFile = new File(path + EXTENSION_DATA);
+        zdxFile = new File(path + EXTENSION_Z_INDEX);
+        zdtFile = new File(path + EXTENSION_Z_DATA);
+
+        if (!idxFile.canRead())
+        {
+            throw new BookException(Msg.READ_FAIL, new Object[] { idxFile.getAbsolutePath() });
+        }
+
+        if (!datFile.canRead())
+        {
+            throw new BookException(Msg.READ_FAIL, new Object[] { datFile.getAbsolutePath() });
+        }
+
+        if (!zdxFile.canRead())
+        {
+            throw new BookException(Msg.READ_FAIL, new Object[] { zdxFile.getAbsolutePath() });
+        }
+
+        if (!zdtFile.canRead())
+        {
+            throw new BookException(Msg.READ_FAIL, new Object[] { zdtFile.getAbsolutePath() });
+        }
     }
 
     /* (non-Javadoc)
@@ -51,6 +143,22 @@
      */
     public final void activate(Lock lock)
     {
+        try
+        {
+            idxRaf = new RandomAccessFile(idxFile, FileUtil.MODE_READ);
+            datRaf = new RandomAccessFile(datFile, FileUtil.MODE_READ);
+            zdxRaf = new RandomAccessFile(zdxFile, FileUtil.MODE_READ);
+            zdtRaf = new RandomAccessFile(zdtFile, FileUtil.MODE_READ);
+        }
+        catch (IOException ex)
+        {
+            log.error("failed to open files", ex); //$NON-NLS-1$
+            idxRaf = null;
+            datRaf = null;
+            zdxRaf = null;
+            zdtRaf = null;
+        }
+        active = true;
     }
 
     /* (non-Javadoc)
@@ -58,7 +166,30 @@
      */
     public final void deactivate(Lock lock)
     {
-    }
+        try
+        {
+            idxRaf.close();
+            datRaf.close();
+            zdxRaf.close();
+            zdtRaf.close();
+        }
+        catch (IOException ex)
+        {
+            log.error("failed to close nt files", ex); //$NON-NLS-1$
+        }
+        catch (NullPointerException ex)
+        {
+            // ignore this might be OT only
+        }
+        finally
+        {
+            idxRaf = null;
+            datRaf = null;
+            zdxRaf = null;
+            zdtRaf = null;
+        }
+        active = false;
+   }
 
     /* (non-Javadoc)
      * @see org.crosswire.jsword.book.sword.KeyBackend#readIndex()
@@ -66,7 +197,84 @@
     /* @Override */
     public Key readIndex()
     {
-        return new DefaultKeyList(null, getBookMetaData().getName());
+        checkActive();
+        SwordBookMetaData bmd = getBookMetaData();
+        String charset = bmd.getBookCharset();
+
+        keys = new DefaultKeyList(null, bmd.getName());
+
+        boolean isDailyDevotional = bmd.getBookCategory().equals(BookCategory.DAILY_DEVOTIONS);
+        // We use 1972 because it is a leap year.
+        Calendar greg = new GregorianCalendar(1972, Calendar.JANUARY, 1);
+        DateFormat nameDF = new SimpleDateFormat("d MMMM"); //$NON-NLS-1$
+
+        long entries;
+        try
+        {
+            entries = idxRaf.length() / IDX_ENTRY_SIZE;
+        }
+        catch (IOException ex)
+        {
+            Reporter.informUser(this, ex);
+            return keys;
+        }
+
+        for (int entry = 0; entry < entries; entry++)
+        {
+            try
+            {
+                // Read the offset and size for this key from the index
+                byte[] buffer = SwordUtil.readRAF(idxRaf, entry * IDX_ENTRY_SIZE, IDX_ENTRY_SIZE);
+                int offset = SwordUtil.decodeLittleEndian32(buffer, 0);
+                int size = SwordUtil.decodeLittleEndian32(buffer, 4);
+
+                // Now read the data file for this key using the offset and size
+                byte[] data = SwordUtil.readRAF(datRaf, offset, size);
+
+                decipher(data);
+
+                int keyend = SwordUtil.findByte(data, SEPARATOR);
+                if (keyend == -1)
+                {
+                    DataPolice.report("Failed to find keyname. offset=" + offset + " data='" + new String(data) + "'"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+                    continue;
+                }
+
+                byte[] keydata = new byte[keyend];
+                System.arraycopy(data, 0, keydata, 0, keyend);
+
+                String keytitle = SwordUtil.decode(keys, keydata, charset).trim();
+
+                // for some wierd reason plain text (i.e. SourceType=0) dicts
+                // all get \ added to the ends of the index entries.
+                if (keytitle.endsWith("\\")) //$NON-NLS-1$
+                {
+                    keytitle = keytitle.substring(0, keytitle.length() - 1);
+                }
+
+                if (isDailyDevotional)
+                {
+                    String[] parts = StringUtil.splitAll(keytitle, '.');
+                    greg.set(Calendar.MONTH, Integer.parseInt(parts[0]) - 1);
+                    greg.set(Calendar.DATE, Integer.parseInt(parts[1]));
+                    keytitle = nameDF.format(greg.getTime());
+                }
+
+                Key key = new IndexKey(keytitle, offset, size, keys);
+
+                keys.addAll(key);
+            }
+            catch (IOException ex)
+            {
+                log.error("Ignoring entry", ex); //$NON-NLS-1$
+            }
+            catch (NumberFormatException e)
+            {
+                log.error("Ignoring entry", e); //$NON-NLS-1$
+            }
+        }
+
+        return keys;
     }
 
     /* (non-Javadoc)
@@ -75,8 +283,90 @@
     /* @Override */
     public String getRawText(Key key) throws BookException
     {
-        // LATER(joe): implement this
-        throw new BookException(Msg.COMPRESSION_UNSUPPORTED);
+        checkActive();
+        String charset = getBookMetaData().getBookCharset();
+
+        if (!(key instanceof IndexKey))
+        {
+            throw new BookException(Msg.BAD_KEY, new Object[] { ClassUtil.getShortClassName(key.getClass()), key.getName() });
+        }
+
+        IndexKey ikey = (IndexKey) key;
+
+        try
+        {
+            byte[] data = SwordUtil.readRAF(datRaf, ikey.offset, ikey.size);
+
+            int keyend = SwordUtil.findByte(data, SEPARATOR);
+            if (keyend == -1)
+            {
+                throw new BookException(Msg.READ_FAIL);
+            }
+
+            int remainder = data.length - (keyend + 1);
+            byte[] temp = new byte[remainder];
+            System.arraycopy(data, keyend + 1, temp, 0, remainder);
+
+            String linkCheck = new String(temp, 0, 5, charset);
+            if ("@LINK".equals(linkCheck)) //$NON-NLS-1$
+            {
+                keyend = SwordUtil.findByte(temp, SEPARATOR);
+                String linkKey = new String(temp, 6, temp.length - (keyend + 1), charset).trim();
+                ikey = (IndexKey) keys.get(keys.indexOf(new IndexKey(linkKey)));
+                return getRawText(ikey);
+            }
+
+            int blockNum = SwordUtil.decodeLittleEndian32(temp, 0);
+            int entry = SwordUtil.decodeLittleEndian32(temp, 4);
+
+            // Can we get the data from the cache
+            byte[] uncompressed = null;
+            if (blockNum == lastBlockNum)
+            {
+                uncompressed = lastUncompressed;
+            }
+            else
+            {
+                temp = SwordUtil.readRAF(zdxRaf, blockNum * ZDX_ENTRY_SIZE, ZDX_ENTRY_SIZE);
+                if (temp == null || temp.length == 0)
+                {
+                    return ""; //$NON-NLS-1$
+                }
+
+                int blockStart = SwordUtil.decodeLittleEndian32(temp, 0);
+                int blockSize = SwordUtil.decodeLittleEndian32(temp, 4);
+
+                temp = SwordUtil.readRAF(zdtRaf, blockStart, blockSize);
+                
+                decipher(temp);
+                
+                uncompressed = SwordUtil.uncompress(temp);
+
+                // cache the uncompressed data for next time
+                lastBlockNum = blockNum;
+                lastUncompressed = uncompressed;
+            }
+
+            // get the "entry" from this block.
+            int entryCount = SwordUtil.decodeLittleEndian32(uncompressed, 0);
+            if (entry >= entryCount)
+            {
+                return ""; //$NON-NLS-1$
+            }
+            int entryOffset = BLOCK_ENTRY_COUNT + (BLOCK_ENTRY_SIZE*entry);
+            int entryStart = SwordUtil.decodeLittleEndian32(uncompressed, entryOffset);
+            // Note: the actual entry is '\0' terminated
+            int entrySize = SwordUtil.decodeLittleEndian32(uncompressed, entryOffset + 4);
+            byte[] entryBytes = new byte[entrySize];
+            System.arraycopy(uncompressed, entryStart, entryBytes, 0, entrySize);
+            
+            String ret = SwordUtil.decode(key, entryBytes, charset).trim();
+            return ret;
+        }
+        catch (Exception ex)
+        {
+            throw new BookException(Msg.READ_FAIL, ex);
+        }
     }
 
     /* (non-Javadoc)
@@ -85,6 +375,57 @@
     /* @Override */
     public boolean isSupported()
     {
-        return false;
+        return true;
     }
+
+    /**
+     * Helper method so we can quickly activate ourselves on access
+     */
+    protected final void checkActive()
+    {
+        if (!active)
+        {
+            Activator.activate(this);
+        }
+    }
+
+    /**
+     * A Key that knows where the data is in the real file.
+     */
+    static class IndexKey extends DefaultLeafKeyList
+    {
+        /**
+         * Setup with the key name and positions of data in the file
+         */
+        protected IndexKey(String text, int offset, int size, Key parent)
+        {
+            super(text, text, parent);
+
+            this.offset = offset;
+            this.size = size;
+        }
+
+        /**
+         * Setup with the key name. Use solely for searching.
+         */
+        protected IndexKey(String text)
+        {
+            super(text, text, null);
+
+            this.offset = -1;
+            this.size = -1;
+        }
+
+        /* (non-Javadoc)
+         * @see java.lang.Object#clone()
+         */
+        public Object clone()
+        {
+            return super.clone();
+        }
+
+        protected int offset;
+        protected int size;
+    }
+
 }

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/examples/DictToOsis.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/examples/DictToOsis.java	2006-07-31 20:03:31 UTC (rev 1112)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/examples/DictToOsis.java	2006-08-01 12:17:46 UTC (rev 1113)
@@ -54,7 +54,7 @@
     /**
      * The name of a Bible to find
      */
-    private static final String BOOK_NAME = "Thayer"; //$NON-NLS-1$
+    private static final String BOOK_NAME = "WebstersDict"; //$NON-NLS-1$
 
     /**
      * @param args



More information about the jsword-svn mailing list