[jsword-svn] r1697 - in trunk: bibledesktop/src/main/resources/xsl/cswing common common/src/main/java/org/crosswire/common/diff 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
Sat Oct 6 20:51:41 MST 2007
Author: dmsmith
Date: 2007-10-06 20:51:41 -0700 (Sat, 06 Oct 2007)
New Revision: 1697
Modified:
trunk/bibledesktop/src/main/resources/xsl/cswing/simple.xsl
trunk/common/JSwordDictionary.txt
trunk/common/src/main/java/org/crosswire/common/diff/PatchEntry.java
trunk/jsword/src/main/java/org/crosswire/jsword/book/OSISUtil.java
trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ConfigEntry.java
Log:
Improved the RTF handling of the About field of the conf. Added support for all existing RTF codes found in a scan of the public confs.
Modified: trunk/bibledesktop/src/main/resources/xsl/cswing/simple.xsl
===================================================================
--- trunk/bibledesktop/src/main/resources/xsl/cswing/simple.xsl 2007-08-29 00:39:17 UTC (rev 1696)
+++ trunk/bibledesktop/src/main/resources/xsl/cswing/simple.xsl 2007-10-07 03:51:41 UTC (rev 1697)
@@ -272,6 +272,12 @@
== Div provides the major containers for a work.
== Divs are milestoneable.
-->
+ <xsl:template match="div[@type='x-center']">
+ <div align="center">
+ <xsl:apply-templates/>
+ </div>
+ </xsl:template>
+
<xsl:template match="div">
<xsl:apply-templates/>
</xsl:template>
Modified: trunk/common/JSwordDictionary.txt
===================================================================
--- trunk/common/JSwordDictionary.txt 2007-08-29 00:39:17 UTC (rev 1696)
+++ trunk/common/JSwordDictionary.txt 2007-10-07 03:51:41 UTC (rev 1697)
@@ -28,3 +28,4 @@
filesystem
download
config
+internationalize
Modified: trunk/common/src/main/java/org/crosswire/common/diff/PatchEntry.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/diff/PatchEntry.java 2007-08-29 00:39:17 UTC (rev 1696)
+++ trunk/common/src/main/java/org/crosswire/common/diff/PatchEntry.java 2007-10-07 03:51:41 UTC (rev 1697)
@@ -21,8 +21,6 @@
*/
package org.crosswire.common.diff;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/OSISUtil.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/OSISUtil.java 2007-08-29 00:39:17 UTC (rev 1696)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/OSISUtil.java 2007-10-07 03:51:41 UTC (rev 1697)
@@ -28,6 +28,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -978,7 +979,168 @@
}
return div.cloneContent();
}
+
+ public static List rtfToOsis(String rtf)
+ {
+ Element div = factory().createDiv();
+ Stack stack = new Stack();
+ stack.push(div);
+ int strlen = rtf.length();
+
+ StringBuffer text = new StringBuffer(strlen);
+
+ int i = 0;
+ for (i = 0; i < strlen; i++)
+ {
+ char curChar = rtf.charAt(i);
+ if (curChar != '\\')
+ {
+ text.append(curChar);
+ 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$
+ {
+ Element currentElement = (Element) stack.pop();
+ currentElement.addContent(text.toString());
+ text.delete(0, text.length());
+ stack.clear();
+ stack.push(div);
+ i += (i + 5 < strlen && rtf.charAt(i + 5) == ' ') ? 5 : 4;
+ continue;
+ }
+
+ // Simulate a paragraph break.
+ if (remaining.startsWith("\\par")) //$NON-NLS-1$
+ {
+
+ Element currentElement = (Element) stack.peek();
+ currentElement.addContent(text.toString());
+ text.delete(0, text.length());
+ currentElement.addContent(OSISUtil.factory.createLB());
+ i += (i + 4 < strlen && rtf.charAt(i + 4) == ' ') ? 4 : 3;
+ continue;
+ }
+
+ // OSIS does not have the notion of centered text.
+ // So we define our own
+ if (remaining.startsWith("\\qc")) //$NON-NLS-1$
+ {
+ Element centerDiv = OSISUtil.factory.createDiv();
+ centerDiv.setAttribute(OSIS_ATTR_TYPE, "x-center"); //$NON-NLS-1$
+ Element currentElement = (Element) stack.peek();
+ currentElement.addContent(text.toString());
+ text.delete(0, text.length());
+ currentElement.addContent(centerDiv);
+ stack.push(centerDiv);
+ // skip following space, if any
+ i += (i + 3 < strlen && rtf.charAt(i + 3) == ' ') ? 3 : 2;
+ continue;
+ }
+
+ // convert Unicode representations to Unicode
+ if (remaining.startsWith("\\u")) //$NON-NLS-1$
+ {
+ StringBuffer buf = new StringBuffer();
+ i += 2;
+ while (i < strlen)
+ {
+ char curDigit = rtf.charAt(i);
+ if (curDigit != '-' && !Character.isDigit(curDigit))
+ {
+ break;
+ }
+ buf.append(curDigit);
+ i++;
+ }
+ // At this point:
+ // buf contains the numeric representation of the number, 16-bit signed
+ // charAt(i) is the substitution character if Unicode is not supported
+ int value = Integer.parseInt(buf.toString());
+ if (value < 0)
+ {
+ value += 65536;
+ }
+ text.append((char) value);
+ // don't advance since i is on the substitute character.
+ continue;
+ }
+
+ // close italic and bold
+ if (remaining.startsWith("\\i0") || remaining.startsWith("\\b0")) //$NON-NLS-1$ //$NON-NLS-2$
+ {
+ Element currentElement = (Element) stack.pop();
+ currentElement.addContent(text.toString());
+ text.delete(0, text.length());
+ i += (i + 3 < strlen && rtf.charAt(i + 3) == ' ') ? 3 : 2;
+ continue;
+ }
+
+ // Skip escaped whitespace
+ if (remaining.startsWith(" ") || remaining.startsWith("\n")) //$NON-NLS-1$ //$NON-NLS-2$
+ {
+ i += 1;
+ continue;
+ }
+
+ // start italic
+ if (remaining.startsWith("\\i")) //$NON-NLS-1$
+ {
+ Element hiElement = OSISUtil.factory.createHI();
+ hiElement.setAttribute(OSIS_ATTR_TYPE, HI_ITALIC);
+ Element currentElement = (Element) stack.peek();
+ currentElement.addContent(text.toString());
+ text.delete(0, text.length());
+ currentElement.addContent(hiElement);
+ stack.push(hiElement);
+ i += (i + 2 < strlen && rtf.charAt(i + 2) == ' ') ? 2 : 1;
+ continue;
+ }
+
+ // start bold
+ if (remaining.startsWith("\\b")) //$NON-NLS-1$
+ {
+ Element hiElement = OSISUtil.factory.createHI();
+ hiElement.setAttribute(OSIS_ATTR_TYPE, HI_BOLD);
+ Element currentElement = (Element) stack.peek();
+ currentElement.addContent(text.toString());
+ text.delete(0, text.length());
+ currentElement.addContent(hiElement);
+ stack.push(hiElement);
+ i += (i + 2 < strlen && rtf.charAt(i + 2) == ' ') ? 2 : 1;
+ continue;
+ }
+
+ }
+// div.addContent(text.toString());
+// // If the fragment is already in a document, then use that.
+// Document doc = div.getDocument();
+// if (doc == null)
+// {
+// doc = new Document(div);
+// }
+// SAXEventProvider ep = new JDOMSAXEventProvider(doc);
+// ContentHandler osis = new PrettySerializingContentHandler(FormatType.CLASSIC_INDENT);
+// try
+// {
+// ep.provideSAXEvents(osis);
+// }
+// catch (SAXException e)
+// {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// }
+// System.err.println(osis.toString());
+ return div.cloneContent();
+ }
+
/**
* Find all the instances of elements of type <code>find</code> under
* the element <code>div</code>. For internal use only.
Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ConfigEntry.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ConfigEntry.java 2007-08-29 00:39:17 UTC (rev 1696)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ConfigEntry.java 2007-10-07 03:51:41 UTC (rev 1697)
@@ -269,7 +269,7 @@
Element nameEle = factory.createCell();
Element hiEle = factory.createHI();
- hiEle.setAttribute("rend", "bold"); //$NON-NLS-1$ //$NON-NLS-2$
+ hiEle.setAttribute(OSISUtil.OSIS_ATTR_TYPE, OSISUtil.HI_BOLD);
nameEle.addContent(hiEle);
Element valueElement = factory.createCell();
rowEle.addContent(nameEle);
@@ -281,19 +281,18 @@
if (value != null)
{
String text = value.toString();
+ text = XMLUtil.escape(text);
if (allowsRTF())
{
- text = handleRTF(text);
+ valueElement.addContent(OSISUtil.rtfToOsis(text));
}
-
- String expandedValue = XMLUtil.escape(text);
- if (allowsContinuation() || allowsRTF())
+ else if (allowsContinuation())
{
- valueElement.addContent(processLines(factory, expandedValue));
+ valueElement.addContent(processLines(factory, text));
}
else
{
- valueElement.addContent(expandedValue);
+ valueElement.addContent(text);
}
}
@@ -306,13 +305,17 @@
while (iter.hasNext())
{
String text = (String) iter.next();
+ text = XMLUtil.escape(text);
+ Element itemEle = factory.createL();
+ listEle.addContent(itemEle);
if (allowsRTF())
{
- text = handleRTF(text);
+ itemEle.addContent(OSISUtil.rtfToOsis(text));
}
- Element itemEle = factory.createL();
- listEle.addContent(itemEle);
- itemEle.addContent(XMLUtil.escape(text));
+ else
+ {
+ itemEle.addContent(text);
+ }
}
}
return rowEle;
More information about the jsword-svn
mailing list