Clover coverage report -
Coverage timestamp: Sun Apr 18 2004 21:32:30 EDT
file stats: LOC: 134   Methods: 5
NCLOC: 72   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AttributeMapper.java 25% 47.2% 80% 41.5%
coverage coverage
 1   
 /*
 2   
  * SimplyHTML, a word processor based on Java, HTML and CSS
 3   
  * Copyright (C) 2002 Ulrich Hilger
 4   
  *
 5   
  * This program is free software; you can redistribute it and/or
 6   
  * modify it under the terms of the GNU General Public License
 7   
  * as published by the Free Software Foundation; either version 2
 8   
  * of the License, or (at your option) any later version.
 9   
  *
 10   
  * This program is distributed in the hope that it will be useful,
 11   
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12   
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13   
  * GNU General Public License for more details.
 14   
  *
 15   
  * You should have received a copy of the GNU General Public License
 16   
  * along with this program; if not, write to the Free Software
 17   
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 18   
  */
 19   
 
 20   
 import javax.swing.text.SimpleAttributeSet;
 21   
 import javax.swing.text.AttributeSet;
 22   
 import javax.swing.text.html.CSS;
 23   
 import javax.swing.text.html.HTML;
 24   
 
 25   
 /**
 26   
  * <p>Maps HTML and CSS attributes to their equivalents to
 27   
  * compensate discrepancies in HTML and CSS rendering of
 28   
  * various different view environments.</p>
 29   
  *
 30   
  * <p>Introduced in stage 5 this class only contains hard wired
 31   
  * fixes to certain discrepancies. Should there come up an increased
 32   
  * number of necessary fixes in future stages, a more generic way
 33   
  * of mapping (such as through a Hashtable of from/to values), etc.
 34   
  * will be done.</p>
 35   
  *
 36   
  * @author Ulrich Hilger
 37   
  * @author Light Development
 38   
  * @author <a href="http://www.lightdev.com">http://www.lightdev.com</a>
 39   
  * @author <a href="mailto:info@lightdev.com">info@lightdev.com</a>
 40   
  * @author published under the terms and conditions of the
 41   
  *      GNU General Public License,
 42   
  *      for details see file gpl.txt in the distribution
 43   
  *      package of this software
 44   
  *
 45   
  * @version stage 11, April 27, 2003
 46   
  */
 47   
 
 48   
 public class AttributeMapper extends SimpleAttributeSet {
 49   
 
 50   
   public static final int toHTML = 1;
 51   
   public static final int toJava = 2;
 52   
 
 53  0
   public AttributeMapper() {
 54  0
     super();
 55   
   }
 56   
 
 57  88
   public AttributeMapper(AttributeSet a) {
 58  88
     super(a);
 59   
   }
 60   
 
 61  88
   public AttributeSet getMappedAttributes(int direction) {
 62  88
     switch(direction) {
 63  26
       case toHTML:
 64  26
         mapToHTMLAttributes();
 65  26
         break;
 66  62
       case toJava:
 67  62
         mapToJavaAttributes();
 68  62
         break;
 69   
     }
 70   
     //System.out.println("AttributeMapper transformed attributes=");
 71   
     //de.calcom.cclib.html.HTMLDiag hd = new de.calcom.cclib.html.HTMLDiag();
 72   
     //hd.listAttributes(this, 2);
 73  88
     return this;
 74   
   }
 75   
 
 76  26
   private void mapToHTMLAttributes() {
 77  26
     Object cssFontFamily = getAttribute(CSS.Attribute.FONT_FAMILY);
 78  26
     if(cssFontFamily != null) {
 79  0
       if(cssFontFamily.toString().equalsIgnoreCase("SansSerif")) {
 80  0
         addAttribute(CSS.Attribute.FONT_FAMILY, "SansSerif, Sans-Serif");
 81   
         //System.out.println("mapToHTMLAttributes SansSerif, Sans-Serif");
 82   
       }
 83  0
       else if(cssFontFamily.toString().indexOf("Monospaced") > -1) {
 84  0
         addAttribute(CSS.Attribute.FONT_FAMILY, "Monospace, Monospaced");
 85   
       }
 86   
     }
 87   
     /*
 88   
     Object cssFontSize = getAttribute(CSS.Attribute.FONT_SIZE);
 89   
     if(cssFontSize != null) {
 90   
       int size = new Float(new LengthValue(cssFontSize).getValue() / 1.3).intValue();
 91   
       addAttribute(CSS.Attribute.FONT_SIZE, Integer.toString(size) + "pt");
 92   
     }
 93   
     */
 94   
   }
 95   
 
 96  62
   private void mapToJavaAttributes() {
 97  62
     Object htmlFontFace = getAttribute(HTML.Attribute.FACE);
 98  62
     Object cssFontFamily = getAttribute(CSS.Attribute.FONT_FAMILY);
 99  62
     if(htmlFontFace != null) {
 100  0
       if(cssFontFamily != null) {
 101  0
         removeAttribute(HTML.Attribute.FACE);
 102  0
         if(cssFontFamily.toString().indexOf("Sans-Serif") > -1) {
 103  0
           Util.styleSheet().addCSSAttribute(this, CSS.Attribute.FONT_FAMILY, "SansSerif");
 104   
         }
 105  0
         else if(cssFontFamily.toString().indexOf("Monospace") > -1) {
 106  0
           Util.styleSheet().addCSSAttribute(this, CSS.Attribute.FONT_FAMILY, "Monospaced");
 107   
         }
 108   
       }
 109   
       else {
 110  0
         removeAttribute(HTML.Attribute.FACE);
 111  0
         if(htmlFontFace.toString().indexOf("Sans-Serif") > -1) {
 112  0
           Util.styleSheet().addCSSAttribute(this, CSS.Attribute.FONT_FAMILY, "SansSerif");
 113   
         }
 114  0
         else if(htmlFontFace.toString().indexOf("Monospace") > -1) {
 115  0
           Util.styleSheet().addCSSAttribute(this, CSS.Attribute.FONT_FAMILY, "Monospaced");
 116   
         }
 117   
         else {
 118  0
           Util.styleSheet().addCSSAttribute(this, CSS.Attribute.FONT_FAMILY, htmlFontFace.toString());
 119   
         }
 120   
       }
 121   
     }
 122   
     else {
 123  62
       if(cssFontFamily != null) {
 124  21
         if(cssFontFamily.toString().indexOf("Sans-Serif") > -1) {
 125  0
           Util.styleSheet().addCSSAttribute(this, CSS.Attribute.FONT_FAMILY, "SansSerif");
 126   
         }
 127  21
         else if(cssFontFamily.toString().indexOf("Monospace") > -1) {
 128  0
           Util.styleSheet().addCSSAttribute(this, CSS.Attribute.FONT_FAMILY, "Monospaced");
 129   
         }
 130   
       }
 131   
     }
 132   
   }
 133   
 
 134   
 }