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 as published by
5    * the Free Software Foundation. This program is distributed in the hope
6    * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7    * 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   * Copyright: 2005 - 2012
18   *     The copyright to this program is held by it's authors.
19   *
20   * ID: $Id: FontTag.java 2221 2012-01-25 21:32:57Z dmsmith $
21   */
22  package org.crosswire.jsword.book.filter.thml;
23  
24  import org.crosswire.common.xml.XMLUtil;
25  import org.crosswire.jsword.book.Book;
26  import org.crosswire.jsword.book.DataPolice;
27  import org.crosswire.jsword.book.OSISUtil;
28  import org.crosswire.jsword.passage.Key;
29  import org.jdom.Element;
30  import org.xml.sax.Attributes;
31  
32  /**
33   * THML Tag to process the font element.
34   * 
35   * @see gnu.lgpl.License for license details.<br>
36   *      The copyright to this program is held by it's authors.
37   * @author Joe Walker [joe at eireneh dot com]
38   */
39  public class FontTag extends AbstractTag {
40      /* (non-Javadoc)
41       * @see org.crosswire.jsword.book.filter.thml.Tag#getTagName()
42       */
43      public String getTagName() {
44          return "font";
45      }
46  
47      @Override
48      public Element processTag(Book book, Key key, Element ele, Attributes attrs) {
49          Element seg = OSISUtil.factory().createSeg();
50          StringBuilder buf = new StringBuilder();
51  
52          String color = attrs.getValue("color");
53          if (color != null) {
54              buf.append(OSISUtil.SEG_COLORPREFIX);
55              buf.append(color);
56              buf.append(';');
57          }
58  
59          String size = attrs.getValue("size");
60          if (size != null) {
61              buf.append(OSISUtil.SEG_SIZEPREFIX);
62              buf.append(size);
63              buf.append(';');
64          }
65  
66          String type = buf.toString();
67          if (type.length() > 0) {
68              seg.setAttribute(OSISUtil.OSIS_ATTR_TYPE, type);
69          } else {
70              DataPolice.report(book, key, "Missing color/size attribute.");
71              XMLUtil.debugSAXAttributes(attrs);
72          }
73  
74          if (ele != null) {
75              ele.addContent(seg);
76          }
77  
78          return seg;
79      }
80  }
81