You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by hi...@apache.org on 2001/05/10 15:36:06 UTC

cvs commit: xml-batik/sources/org/apache/batik/extension ExtensionElement.java StylableExtensionElement.java

hillion     01/05/10 06:36:06

  Modified:    sources/org/apache/batik/dom/svg SVGOMDocument.java
  Added:       sources/org/apache/batik/extension ExtensionElement.java
                        StylableExtensionElement.java
  Log:
  - Element factories now stored in a non-static table,
  - added support classes to implement custom elements.
  
  Revision  Changes    Path
  1.34      +7 -7      xml-batik/sources/org/apache/batik/dom/svg/SVGOMDocument.java
  
  Index: SVGOMDocument.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/dom/svg/SVGOMDocument.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- SVGOMDocument.java	2001/04/29 08:24:54	1.33
  +++ SVGOMDocument.java	2001/05/10 13:36:03	1.34
  @@ -67,7 +67,7 @@
    * This class implements {@link org.w3c.dom.svg.SVGDocument}.
    *
    * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
  - * @version $Id: SVGOMDocument.java,v 1.33 2001/04/29 08:24:54 dino Exp $
  + * @version $Id: SVGOMDocument.java,v 1.34 2001/05/10 13:36:03 hillion Exp $
    */
   public class SVGOMDocument
       extends    AbstractDocument
  @@ -90,13 +90,13 @@
       /**
        * The custom elements factories.
        */
  -    protected static HashTable customFactories;
  +    protected HashTable customFactories;
   
       /**
        * The SVG element factories.
        */
  -    protected static HashTable factories = new HashTable();
  -    static {
  +    protected HashTable factories = new HashTable();
  +    {
           factories.put(SVG_A_TAG,
                         new AElementFactory());
   
  @@ -344,9 +344,9 @@
       /**
        * Allows the user to register a new element factory.
        */
  -    public static void registerCustomElementFactory(String namespaceURI,
  -                                                    String localName,
  -                                                    ElementFactory factory) {
  +    public void registerCustomElementFactory(String namespaceURI,
  +                                             String localName,
  +                                             ElementFactory factory) {
           if (customFactories == null) {
               customFactories = new HashTable();
           }
  
  
  
  1.1                  xml-batik/sources/org/apache/batik/extension/ExtensionElement.java
  
  Index: ExtensionElement.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included with this distribution in  *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.batik.extension;
  
  import org.apache.batik.css.ElementWithID;
  import org.apache.batik.css.ElementWithPseudoClass;
  import org.apache.batik.css.HiddenChildElement;
  import org.apache.batik.css.HiddenChildElementSupport;
  
  import org.apache.batik.dom.AbstractDocument;
  import org.apache.batik.dom.AbstractElement;
  
  import org.w3c.dom.DOMException;
  import org.w3c.dom.Element;
  import org.w3c.dom.Node;
  
  /**
   * This class implements the basic features an element must have in order
   * to be usable as a foreign element within an SVGOMDocument.
   *
   * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
   * @version $Id: ExtensionElement.java,v 1.1 2001/05/10 13:36:06 hillion Exp $
   */
  public abstract class ExtensionElement
      extends    AbstractElement
      implements ElementWithID,
                 ElementWithPseudoClass,
                 HiddenChildElement {
      
      /**
       * The element ID attribute name.
       */
      protected final static String ID_NAME = "id";
  
      /**
       * The parent element.
       */
      protected transient Element parentElement;
  
      /**
       * Creates a new Element object.
       */
      protected ExtensionElement() {
      }
  
      /**
       * Creates a new Element object.
       * @param name The element name, for validation purposes.
       * @param owner The owner document.
       */
      protected ExtensionElement(String name, AbstractDocument owner) {
          super(name, owner);
      }
      
      // HiddenChildElement //////////////////////////////////////////////////
  
      /**
       * The parent element of this element.
       */
      public Element getParentElement() {
          return parentElement;
      }
  
      /**
       * Sets the parent element.
       */
      public void setParentElement(Element elt) {
          parentElement = elt;
      }
  
      // ExtendedNode //////////////////////////////////////////////////
  
      /**
       * Tests whether this node is readonly.
       */
      public boolean isReadonly() {
          return false;
      }
  
      /**
       * Sets this node readonly attribute.
       */
      public void setReadonly(boolean v) {
      }
  
      // ElementWithID /////////////////////////////////////////////////
  
      /**
       * Sets the element ID attribute name.
       * @param uri The namespace uri.
       * @param s   The attribute local name.
       */
      public void setIDName(String uri, String s) {
          if (uri != null || s == null || !s.equals(ID_NAME)) {
  	    throw createDOMException
  		(DOMException.NO_MODIFICATION_ALLOWED_ERR,
  		 "id.name",
  		 new Object[] { s });
          }
      }
  
      /**
       * Returns the ID of this element or the empty string.
       */
      public String getID() {
          return getAttribute(ID_NAME);
      }
  
      // ElementWithPseudoClass ////////////////////////////////////////
  
      /**
       * Whether this element matches the given pseudo-class.
       * This methods supports the :first-child pseudo class.
       */
      public boolean matchPseudoClass(String pseudoClass) {
          if (pseudoClass.equals("first-child")) {
              Node n = getPreviousSibling();
              while (n != null && n.getNodeType() != ELEMENT_NODE) {
                  n = n.getPreviousSibling();
              }
              return n == null;
          }
          return false;
      }
  
  }
  
  
  
  1.1                  xml-batik/sources/org/apache/batik/extension/StylableExtensionElement.java
  
  Index: StylableExtensionElement.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included with this distribution in  *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.batik.extension;
  
  import org.apache.batik.css.ElementNonCSSPresentationalHints;
  import org.apache.batik.css.ExtendedElementCSSInlineStyle;
  
  import org.apache.batik.dom.AbstractDocument;
  import org.apache.batik.dom.svg.ElementNonCSSPresentationalHintsSupport;
  import org.apache.batik.dom.svg.SVGStylableSupport;
  import org.apache.batik.dom.util.OverrideStyleElement;
  
  import org.w3c.dom.css.CSSStyleDeclaration;
  
  /**
   * This class implements the basic features an element must have in order
   * to be usable as a foreign element within an SVGOMDocument, and the support
   * for both the 'style' attribute and the style attributes (ie: fill="red", ...).
   *
   * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
   * @version $Id: StylableExtensionElement.java,v 1.1 2001/05/10 13:36:06 hillion Exp $
   */
  public abstract class StylableExtensionElement
      extends    ExtensionElement
      implements OverrideStyleElement,
  	       ExtendedElementCSSInlineStyle,
  	       ElementNonCSSPresentationalHints {
      /**
       * Creates a new Element object.
       */
      protected StylableExtensionElement() {
      }
  
      /**
       * Creates a new Element object.
       * @param name The element name, for validation purposes.
       * @param owner The owner document.
       */
      protected StylableExtensionElement(String name, AbstractDocument owner) {
          super(name, owner);
      }
      
      /**
       * The stylable support.
       */
      protected SVGStylableSupport stylableSupport;
  
      /**
       * Returns stylableSupport different from null.
       */
      protected final SVGStylableSupport getStylableSupport() {
  	if (stylableSupport == null) {
  	    stylableSupport = new SVGStylableSupport();
  	}
  	return stylableSupport;
      }
  
      /**
       * Implements {@link
       * org.apache.batik.css.ExtendedElementCSSInlineStyle#hasStyle()}.
       */
      public boolean hasStyle() {
          return SVGStylableSupport.hasStyle(this);
      }
  
      /**
       * <b>DOM</b>: Implements {@link org.w3c.dom.svg.SVGStylable#getStyle()}.
       */
      public CSSStyleDeclaration getStyle() {
          return getStylableSupport().getStyle(this);
      }
  
      // OverrideStyleElement ///////////////////////////////////////////
  
      /**
       * Implements {@link
       * OverrideStyleElement#hasOverrideStyle(String)}.
       */
      public boolean hasOverrideStyle(String pseudoElt) {
  	return getStylableSupport().hasOverrideStyle(pseudoElt);
      }    
  
      /**
       * Implements {@link
       * OverrideStyleElement#getOverrideStyle(String)}.
       */
      public CSSStyleDeclaration getOverrideStyle(String pseudoElt) {
  	return getStylableSupport().getOverrideStyle(pseudoElt, this);
      }
  
      // ElementNonCSSPresentationalHints ////////////////////////////////////
  
      /**
       * Returns the translation of the non-CSS hints to the corresponding
       * CSS rules. The result can be null.
       */
      public CSSStyleDeclaration getNonCSSPresentationalHints() {
  	return ElementNonCSSPresentationalHintsSupport.
              getNonCSSPresentationalHints(this);
      }
  
      
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org