01: /*
02: ItsNat Java Web Application Framework
03: Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
04: Author: Jose Maria Arranz Santamaria
05:
06: This program is free software: you can redistribute it and/or modify
07: it under the terms of the GNU Affero General Public License as published by
08: the Free Software Foundation, either version 3 of the License, or
09: (at your option) any later version. See the GNU Affero General Public
10: License for more details. See the copy of the GNU Affero General Public License
11: included in this program. If not, see <http://www.gnu.org/licenses/>.
12: */
13:
14: package org.itsnat.impl.core.css;
15:
16: import java.util.ArrayList;
17: import java.util.List;
18: import org.w3c.dom.DOMException;
19: import org.w3c.dom.css.CSSValue;
20: import org.w3c.dom.css.CSSValueList;
21: import org.itsnat.impl.core.css.lex.SourceCode;
22: import org.itsnat.impl.core.css.lex.Space;
23:
24: /**
25: *
26: * @author jmarranz
27: */
28: public class CSSValueListImpl extends CSSValueImpl implements
29: CSSValueList {
30: protected List values = new ArrayList();
31:
32: /** Creates a new instance of CSSValueListImpl */
33: public CSSValueListImpl(SourceCode cssTextCode, SourceCode[] parts,
34: int code, ObjectValueParent parent) {
35: super (cssTextCode, code, parent);
36:
37: rebuild(parts);
38: }
39:
40: public int getLength() {
41: return values.size();
42: }
43:
44: public CSSValue item(int index) {
45: return (CSSValue) values.get(index);
46: }
47:
48: public short getCssValueType() {
49: return CSS_VALUE_LIST;
50: }
51:
52: public void rebuild(SourceCode cssTextCode) {
53: values.clear();
54: SourceCode[] parts = cssTextCode.split(new Space(' '));
55: rebuild(parts);
56: }
57:
58: public void rebuild(SourceCode[] parts) {
59: values.clear();
60: for (int i = 0; i < parts.length; i++) {
61: CSSValueImpl item = CSSValueImpl.newCSSValue(parts[i], i,
62: this );
63: values.add(item);
64: }
65: }
66:
67: public Object getUpdatedChildObjectValueFromElement(
68: Object requester, int requesterCode) {
69: CSSValueListImpl current = (CSSValueListImpl) parent
70: .getUpdatedChildObjectValueFromElement(this , getCode());
71: if (current != this ) // Ha cambiado (si hubiera cambiado además el tipo de objeto fallaría el cast)
72: {
73: if (current.getLength() != getLength())
74: throw new DOMException(DOMException.INVALID_ACCESS_ERR,
75: "Changed the number of values"); // Ha cambiado el número de elementos
76:
77: return current.item(requesterCode);
78: } else
79: return requester;
80: }
81:
82: public void notifyToElementChangedCSSText(SourceCode cssText,
83: Object requester) {
84: // Basta que haya cambiado uno para regenerar la cadena con todos los elementos
85: StringBuffer parentCssText = new StringBuffer();
86: for (int i = 0; i < values.size(); i++) {
87: if (i != 0)
88: parentCssText.append(" ");
89: CSSValueImpl valueItem = (CSSValueImpl) values.get(i);
90: parentCssText.append(valueItem.getCssTextSourceCode(false)
91: .toString());
92: }
93:
94: this .cssTextCode = new SourceCode(parentCssText.toString());
95: parent.notifyToElementChangedCSSText(cssTextCode, this);
96: }
97: }
|