KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > steadystate > css > dom > CSSStyleSheetListImpl


1 /*
2  * CSSStyleSheetListImpl.java
3  *
4  * Created on 22. Februar 2005, 22:04
5  */

6
7 package com.steadystate.css.dom;
8
9 import java.util.Iterator JavaDoc;
10 import java.util.List JavaDoc;
11 import java.util.Vector JavaDoc;
12
13 import org.w3c.dom.css.CSSStyleSheet;
14 import org.w3c.dom.stylesheets.StyleSheet;
15 import org.w3c.dom.stylesheets.StyleSheetList;
16
17 /**
18  *
19  * @author koch
20  * @version $Release$
21  */

22 public class CSSStyleSheetListImpl implements StyleSheetList
23 {
24     
25     private List JavaDoc cssStyleSheets; // List of CSSStyleSheet
26

27     private List JavaDoc getCSSStyleSheets()
28     {
29         if (this.cssStyleSheets == null)
30         {
31             this.cssStyleSheets = new Vector JavaDoc();
32         }
33         return this.cssStyleSheets;
34     }
35     
36
37     /** Creates a new instance of CSSStyleSheetListImpl */
38     public CSSStyleSheetListImpl()
39     {
40     }
41     
42
43     // start StyleSheetList
44
public int getLength()
45     {
46         return this.getCSSStyleSheets().size();
47     }
48     
49     public StyleSheet item(int index)
50     {
51         return (StyleSheet) this.getCSSStyleSheets().get(index);
52     }
53     
54     /**
55      * Adds a CSSStyleSheet.
56      *
57      * @param cssStyleSheet the CSSStyleSheet
58      */

59     public void add(CSSStyleSheet cssStyleSheet)
60     {
61         this.getCSSStyleSheets().add(cssStyleSheet);
62     }
63     // end StyleSheetList
64

65     /**
66      * Merges all StyleSheets in this list into one.
67      *
68      * @return the new (merged) StyleSheet
69      */

70     public StyleSheet merge()
71     {
72         CSSStyleSheetImpl merged = new CSSStyleSheetImpl();
73         CSSRuleListImpl cssRuleList = new CSSRuleListImpl();
74         Iterator JavaDoc it = this.getCSSStyleSheets().iterator();
75         while (it.hasNext())
76         {
77             CSSStyleSheetImpl cssStyleSheet = (CSSStyleSheetImpl) it.next();
78             CSSMediaRuleImpl cssMediaRule =
79                 new CSSMediaRuleImpl(merged, null, cssStyleSheet.getMedia());
80             cssMediaRule.setRuleList(
81                 (CSSRuleListImpl) cssStyleSheet.getCssRules());
82             cssRuleList.add(cssMediaRule);
83         }
84         merged.setRuleList(cssRuleList);
85         merged.setMedia("all");
86         return merged;
87     }
88     
89 }
90
Popular Tags