001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.css.engine.value;
020:
021: import org.w3c.dom.DOMException;
022: import org.w3c.dom.css.CSSValue;
023:
024: /**
025: * This class represents a list of values.
026: *
027: * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
028: * @version $Id: ListValue.java 476924 2006-11-19 21:13:26Z dvholten $
029: */
030: public class ListValue extends AbstractValue {
031:
032: /**
033: * The length of the list.
034: */
035: protected int length;
036:
037: /**
038: * The items.
039: */
040: protected Value[] items = new Value[5];
041:
042: /**
043: * The list separator.
044: */
045: protected char separator = ',';
046:
047: /**
048: * Creates a ListValue.
049: */
050: public ListValue() {
051: }
052:
053: /**
054: * Creates a ListValue with the given separator.
055: */
056: public ListValue(char s) {
057: separator = s;
058: }
059:
060: /**
061: * Returns the separator used for this list.
062: */
063: public char getSeparatorChar() {
064: return separator;
065: }
066:
067: /**
068: * Implements {@link Value#getCssValueType()}.
069: */
070: public short getCssValueType() {
071: return CSSValue.CSS_VALUE_LIST;
072: }
073:
074: /**
075: * A string representation of the current value.
076: */
077: public String getCssText() {
078: StringBuffer sb = new StringBuffer(length * 8);
079: if (length > 0) {
080: sb.append(items[0].getCssText());
081: }
082: for (int i = 1; i < length; i++) {
083: sb.append(separator);
084: sb.append(items[i].getCssText());
085: }
086: return sb.toString();
087: }
088:
089: /**
090: * Implements {@link Value#getLength()}.
091: */
092: public int getLength() throws DOMException {
093: return length;
094: }
095:
096: /**
097: * Implements {@link Value#item(int)}.
098: */
099: public Value item(int index) throws DOMException {
100: return items[index];
101: }
102:
103: /**
104: * Returns a printable representation of this value.
105: */
106: public String toString() {
107: return getCssText();
108: }
109:
110: /**
111: * Appends an item to the list.
112: */
113: public void append(Value v) {
114: if (length == items.length) {
115: Value[] t = new Value[length * 2];
116: System.arraycopy(items, 0, t, 0, length);
117: items = t;
118: }
119: items[length++] = v;
120: }
121: }
|