[Tynstep-svn] r258 - in trunk/step: step-core/src/main/java/com/tyndalehouse/step/core/utils step-core/src/main/java/com/tyndalehouse/step/core/xsl/impl step-core/src/main/resources/com/tyndalehouse/step/core/service/impl step-core/src/test/java/com/tyndalehouse/step/core/service/impl step-web/src/main/resources step-web/src/main/webapp/js
ChrisBurrell at crosswire.org
ChrisBurrell at crosswire.org
Wed Apr 25 05:56:21 MST 2012
Author: ChrisBurrell
Date: 2012-04-25 05:56:21 -0700 (Wed, 25 Apr 2012)
New Revision: 258
Modified:
trunk/step/step-core/src/main/java/com/tyndalehouse/step/core/utils/StringConversionUtils.java
trunk/step/step-core/src/main/java/com/tyndalehouse/step/core/xsl/impl/InterlinearProviderImpl.java
trunk/step/step-core/src/main/resources/com/tyndalehouse/step/core/service/impl/interlinear.xsl
trunk/step/step-core/src/test/java/com/tyndalehouse/step/core/service/impl/JSwordServiceImplTest.java
trunk/step/step-web/src/main/resources/log4j.properties
trunk/step/step-web/src/main/webapp/js/init.js
trunk/step/step-web/src/main/webapp/js/interlinear_popup.js
Log:
commiting TYNSTEP-142 and TYNSTEP-143
Modified: trunk/step/step-core/src/main/java/com/tyndalehouse/step/core/utils/StringConversionUtils.java
===================================================================
--- trunk/step/step-core/src/main/java/com/tyndalehouse/step/core/utils/StringConversionUtils.java 2012-04-25 11:00:50 UTC (rev 257)
+++ trunk/step/step-core/src/main/java/com/tyndalehouse/step/core/utils/StringConversionUtils.java 2012-04-25 12:56:21 UTC (rev 258)
@@ -1,5 +1,8 @@
package com.tyndalehouse.step.core.utils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* A collection of utility methods enabling us to convert Strings, references one way or another.
*
@@ -9,6 +12,7 @@
private static final char KEY_SEPARATOR = ':';
private static final String STRONG_PREFIX = "strong:";
private static final int LANGUAGE_INDICATOR = STRONG_PREFIX.length();
+ private static final Logger LOGGER = LoggerFactory.getLogger(StringConversionUtils.class);
/**
* hiding implementation
@@ -18,11 +22,11 @@
}
/**
- * Not all bibles encode strong numbers as strong:[HG]\d+ unfortunately, so instead we cope for strong: and
- * strong:H.
+ * Not all bibles encode strong numbers as strong:[HG]\d+ unfortunately, so instead we cope for strong:
+ * and strong:H.
*
- * In essence we chop off any of the following prefixes: strong:G, strong:H, strong:, H, G. We don't use a regularl
- * expression, since this will be much quicker
+ * In essence we chop off any of the following prefixes: strong:G, strong:H, strong:, H, G. We don't use a
+ * regularl expression, since this will be much quicker
*
* @param strong strong key
* @return the key containing just the digits
@@ -63,6 +67,8 @@
* @return the shortened key
*/
public static String getAnyKey(final String potentialKey, final boolean trimInitial) {
+ LOGGER.debug("Looking for key [{}] with trimInitial [{}]", potentialKey, trimInitial);
+
// find first colon and start afterwards, -1 yields 0, which is the beginning of the string
// so we can work with that.
int start = potentialKey.lastIndexOf(KEY_SEPARATOR) + 1;
@@ -76,10 +82,11 @@
}
// finally, we may have 0s:
- while (potentialKey.charAt(start) == '0') {
+ while (start < potentialKey.length() && potentialKey.charAt(start) == '0') {
start++;
}
}
+
return potentialKey.substring(start);
}
}
Modified: trunk/step/step-core/src/main/java/com/tyndalehouse/step/core/xsl/impl/InterlinearProviderImpl.java
===================================================================
--- trunk/step/step-core/src/main/java/com/tyndalehouse/step/core/xsl/impl/InterlinearProviderImpl.java 2012-04-25 11:00:50 UTC (rev 257)
+++ trunk/step/step-core/src/main/java/com/tyndalehouse/step/core/xsl/impl/InterlinearProviderImpl.java 2012-04-25 12:56:21 UTC (rev 258)
@@ -118,6 +118,9 @@
// There are at most strongs.length words, and we might have morphological data to help
for (final String s : strongs) {
boolean foundMatchForStrong = false;
+
+ // find corresponding strong:
+ LOGGER.debug("Finding strong key [{}]", s);
final String strongKey = getAnyKey(s);
// each could be using the morphs we have, so try them all - this gets skipped if we have no
Modified: trunk/step/step-core/src/main/resources/com/tyndalehouse/step/core/service/impl/interlinear.xsl
===================================================================
--- trunk/step/step-core/src/main/resources/com/tyndalehouse/step/core/service/impl/interlinear.xsl 2012-04-25 11:00:50 UTC (rev 257)
+++ trunk/step/step-core/src/main/resources/com/tyndalehouse/step/core/service/impl/interlinear.xsl 2012-04-25 12:56:21 UTC (rev 258)
@@ -379,6 +379,7 @@
<xsl:if test="normalize-space($interlinearVersion) != ''">
<xsl:call-template name="outputVersionNames">
<xsl:with-param name="versions" select="$interlinearVersion" />
+ <xsl:with-param name="printVersions" select="'print'" />
</xsl:call-template>
</xsl:if>
</span>
@@ -402,6 +403,7 @@
<xsl:if test="normalize-space($interlinearVersion) != ''">
<xsl:call-template name="outputVersionNames">
<xsl:with-param name="versions" select="$interlinearVersion" />
+ <xsl:with-param name="printVersions" select="'print'" />
</xsl:call-template>
</xsl:if>
</span>
@@ -541,16 +543,13 @@
</xsl:if>
<!-- start the block only if we have english to show? -->
-
- <xsl:variable name="remainingText" select="concat($innerWordText, $nextText)" />
+ <xsl:variable name="remainingText" select="$innerWordText" />
<xsl:if test="$remainingText != ''">
-
<span class="{$classes}" onclick="javascript:showAllStrongMorphs("{@lemma} {@morph}")">
-
<xsl:if test="normalize-space($remainingText) != ''">
<!-- 1st - Output first line or a blank if no text available. -->
<span class="text">
- <xsl:call-template name="outputNonBlank">
+ <xsl:call-template name="outputNonBlank">
<xsl:with-param name="string" select="$remainingText" />
</xsl:call-template>
</span>
@@ -1386,32 +1385,48 @@
<xsl:template name="outputVersionNames">
<xsl:param name="versions" />
+ <xsl:param name="printVersions" />
<xsl:variable name="nextVersion" select="normalize-space(substring-before($versions, ','))" />
<!-- if next version is not empty, then there was a comma, so we output this version and call template again -->
<xsl:choose>
<xsl:when test="normalize-space($nextVersion) != ''">
- <span class="interlinear"><span class="smallHeaders">
- <xsl:call-template name="outputNonBlank">
- <xsl:with-param name="string">
- <xsl:value-of select="$nextVersion" />
- </xsl:with-param>
- </xsl:call-template></span>
+ <span class="interlinear">
+ <xsl:choose>
+ <xsl:when test="$printVersions != 'no-print'">
+ <span class="smallHeaders">
+ <xsl:call-template name="outputNonBlank">
+ <xsl:with-param name="string">
+ <xsl:value-of select="$nextVersion" />
+ </xsl:with-param>
+ </xsl:call-template>
+ </span>
+ </xsl:when>
+ <xsl:otherwise> </xsl:otherwise>
+ </xsl:choose>
</span>
<xsl:call-template name="outputVersionNames">
<xsl:with-param name="versions" select="substring-after($versions, ',')" />
+ <xsl:with-param name="printVersions" select="$printVersions" />
</xsl:call-template>
</xsl:when>
<!-- otherwise, then we can use the remainder as the version, as long as version not empty (for e.g. a trailing comma) -->
<xsl:otherwise>
<xsl:if test="normalize-space($versions) != ''" >
- <span class="interlinear"><span class="smallHeaders">
- <xsl:call-template name="outputNonBlank">
- <xsl:with-param name="string">
- <xsl:value-of select="$versions" />
- </xsl:with-param>
- </xsl:call-template></span>
+ <span class="interlinear">
+ <xsl:choose>
+ <xsl:when test="$printVersions != 'no-print'">
+ <span class="smallHeaders">
+ <xsl:call-template name="outputNonBlank">
+ <xsl:with-param name="string">
+ <xsl:value-of select="$versions" />
+ </xsl:with-param>
+ </xsl:call-template>
+ </span>
+ </xsl:when>
+ <xsl:otherwise> </xsl:otherwise>
+ </xsl:choose>
</span>
</xsl:if>
</xsl:otherwise>
@@ -1589,15 +1604,41 @@
<!-- If the parent of the text is a verse then, we need to wrap in span. This applies
to any punctuation really, since all other words should be contained in a W -->
<xsl:template match="text()" mode="jesus">
- <xsl:call-template name="matchSimpleText"></xsl:call-template>
+ <xsl:call-template name="matchSimpleText"></xsl:call-template>
</xsl:template>
-
+ <!-- Matching simple text when not matched elsewhere? -->
<xsl:template match="text()" name="matchSimpleText">
<xsl:choose>
<xsl:when test="jsword:org.apache.commons.lang.StringUtils.containsOnly(normalize-space(.), $punctuation)" />
- <xsl:when test="name(..) = 'verse' and normalize-space(.) != ''"><span class="w"><span class="text"><xsl:value-of select="."/></span></span></xsl:when>
+ <xsl:when test="name(..) = 'verse' and normalize-space(.) != ''">
+ <span class="w">
+ <span class="text"><xsl:value-of select="."/></span>
+ <!-- now we need to put the set of spans for strongs/morphs/interlinear versions -->
+
+ <!-- output a filling gap for strongs -->
+ <xsl:if test="$StrongsNumbers = 'true'">
+ <span class="text"> </span>
+ </xsl:if>
+
+ <!-- output a filling gap for morphs -->
+ <xsl:if test="$Morph = 'true'">
+ <span class="text"> </span>
+ </xsl:if>
+
+ <!-- fill up with spaces where we have extra versions shown -->
+ <xsl:if test="normalize-space($interlinearVersion) != ''">
+ <xsl:call-template name="outputVersionNames">
+ <xsl:with-param name="versions" select="$interlinearVersion" />
+ <xsl:with-param name="printVersions" select="'no-print'" />
+ </xsl:call-template>
+ </xsl:if>
+
+
+
+ </span>
+ </xsl:when>
<xsl:when test="normalize-space(.) != ''"><xsl:value-of select="."/></xsl:when>
</xsl:choose>
</xsl:template>
Modified: trunk/step/step-core/src/test/java/com/tyndalehouse/step/core/service/impl/JSwordServiceImplTest.java
===================================================================
--- trunk/step/step-core/src/test/java/com/tyndalehouse/step/core/service/impl/JSwordServiceImplTest.java 2012-04-25 11:00:50 UTC (rev 257)
+++ trunk/step/step-core/src/test/java/com/tyndalehouse/step/core/service/impl/JSwordServiceImplTest.java 2012-04-25 12:56:21 UTC (rev 258)
@@ -71,38 +71,6 @@
}
/**
- * tests what happens when we select interlinear
- *
- * @throws NoSuchKeyException uncaught exceptions
- * @throws BookException uncaught exception
- * @throws IOException uncaught exception
- * @throws JDOMException uncaught exception
- *
- */
- @Test
- public void testInterlinearRomans1v4() throws NoSuchKeyException, BookException, JDOMException,
- IOException {
- final Book currentBook = Books.installed().getBook("KJV");
- final BookData bookData = new BookData(currentBook, currentBook.getKey("Romans 1:4"));
- final Element osisFragment = bookData.getOsisFragment();
-
- final XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
- LOGGER.debug(xmlOutputter.outputString(osisFragment));
-
- // do the test
- final JSwordServiceImpl jsi = new JSwordServiceImpl(null);
- final List<LookupOption> options = new ArrayList<LookupOption>();
- options.add(INTERLINEAR);
-
- final String osisText = jsi.getOsisText("KJV", "Romans 1:4", options, "Byz");
- final SAXBuilder sb = new SAXBuilder();
- final Document d = sb.build(new StringReader(osisText));
-
- LOGGER.debug("\n {}", xmlOutputter.outputString(d));
- Assert.assertTrue(osisText.contains("span"));
- }
-
- /**
* tests that the XSLT transformation is handled correctly
*
* @throws BookException uncaught exception
Modified: trunk/step/step-web/src/main/resources/log4j.properties
===================================================================
--- trunk/step/step-web/src/main/resources/log4j.properties 2012-04-25 11:00:50 UTC (rev 257)
+++ trunk/step/step-web/src/main/resources/log4j.properties 2012-04-25 12:56:21 UTC (rev 258)
@@ -11,4 +11,4 @@
log4j.category.com.tyndalehouse=INFO
log4j.category.com.tyndalehouse.step.rest.controllers.FrontController=INFO
log4j.category.org.crosswire.jsword.book.sword.ConfigEntry=WARN
-log4j.category.com.tyndalehouse.step.core.xsl.impl.InterlinearProviderImpl=TRACE
+log4j.category.com.tyndalehouse.step.core.xsl.impl.InterlinearProviderImpl=WARN
Modified: trunk/step/step-web/src/main/webapp/js/init.js
===================================================================
--- trunk/step/step-web/src/main/webapp/js/init.js 2012-04-25 11:00:50 UTC (rev 257)
+++ trunk/step/step-web/src/main/webapp/js/init.js 2012-04-25 12:56:21 UTC (rev 258)
@@ -148,18 +148,8 @@
var ii = 0;
$.getJSON(BIBLE_GET_BIBLE_VERSIONS + "false", function(versionsFromServer) {
-
- $.each(versionsFromServer, function(index, item) {
- var showingText = "[" + item.initials + "] " + item.name;
- if(item.hasStrongs) {
- strongedVersions[ii++] = { label: showingText, value: item.initials};
- }
- });
-
- //add the ALL Version, by iterating through all found versions and adding them as the value
- var allVersionsKey = "";
var passages = initPassages(versionsFromServer, options);
- initInterlinearPopup(strongedVersions);
+ initInterlinearPopup(versionsFromServer);
initModules(passages);
});
}
@@ -168,11 +158,11 @@
* sets up the interlinear popup with the available versions
* @param strongedVersions the list of strong versions
*/
-function initInterlinearPopup(strongedVersions) {
+function initInterlinearPopup(versionsFromServer) {
$(".interlinearPopup").each(function(index, interlinearPopup) {
- new InterlinearPopup(strongedVersions, index, interlinearPopup);
+ new InterlinearPopup(versionsFromServer, index, interlinearPopup);
});
-}
+};
/**
* creates the passages components
Modified: trunk/step/step-web/src/main/webapp/js/interlinear_popup.js
===================================================================
--- trunk/step/step-web/src/main/webapp/js/interlinear_popup.js 2012-04-25 11:00:50 UTC (rev 257)
+++ trunk/step/step-web/src/main/webapp/js/interlinear_popup.js 2012-04-25 12:56:21 UTC (rev 258)
@@ -10,7 +10,7 @@
*
* @param an array of Bible versions that contain strong numbers
*/
-function InterlinearPopup(strongedVersions, passageId, interlinearPopup) {
+function InterlinearPopup(versionsFromServer, passageId, interlinearPopup) {
this.passageId = passageId;
this.interlinearPopup = $(interlinearPopup);
@@ -20,11 +20,38 @@
//first set up the passage id
this.interlinearPopup.attr("passage-id", this.passageId);
+ //the interelinear popup is now dependant on the set of versions shown:
+ this.interlinearPopup.hear("version-list-refresh", function(selfElement, versions) {
+ self.refreshCheckBoxes(versions);
+ });
+
+
//now do the handlers
+ this.refreshCheckBoxes(versionsFromServer);
+ this.addShowHandler();
+}
+
+/**
+ * sets up all the checkboxes
+ */
+InterlinearPopup.prototype.refreshCheckBoxes = function(versionsFromServer) {
+ var strongedVersions = [];
+ var ii = 0;
+
+ //delete current popup
+ $("table", this.interlinearPopup).remove();
+
+ //iterate through all versions for those that have strong numbers
+ $.each(versionsFromServer, function(index, item) {
+ var showingText = "[" + item.initials + "] " + item.name;
+ if(item.hasStrongs) {
+ strongedVersions[ii++] = { label: showingText, value: item.initials};
+ }
+ });
+
this.createCheckboxes(strongedVersions);
this.addHandlersToCheckboxes();
this.addAllOptionsHandler();
- this.addShowHandler();
}
/**
More information about the Tynstep-svn
mailing list