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.dom.svg;
020:
021: import org.apache.batik.dom.AbstractDocument;
022: import org.apache.batik.dom.util.DoublyIndexedTable;
023: import org.apache.batik.dom.util.XLinkSupport;
024: import org.apache.batik.dom.util.XMLSupport;
025: import org.apache.batik.util.SVGTypes;
026:
027: import org.w3c.dom.Node;
028: import org.w3c.dom.svg.SVGAnimatedLength;
029: import org.w3c.dom.svg.SVGElementInstance;
030: import org.w3c.dom.svg.SVGUseElement;
031:
032: /**
033: * This class implements {@link org.w3c.dom.svg.SVGUseElement}.
034: *
035: * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
036: * @version $Id: SVGOMUseElement.java 489964 2006-12-24 01:30:23Z cam $
037: */
038: public class SVGOMUseElement extends SVGURIReferenceGraphicsElement
039: implements SVGUseElement {
040:
041: /**
042: * Table mapping XML attribute names to TraitInformation objects.
043: */
044: protected static DoublyIndexedTable xmlTraitInformation;
045: static {
046: DoublyIndexedTable t = new DoublyIndexedTable(
047: SVGURIReferenceGraphicsElement.xmlTraitInformation);
048: t.put(null, SVG_X_ATTRIBUTE, new TraitInformation(true,
049: SVGTypes.TYPE_LENGTH, PERCENTAGE_VIEWPORT_WIDTH));
050: t.put(null, SVG_Y_ATTRIBUTE, new TraitInformation(true,
051: SVGTypes.TYPE_LENGTH, PERCENTAGE_VIEWPORT_HEIGHT));
052: t.put(null, SVG_WIDTH_ATTRIBUTE, new TraitInformation(true,
053: SVGTypes.TYPE_LENGTH, PERCENTAGE_VIEWPORT_WIDTH));
054: t.put(null, SVG_HEIGHT_ATTRIBUTE, new TraitInformation(true,
055: SVGTypes.TYPE_LENGTH, PERCENTAGE_VIEWPORT_HEIGHT));
056: xmlTraitInformation = t;
057: }
058:
059: /**
060: * The attribute initializer.
061: */
062: protected static final AttributeInitializer attributeInitializer;
063: static {
064: attributeInitializer = new AttributeInitializer(4);
065: attributeInitializer.addAttribute(
066: XMLSupport.XMLNS_NAMESPACE_URI, null, "xmlns:xlink",
067: XLinkSupport.XLINK_NAMESPACE_URI);
068: attributeInitializer.addAttribute(
069: XLinkSupport.XLINK_NAMESPACE_URI, "xlink", "type",
070: "simple");
071: attributeInitializer.addAttribute(
072: XLinkSupport.XLINK_NAMESPACE_URI, "xlink", "show",
073: "embed");
074: attributeInitializer.addAttribute(
075: XLinkSupport.XLINK_NAMESPACE_URI, "xlink", "actuate",
076: "onLoad");
077: }
078:
079: /**
080: * The 'x' attribute value.
081: */
082: protected SVGOMAnimatedLength x;
083:
084: /**
085: * The 'y' attribute value.
086: */
087: protected SVGOMAnimatedLength y;
088:
089: /**
090: * The 'width' attribute value.
091: */
092: protected SVGOMAnimatedLength width;
093:
094: /**
095: * The 'height' attribute value.
096: */
097: protected SVGOMAnimatedLength height;
098:
099: /**
100: * Store the shadow tree of the use element.
101: */
102: protected SVGOMUseShadowRoot shadowTree;
103:
104: /**
105: * Creates a new SVGOMUseElement object.
106: */
107: protected SVGOMUseElement() {
108: }
109:
110: /**
111: * Creates a new SVGOMUseElement object.
112: * @param prefix The namespace prefix.
113: * @param owner The owner document.
114: */
115: public SVGOMUseElement(String prefix, AbstractDocument owner) {
116: super (prefix, owner);
117: initializeLiveAttributes();
118: }
119:
120: /**
121: * Initializes all live attributes for this element.
122: */
123: protected void initializeAllLiveAttributes() {
124: super .initializeAllLiveAttributes();
125: initializeLiveAttributes();
126: }
127:
128: /**
129: * Initializes the live attribute values of this element.
130: */
131: private void initializeLiveAttributes() {
132: x = createLiveAnimatedLength(null, SVG_X_ATTRIBUTE,
133: SVG_USE_X_DEFAULT_VALUE,
134: SVGOMAnimatedLength.HORIZONTAL_LENGTH, false);
135: y = createLiveAnimatedLength(null, SVG_Y_ATTRIBUTE,
136: SVG_USE_Y_DEFAULT_VALUE,
137: SVGOMAnimatedLength.VERTICAL_LENGTH, false);
138: width = createLiveAnimatedLength(null, SVG_WIDTH_ATTRIBUTE,
139: null, SVGOMAnimatedLength.HORIZONTAL_LENGTH, true);
140: height = createLiveAnimatedLength(null, SVG_HEIGHT_ATTRIBUTE,
141: null, SVGOMAnimatedLength.VERTICAL_LENGTH, true);
142: }
143:
144: /**
145: * <b>DOM</b>: Implements {@link Node#getLocalName()}.
146: */
147: public String getLocalName() {
148: return SVG_USE_TAG;
149: }
150:
151: /**
152: * <b>DOM</b>: Implements {@link SVGUseElement#getX()}.
153: */
154: public SVGAnimatedLength getX() {
155: return x;
156: }
157:
158: /**
159: * <b>DOM</b>: Implements {@link SVGUseElement#getY()}.
160: */
161: public SVGAnimatedLength getY() {
162: return y;
163: }
164:
165: /**
166: * <b>DOM</b>: Implements {@link SVGUseElement#getWidth()}.
167: */
168: public SVGAnimatedLength getWidth() {
169: return width;
170: }
171:
172: /**
173: * <b>DOM</b>: Implements {@link SVGUseElement#getHeight()}.
174: */
175: public SVGAnimatedLength getHeight() {
176: return height;
177: }
178:
179: /**
180: * <b>DOM</b>: Implements {@link SVGUseElement#getInstanceRoot()}.
181: */
182: public SVGElementInstance getInstanceRoot() {
183: throw new UnsupportedOperationException(
184: "SVGUseElement.getInstanceRoot is not implemented"); // XXX
185: }
186:
187: /**
188: * <b>DOM</b>: Implements {@link SVGUseElement#getAnimatedInstanceRoot()}.
189: */
190: public SVGElementInstance getAnimatedInstanceRoot() {
191: throw new UnsupportedOperationException(
192: "SVGUseElement.getAnimatedInstanceRoot is not implemented"); // XXX
193: }
194:
195: // CSSNavigableNode ///////////////////////////////////////////////
196:
197: /**
198: * Returns the CSS first child node of this node.
199: */
200: public Node getCSSFirstChild() {
201: if (shadowTree != null) {
202: return shadowTree.getFirstChild();
203: }
204: return null;
205: }
206:
207: /**
208: * Returns the CSS last child of this stylable element.
209: */
210: public Node getCSSLastChild() {
211: // use element shadow trees only ever have a single element
212: return getCSSFirstChild();
213: }
214:
215: /**
216: * Returns whether this node is the root of a (conceptual) hidden tree
217: * that selectors will not work across. Returns true here, since CSS
218: * selectors cannot work in the conceptual cloned sub-tree of the
219: * content referenced by the 'use' element.
220: */
221: public boolean isHiddenFromSelectors() {
222: return true;
223: }
224:
225: /**
226: * Sets the shadow tree for this 'use' element.
227: */
228: public void setUseShadowTree(SVGOMUseShadowRoot r) {
229: shadowTree = r;
230: }
231:
232: /**
233: * Returns the AttributeInitializer for this element type.
234: * @return null if this element has no attribute with a default value.
235: */
236: protected AttributeInitializer getAttributeInitializer() {
237: return attributeInitializer;
238: }
239:
240: /**
241: * Returns a new uninitialized instance of this object's class.
242: */
243: protected Node newNode() {
244: return new SVGOMUseElement();
245: }
246:
247: /**
248: * Returns the table of TraitInformation objects for this element.
249: */
250: protected DoublyIndexedTable getTraitInformationTable() {
251: return xmlTraitInformation;
252: }
253: }
|