Clover coverage report - ATP library for Java - 3.6.4-stable-060214
Coverage timestamp: Вт фев 14 2006 13:45:22 MSK
file stats: LOC: 171   Methods: 2
NCLOC: 103   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TokenStyleManager.java 0% 0% 0% 0%
coverage
 1    /*
 2    * Copyright (c) 2001-2004,
 3    * RedVerst Group, ISP RAS http://www.ispras.ru
 4    * All rights reserved.
 5    *
 6    * Redistribution and use in source and binary forms, with or without
 7    * modification, are permitted provided that the following conditions are met:
 8    *
 9    * 1. Redistributions of source code must retain the above copyright notice, this
 10    * list of conditions and the following disclaimer.
 11    *
 12    * 2. Redistributions in binary form must reproduce the above copyright notice,
 13    * this list of conditions and the following disclaimer in the documentation
 14    * and/or other materials provided with the distribution.
 15    *
 16    * 3. The names "ATP", "TreeDL", "RedVerst", "ISP RAS"
 17    * may not be used to endorse or promote products derived from this software
 18    * without specific prior written permission.
 19    *
 20    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 21    * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 22    * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 23    * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 24    * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 25    * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 26    * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 27    * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 28    * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 29    * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 30    */
 31   
 32    package com.unitesk.atp.tree.generation;
 33   
 34    import java.io.InputStream;
 35    import java.io.IOException;
 36    import java.io.File;
 37   
 38    import java.util.Enumeration;
 39    import java.util.HashMap;
 40    import java.util.Iterator;
 41    import java.util.Map;
 42    import java.util.Properties;
 43   
 44    import com.unitesk.atp.tree.tool.Tool;
 45    import com.unitesk.atp.messages.*;
 46   
 47    /**
 48    * Token Style Manager provides token styles for html generation.
 49    * It reads token styles from file (in property format).
 50    *
 51    * @author <A href="mailto:demakov@ispras.ru">Alexey Demakov</A>
 52    * @version $Id: TokenStyleManager.java,v 1.3 2004/10/11 15:00:45 all-x Exp $
 53    */
 54    public class TokenStyleManager
 55    {
 56    protected String[] styles = null;
 57   
 58    /**
 59    * Constructs Token Style manager.
 60    *
 61    * @param token_types_interface Interface that defines tokens
 62    * types as constants.
 63    * @param tokenstyle_file File name with map from token type name
 64    * to token style name.
 65    */
 66  0 public TokenStyleManager( Class token_types_interface
 67    , String tokenstyle_file
 68    , MessageBox mbox
 69    )
 70    {
 71  0 InputStream in = Tool.findFile( tokenstyle_file );
 72   
 73  0 Properties name_to_style = new Properties();
 74   
 75  0 Map type_to_style = new HashMap/*Integer,String*/();
 76   
 77  0 if( in != null )
 78    {
 79  0 try
 80    {
 81  0 name_to_style.load( in );
 82  0 mbox.info( new FileStatusMessage( FoundFileStatus.status
 83    , tokenstyle_file
 84    )
 85    );
 86    }
 87    catch( IOException e )
 88    {
 89  0 mbox.error( new IOErrorMessage( new File( tokenstyle_file ) ) );
 90    }
 91   
 92  0 Enumeration name_enum = name_to_style.propertyNames();
 93  0 int max = 0;
 94   
 95  0 while( name_enum.hasMoreElements() )
 96    {
 97  0 String name = (String)name_enum.nextElement();
 98  0 String style = name_to_style.getProperty( name );
 99   
 100  0 if( style != null && style.length() > 0 )
 101    {
 102  0 try
 103    {
 104  0 Integer type = (Integer) token_types_interface
 105    .getField( name )
 106    .get( null );
 107  0 type_to_style.put( type, style );
 108  0 max = Math.max( max, type.intValue() );
 109    }
 110    catch( NoSuchFieldException fe )
 111    {
 112  0 mbox.error( new NameNotFoundMessage
 113    ( new File( tokenstyle_file )
 114    , null
 115    , mbox
 116    .getStringManager()
 117    .getString( TokenStyleManager.class
 118    , "message.token"
 119    )
 120    , name
 121    )
 122    );
 123    }
 124    catch( IllegalAccessException fe )
 125    {
 126  0 mbox.error( new NameNotFoundMessage
 127    ( new File( tokenstyle_file )
 128    , null
 129    , mbox
 130    .getStringManager()
 131    .getString( TokenStyleManager.class
 132    , "message.token"
 133    )
 134    , name
 135    )
 136    );
 137    }
 138    }
 139    }
 140   
 141  0 styles = new String[max+1];
 142   
 143  0 Iterator type_enum = type_to_style.entrySet().iterator();
 144   
 145  0 while( type_enum.hasNext() )
 146    {
 147  0 Map.Entry entry = (Map.Entry)type_enum.next();
 148  0 Integer type = (Integer)entry.getKey();
 149  0 String style = (String)entry.getValue();
 150  0 styles[type.intValue()] = style;
 151    }
 152    }
 153    }
 154   
 155    /**
 156    * Returns token style for given token type.
 157    *
 158    * @param type the token type.
 159    * @return token style for this token type or <code>null</code>
 160    * if style is not defined.
 161    */
 162  0 public String getStyle( int type )
 163    {
 164  0 if( styles != null && 0 <= type && type < styles.length )
 165    {
 166  0 return styles[type];
 167    } else {
 168  0 return null;
 169    }
 170    }
 171    }