View Javadoc
1   /*
2    * Copyright (c) 2002-2025 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.css;
16  
17  import java.io.Serializable;
18  
19  import org.htmlunit.cssparser.dom.MediaListImpl;
20  import org.htmlunit.cssparser.parser.media.MediaQuery;
21  
22  /**
23   * A MediaList.
24   *
25   * @author Daniel Gredler
26   * @author Ronald Brill
27   * @author Ahmed Ashour
28   * @author Frank Danek
29   */
30  public class CssMediaList implements Serializable {
31  
32      private final MediaListImpl wrappedList_;
33  
34      /**
35       * Creates a new instance.
36       * @param wrappedList the wrapped media list that this host object exposes
37       */
38      public CssMediaList(final MediaListImpl wrappedList) {
39          wrappedList_ = wrappedList;
40      }
41  
42      /**
43       * Returns the item or items corresponding to the specified index or key.
44       * @param index the index or key corresponding to the element or elements to return
45       * @return the element or elements corresponding to the specified index or key
46       */
47      public MediaQuery getMediaQuery(final int index) {
48          if (index < 0 || index >= getLength()) {
49              return null;
50          }
51          return wrappedList_.mediaQuery(index);
52      }
53  
54      /**
55       * Returns the number of media in the list.
56       * @return the number of media in the list
57       */
58      public int getLength() {
59          return wrappedList_.getLength();
60      }
61  
62      /**
63       * The parsable textual representation of the media list.
64       * This is a comma-separated list of media.
65       * @return the parsable textual representation.
66       */
67      public String getMediaText() {
68          return wrappedList_.getMediaText();
69      }
70  }