Skip to main content
summaryrefslogtreecommitdiffstats
blob: a84b3b1a029d5786743ae4b25fc161be95d21888 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*******************************************************************************
 * Copyright (c) 2004, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.css.core.internal.document;



import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
import org.w3c.dom.DOMException;
import org.w3c.dom.stylesheets.MediaList;


/**
 * 
 */
class MediaListImpl extends CSSRegionContainer implements MediaList {

	int mediumCounter;

	/**
	 * MediaListImpl constructor comment.
	 */
	MediaListImpl() {
		super();
	}

	/**
	 * MediaListImpl constructor comment.
	 */
	MediaListImpl(MediaListImpl that) {
		super(that);
	}

	/**
	 * Adds the medium <code>newMedium</code> to the end of the list. If the
	 * <code>newMedium</code> is already used, it is first removed.
	 * 
	 * @param newMediumThe
	 *            new medium to add.
	 * @exception DOMException
	 *                INVALID_CHARACTER_ERR: If the medium contains characters
	 *                that are invalid in the underlying style language. <br>
	 *                NO_MODIFICATION_ALLOWED_ERR: Raised if this list is
	 *                readonly.
	 */
	public void appendMedium(String newMedium) throws DOMException {
		if (newMedium == null)
			return;

		CSSNodeListImpl m = getMedia();
		for (int i = 0; i != m.getLength(); i++) {
			if (newMedium.equals(item(i)))
				return;
		}

		setAttribute("medium" + Integer.toString(mediumCounter++), newMedium);//$NON-NLS-1$
	}

	public ICSSNode cloneNode(boolean deep) {
		MediaListImpl cloned = new MediaListImpl(this);
		return cloned;
	}

	/**
	 * Deletes the medium indicated by <code>oldMedium</code> from the list.
	 * 
	 * @param oldMediumThe
	 *            medium to delete in the media list.
	 * @exception DOMException
	 *                NO_MODIFICATION_ALLOWED_ERR: Raised if this list is
	 *                readonly. <br>
	 *                NOT_FOUND_ERR: Raised if <code>oldMedium</code> is not
	 *                in the list.
	 */
	public void deleteMedium(String oldMedium) throws DOMException {
		for (int i = 0; i != getLength(); i++) {
			if (oldMedium.equals(item(i))) {
				removeAttributeNode((CSSAttrImpl) fAttrs.item(i));
			}
		}
	}

	/**
	 * The number of media in the list. The range of valid media is
	 * <code>0</code> to <code>length-1</code> inclusive.
	 */
	public int getLength() {
		return getMedia().getLength();
	}

	/**
	 * @return CSSNodeListImpl
	 */
	CSSNodeListImpl getMedia() {
		if (fAttrs == null)
			fAttrs = new CSSNamedNodeMapImpl();
		return fAttrs;
	}

	/**
	 * The parsable textual representation of the media list. This is a
	 * comma-separated list of media.
	 * 
	 * @exception DOMException
	 *                SYNTAX_ERR: Raised if the specified string value has a
	 *                syntax error and is unparsable. <br>
	 *                NO_MODIFICATION_ALLOWED_ERR: Raised if this media list
	 *                is readonly.
	 */
	public String getMediaText() {
		return getCssText();
	}

	/**
	 * Insert the method's description here. Creation date: (2001/01/17
	 * 18:50:29)
	 * 
	 * @return short
	 */
	public short getNodeType() {
		return MEDIALIST_NODE;
	}

	/**
	 * Returns the <code>index</code> th in the list. If <code>index</code>
	 * is greater than or equal to the number of media in the list, this
	 * returns <code>null</code>.
	 * 
	 * @param index
	 *            Index into the collection.
	 * @return The medium at the <code>index</code> th position in the
	 *         <code>MediaList</code>, or <code>null</code> if that is
	 *         not a valid index.
	 */
	public String item(int index) {
		if (index < 0 || getLength() <= index)
			return null;

		return ((CSSAttrImpl) getMedia().item(index)).getValue();
	}

	/**
	 * setMediaText method comment.
	 */
	public void setMediaText(String mediaText) throws DOMException {
		setCssText(mediaText);
	}
}

Back to the top