Coverage Report - uk.ac.ebi.xchars.palette.XCharsPalette
 
Classes in this File Line Coverage Branch Coverage Complexity
XCharsPalette
0%
0/43
0%
0/4
0
 
 1  
 package uk.ac.ebi.xchars.palette;
 2  
 
 3  
 import java.io.Serializable;
 4  
 import java.util.ArrayList;
 5  
 import java.util.Collections;
 6  
 import java.util.Enumeration;
 7  
 import java.util.Iterator;
 8  
 import java.util.List;
 9  
 import java.util.ResourceBundle;
 10  
 
 11  
 import uk.ac.ebi.xchars.SpecialCharacters;
 12  
 import uk.ac.ebi.xchars.domain.XCharsClass;
 13  
 
 14  
 public class XCharsPalette implements Serializable {
 15  
 
 16  
         private static final long serialVersionUID = -6882923092921136526L;
 17  
         
 18  0
         private List<XCharsPaletteElement> favouriteTagElements = new ArrayList<XCharsPaletteElement>();
 19  0
         private List<XCharsPaletteClass> xcharsPaletteClasses = new ArrayList<XCharsPaletteClass>();
 20  
 
 21  0
         private static List<String> unclosedTags = new ArrayList<String>();
 22  0
         private static List<String> favouriteTags = new ArrayList<String>();
 23  
 
 24  
         static {
 25  
                 try {
 26  0
                         ResourceBundle bundle = ResourceBundle.getBundle("xcharsUnclosed");
 27  0
                         ResourceBundle favourite = ResourceBundle.getBundle("xcharsFavourites");
 28  0
                         Enumeration<String> keys = bundle.getKeys();
 29  0
                         while ( keys.hasMoreElements() ) {
 30  0
                                 unclosedTags.add(keys.nextElement());
 31  
                         }
 32  
 
 33  
                         // Important to preserver the order
 34  0
                         int counter = 1;
 35  0
                         while ( counter < 30 ) {
 36  0
                                 String value = favourite.getString(String.valueOf(counter));
 37  0
                                 if ( value != null )
 38  0
                                         favouriteTags.add(value);
 39  
                                 else
 40  0
                                         counter = 30;
 41  0
                                 ++counter;
 42  0
                         }
 43  0
                 } catch ( Exception e ) {
 44  0
                         System.err.println("XCharsPalette: unable to load favourites");
 45  0
                 }
 46  0
         }
 47  
 
 48  0
         public XCharsPalette (SpecialCharacters sc) {
 49  0
                 getXmlElements(sc);
 50  0
         }
 51  
 
 52  
         public List<XCharsPaletteClass> getXcharsPaletteClasses () {
 53  0
                 return xcharsPaletteClasses;
 54  
         }
 55  
 
 56  
         /**
 57  
          * Gets all the specialCharacter XML elements for the character classes.
 58  
          *
 59  
          * @param sc
 60  
          */
 61  
         private void getXmlElements (SpecialCharacters sc) {
 62  
 
 63  
                 //create XCharsPaletteClass Objects which contain the name of the class, the corresponding elements
 64  
                 //and their Xml- Default- and Ascii Encoding
 65  
                 //add all XCharsPalette Objects to the xcharsPaletteClasses list
 66  
 
 67  0
                 for ( Iterator classTypes = sc.getCharacterClasses().keySet().iterator(); classTypes.hasNext(); )
 68  
                 {
 69  0
                         String classType = (String) classTypes.next();
 70  0
                         XCharsClass xcharclass = (XCharsClass) sc.getCharacterClasses().get(classType);
 71  0
                         XCharsPaletteClass xcharsPaletteClass = new XCharsPaletteClass(sc, xcharclass);
 72  0
                         xcharsPaletteClasses.add(xcharsPaletteClass);
 73  0
                 }
 74  
 
 75  0
                 for ( Iterator classTypes = sc.getFormattingClasses().keySet().iterator(); classTypes.hasNext(); )
 76  
                 {
 77  0
                         String classType = (String) classTypes.next();
 78  0
                         XCharsClass xcharclass = (XCharsClass) sc.getFormattingClasses().get(classType);
 79  0
                         XCharsPaletteClass xcharsPaletteClass = new XCharsPaletteClass(sc, xcharclass);
 80  0
                         xcharsPaletteClasses.add(xcharsPaletteClass);
 81  0
                 }
 82  0
                 Collections.sort(xcharsPaletteClasses);
 83  0
         }
 84  
 
 85  
 
 86  
         /**
 87  
          * Returns the list of the curators favourite tags. Is dependent on the resources,
 88  
          * xcharsFavourites.properties
 89  
          *
 90  
          * @return list of favourite tags
 91  
          */
 92  
         public boolean isFavouriteTag (String completeTag) {
 93  0
                 return favouriteTags.contains(completeTag);
 94  
         }
 95  
 
 96  
         public List<XCharsPaletteElement> getFavouriteTagElements () {
 97  0
                 return favouriteTagElements;
 98  
         }
 99  
 
 100  
         public List<String> getFavouriteTags () {
 101  0
                 return favouriteTags;
 102  
         }
 103  
 
 104  
         // -------------------------------- STATIC METHODS -----------------------//
 105  
 
 106  
         /**
 107  
          * Returns true if this classType contains tags which should not be closed
 108  
          * in a single element even though it contains no character within the tag.<br/>
 109  
          * For example: &lt;ital&gt; should contain something between the two tags
 110  
          * instead of &lt;ital/&gt;
 111  
          *
 112  
          * @return the list of tags which should be closed within a tag.
 113  
          */
 114  
         public static boolean isUnclosedTag (String xcharClassType) {
 115  0
                 return unclosedTags.contains(xcharClassType);
 116  
         }
 117  
 
 118  
 
 119  
 }