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.dom;
020:
021: import org.apache.batik.css.engine.CSSEngine;
022: import org.apache.batik.css.engine.StyleDeclaration;
023: import org.apache.batik.css.engine.StyleDeclarationProvider;
024: import org.apache.batik.css.engine.value.Value;
025:
026: /**
027: * A class for SVG style declarations that store their properties in a
028: * {@link org.apache.batik.css.engine.StyleDeclaration}.
029: *
030: * @author <a href="mailto:cam%40mcc%2eid%2eau">Cameron McCormack</a>
031: * @version $Id: CSSOMStoredStyleDeclaration.java 475477 2006-11-15 22:44:28Z cam $
032: */
033: public abstract class CSSOMStoredStyleDeclaration extends
034: CSSOMSVGStyleDeclaration implements
035: CSSOMStyleDeclaration.ValueProvider,
036: CSSOMStyleDeclaration.ModificationHandler,
037: StyleDeclarationProvider {
038:
039: /**
040: * The object storing the properties.
041: */
042: protected StyleDeclaration declaration;
043:
044: /**
045: * Creates a new CSSOMStoredStyleDeclaration.
046: */
047: public CSSOMStoredStyleDeclaration(CSSEngine eng) {
048: super (null, null, eng);
049: valueProvider = this ;
050: setModificationHandler(this );
051: }
052:
053: /**
054: * Returns the object storing the properties of this style declaration.
055: */
056: public StyleDeclaration getStyleDeclaration() {
057: return declaration;
058: }
059:
060: /**
061: * Sets the object storing the properties of this style declaration.
062: */
063: public void setStyleDeclaration(StyleDeclaration sd) {
064: declaration = sd;
065: }
066:
067: // ValueProvider /////////////////////////////////////////////////////////
068:
069: /**
070: * Returns the current value associated with this object.
071: */
072: public Value getValue(String name) {
073: int idx = cssEngine.getPropertyIndex(name);
074: for (int i = 0; i < declaration.size(); i++) {
075: if (idx == declaration.getIndex(i)) {
076: return declaration.getValue(i);
077: }
078: }
079: return null;
080: }
081:
082: /**
083: * Tells whether the given property is important.
084: */
085: public boolean isImportant(String name) {
086: int idx = cssEngine.getPropertyIndex(name);
087: for (int i = 0; i < declaration.size(); i++) {
088: if (idx == declaration.getIndex(i)) {
089: return declaration.getPriority(i);
090: }
091: }
092: return false;
093: }
094:
095: /**
096: * Returns the text of the declaration.
097: */
098: public String getText() {
099: return declaration.toString(cssEngine);
100: }
101:
102: /**
103: * Returns the length of the declaration.
104: */
105: public int getLength() {
106: return declaration.size();
107: }
108:
109: /**
110: * Returns the value at the given.
111: */
112: public String item(int idx) {
113: return cssEngine.getPropertyName(declaration.getIndex(idx));
114: }
115: }
|