[jsword-svn] r1702 - in trunk: common jsword/src/main/java/org/crosswire/jsword/book jsword/src/main/java/org/crosswire/jsword/book/sword

dmsmith at www.crosswire.org dmsmith at www.crosswire.org
Wed Oct 24 15:30:37 MST 2007


Author: dmsmith
Date: 2007-10-24 15:30:36 -0700 (Wed, 24 Oct 2007)
New Revision: 1702

Modified:
   trunk/common/JSwordDictionary.txt
   trunk/jsword/src/main/java/org/crosswire/jsword/book/OSISUtil.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ConfigEntryTable.java
Log:
fixed a conf problem.
improved rtf handling
more dictionary inclusions

Modified: trunk/common/JSwordDictionary.txt
===================================================================
--- trunk/common/JSwordDictionary.txt	2007-10-24 20:15:07 UTC (rev 1701)
+++ trunk/common/JSwordDictionary.txt	2007-10-24 22:30:36 UTC (rev 1702)
@@ -29,3 +29,7 @@
 download
 config
 internationalize
+osis
+html
+stylesheet
+stylesheets

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/OSISUtil.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/OSISUtil.java	2007-10-24 20:15:07 UTC (rev 1701)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/OSISUtil.java	2007-10-24 22:30:36 UTC (rev 1702)
@@ -1000,13 +1000,11 @@
                 continue;
             }
 
-            String remaining = rtf.substring(i);
-
             // The following are ordered from most to least common
             // and when one is a prefix of another, it follows.
 
             // Used to end all open attributes. Only \qc in our implementation.
-            if (remaining.startsWith("\\pard")) //$NON-NLS-1$
+            if (rtf.startsWith("\\pard", i)) //$NON-NLS-1$
             {
                 Element currentElement = (Element) stack.pop();
                 currentElement.addContent(text.toString());
@@ -1018,7 +1016,7 @@
             }
 
             // Simulate a paragraph break.
-            if (remaining.startsWith("\\par")) //$NON-NLS-1$
+            if (rtf.startsWith("\\par", i)) //$NON-NLS-1$
             {
 
                 Element currentElement = (Element) stack.peek();
@@ -1031,7 +1029,7 @@
 
             // OSIS does not have the notion of centered text.
             // So we define our own
-            if (remaining.startsWith("\\qc")) //$NON-NLS-1$
+            if (rtf.startsWith("\\qc", i)) //$NON-NLS-1$
             {
                 Element centerDiv = OSISUtil.factory.createDiv();
                 centerDiv.setAttribute(OSIS_ATTR_TYPE, "x-center"); //$NON-NLS-1$
@@ -1046,7 +1044,7 @@
             }
 
             // convert Unicode representations to Unicode
-            if (remaining.startsWith("\\u")) //$NON-NLS-1$
+            if (rtf.startsWith("\\u", i)) //$NON-NLS-1$
             {
                 StringBuffer buf = new StringBuffer();
                 i += 2;
@@ -1074,7 +1072,7 @@
             }
 
             // close italic and bold
-            if (remaining.startsWith("\\i0") || remaining.startsWith("\\b0")) //$NON-NLS-1$ //$NON-NLS-2$
+            if (rtf.startsWith("\\i0", i) || rtf.startsWith("\\b0", i)) //$NON-NLS-1$ //$NON-NLS-2$
             {
                 Element currentElement = (Element) stack.pop();
                 currentElement.addContent(text.toString());
@@ -1084,14 +1082,14 @@
             }
 
             // Skip escaped whitespace
-            if (remaining.startsWith(" ") || remaining.startsWith("\n")) //$NON-NLS-1$ //$NON-NLS-2$
+            if (rtf.startsWith(" ", i) || rtf.startsWith("\n", i)) //$NON-NLS-1$ //$NON-NLS-2$
             {
                 i += 1;
                 continue;
             }
 
             // start italic
-            if (remaining.startsWith("\\i")) //$NON-NLS-1$
+            if (rtf.startsWith("\\i", i)) //$NON-NLS-1$
             {
                 Element hiElement = OSISUtil.factory.createHI();
                 hiElement.setAttribute(OSIS_ATTR_TYPE, HI_ITALIC);
@@ -1105,7 +1103,7 @@
             }
 
             // start bold
-            if (remaining.startsWith("\\b")) //$NON-NLS-1$
+            if (rtf.startsWith("\\b", i)) //$NON-NLS-1$
             {
                 Element hiElement = OSISUtil.factory.createHI();
                 hiElement.setAttribute(OSIS_ATTR_TYPE, HI_BOLD);

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ConfigEntryTable.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ConfigEntryTable.java	2007-10-24 20:15:07 UTC (rev 1701)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ConfigEntryTable.java	2007-10-24 22:30:36 UTC (rev 1702)
@@ -35,6 +35,8 @@
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.crosswire.common.util.Language;
 import org.crosswire.common.util.Languages;
@@ -287,7 +289,6 @@
 
     /**
      * Sort the keys for a more meaningful presentation order.
-     * TODO(DM): Replace this with a conversion of the properties to XML and then by XSLT to HTML.
      */
     public Element toOSIS()
     {
@@ -368,15 +369,15 @@
                 continue;
             }
 
-            int eqpos = line.indexOf('=');
-            if (eqpos == -1)
+            Matcher matcher = KEY_VALUE_PATTERN.matcher(line);
+            if (!matcher.matches())
             {
                 log.warn("Expected to see '=' in " + internal + ": " + line); //$NON-NLS-1$ //$NON-NLS-2$
                 continue;
             }
 
-            String key = line.substring(0, eqpos).trim();
-            String value = line.substring(eqpos + 1).trim();
+            String key = matcher.group(1).trim();
+            String value = matcher.group(2).trim();
             // Only CIPHER_KEYS that are empty are not ignored
             if (value.length() == 0 && !ConfigEntryType.CIPHER_KEY.getName().equals(key))
             {
@@ -557,7 +558,7 @@
      */
     private boolean isKeyLine(String line)
     {
-        return line.indexOf('=') != -1;
+        return KEY_VALUE_PATTERN.matcher(line).matches();
     }
 
     /**
@@ -579,8 +580,9 @@
         }
         if (datapath.startsWith("./")) //$NON-NLS-1$
         {
-            add(ConfigEntryType.DATA_PATH, datapath.substring(2));
+            datapath = datapath.substring(2);
         }
+        add(ConfigEntryType.DATA_PATH, datapath);
     }
 
     private boolean isLeftToRight(Language language)
@@ -962,4 +964,14 @@
      * so that it can be updated.
      */
     private File configFile;
+
+    /**
+     * Pattern that matches a key=value.
+     * The key can contain ascii letters, numbers, underscore and period.
+     * The key must begin at the beginning of the line.
+     * The = sign following the key may be surrounded by whitespace.
+     * The value may contain anything, including an = sign.
+     */
+    private static final Pattern KEY_VALUE_PATTERN = Pattern.compile("^([A-Za-z0-9_.]+)\\s*=\\s*(.*)$"); //$NON-NLS-1$
+
 }




More information about the jsword-svn mailing list