[jsword-svn] jsword/java/limbo/org/crosswire/jsword/book/remote s

jswordcvs at crosswire.org jswordcvs at crosswire.org
Tue Oct 5 15:03:11 MST 2004


Update of /cvs/jsword/jsword/java/limbo/org/crosswire/jsword/book/remote
In directory www.crosswire.org:/tmp/cvs-serv9907/java/limbo/org/crosswire/jsword/book/remote

Modified Files:
	RemoteBookDriver.java HttpRemoter.java LocalRemoter.java 
	ConverterTest.java FixtureRemoter.java Converter.java 
	RemoteBook.java LocalRemoterTest.java Remoter.java 
Log Message:
Improvments on reading SwordBookMetaData

Index: LocalRemoter.java
===================================================================
RCS file: /cvs/jsword/jsword/java/limbo/org/crosswire/jsword/book/remote/LocalRemoter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** LocalRemoter.java	27 Jul 2004 21:42:34 -0000	1.3
--- LocalRemoter.java	5 Oct 2004 22:03:09 -0000	1.4
***************
*** 115,126 ****
      }
  
-     /* (non-Javadoc)
-      * @see org.crosswire.jsword.book.remote.Remoter#getSpeed()
-      */
-     public int getSpeed()
-     {
-         return BookMetaData.SPEED_REMOTE_FASTEST;
-     }
- 
      /**
       * Lookup a BibleMetaData using the UID that we assigned to it earlier
     */
--- 115,118 ----
***************
*** 168,172 ****
       * The filter to select the bibles we are exporting
       */
!     private static final BookFilter FILTER = BookFilters.getFaster(BookMetaData.SPEED_SLOWEST);
  
      /**
--- 160,164 ----
       * The filter to select the bibles we are exporting
       */
!     private static final BookFilter FILTER = BookFilters.getAll();
  
      /**

Index: HttpRemoter.java
===================================================================
RCS file: /cvs/jsword/jsword/java/limbo/org/crosswire/jsword/book/remote/HttpRemoter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** HttpRemoter.java	21 Sep 2004 17:46:23 -0000	1.2
--- HttpRemoter.java	5 Oct 2004 22:03:09 -0000	1.3
***************
*** 8,12 ****
  
  import org.crosswire.common.util.Logger;
- import org.crosswire.jsword.book.BookMetaData;
  import org.jdom.Document;
  import org.jdom.input.SAXBuilder;
--- 8,11 ----
***************
*** 84,95 ****
  
      /**
-      * How fast are we?
-      */
-     public int getSpeed()
-     {
-         return BookMetaData.SPEED_REMOTE_SLOW;
-     }
- 
-     /**
       * Convert a RemoteMethod to a String which we can append to a base url
       * to get a complete URL which will get us the required XML document.
     */
--- 83,86 ----

Index: Converter.java
===================================================================
RCS file: /cvs/jsword/jsword/java/limbo/org/crosswire/jsword/book/remote/Converter.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Converter.java	21 Sep 2004 17:46:23 -0000	1.4
--- Converter.java	5 Oct 2004 22:03:09 -0000	1.5
***************
*** 3,8 ****
  import java.io.PrintWriter;
  import java.io.StringWriter;
- import java.net.MalformedURLException;
- import java.text.ParseException;
  import java.util.ArrayList;
  import java.util.Iterator;
--- 3,6 ----
***************
*** 12,17 ****
  import org.crosswire.jsword.book.BookMetaData;
  import org.crosswire.jsword.book.BookType;
- import org.crosswire.jsword.book.Openness;
- import org.crosswire.jsword.book.basic.DefaultBookMetaData;
  import org.crosswire.jsword.passage.DefaultKeyList;
  import org.crosswire.jsword.passage.Key;
--- 10,13 ----
***************
*** 53,60 ****
      private static final String ELEMENT_ROOT = "root"; //$NON-NLS-1$
      private static final String ELEMENT_TYPE = "type"; //$NON-NLS-1$
-     private static final String ELEMENT_LICENCE = "licence"; //$NON-NLS-1$
-     private static final String ELEMENT_OPENNESS = "openness"; //$NON-NLS-1$
-     private static final String ELEMENT_PUB = "pub"; //$NON-NLS-1$
-     private static final String ELEMENT_EDITION = "edition"; //$NON-NLS-1$
      private static final String ELEMENT_NAME = "name"; //$NON-NLS-1$
      private static final String ATTRIBUTE_ID = "id"; //$NON-NLS-1$
--- 49,52 ----
***************
*** 75,83 ****
       *   [metadata id="uid"]
       *     [name]King James Version[/name]
!      *     [edition][/edition]
!      *     [initials]KJV[/initials]
!      *     [pub]1900[/pub]
!      *     [openness]PD[/openness]
!      *   [/metadata]
       * [/root]
       * </pre>
--- 67,71 ----
       *   [metadata id="uid"]
       *     [name]King James Version[/name]
! \     *   [/metadata]
       * [/root]
       * </pre>
***************
*** 85,135 ****
       * @return BibleMetaData[]
       */
!     public static BookMetaData[] convertDocumentToBookMetaDatas(RemoteBookDriver driver, Document doc, Remoter remoter, int speed) throws ConverterException
      {
!         try
!         {
!             Element root = doc.getRootElement();
!             List bmds = root.getChildren(ELEMENT_METADATA);
!             BookMetaData[] rbmds = new BookMetaData[bmds.size()];
!             int i = 0;
! 
!             for (Iterator it = bmds.iterator(); it.hasNext();)
!             {
!                 Element bmdele = (Element) it.next();
  
!                 String id = bmdele.getAttributeValue(ATTRIBUTE_ID);
  
!                 String name = bmdele.getChildTextTrim(ELEMENT_NAME);
!                 String edition = bmdele.getChildTextTrim(ELEMENT_EDITION);
!                 String pubstr = bmdele.getChildTextTrim(ELEMENT_PUB);
!                 String openstr = bmdele.getChildTextTrim(ELEMENT_OPENNESS);
!                 String licencestr = bmdele.getChildTextTrim(ELEMENT_LICENCE);
!                 String typestr = bmdele.getChildTextTrim(ELEMENT_TYPE);
  
!                 BookType type = BookType.fromString(typestr);
  
!                 Book book = new RemoteBook(remoter, driver, name, type, edition, pubstr, openstr, licencestr, speed);
  
!                 BookMetaData bmd = book.getBookMetaData();
!                 driver.registerID(id, bmd);
  
!                 rbmds[i++] = bmd;
!             }
  
!             return rbmds;
!         }
!         catch (MalformedURLException ex)
!         {
!             throw new ConverterException(Msg.CONVERT_BMD, ex);
!         }
!         catch (ParseException ex)
!         {
!             throw new ConverterException(Msg.CONVERT_BMD, ex);
          }
      }
  
      /**
       * Reverse of convertDocumentToBibleMetaDatas().
!      * @see Converter#convertDocumentToBookMetaDatas(RemoteBookDriver, Document, Remoter, int)
       */
      public static Document convertBookMetaDatasToDocument(BookMetaData[] bmds, String[] ids)
--- 73,108 ----
       * @return BibleMetaData[]
       */
!     public static BookMetaData[] convertDocumentToBookMetaDatas(RemoteBookDriver driver, Document doc, Remoter remoter)
      {
!         Element root = doc.getRootElement();
!         List bmds = root.getChildren(ELEMENT_METADATA);
!         BookMetaData[] rbmds = new BookMetaData[bmds.size()];
!         int i = 0;
  
!         for (Iterator it = bmds.iterator(); it.hasNext();)
!         {
!             Element bmdele = (Element) it.next();
  
!             String id = bmdele.getAttributeValue(ATTRIBUTE_ID);
  
!             String name = bmdele.getChildTextTrim(ELEMENT_NAME);
!             String typestr = bmdele.getChildTextTrim(ELEMENT_TYPE);
  
!             BookType type = BookType.fromString(typestr);
  
!             Book book = new RemoteBook(remoter, driver, name, type);
  
!             BookMetaData bmd = book.getBookMetaData();
!             driver.registerID(id, bmd);
  
!             rbmds[i++] = bmd;
          }
+ 
+         return rbmds;
      }
  
      /**
       * Reverse of convertDocumentToBibleMetaDatas().
!      * @see Converter#convertDocumentToBookMetaDatas(RemoteBookDriver, Document, Remoter)
       */
      public static Document convertBookMetaDatasToDocument(BookMetaData[] bmds, String[] ids)
***************
*** 150,180 ****
              bmdele.addContent(temp);
  
-             temp = new Element(ELEMENT_EDITION);
-             temp.addContent(bmd.getEdition());
-             bmdele.addContent(temp);
- 
-             String pubstr = DefaultBookMetaData.formatPublishedDate(bmd.getFirstPublished());
-             if (pubstr != null)
-             {
-                 temp = new Element(ELEMENT_PUB);
-                 temp.addContent(pubstr);
-                 bmdele.addContent(temp);
-             }
- 
-             Openness open = bmd.getOpenness();
-             if (open != null)
-             {
-                 temp = new Element(ELEMENT_OPENNESS);
-                 temp.addContent(open.toString());
-                 bmdele.addContent(temp);
-             }
- 
-             if (bmd.getLicence() != null)
-             {
-                 temp = new Element(ELEMENT_LICENCE);
-                 temp.addContent(bmd.getLicence().toExternalForm());
-                 bmdele.addContent(temp);
-             }
- 
              root.addContent(bmdele);
          }
--- 123,126 ----

Index: RemoteBookDriver.java
===================================================================
RCS file: /cvs/jsword/jsword/java/limbo/org/crosswire/jsword/book/remote/RemoteBookDriver.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** RemoteBookDriver.java	25 Jun 2004 11:15:16 -0000	1.1
--- RemoteBookDriver.java	5 Oct 2004 22:03:09 -0000	1.2
***************
*** 82,86 ****
                      Document doc = remoter.execute(method);
  
!                     rbmd = Converter.convertDocumentToBookMetaDatas(this, doc, remoter, remoter.getSpeed());
                  }
                  catch (Exception ex)
--- 82,86 ----
                      Document doc = remoter.execute(method);
  
!                     rbmd = Converter.convertDocumentToBookMetaDatas(this, doc, remoter);
                  }
                  catch (Exception ex)

Index: Remoter.java
===================================================================
RCS file: /cvs/jsword/jsword/java/limbo/org/crosswire/jsword/book/remote/Remoter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Remoter.java	25 Jun 2004 11:15:16 -0000	1.1
--- Remoter.java	5 Oct 2004 22:03:09 -0000	1.2
***************
*** 39,45 ****
      public String getRemoterName();
  
-     /**
-      * The speed of the Remoter
-      */
-     public int getSpeed();
  }
--- 39,41 ----

Index: FixtureRemoter.java
===================================================================
RCS file: /cvs/jsword/jsword/java/limbo/org/crosswire/jsword/book/remote/FixtureRemoter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** FixtureRemoter.java	8 Aug 2004 12:26:34 -0000	1.1
--- FixtureRemoter.java	5 Oct 2004 22:03:09 -0000	1.2
***************
*** 1,5 ****
  package org.crosswire.jsword.book.remote;
  
- import org.crosswire.jsword.book.BookMetaData;
  import org.jdom.Document;
  
--- 1,4 ----
***************
*** 46,55 ****
      }
  
-     /**
-      * How fast are we?
-      */
-     public int getSpeed()
-     {
-         return BookMetaData.SPEED_INACCURATE;
-     }
  }
--- 45,47 ----

Index: RemoteBook.java
===================================================================
RCS file: /cvs/jsword/jsword/java/limbo/org/crosswire/jsword/book/remote/RemoteBook.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** RemoteBook.java	21 Sep 2004 17:46:23 -0000	1.6
--- RemoteBook.java	5 Oct 2004 22:03:09 -0000	1.7
***************
*** 1,7 ****
  package org.crosswire.jsword.book.remote;
  
- import java.net.MalformedURLException;
- import java.text.ParseException;
- 
  import org.crosswire.common.util.Logger;
  import org.crosswire.common.xml.JDOMSAXEventProvider;
--- 1,4 ----
***************
*** 55,61 ****
       * Basic constructor for a SerBook
       */
!     public RemoteBook(Remoter remoter, RemoteBookDriver driver, String name, BookType type, String edition, String pubstr, String openstr, String licencestr, int speed) throws MalformedURLException, ParseException
      {
!         BookMetaData bmd = new DefaultBookMetaData(driver, this, name, type, speed, edition, openstr, licencestr, pubstr);
          setBookMetaData(bmd);
  
--- 52,58 ----
       * Basic constructor for a SerBook
       */
!     public RemoteBook(Remoter remoter, RemoteBookDriver driver, String name, BookType type)
      {
!         BookMetaData bmd = new DefaultBookMetaData(driver, this, name, type);
          setBookMetaData(bmd);
  

Index: ConverterTest.java
===================================================================
RCS file: /cvs/jsword/jsword/java/limbo/org/crosswire/jsword/book/remote/ConverterTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ConverterTest.java	8 Aug 2004 12:26:34 -0000	1.1
--- ConverterTest.java	5 Oct 2004 22:03:09 -0000	1.2
***************
*** 57,65 ****
          t1 = new BookMetaData[]
          {
!             new DefaultBookMetaData(rbd, null, "v1", BookType.BIBLE, BookMetaData.SPEED_MEDIUM), //$NON-NLS-1$
!             new DefaultBookMetaData(rbd, null, "v2", BookType.BIBLE, BookMetaData.SPEED_MEDIUM), //$NON-NLS-1$
!             new DefaultBookMetaData(rbd, null, "v3", BookType.BIBLE, BookMetaData.SPEED_MEDIUM), //$NON-NLS-1$
!             new DefaultBookMetaData(rbd, null, "test version", BookType.BIBLE, BookMetaData.SPEED_MEDIUM, "tv", "PD", "http://nowhere.com/test", "1900-10-20"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
!             new DefaultBookMetaData(rbd, null, "test version", BookType.BIBLE, BookMetaData.SPEED_MEDIUM, null, (String) null, null, null), //$NON-NLS-1$
          };
          uid1 = new String[]
--- 57,65 ----
          t1 = new BookMetaData[]
          {
!             new DefaultBookMetaData(rbd, null, "v1", BookType.BIBLE), //$NON-NLS-1$
!             new DefaultBookMetaData(rbd, null, "v2", BookType.BIBLE), //$NON-NLS-1$
!             new DefaultBookMetaData(rbd, null, "v3", BookType.BIBLE), //$NON-NLS-1$
!             new DefaultBookMetaData(rbd, null, "test version", BookType.BIBLE), //$NON-NLS-1$
!             new DefaultBookMetaData(rbd, null, "test version", BookType.BIBLE), //$NON-NLS-1$
          };
          uid1 = new String[]
***************
*** 73,77 ****
  
          doc = Converter.convertBookMetaDatasToDocument(t1, uid1);
!         t2 = Converter.convertDocumentToBookMetaDatas(rbd, doc, new FixtureRemoter(), BookMetaData.SPEED_INACCURATE);
          assertEquals(t1.length, 5);
          assertEquals(t2.length, 5);
--- 73,77 ----
  
          doc = Converter.convertBookMetaDatasToDocument(t1, uid1);
!         t2 = Converter.convertDocumentToBookMetaDatas(rbd, doc, new FixtureRemoter());
          assertEquals(t1.length, 5);
          assertEquals(t2.length, 5);
***************
*** 82,91 ****
              //assertEquals(uid1[i], driver.getID(t2[i]));
              assertEquals(t1[i].getName(), t2[i].getName());
-             assertEquals(t1[i].getEdition(), t2[i].getEdition());
              // We scrapped this test because exact times were getting confused
-             //assertEquals(t1[i].getFirstPublished(), t2[i].getFirstPublished());
              assertEquals(t1[i].getInitials(), t2[i].getInitials());
-             assertEquals(t1[i].getLicence(), t2[i].getLicence());
-             assertEquals(t1[i].getOpenness(), t2[i].getOpenness());
              // this did check for not equals - surely this was wrong???
              assertTrue(t1[i].equals(t2[i]));
--- 82,87 ----
***************
*** 94,98 ****
          t1 = new BookMetaData[] { };
          doc = Converter.convertBookMetaDatasToDocument(t1, new String[] { });
!         t2 = Converter.convertDocumentToBookMetaDatas(null, doc, null, BookMetaData.SPEED_INACCURATE);
          assertEquals(t1.length, 0);
          assertEquals(t2.length, 0);
--- 90,94 ----
          t1 = new BookMetaData[] { };
          doc = Converter.convertBookMetaDatasToDocument(t1, new String[] { });
!         t2 = Converter.convertDocumentToBookMetaDatas(null, doc, null);
          assertEquals(t1.length, 0);
          assertEquals(t2.length, 0);

Index: LocalRemoterTest.java
===================================================================
RCS file: /cvs/jsword/jsword/java/limbo/org/crosswire/jsword/book/remote/LocalRemoterTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** LocalRemoterTest.java	8 Aug 2004 12:26:34 -0000	1.1
--- LocalRemoterTest.java	5 Oct 2004 22:03:09 -0000	1.2
***************
*** 50,54 ****
      public void testGetBibles() throws Exception
      {
!         BookFilter filter = BookFilters.both(BookFilters.getFaster(BookMetaData.SPEED_SLOWEST), BookFilters.getBibles());
          List lbmds = Books.installed().getBookMetaDatas(filter);
          BookMetaData[] names1 = (BookMetaData[]) lbmds.toArray(new BookMetaData[lbmds.size()]);
--- 50,54 ----
      public void testGetBibles() throws Exception
      {
!         BookFilter filter = BookFilters.getBibles();
          List lbmds = Books.installed().getBookMetaDatas(filter);
          BookMetaData[] names1 = (BookMetaData[]) lbmds.toArray(new BookMetaData[lbmds.size()]);
***************
*** 57,61 ****
          RemoteMethod method = new RemoteMethod(MethodName.GETBIBLES);
          Document doc = remote.execute(method);
!         BookMetaData[] names2 = Converter.convertDocumentToBookMetaDatas(rbd, doc, new FixtureRemoter(), BookMetaData.SPEED_INACCURATE);
  
          assertEquals(names1.length, names2.length);
--- 57,61 ----
          RemoteMethod method = new RemoteMethod(MethodName.GETBIBLES);
          Document doc = remote.execute(method);
!         BookMetaData[] names2 = Converter.convertDocumentToBookMetaDatas(rbd, doc, new FixtureRemoter());
  
          assertEquals(names1.length, names2.length);



More information about the jsword-svn mailing list