[jsword-svn]
jsword/java/jsword/org/crosswire/jsword/book/filter/gbf s
jswordcvs at crosswire.org
jswordcvs at crosswire.org
Sun May 8 18:29:08 MST 2005
Update of /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/filter/gbf
In directory www.crosswire.org:/tmp/cvs-serv6194/java/jsword/org/crosswire/jsword/book/filter/gbf
Modified Files:
GBFFilter.java Msg.java Tag.java
Added Files:
GBFTags.java AbstractTag.java GBFTagBuilders.java
Removed Files:
PoetryTagBuilder.java EndOfLineTagBuilder.java
OTQuoteTagBuilder.java UnderlineTagBuilder.java
HeaderTagBuilder.java BoldTagBuilder.java
TextFootnoteTagBuilder.java TextTagBuilder.java
ParagraphTagBuilder.java ItalicTagBuilder.java
StrongsWordTagBuilder.java JustifyTagBuilder.java
PsalmTitleTagBuilder.java StrongsMorphTagBuilder.java
FootnoteTagBuilder.java CrossRefTagBuilder.java
TitleTagBuilder.java RedLetterTagBuilder.java
IgnoredTagBuilder.java
Log Message:
Moved unused code to limbo.
Upgraded support-tools: checkstyle, pmd and findbugs to most recent.
Addressed over 100 issues reported by findbugs and checkstyle.
Resulted in major refactoring of GBFFilter.
Net result is that code size is significantly smaller.
--- BoldTagBuilder.java DELETED ---
--- ParagraphTagBuilder.java DELETED ---
--- EndOfLineTagBuilder.java DELETED ---
--- StrongsMorphTagBuilder.java DELETED ---
--- ItalicTagBuilder.java DELETED ---
--- NEW FILE: GBFTagBuilders.java ---
package org.crosswire.jsword.book.filter.gbf;
import java.util.HashMap;
import java.util.Map;
import org.crosswire.common.util.Logger;
import org.crosswire.jsword.book.filter.gbf.GBFTags.BoldStartTag;
import org.crosswire.jsword.book.filter.gbf.GBFTags.CrossRefStartTag;
import org.crosswire.jsword.book.filter.gbf.GBFTags.DefaultEndTag;
import org.crosswire.jsword.book.filter.gbf.GBFTags.EOLTag;
import org.crosswire.jsword.book.filter.gbf.GBFTags.FootnoteEndTag;
import org.crosswire.jsword.book.filter.gbf.GBFTags.FootnoteStartTag;
import org.crosswire.jsword.book.filter.gbf.GBFTags.HeaderStartTag;
import org.crosswire.jsword.book.filter.gbf.GBFTags.IgnoredTag;
import org.crosswire.jsword.book.filter.gbf.GBFTags.ItalicStartTag;
import org.crosswire.jsword.book.filter.gbf.GBFTags.JustifyRightTag;
import org.crosswire.jsword.book.filter.gbf.GBFTags.OTQuoteStartTag;
import org.crosswire.jsword.book.filter.gbf.GBFTags.ParagraphTag;
import org.crosswire.jsword.book.filter.gbf.GBFTags.PoetryStartTag;
import org.crosswire.jsword.book.filter.gbf.GBFTags.PsalmStartTag;
import org.crosswire.jsword.book.filter.gbf.GBFTags.RedLetterStartTag;
import org.crosswire.jsword.book.filter.gbf.GBFTags.StrongsMorphTag;
import org.crosswire.jsword.book.filter.gbf.GBFTags.StrongsWordTag;
import org.crosswire.jsword.book.filter.gbf.GBFTags.TextFootnoteTag;
import org.crosswire.jsword.book.filter.gbf.GBFTags.TextTag;
import org.crosswire.jsword.book.filter.gbf.GBFTags.TitleStartTag;
import org.crosswire.jsword.book.filter.gbf.GBFTags.UnderlineStartTag;
/**
* This class is a convienence to get GBF Tags.
*
* The best place to go for more information about the GBF spec that I have
* found is: <a href="http://ebible.org/bible/gbf.htm">http://ebible.org/bible/gbf.htm</a>
*
* <p><table border='1' cellPadding='3' cellSpacing='0'>
* <tr><td bgColor='white' class='TableRowColor'><font size='-7'>
*
* Distribution Licence:<br />
* JSword is free software; you can redistribute it
* and/or modify it under the terms of the GNU General Public License,
* version 2 as published by the Free Software Foundation.<br />
* 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
* General Public License for more details.<br />
* The License is available on the internet
* <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, or by writing to:
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA<br />
* The copyright to this program is held by it's authors.
* </font></td></tr></table>
* @see gnu.gpl.Licence
* @author Joe Walker [joe at eireneh dot com]
* @author DM Smith [dmsmith555 at yahoo dot com]
* @version $Id: GBFTagBuilders.java,v 1.1 2005/05/09 01:29:06 dmsmith Exp $
*/
public class GBFTagBuilders
{
/**
*
*/
private GBFTagBuilders()
{
}
/**
* @param name
* @return return a GBF Tag for the given tag name
*/
public static Tag getTag(String name)
{
Tag tag = null;
int length = name.length();
if (length > 0)
{
// Only the first two letters of the tag are indicative of the tag
// The rest, if present, is data.
TagBuilder builder = null;
if (length == 2)
{
builder = (TagBuilder) BUILDERS.get(name);
}
else
{
builder = (TagBuilder) BUILDERS.get(name.substring(0, 2));
}
Tag reply = null;
if (builder != null)
{
reply = builder.createTag(name);
}
if (reply == null)
{
// I'm not confident enough that we handle all the GBF tags
// that I will blame the module instead of the program
log.warn("Ignoring tag of <" + name + ">"); //$NON-NLS-1$ //$NON-NLS-2$
//DataPolice.report("Ignoring tag of <" + name + ">");
}
}
return tag;
}
/**
* @param text
* @return get a Text Tag object containing the text
*/
public static Tag getTextTag(String text)
{
return new TextTag(text);
}
/**
*
*/
private static final class BoldStartTagBuilder implements TagBuilder
{
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.TagBuilder#createTag(java.lang.String)
*/
public Tag createTag(String name)
{
return new BoldStartTag(name);
}
}
/**
*
*/
private static final class CrossRefStartTagBuilder implements TagBuilder
{
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.TagBuilder#createTag(java.lang.String)
*/
public Tag createTag(final String name)
{
return new CrossRefStartTag(name);
}
}
/**
*
*/
private static final class DefaultEndTagBuilder implements TagBuilder
{
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.TagBuilder#createTag(java.lang.String)
*/
public Tag createTag(String name)
{
return new DefaultEndTag(name);
}
}
/**
*
*/
private static final class EndOfLineTagBuilder implements TagBuilder
{
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.TagBuilder#createTag(java.lang.String)
*/
public Tag createTag(final String name)
{
return new EOLTag(name);
}
}
/**
*
*/
private static final class FootnoteStartTagBuilder implements TagBuilder
{
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.TagBuilder#createTag(java.lang.String)
*/
public Tag createTag(String name)
{
return new FootnoteStartTag(name);
}
}
/**
*
*/
private static final class FootnoteEndTagBuilder implements TagBuilder
{
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.TagBuilder#createTag(java.lang.String)
*/
public Tag createTag(String name)
{
return new FootnoteEndTag(name);
}
}
/**
*
*/
private static final class HeaderStartTagBuilder implements TagBuilder
{
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.TagBuilder#createTag(java.lang.String)
*/
public Tag createTag(String name)
{
return new HeaderStartTag(name);
}
}
/**
*
*/
private static final class IgnoredTagBuilder implements TagBuilder
{
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.TagBuilder#createTag(java.lang.String)
*/
public Tag createTag(final String name)
{
return new IgnoredTag(name);
}
}
/**
*
*/
private static final class ItalicStartTagBuilder implements TagBuilder
{
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.TagBuilder#createTag(java.lang.String)
*/
public Tag createTag(String name)
{
return new ItalicStartTag(name);
}
}
/**
*
*/
private static final class JustifyRightTagBuilder implements TagBuilder
{
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.TagBuilder#createTag(java.lang.String)
*/
public Tag createTag(String name)
{
return new JustifyRightTag(name);
}
}
/**
*
*/
private static final class OTQuoteStartTagBuilder implements TagBuilder
{
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.TagBuilder#createTag(java.lang.String)
*/
public Tag createTag(String name)
{
return new OTQuoteStartTag(name);
}
}
/**
*
*/
private static final class ParagraphTagBuilder implements TagBuilder
{
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.TagBuilder#createTag(java.lang.String)
*/
public Tag createTag(String name)
{
return new ParagraphTag(name);
}
}
/**
*
*/
private static final class PoetryStartTagBuilder implements TagBuilder
{
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.TagBuilder#createTag(java.lang.String)
*/
public Tag createTag(String name)
{
return new PoetryStartTag(name);
}
}
/**
*
*/
private static final class PsalmTitleStartTagBuilder implements TagBuilder
{
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.TagBuilder#createTag(java.lang.String)
*/
public Tag createTag(String name)
{
return new PsalmStartTag(name);
}
}
/**
*
*/
private static final class RedLetterStartTagBuilder implements TagBuilder
{
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.TagBuilder#createTag(java.lang.String)
*/
public Tag createTag(String name)
{
return new RedLetterStartTag(name);
}
}
/**
*
*/
private static final class StrongsMorphTagBuilder implements TagBuilder
{
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.TagBuilder#createTag(java.lang.String)
*/
public Tag createTag(final String name)
{
return new StrongsMorphTag(name);
}
}
/**
*
*/
private static final class StrongsWordTagBuilder implements TagBuilder
{
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.TagBuilder#createTag(java.lang.String)
*/
public Tag createTag(final String name)
{
return new StrongsWordTag(name);
}
}
/**
*
*/
private static final class TextFootnoteTagBuilder implements TagBuilder
{
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.TagBuilder#createTag(java.lang.String)
*/
public Tag createTag(String name)
{
return new TextFootnoteTag(name);
}
}
/**
*
*/
private static final class TitleStartTagBuilder implements TagBuilder
{
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.TagBuilder#createTag(java.lang.String)
*/
public Tag createTag(String name)
{
return new TitleStartTag(name);
}
}
/**
*
*/
private static final class UnderlineStartTagBuilder implements TagBuilder
{
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.TagBuilder#createTag(java.lang.String)
*/
public Tag createTag(String name)
{
return new UnderlineStartTag(name);
}
}
/**
* The log stream
*/
private static final Logger log = Logger.getLogger(GBFTagBuilders.class);
/**
* The <code>BUILDERS</code> maps the 2 letter GBF tag to a class that proxies for the tag.
*/
private static final Map BUILDERS = new HashMap();
static
{
TagBuilder defaultEndTagBuilder = new DefaultEndTagBuilder();
TagBuilder ignoreTagBuilder = new IgnoredTagBuilder();
BUILDERS.put("FB", new BoldStartTagBuilder()); //$NON-NLS-1$
BUILDERS.put("Fb", defaultEndTagBuilder); //$NON-NLS-1$
BUILDERS.put("FI", new ItalicStartTagBuilder()); //$NON-NLS-1$
BUILDERS.put("Fi", defaultEndTagBuilder); //$NON-NLS-1$
BUILDERS.put("FR", new RedLetterStartTagBuilder()); //$NON-NLS-1$
BUILDERS.put("Fr", defaultEndTagBuilder); //$NON-NLS-1$
BUILDERS.put("FU", new UnderlineStartTagBuilder()); //$NON-NLS-1$
BUILDERS.put("Fu", defaultEndTagBuilder); //$NON-NLS-1$
BUILDERS.put("RX", new CrossRefStartTagBuilder()); //$NON-NLS-1$
BUILDERS.put("Rx", defaultEndTagBuilder); //$NON-NLS-1$
BUILDERS.put("CL", new EndOfLineTagBuilder()); //$NON-NLS-1$
BUILDERS.put("CM", new ParagraphTagBuilder()); //$NON-NLS-1$
BUILDERS.put("RF", new FootnoteStartTagBuilder()); //$NON-NLS-1$
BUILDERS.put("Rf", new FootnoteEndTagBuilder()); //$NON-NLS-1$
BUILDERS.put("RB", new TextFootnoteTagBuilder()); //$NON-NLS-1$
BUILDERS.put("TS", new HeaderStartTagBuilder()); //$NON-NLS-1$
BUILDERS.put("Ts", defaultEndTagBuilder); //$NON-NLS-1$
BUILDERS.put("TB", new PsalmTitleStartTagBuilder()); //$NON-NLS-1$
BUILDERS.put("Tb", defaultEndTagBuilder); //$NON-NLS-1$
BUILDERS.put("TH", new TitleStartTagBuilder()); //$NON-NLS-1$
BUILDERS.put("Th", defaultEndTagBuilder); //$NON-NLS-1$
BUILDERS.put("BA", ignoreTagBuilder); //$NON-NLS-1$
BUILDERS.put("BC", ignoreTagBuilder); //$NON-NLS-1$
BUILDERS.put("BI", ignoreTagBuilder); //$NON-NLS-1$
BUILDERS.put("BN", ignoreTagBuilder); //$NON-NLS-1$
BUILDERS.put("BO", ignoreTagBuilder); //$NON-NLS-1$
BUILDERS.put("BP", ignoreTagBuilder); //$NON-NLS-1$
BUILDERS.put("JR", new JustifyRightTagBuilder()); //$NON-NLS-1$
BUILDERS.put("JL", ignoreTagBuilder); //$NON-NLS-1$
BUILDERS.put("FO", new OTQuoteStartTagBuilder()); //$NON-NLS-1$
BUILDERS.put("Fo", defaultEndTagBuilder); //$NON-NLS-1$
BUILDERS.put("PP", new PoetryStartTagBuilder()); //$NON-NLS-1$
BUILDERS.put("Pp", defaultEndTagBuilder); //$NON-NLS-1$
TagBuilder builder = new StrongsWordTagBuilder();
BUILDERS.put("WH", builder); //$NON-NLS-1$
BUILDERS.put("WG", builder); //$NON-NLS-1$
BUILDERS.put("WT", new StrongsMorphTagBuilder()); //$NON-NLS-1$
}
}
--- NEW FILE: GBFTags.java ---
package org.crosswire.jsword.book.filter.gbf;
import java.util.LinkedList;
import org.crosswire.common.util.ClassUtil;
import org.crosswire.jsword.book.DataPolice;
import org.crosswire.jsword.book.OSISUtil;
import org.crosswire.jsword.book.OSISUtil.ObjectFactory;
import org.crosswire.jsword.passage.KeyFactory;
import org.crosswire.jsword.passage.NoSuchKeyException;
import org.crosswire.jsword.passage.Passage;
import org.crosswire.jsword.passage.PassageKeyFactory;
import org.jdom.Content;
import org.jdom.Element;
import org.jdom.Text;
/**
* A holder of all of the GBF Tag Handler classes.
*
* <p><table border='1' cellPadding='3' cellSpacing='0'>
* <tr><td bgColor='white' class='TableRowColor'><font size='-7'>
*
* Distribution Licence:<br />
* JSword is free software; you can redistribute it
* and/or modify it under the terms of the GNU General Public License,
* version 2 as published by the Free Software Foundation.<br />
* 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
* General Public License for more details.<br />
* The License is available on the internet
* <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, or by writing to:
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA<br />
* The copyright to this program is held by it's authors.
* </font></td></tr></table>
* @see gnu.gpl.Licence
* @author Joe Walker [joe at eireneh dot com]
* @author DM Smith [dmsmith555 at yahoo dot com]
* @version $Id: GBFTags.java,v 1.1 2005/05/09 01:29:06 dmsmith Exp $
*/
public final class GBFTags
{
/**
*
*/
public static final class DefaultEndTag extends AbstractTag
{
/**
* @param name
*/
public DefaultEndTag(String name)
{
super(name);
}
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.Tag#updateOsisStack(java.util.LinkedList)
*/
public void updateOsisStack(LinkedList stack)
{
stack.removeFirst();
}
}
/**
*
*/
public static final class BoldStartTag extends AbstractTag
{
/**
* @param name
*/
public BoldStartTag(String name)
{
super(name);
}
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.Tag#updateOsisStack(java.util.LinkedList)
*/
public void updateOsisStack(LinkedList stack)
{
Element hi = OSIS_FACTORY.createHI();
hi.setAttribute(OSISUtil.ATTRIBUTE_HI_TYPE, OSISUtil.HI_BOLD);
Element current = (Element) stack.get(0);
current.addContent(hi);
stack.addFirst(hi);
}
}
/**
*
*/
public static final class CrossRefStartTag extends AbstractTag
{
public CrossRefStartTag(String name)
{
super(name);
}
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.Tag#updateOsisStack(java.util.LinkedList)
*/
public void updateOsisStack(LinkedList stack)
{
Element seg = OSIS_FACTORY.createReference();
String refstr = getName().substring(2);
try
{
Passage ref = (Passage) KEY_FACTORY.getKey(refstr);
seg.setAttribute(OSISUtil.ATTRIBUTE_REFERENCE_OSISREF, ref.getOSISName());
}
catch (NoSuchKeyException ex)
{
DataPolice.report("unable to parse reference: " + refstr); //$NON-NLS-1$
}
Element current = (Element) stack.get(0);
current.addContent(seg);
stack.addFirst(seg);
}
}
/**
*
*/
public static final class EOLTag extends AbstractTag
{
/**
* @param name
*/
public EOLTag(String name)
{
super(name);
}
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.Tag#updateOsisStack(java.util.LinkedList)
*/
public void updateOsisStack(LinkedList stack)
{
if (stack.size() == 0)
{
Element p = OSIS_FACTORY.createLB();
stack.addFirst(p);
// log.warn("failing to add to element on empty stack");
}
else
{
Element p = OSIS_FACTORY.createP();
Element ele = (Element) stack.get(0);
ele.addContent(p);
}
}
}
/**
*
*/
public static final class FootnoteStartTag extends AbstractTag
{
/**
* @param name
*/
public FootnoteStartTag(String name)
{
super(name);
}
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.Tag#updateOsisStack(java.util.LinkedList)
*/
public void updateOsisStack(LinkedList stack)
{
Element current = (Element) stack.get(0);
Element note = OSIS_FACTORY.createNote();
note.setAttribute(OSISUtil.ATTRIBUTE_NOTE_TYPE, OSISUtil.NOTETYPE_STUDY);
current.addContent(note);
stack.addFirst(note);
}
}
/**
*
*/
public static final class FootnoteEndTag extends AbstractTag
{
/**
* @param name
*/
public FootnoteEndTag(String name)
{
super(name);
}
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.Tag#updateOsisStack(java.util.LinkedList)
*/
public void updateOsisStack(LinkedList stack)
{
Object pop = stack.removeFirst();
if (pop instanceof Element)
{
Element note = (Element) pop;
if (note.getContentSize() < 1)
{
Element ele = (Element) stack.get(0);
ele.removeContent(note);
}
}
else
{
DataPolice.report("expected to pop a Note, but found " + ClassUtil.getShortClassName(pop.getClass())); //$NON-NLS-1$
}
}
}
/**
*
*/
public static final class HeaderStartTag extends AbstractTag
{
/**
* @param name
*/
public HeaderStartTag(String name)
{
super(name);
}
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.Tag#updateOsisStack(java.util.LinkedList)
*/
public void updateOsisStack(LinkedList stack)
{
Element title = OSIS_FACTORY.createTitle();
Element current = (Element) stack.get(0);
current.addContent(title);
stack.addFirst(title);
}
}
/**
*
*/
public static final class IgnoredTag extends AbstractTag
{
/**
* @param name
*/
public IgnoredTag(String name)
{
super(name);
}
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.Tag#updateOsisStack(java.util.LinkedList)
*/
public void updateOsisStack(LinkedList stack)
{
}
}
/**
*
*/
public static final class ItalicStartTag extends AbstractTag
{
/**
* @param name
*/
public ItalicStartTag(String name)
{
super(name);
}
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.Tag#updateOsisStack(java.util.LinkedList)
*/
public void updateOsisStack(LinkedList stack)
{
Element hi = OSIS_FACTORY.createHI();
hi.setAttribute(OSISUtil.ATTRIBUTE_HI_TYPE, OSISUtil.HI_ITALIC);
Element current = (Element) stack.get(0);
current.addContent(hi);
stack.addFirst(hi);
}
}
/**
*
*/
public static final class JustifyRightTag extends AbstractTag
{
/**
* @param name
*/
public JustifyRightTag(String name)
{
super(name);
}
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.Tag#updateOsisStack(java.util.LinkedList)
*/
public void updateOsisStack(LinkedList stack)
{
// LATER(joe): is div the right thing?
Element seg = OSIS_FACTORY.createSeg();
seg.setAttribute(OSISUtil.ATTRIBUTE_SEG_TYPE, OSISUtil.SEG_JUSTIFYRIGHT);
Element current = (Element) stack.get(0);
current.addContent(seg);
stack.addFirst(seg);
}
}
/**
*
*/
public static final class JustifyLeftTag extends AbstractTag
{
/**
* @param name
*/
public JustifyLeftTag(String name)
{
super(name);
}
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.Tag#updateOsisStack(java.util.LinkedList)
*/
public void updateOsisStack(LinkedList stack)
{
}
}
/**
*
*/
public static final class OTQuoteStartTag extends AbstractTag
{
/**
* @param name
*/
public OTQuoteStartTag(String name)
{
super(name);
}
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.Tag#updateOsisStack(java.util.LinkedList)
*/
public void updateOsisStack(LinkedList stack)
{
Element q = OSIS_FACTORY.createQ();
Element current = (Element) stack.get(0);
current.addContent(q);
stack.addFirst(q);
}
}
/**
*
*/
public static final class ParagraphTag extends AbstractTag
{
/**
* @param name
*/
public ParagraphTag(String name)
{
super(name);
}
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.Tag#updateOsisStack(java.util.LinkedList)
*/
public void updateOsisStack(LinkedList stack)
{
if (stack.size() == 0)
{
Element p = OSIS_FACTORY.createLB();
stack.addFirst(p);
}
else
{
Element p = OSIS_FACTORY.createP();
Element ele = (Element) stack.get(0);
ele.addContent(p);
}
}
}
/**
*
*/
public static final class PoetryStartTag extends AbstractTag
{
/**
* @param name
*/
public PoetryStartTag(String name)
{
super(name);
}
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.Tag#updateOsisStack(java.util.LinkedList)
*/
public void updateOsisStack(LinkedList stack)
{
// LATER(joe): is speech the right thing?
Element speech = OSIS_FACTORY.createLG();
Element current = (Element) stack.get(0);
current.addContent(speech);
stack.addFirst(speech);
}
}
/**
*
*/
public static final class PsalmStartTag extends AbstractTag
{
/**
* @param name
*/
public PsalmStartTag(String name)
{
super(name);
}
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.Tag#updateOsisStack(java.util.LinkedList)
*/
public void updateOsisStack(LinkedList stack)
{
Element title = OSIS_FACTORY.createTitle();
Element current = (Element) stack.get(0);
current.addContent(title);
stack.addFirst(title);
}
}
/**
*
*/
public static final class RedLetterStartTag extends AbstractTag
{
/**
* @param name
*/
public RedLetterStartTag(String name)
{
super(name);
}
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.Tag#updateOsisStack(java.util.LinkedList)
*/
public void updateOsisStack(LinkedList stack)
{
Element speaker = OSIS_FACTORY.createSpeaker();
speaker.setAttribute(OSISUtil.ATTRIBUTE_SPEAKER_WHO, Msg.NAME_JESUS.toString());
Element current = (Element) stack.get(0);
current.addContent(speaker);
stack.addFirst(speaker);
}
}
/**
*
*/
public static final class StrongsMorphTag extends AbstractTag
{
public StrongsMorphTag(String name)
{
super(name);
}
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.Tag#updateOsisStack(java.util.LinkedList)
*/
public void updateOsisStack(LinkedList stack)
{
String name = getName().trim();
Element ele = (Element) stack.get(0);
int size = ele.getContentSize();
if (size == 0)
{
DataPolice.report("No content to attach word to: <" + name + ">."); //$NON-NLS-1$ //$NON-NLS-2$
return;
}
int lastIndex = size - 1;
Content prevObj = ele.getContent(lastIndex);
Element word = null;
if (prevObj instanceof Text)
{
word = OSIS_FACTORY.createW();
ele.removeContent(prevObj);
word.addContent(prevObj);
ele.addContent(word);
}
else if (prevObj instanceof Element)
{
word = (Element) prevObj;
}
else
{
DataPolice.report("No words to attach word to: <" + name + ">."); //$NON-NLS-1$ //$NON-NLS-2$
return;
}
String existingMorph = word.getAttributeValue(OSISUtil.ATTRIBUTE_WORD_MORPH);
StringBuffer newMorph = new StringBuffer();
if (existingMorph != null && existingMorph.length() > 0)
{
newMorph.append(existingMorph).append('|');
}
newMorph.append(OSISUtil.MORPH_STRONGS).append(name.substring(2));
word.setAttribute(OSISUtil.ATTRIBUTE_WORD_MORPH, newMorph.toString());
}
}
/**
*
*/
public static final class StrongsWordTag extends AbstractTag
{
/**
* @param name
*/
public StrongsWordTag(String name)
{
super(name);
}
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.Tag#updateOsisStack(java.util.LinkedList)
*/
public void updateOsisStack(LinkedList stack)
{
String name = getName().trim();
Element ele = (Element) stack.get(0);
int size = ele.getContentSize();
if (size == 0)
{
DataPolice.report("No content to attach word to: <" + name + ">."); //$NON-NLS-1$ //$NON-NLS-2$
return;
}
int lastIndex = size - 1;
Content prevObj = ele.getContent(lastIndex);
Element word = null;
if (prevObj instanceof Text)
{
Text textItem = (Text) prevObj;
word = OSIS_FACTORY.createW();
ele.removeContent(textItem);
word.addContent(textItem);
ele.addContent(word);
}
else if (prevObj instanceof Element)
{
word = (Element) prevObj;
}
else
{
DataPolice.report("No words to attach word to: <" + name + ">."); //$NON-NLS-1$ //$NON-NLS-2$
return;
}
String existingLemma = word.getAttributeValue(OSISUtil.ATTRIBUTE_W_LEMMA);
StringBuffer newLemma = new StringBuffer();
if (existingLemma != null && existingLemma.length() > 0)
{
newLemma.append(existingLemma).append('|');
}
newLemma.append(OSISUtil.LEMMA_STRONGS).append(name.substring(2)); //$NON-NLS-1$
word.setAttribute(OSISUtil.ATTRIBUTE_W_LEMMA, newLemma.toString());
}
}
/**
*
*/
public static final class TextFootnoteTag extends AbstractTag
{
/**
* @param name
*/
public TextFootnoteTag(String name)
{
super(name);
}
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.Tag#updateOsisStack(java.util.LinkedList)
*/
public void updateOsisStack(LinkedList stack)
{
Element note = OSIS_FACTORY.createNote();
note.setAttribute(OSISUtil.ATTRIBUTE_NOTE_TYPE, OSISUtil.NOTETYPE_STUDY);
Element current = (Element) stack.get(0);
current.addContent(note);
stack.addFirst(note);
}
}
/**
*
*/
public static final class TextTag extends AbstractTag
{
/**
* @param name
*/
public TextTag(String name)
{
super(name);
}
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.Tag#updateOsisStack(java.util.LinkedList)
*/
public void updateOsisStack(LinkedList stack)
{
if (stack.size() == 0)
{
stack.addFirst(getName());
}
else
{
Element ele = (Element) stack.get(0);
ele.addContent(getName());
}
}
}
/**
*
*/
public static final class TitleStartTag extends AbstractTag
{
/**
* @param name
*/
public TitleStartTag(String name)
{
super(name);
}
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.Tag#updateOsisStack(java.util.LinkedList)
*/
public void updateOsisStack(LinkedList stack)
{
Element title = OSIS_FACTORY.createTitle();
Element current = (Element) stack.get(0);
current.addContent(title);
stack.addFirst(title);
}
}
/**
*
*/
public static final class UnderlineStartTag extends AbstractTag
{
/**
* @param name
*/
public UnderlineStartTag(String name)
{
super(name);
}
/* (non-Javadoc)
* @see org.crosswire.jsword.book.filter.gbf.Tag#updateOsisStack(java.util.LinkedList)
*/
public void updateOsisStack(LinkedList stack)
{
Element hi = OSIS_FACTORY.createHI();
hi.setAttribute(OSISUtil.ATTRIBUTE_HI_TYPE, OSISUtil.HI_UNDERLINE);
Element current = (Element) stack.get(0);
current.addContent(hi);
stack.addFirst(hi);
}
}
/**
* To convert strings into Biblical keys.
*/
protected static final KeyFactory KEY_FACTORY = PassageKeyFactory.instance();
/**
* To create OSIS DOM nodes.
*/
protected static final ObjectFactory OSIS_FACTORY = OSISUtil.factory();
}
--- HeaderTagBuilder.java DELETED ---
--- TitleTagBuilder.java DELETED ---
--- UnderlineTagBuilder.java DELETED ---
--- FootnoteTagBuilder.java DELETED ---
--- NEW FILE: AbstractTag.java ---
/**
* Distribution Licence:
* JSword is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 2 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 General Public License for more details.
*
* The License is available on the internet at:
* http://www.gnu.org/copyleft/gpl.html
* or by writing to:
* Free Software Foundation, Inc.
* 59 Temple Place - Suite 330
* Boston, MA 02111-1307, USA
*
* The copyright to this program is held by it's authors.
*/
package org.crosswire.jsword.book.filter.gbf;
/**
*
* @see gnu.gpl.Licence
* @author DM Smith [ dmsmith555 at yahoo dot com]
* @version $Id: AbstractTag.java,v 1.1 2005/05/09 01:29:06 dmsmith Exp $
*/
public abstract class AbstractTag implements Tag
{
/**
* @param name
*/
public AbstractTag(String name)
{
this.name = name;
}
/**
* @return Returns the name.
*/
public String getName()
{
return name;
}
private String name;
}
--- PsalmTitleTagBuilder.java DELETED ---
--- JustifyTagBuilder.java DELETED ---
Index: GBFFilter.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/filter/gbf/GBFFilter.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** GBFFilter.java 24 Mar 2005 03:14:29 -0000 1.9
--- GBFFilter.java 9 May 2005 01:29:06 -0000 1.10
***************
*** 5,9 ****
import java.util.List;
- import org.crosswire.common.util.Logger;
import org.crosswire.jsword.book.DataPolice;
import org.crosswire.jsword.book.OSISUtil;
--- 5,8 ----
***************
*** 85,89 ****
{
// no more tags to decode
! taglist.add(createText(remains));
remains = null;
break;
--- 84,88 ----
{
// no more tags to decode
! taglist.add(GBFTagBuilders.getTextTag(remains));
remains = null;
break;
***************
*** 94,98 ****
{
DataPolice.report("ignoring unmatched '<' or '>' in gbf: " + remains); //$NON-NLS-1$
! taglist.add(createText(remains));
remains = null;
break;
--- 93,97 ----
{
DataPolice.report("ignoring unmatched '<' or '>' in gbf: " + remains); //$NON-NLS-1$
! taglist.add(GBFTagBuilders.getTextTag(remains));
remains = null;
break;
***************
*** 103,107 ****
{
DataPolice.report("ignoring transposed '<' or '>' in gbf: " + remains); //$NON-NLS-1$
! taglist.add(createText(remains));
remains = null;
break;
--- 102,106 ----
{
DataPolice.report("ignoring transposed '<' or '>' in gbf: " + remains); //$NON-NLS-1$
! taglist.add(GBFTagBuilders.getTextTag(remains));
remains = null;
break;
***************
*** 123,127 ****
if (!(SEPARATORS.indexOf(currentChar) >= 0))
{
! taglist.add(createText(start.substring(beginIndex, i)));
beginIndex = i;
inSepStr = false;
--- 122,126 ----
if (!(SEPARATORS.indexOf(currentChar) >= 0))
{
! taglist.add(GBFTagBuilders.getTextTag(start.substring(beginIndex, i)));
beginIndex = i;
inSepStr = false;
***************
*** 131,161 ****
if (beginIndex < strLen)
{
! taglist.add(createText(start.substring(beginIndex)));
}
}
String tag = remains.substring(ltpos + 1, gtpos);
! if (tag.length() > 0)
{
! Tag reply = null;
!
! for (int i = 0; i < BUILDERS.length; i++)
! {
! reply = BUILDERS[i].createTag(tag);
! if (reply != null)
! {
! break;
! }
! }
!
! if (reply == null)
! {
! // I'm not confident enough that we handle all the GBF tags
! // that I will blame the module instead of the program
!
! log.warn("Ignoring tag of <" + tag + ">"); //$NON-NLS-1$ //$NON-NLS-2$
! //DataPolice.report("Ignoring tag of <" + tag + ">");
! }
! else
{
taglist.add(reply);
--- 130,143 ----
if (beginIndex < strLen)
{
! taglist.add(GBFTagBuilders.getTextTag(start.substring(beginIndex)));
}
}
String tag = remains.substring(ltpos + 1, gtpos);
! int length = tag.length();
! if (length > 0)
{
! Tag reply = GBFTagBuilders.getTag(tag);
! if (reply != null)
{
taglist.add(reply);
***************
*** 169,208 ****
}
- /**
- * The log stream
- */
- protected static final Logger log = Logger.getLogger(GBFFilter.class);
-
- /**
- * Create a text tag which might involve some fancy parsing
- */
- private static Tag createText(String text)
- {
- return TEXT.createTag(text);
- }
-
private static final String SEPARATORS = " ,:;.?!"; //$NON-NLS-1$
- private static final TagBuilder TEXT = new TextTagBuilder();
- private static final TagBuilder[] BUILDERS = new TagBuilder[]
- {
- new BoldTagBuilder(),
- new CrossRefTagBuilder(),
- new EndOfLineTagBuilder(),
- new FootnoteTagBuilder(),
- new HeaderTagBuilder(),
- new IgnoredTagBuilder(),
- new ItalicTagBuilder(),
- new JustifyTagBuilder(),
- new OTQuoteTagBuilder(),
- new ParagraphTagBuilder(),
- new PoetryTagBuilder(),
- new PsalmTitleTagBuilder(),
- new RedLetterTagBuilder(),
- new StrongsMorphTagBuilder(),
- new StrongsWordTagBuilder(),
- new TitleTagBuilder(),
- new TextFootnoteTagBuilder(),
- new UnderlineTagBuilder(),
- };
}
--- 151,155 ----
--- PoetryTagBuilder.java DELETED ---
--- CrossRefTagBuilder.java DELETED ---
--- RedLetterTagBuilder.java DELETED ---
--- TextTagBuilder.java DELETED ---
--- TextFootnoteTagBuilder.java DELETED ---
Index: Tag.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/filter/gbf/Tag.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Tag.java 11 May 2004 23:54:19 -0000 1.3
--- Tag.java 9 May 2005 01:29:06 -0000 1.4
***************
*** 6,10 ****
* GBF Tag interface.
* <p>For copy and paste purposes, the canonical single Tag is
! * EndOfLineTagBuilder and the canonical paired tag is PoetryTagBuilder.
*
* <p><table border='1' cellPadding='3' cellSpacing='0'>
--- 6,10 ----
* GBF Tag interface.
* <p>For copy and paste purposes, the canonical single Tag is
! * EndOfLineTagBuilder and the canonical paired tag is PoetryStartTagBuilder.
*
* <p><table border='1' cellPadding='3' cellSpacing='0'>
Index: Msg.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/filter/gbf/Msg.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** Msg.java 13 Jun 2004 22:12:32 -0000 1.7
--- Msg.java 9 May 2005 01:29:06 -0000 1.8
***************
*** 29,33 ****
class Msg extends MsgBase
{
! static final Msg NAME_JESUS = new Msg("RedLetterTagBuilder.NameJesus"); //$NON-NLS-1$
/**
--- 29,33 ----
class Msg extends MsgBase
{
! static final Msg NAME_JESUS = new Msg("RedLetterStartTagBuilder.NameJesus"); //$NON-NLS-1$
/**
--- OTQuoteTagBuilder.java DELETED ---
--- StrongsWordTagBuilder.java DELETED ---
--- IgnoredTagBuilder.java DELETED ---
More information about the jsword-svn
mailing list