Source code: com/steadystate/css/dom/MediaListImpl.java
1 /*
2 * MediaListImpl.java
3 *
4 * Steady State CSS2 Parser
5 *
6 * Copyright (C) 1999, 2002 Steady State Software Ltd. All rights reserved.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 * To contact the authors of the library, write to Steady State Software Ltd.,
23 * 49 Littleworth, Wing, Buckinghamshire, LU7 0JX, England
24 *
25 * http://www.steadystate.com/css/
26 * mailto:css@steadystate.co.uk
27 *
28 * $Id: MediaListImpl.java,v 1.1.1.1 2003/12/28 21:22:55 davidsch Exp $
29 */
30
31 package com.steadystate.css.dom;
32
33 import java.io.Serializable;
34 import java.util.*;
35 import org.w3c.dom.*;
36 import org.w3c.dom.stylesheets.*;
37 import org.w3c.css.sac.*;
38
39 /**
40 *
41 * @author David Schweinsberg
42 * @version $Release$
43 */
44 public class MediaListImpl implements MediaList, Serializable {
45
46 private Vector _media = new Vector();
47
48 public MediaListImpl(SACMediaList mediaList) {
49 for (int i = 0; i < mediaList.getLength(); i++) {
50 _media.addElement(mediaList.item(i));
51 }
52 }
53
54 public String getMediaText() {
55 StringBuffer sb = new StringBuffer("");
56 for (int i = 0; i < _media.size(); i++) {
57 sb.append(_media.elementAt(i).toString());
58 if (i < _media.size() - 1) {
59 sb.append( ", " );
60 }
61 }
62 return sb.toString();
63 }
64
65 public void setMediaText(String mediaText) throws DOMException {
66 /*
67 try
68 {
69 StringReader sr = new StringReader( mediaText );
70 CSS2Parser parser = new CSS2Parser( sr );
71 ASTMediaList ml = parser.mediaList();
72 _media = ml._media;
73 }
74 catch( ParseException e )
75 {
76 throw new DOMExceptionImpl(
77 DOMException.SYNTAX_ERR,
78 DOMExceptionImpl.SYNTAX_ERROR,
79 e.getMessage() );
80 }
81 */
82 }
83
84 public int getLength() {
85 return _media.size();
86 }
87
88 public String item(int index) {
89 return (index < _media.size()) ? (String) _media.elementAt(index) : null;
90 }
91
92 public void deleteMedium(String oldMedium) throws DOMException {
93 for (int i = 0; i < _media.size(); i++) {
94 String str = (String) _media.elementAt(i);
95 if (str.equalsIgnoreCase(oldMedium)) {
96 _media.removeElementAt(i);
97 return;
98 }
99 }
100 throw new DOMExceptionImpl(
101 DOMException.NOT_FOUND_ERR,
102 DOMExceptionImpl.NOT_FOUND);
103 }
104
105 public void appendMedium(String newMedium) throws DOMException {
106 _media.addElement(newMedium);
107 }
108
109 public String toString() {
110 return getMediaText();
111 }
112 }