You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SVGElementImpl.java 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*-- $Id$ --
  2. ============================================================================
  3. The Apache Software License, Version 1.1
  4. ============================================================================
  5. Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modifica-
  7. tion, are permitted provided that the following conditions are met:
  8. 1. Redistributions of source code must retain the above copyright notice,
  9. this list of conditions and the following disclaimer.
  10. 2. Redistributions in binary form must reproduce the above copyright notice,
  11. this list of conditions and the following disclaimer in the documentation
  12. and/or other materials provided with the distribution.
  13. 3. The end-user documentation included with the redistribution, if any, must
  14. include the following acknowledgment: "This product includes software
  15. developed by the Apache Software Foundation (http://www.apache.org/)."
  16. Alternately, this acknowledgment may appear in the software itself, if
  17. and wherever such third-party acknowledgments normally appear.
  18. 4. The names "FOP" and "Apache Software Foundation" must not be used to
  19. endorse or promote products derived from this software without prior
  20. written permission. For written permission, please contact
  21. apache@apache.org.
  22. 5. Products derived from this software may not be called "Apache", nor may
  23. "Apache" appear in their name, without prior written permission of the
  24. Apache Software Foundation.
  25. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  26. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  27. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  28. APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  29. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  30. DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  31. OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  32. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  34. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. This software consists of voluntary contributions made by many individuals
  36. on behalf of the Apache Software Foundation and was originally created by
  37. James Tauber <jtauber@jtauber.com>. For more information on the Apache
  38. Software Foundation, please see <http://www.apache.org/>.
  39. */
  40. package org.apache.fop.dom.svg;
  41. import org.apache.fop.datatypes.*;
  42. import org.w3c.dom.css.CSSStyleDeclaration;
  43. import org.w3c.dom.css.CSSValue;
  44. import org.w3c.dom.svg.*;
  45. import org.w3c.dom.*;
  46. import java.util.*;
  47. public abstract class SVGElementImpl extends ElementImpl implements SVGElement {
  48. String idString = "";
  49. CSSStyleDeclaration styleDec;
  50. public String getId()
  51. {
  52. return idString;
  53. }
  54. public void setId(String id)
  55. {
  56. idString = id;
  57. }
  58. public SVGSVGElement getOwnerSVGElement( )
  59. {
  60. return null;
  61. }
  62. public SVGElement getViewportElement( )
  63. {
  64. return null;
  65. }
  66. public SVGAnimatedString getClassName( )
  67. {
  68. return null;
  69. }
  70. public void setClassName( SVGAnimatedString className )
  71. {
  72. }
  73. public CSSValue getPresentationAttribute ( String name )
  74. {
  75. CSSStyleDeclaration style;
  76. style = getStyle();
  77. CSSValue val;
  78. val = style.getPropertyCSSValue(name);
  79. if(val == null) {
  80. // get "style" element style for this
  81. SVGSVGElement svg = getOwnerSVGElement();
  82. }
  83. if(val == null) {
  84. // get element parents style
  85. Node par = getParentNode();
  86. if(par instanceof SVGStylable) {
  87. val = ((SVGStylable)par).getPresentationAttribute(name);
  88. }
  89. }
  90. return val;
  91. }
  92. public CSSValue getAnimatedPresentationAttribute ( String name )
  93. {
  94. return getPresentationAttribute(name);
  95. }
  96. public CSSStyleDeclaration getStyle( )
  97. {
  98. return styleDec;
  99. }
  100. public void setStyle(CSSStyleDeclaration dec)
  101. {
  102. styleDec = dec;
  103. }
  104. /* SVGElement parent = null;
  105. public SVGElement getGraphicParent()
  106. {
  107. return parent;
  108. }
  109. public void setParent(SVGElement graph)
  110. {
  111. parent = graph;
  112. }*/
  113. /* Hashtable style = null;
  114. public void setStyle(Hashtable st)
  115. {
  116. style = st;
  117. }
  118. public Hashtable oldgetStyle()
  119. {
  120. Hashtable ret = null;
  121. if(parent != null) {
  122. ret = parent.oldgetStyle();
  123. if(ret != null)
  124. ret = (Hashtable)ret.clone();
  125. }
  126. if(ret == null) {
  127. ret = style;
  128. } else {
  129. if(style != null) {
  130. for(Enumeration e = style.keys(); e.hasMoreElements(); ) {
  131. String str = (String)e.nextElement();
  132. ret.put(str, style.get(str));
  133. }
  134. }
  135. }
  136. return ret;
  137. }
  138. Hashtable defs = new Hashtable();
  139. public void addDefs(Hashtable table)
  140. {
  141. for(Enumeration e = table.keys(); e.hasMoreElements(); ) {
  142. String str = (String)e.nextElement();
  143. defs.put(str, table.get(str));
  144. }
  145. }
  146. public Hashtable getDefs()
  147. {
  148. Hashtable ret = null;
  149. if(parent != null) {
  150. ret = parent.getDefs();
  151. if(ret != null)
  152. ret = (Hashtable)ret.clone();
  153. }
  154. if(ret == null) {
  155. ret = defs;
  156. } else {
  157. if(defs != null) {
  158. for(Enumeration e = defs.keys(); e.hasMoreElements(); ) {
  159. String str = (String)e.nextElement();
  160. ret.put(str, defs.get(str));
  161. }
  162. }
  163. }
  164. return ret;
  165. }
  166. public SVGElement locateDef(String str)
  167. {
  168. Object obj = null;
  169. if(defs != null) {
  170. obj = defs.get(str);
  171. }
  172. if(obj == null) {
  173. NodeList list = getChildNodes();
  174. for(int count = 0; count < list.getLength(); count++) {
  175. Object o = list.item(count);
  176. if(o instanceof SVGElement) {
  177. String s;
  178. s = ((SVGElement)o).getId();
  179. if(str.equals(s)) {
  180. obj = o;
  181. break;
  182. }
  183. }
  184. }
  185. }
  186. if(obj == null && parent != null) {
  187. obj = parent.locateDef(str);
  188. }
  189. return (SVGElement)obj;
  190. }
  191. Vector trans = null;
  192. public void setTransform(Vector tr)
  193. {
  194. trans = tr;
  195. }
  196. public Vector oldgetTransform()
  197. {
  198. return trans;
  199. /* Vector ret = null;
  200. if(parent != null) {
  201. ret = parent.oldgetTransform();
  202. if(ret != null)
  203. ret = (Vector)ret.clone();
  204. }
  205. if(ret == null) {
  206. ret = trans;
  207. } else {
  208. if(trans != null) {
  209. for(Enumeration e = trans.elements(); e.hasMoreElements(); ) {
  210. Object o = e.nextElement();
  211. ret.addElement(o);
  212. }
  213. }
  214. }
  215. return ret;*
  216. }
  217. */
  218. public SVGAnimatedBoolean getExternalResourcesRequired( )
  219. {
  220. return null;
  221. }
  222. public void setExternalResourcesRequired( SVGAnimatedBoolean externalResourcesRequired )
  223. {
  224. }
  225. }