Coverage Report - org.webslinger.rules.CSSRules
 
Classes in this File Line Coverage Branch Coverage Complexity
CSSRules
91%
42/46
100%
9/9
0
 
 1  
 package org.webslinger.rules;
 2  
 
 3  
 import java.io.IOException;
 4  
 import java.util.ArrayList;
 5  
 import java.util.ListIterator;
 6  
 import java.util.HashMap;
 7  
 import java.util.HashSet;
 8  
 import java.util.List;
 9  
 import java.util.Map;
 10  
 
 11  
 import org.webslinger.container.WebslingerContainer;
 12  
 
 13  
 public class CSSRules extends SimpleNode {
 14  22
     protected String defaultTheme = "Default";
 15  
 
 16  
     public CSSRules(int id) {
 17  0
         super(id);
 18  0
     }
 19  
 
 20  
     public CSSRules(Rules p, int id) {
 21  22
         super(p, id);
 22  22
     }
 23  
 
 24  
     /** Accept the visitor. **/
 25  
     public Object jjtAccept(RulesVisitor visitor, Object data) {
 26  0
         return visitor.visit(this, data);
 27  
     }
 28  
 
 29  
     public CompiledRules compile(WebslingerContainer container) throws IOException {
 30  22
         Map<Action, List<CompiledRules.Entry>> entriesPerAction = new HashMap<Action, List<CompiledRules.Entry>>();
 31  22
         ListIterator<Node> it = getChildrenIterator();
 32  119
         while (it.hasNext()) {
 33  97
             CSSRule rule = (CSSRule) it.next();
 34  97
             ListIterator<Node> ruleIt = rule.getChildrenIterator();
 35  97
             ArrayList<CSSSelector> selectorList = new ArrayList<CSSSelector>();
 36  97
             HashMap<Action, ArrayList<CSSAction>> ruleActions = new HashMap<Action, ArrayList<CSSAction>>();
 37  337
             while (ruleIt.hasNext()) {
 38  240
                 Node child = ruleIt.next();
 39  240
                 if (child instanceof CSSSelector) {
 40  116
                     CSSSelector selector = (CSSSelector) child;
 41  116
                     selector.compile(container);
 42  116
                     selectorList.add(selector);
 43  116
                 } else if (child instanceof CSSAction) {
 44  124
                     CSSAction action = (CSSAction) child;
 45  124
                     action.compile(container);
 46  124
                     Action actionAction = action.getAction();
 47  124
                     ArrayList<CSSAction> actions = ruleActions.get(actionAction);
 48  124
                     if (actions == null) {
 49  122
                         actions = new ArrayList<CSSAction>();
 50  122
                         ruleActions.put(actionAction, actions);
 51  
                     }
 52  124
                     actions.add(action);
 53  124
                 } else {
 54  0
                     throw new InternalError();
 55  
                 }
 56  240
             }
 57  97
             for (Map.Entry<Action, ArrayList<CSSAction>> entry: ruleActions.entrySet()) {
 58  122
                 Action actionAction = entry.getKey();
 59  122
                 List<CompiledRules.Entry> actionEntries = entriesPerAction.get(actionAction);
 60  122
                 if (actionEntries == null) {
 61  88
                     actionEntries = new ArrayList<CompiledRules.Entry>();
 62  88
                     entriesPerAction.put(actionAction, actionEntries);
 63  
                 }
 64  122
                 for (CSSSelector selector: selectorList) {
 65  140
                     actionEntries.add(new CompiledRules.Entry(selector, entry.getValue()));
 66  
                 }
 67  122
             }
 68  97
         }
 69  22
         return new CompiledRules(this, entriesPerAction);
 70  
     }
 71  
 
 72  
     void addSetting(String name, String value) {
 73  22
         if ("theme.default".equals(name)) {
 74  22
             defaultTheme = value;
 75  
         }
 76  22
     }
 77  
 
 78  
     public String getDefaultTheme() {
 79  295
         return defaultTheme;
 80  
     }
 81  
 }