Coverage Report - org.crosswire.jsword.book.filter.thml.ScripRefTag
 
Classes in this File Line Coverage Branch Coverage Complexity
ScripRefTag
0%
0/27
0%
0/8
3
 
 1  
 /**
 2  
  * Distribution License:
 3  
  * JSword is free software; you can redistribute it and/or modify it under
 4  
  * the terms of the GNU Lesser General Public License, version 2.1 or later
 5  
  * as published by the Free Software Foundation. This program is distributed
 6  
  * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 7  
  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 8  
  * See the GNU Lesser General Public License for more details.
 9  
  *
 10  
  * The License is available on the internet at:
 11  
  *      http://www.gnu.org/copyleft/lgpl.html
 12  
  * or by writing to:
 13  
  *      Free Software Foundation, Inc.
 14  
  *      59 Temple Place - Suite 330
 15  
  *      Boston, MA 02111-1307, USA
 16  
  *
 17  
  * © CrossWire Bible Society, 2005 - 2016
 18  
  *
 19  
  */
 20  
 package org.crosswire.jsword.book.filter.thml;
 21  
 
 22  
 import org.crosswire.jsword.book.Book;
 23  
 import org.crosswire.jsword.book.DataPolice;
 24  
 import org.crosswire.jsword.book.OSISUtil;
 25  
 import org.crosswire.jsword.passage.Key;
 26  
 import org.crosswire.jsword.passage.KeyUtil;
 27  
 import org.crosswire.jsword.passage.NoSuchKeyException;
 28  
 import org.crosswire.jsword.passage.Passage;
 29  
 import org.crosswire.jsword.passage.PassageKeyFactory;
 30  
 import org.jdom2.Element;
 31  
 import org.xml.sax.Attributes;
 32  
 
 33  
 /**
 34  
  * THML Tag to process the scripRef element.
 35  
  * 
 36  
  * @see gnu.lgpl.License The GNU Lesser General Public License for details.
 37  
  * @author Joe Walker
 38  
  */
 39  0
 public class ScripRefTag extends AbstractTag {
 40  
     /* (non-Javadoc)
 41  
      * @see org.crosswire.jsword.book.filter.thml.Tag#getTagName()
 42  
      */
 43  
     public String getTagName() {
 44  0
         return "scripRef";
 45  
     }
 46  
 
 47  
     @Override
 48  
     public Element processTag(Book book, Key key, Element ele, Attributes attrs) {
 49  0
         Element reference = null;
 50  
 
 51  0
         String refstr = attrs.getValue("passage");
 52  0
         if (refstr != null) {
 53  0
             Passage ref = null;
 54  
             try {
 55  0
                 ref = PassageKeyFactory.instance().getKey(KeyUtil.getVersification(key), refstr, key);
 56  0
             } catch (NoSuchKeyException ex) {
 57  0
                 DataPolice.report(book, key, "Unparsable passage: (" + refstr + ") due to " + ex.getMessage());
 58  0
             }
 59  
 
 60  
             // If we don't have a Passage then use the original string
 61  0
             String osisname = ref != null ? ref.getOsisRef() : refstr;
 62  0
             reference = OSISUtil.factory().createReference();
 63  0
             reference.setAttribute(OSISUtil.OSIS_ATTR_REF, osisname);
 64  0
         } else {
 65  
             // The reference will be filled in by processContent
 66  0
             reference = OSISUtil.factory().createReference();
 67  
         }
 68  
 
 69  0
         if (ele != null) {
 70  0
             ele.addContent(reference);
 71  
         }
 72  
 
 73  0
         return reference;
 74  
     }
 75  
 
 76  
     @Override
 77  
     public void processContent(Book book, Key key, Element ele) {
 78  0
         String refstr = ele.getValue();
 79  
         try {
 80  0
             if (ele.getAttribute(OSISUtil.OSIS_ATTR_REF) == null) {
 81  0
                 Passage ref = PassageKeyFactory.instance().getKey(KeyUtil.getVersification(key), refstr, key);
 82  0
                 String osisname = ref.getOsisRef();
 83  0
                 ele.setAttribute(OSISUtil.OSIS_ATTR_REF, osisname);
 84  
             }
 85  0
         } catch (NoSuchKeyException ex) {
 86  0
             DataPolice.report(book, key, "scripRef has no passage attribute, unable to guess: (" + refstr + ") due to " + ex.getMessage());
 87  0
         }
 88  0
     }
 89  
 }