]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
added stuff to handle style sheets, selectors, styling
authorKeiron Liddle <keiron@apache.org>
Mon, 11 Sep 2000 03:14:05 +0000 (03:14 +0000)
committerKeiron Liddle <keiron@apache.org>
Mon, 11 Sep 2000 03:14:05 +0000 (03:14 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193689 13f79535-47bb-0310-9956-ffa450edef68

12 files changed:
src/org/apache/fop/dom/ElementImpl.java
src/org/apache/fop/dom/NodeImpl.java
src/org/apache/fop/dom/css/CSSStyleRuleImpl.java [new file with mode: 0644]
src/org/apache/fop/dom/css/CSSStyleSheetImpl.java [new file with mode: 0644]
src/org/apache/fop/dom/stylesheets/StyleSheetListImpl.java [new file with mode: 0644]
src/org/apache/fop/dom/svg/SVGAnimatedStringImpl.java [new file with mode: 0644]
src/org/apache/fop/dom/svg/SVGCircleElementImpl.java
src/org/apache/fop/dom/svg/SVGElementImpl.java
src/org/apache/fop/dom/svg/SVGPolygonElementImpl.java
src/org/apache/fop/dom/svg/SVGRectElementImpl.java
src/org/apache/fop/dom/svg/SVGSVGElementImpl.java
src/org/apache/fop/dom/svg/SVGStyleElementImpl.java

index 72f912c1ae91fb7120533c73a746ca5f02e706bc..9e10b6daadd34fc2bd85e7524abdc2a14128467a 100644 (file)
@@ -61,155 +61,12 @@ import java.util.*;
  *
  */
 public class ElementImpl extends NodeImpl implements Element {
-//     Vector childs = new Vector();
-//     Node parent = null;
-//     Document ownerDoc;
 
        public Node replaceChild(Node n, Node no)
        {
                return null;
        }
 
-/*    public String getNodeName()
-       {
-               return null;
-       }
-
-    public short getNodeType()
-       {
-               return 0;
-       }
-
-    public Node getParentNode()
-       {
-               return parent;
-       }
-
-    public NodeList getChildNodes()
-       {
-               return new NodeListImpl(childs);
-       }
-
-    public Node getFirstChild()
-       {
-               return null;
-       }
-
-    public Node getLastChild()
-       {
-               return null;
-       }
-
-    public Node getPreviousSibling()
-       {
-               return null;
-       }
-
-    public Node getNextSibling()
-       {
-               return null;
-       }
-
-    public NamedNodeMap getAttributes()
-       {
-               return null;
-       }
-
-    public Document getOwnerDocument()
-       {
-               return ownerDoc;
-       }
-
-    void setOwnerDocument(Document doc)
-    {
-        ownerDoc = doc;
-               NodeList nl = getChildNodes();
-               for(int count = 0; count < nl.getLength(); count++) {
-                       Node n = nl.item(count);
-                       if(n instanceof ElementImpl) {
-                               ((ElementImpl)n).setOwnerDocument(ownerDoc);
-                       }
-               }
-    }
-
-    public Node insertBefore(Node newChild,
-                                     Node refChild)
-                                     throws DOMException
-       {
-               return null;
-       }
-
-    public Node removeChild(Node oldChild)
-                                    throws DOMException
-       {
-               return null;
-       }
-
-    public Node appendChild(Node newChild)
-                                    throws DOMException
-       {
-               childs.addElement(newChild);
-               if(newChild instanceof ElementImpl) {
-                       ElementImpl ele = (ElementImpl)newChild;
-                       ele.parent = this;
-                       ele.setOwnerDocument(ownerDoc);
-               }
-               return newChild;
-       }
-
-    public boolean hasChildNodes()
-       {
-               return childs.size() > 0;
-       }
-
-    public Node cloneNode(boolean deep)
-       {
-               return null;
-       }
-
-    public void normalize()
-       {
-       }
-
-    public boolean supports(String feature,
-                                 String version)
-       {
-               return false;
-       }
-
-    public String getNamespaceURI()
-       {
-               return SVGDocumentImpl.namespaceURI;
-       }
-
-    public String getPrefix()
-       {
-               return "svg";
-       }
-
-    public void setPrefix(String prefix) throws DOMException
-       {
-       }
-
-    public String getLocalName()
-       {
-               return null;
-       }
-
-    public String getNodeValue() throws DOMException
-       {
-               return null;
-       }
-
-    public void setNodeValue(String nodeValue) throws DOMException
-       {
-       }
-
-    public String getTagName()
-       {
-               return null;
-       }
-*/
     public String getAttribute(String name)
        {
                return null;
@@ -242,7 +99,23 @@ public class ElementImpl extends NodeImpl implements Element {
 
     public NodeList getElementsByTagName(String name)
        {
-               return null;
+               NodeList nl = getChildNodes();
+               Vector eles = new Vector();
+               for(int count = 0; count < nl.getLength(); count++) {
+                       Node el = (Node)nl.item(count);
+                       if(el instanceof Element) {
+                               if(name.equals(((Element)el).getTagName())) {
+                                       eles.addElement(el);
+                               }
+                               NodeList subtags = ((Element)el).getElementsByTagName(name);
+                               for(int c = 0; c < subtags.getLength(); c++) {
+                                       Node node = (Node)subtags.item(c);
+                                       eles.addElement(node);
+                               }
+                       }
+               }
+               NodeList val = new NodeListImpl(eles);
+               return val;
        }
 
     public String getAttributeNS(String namespaceURI,
@@ -298,23 +171,3 @@ public class ElementImpl extends NodeImpl implements Element {
         return false;
     }
 }
-/*
-class NodeListImpl implements NodeList
-{
-       Vector vect = null;
-
-       NodeListImpl(Vector v)
-       {
-               vect = v;
-       }
-
-       public int getLength()
-       {
-               return vect.size();
-       }
-
-       public Node item(int i)
-       {
-               return (Node)vect.elementAt(i);
-       }
-}*/
index f8fe16c97bf5f15d57c43e4cca4c2fdb8773cfd1..eb20a7ecd76886b31da2c41d872aaec2a62ef34c 100644 (file)
@@ -92,21 +92,35 @@ public class NodeImpl implements Node {
 
     public Node getFirstChild()
        {
+               if(childs.size() > 0) {
+                       return (Node)childs.elementAt(0);
+               }
                return null;
        }
 
     public Node getLastChild()
        {
+               if(childs.size() > 0) {
+                       return (Node)childs.elementAt(childs.size() - 1);
+               }
                return null;
        }
 
     public Node getPreviousSibling()
        {
+               int ind = ((NodeImpl)parent).childs.indexOf(this);
+               if(ind > 0) {
+                       return (Node)((NodeImpl)parent).childs.elementAt(ind - 1);
+               }
                return null;
        }
 
     public Node getNextSibling()
        {
+               int ind = ((NodeImpl)parent).childs.indexOf(this);
+               if(ind + 1 < ((NodeImpl)parent).childs.size()) {
+                       return (Node)((NodeImpl)parent).childs.elementAt(ind + 1);
+               }
                return null;
        }
 
@@ -210,89 +224,6 @@ public class NodeImpl implements Node {
                return null;
        }
 
-/*    public String getAttribute(String name)
-       {
-               return null;
-       }
-
-    public void setAttribute(String name, String value) throws DOMException
-       {
-       }
-
-    public void removeAttribute(String name) throws DOMException
-       {
-       }
-
-    public Attr getAttributeNode(String name)
-       {
-               return null;
-       }
-
-    public Attr setAttributeNode(Attr newAttr)
-                                         throws DOMException
-       {
-               return null;
-       }
-
-    public Attr removeAttributeNode(Attr oldAttr)
-                                            throws DOMException
-       {
-               return null;
-       }
-
-    public NodeList getElementsByTagName(String name)
-       {
-               return null;
-       }
-
-    public String getAttributeNS(String namespaceURI,
-                                       String localName)
-       {
-               return null;
-       }
-
-    public void setAttributeNS(String namespaceURI,
-                                       String qualifiedName,
-                                       String value)
-                                       throws DOMException
-       {
-       }
-
-    public void removeAttributeNS(String namespaceURI,
-                                          String localName)
-                                          throws DOMException
-       {
-       }
-
-    public Attr getAttributeNodeNS(String namespaceURI,
-                                           String localName)
-       {
-               return null;
-       }
-
-    public Attr setAttributeNodeNS(Attr newAttr)
-                                           throws DOMException
-       {
-               return null;
-       }
-
-    public NodeList getElementsByTagNameNS(String namespaceURI,
-                                               String localName)
-       {
-               return null;
-       }
-
-    public boolean hasAttributeNS (String namespaceURI,
-                                   String localName)
-  {
-    return false;
-  }
-
-    public boolean hasAttribute (String name)
-  {
-    return false;
-  }
-*/
     public boolean hasAttributes()
     {
         return false;
diff --git a/src/org/apache/fop/dom/css/CSSStyleRuleImpl.java b/src/org/apache/fop/dom/css/CSSStyleRuleImpl.java
new file mode 100644 (file)
index 0000000..c035f60
--- /dev/null
@@ -0,0 +1,323 @@
+/*-- $Id$ -- 
+
+ ============================================================================
+                   The Apache Software License, Version 1.1
+ ============================================================================
+    Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
+ Redistribution and use in source and binary forms, with or without modifica-
+ tion, are permitted provided that the following conditions are met:
+ 1. Redistributions of  source code must  retain the above copyright  notice,
+    this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+    this list of conditions and the following disclaimer in the documentation
+    and/or other materials provided with the distribution.
+ 3. The end-user documentation included with the redistribution, if any, must
+    include  the following  acknowledgment:  "This product includes  software
+    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
+    Alternately, this  acknowledgment may  appear in the software itself,  if
+    and wherever such third-party acknowledgments normally appear.
+ 4. The names "FOP" and  "Apache Software Foundation"  must not be used to
+    endorse  or promote  products derived  from this  software without  prior
+    written permission. For written permission, please contact
+    apache@apache.org.
+ 5. Products  derived from this software may not  be called "Apache", nor may
+    "Apache" appear  in their name,  without prior written permission  of the
+    Apache Software Foundation.
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
+ APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
+ DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
+ ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
+ (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ This software  consists of voluntary contributions made  by many individuals
+ on  behalf of the Apache Software  Foundation and was  originally created by
+ James Tauber <jtauber@jtauber.com>. For more  information on the Apache 
+ Software Foundation, please see <http://www.apache.org/>.
+ */
+
+package org.apache.fop.dom.css;
+
+//import org.apache.fop.dom.svg.*;
+import org.w3c.dom.svg.*;
+
+import org.w3c.dom.css.*;
+import org.w3c.dom.*;
+import org.w3c.dom.stylesheets.*;
+
+import java.util.*;
+
+/**
+ *
+ *
+ */
+public class CSSStyleRuleImpl implements CSSStyleRule {
+    String seltext;
+    String cssText;
+    CSSStyleDeclaration style;
+    CSSStyleSheet styleSheet;
+    Vector selectors = new Vector();
+
+       public CSSStyleRuleImpl(CSSStyleSheet styleSheet)
+       {
+           this.styleSheet = styleSheet;
+       }
+
+    public String getSelectorText()
+    {
+        return seltext;
+    }
+
+    /**
+     * Selectors are comma separated values (except for attributes)
+     * of all the selectors for the style.
+     */
+    public void setSelectorText(String selectorText)
+    {
+        seltext = selectorText;
+        parseSelector();
+    }
+
+    protected void parseSelector()
+    {
+        // need to handle "," in attribute selectors
+        StringTokenizer st = new StringTokenizer(seltext, ",");
+        while(st.hasMoreTokens()) {
+            String sel = st.nextToken().trim();
+            StringTokenizer subt = new StringTokenizer(sel, " \t\n\r");
+            Selector last = null;
+            Selector current = null;
+            int compoundstate = 0;
+            while(subt.hasMoreTokens()) {
+                String str = subt.nextToken().trim();
+                current = new Selector();
+                boolean compounding = false;
+                if(str.equals("*")) {
+                    // all
+                    current.type = Selector.ALL;
+                    current.value = "*";
+                } else if(str.equals(">")) {
+                    // child of
+                    compoundstate = 1;
+                    compounding = true;
+                } else if(str.equals("+")) {
+                    // precedent of
+                    compoundstate = 2;
+                    compounding = true;
+                } else if(str.startsWith("#")) {
+                    // id
+                    current.type = Selector.ID;
+                    current.value = str.substring(1);
+                } else if(str.startsWith(".")) {
+                    // class
+                    current.type = Selector.CLASS;
+                    current.value = str.substring(1);
+                } else if(str.startsWith("[")) {
+                    // attribute
+                    current.type = Selector.ATTRIBUTE;
+                    current.value = str.substring(1, str.length() - 1);
+                } else {
+                    // tag
+                    current.type = Selector.TAG;
+                    if(str.indexOf(":") != -1) {
+                        current.type = Selector.TAG_FIRST_CHILD;
+                        int pos = str.indexOf(":");
+                        current.value = str.substring(0, pos);
+                        current.subValue = str.substring(pos + 1);
+                    } else if(str.indexOf("#") != -1) {
+                        current.type = Selector.TAG_ID;
+                        int pos = str.indexOf("#");
+                        current.value = str.substring(0, pos);
+                        current.subValue = str.substring(pos + 1);
+                    } else if(str.indexOf(".") != -1) {
+                        current.type = Selector.TAG_CLASS;
+                        int pos = str.indexOf(".");
+                        current.value = str.substring(0, pos);
+                        current.subValue = str.substring(pos + 1);
+                    } else {
+                        current.value = str;
+                    }
+                }
+                if(!compounding) {
+                    switch(compoundstate) {
+                        case 0:
+                            if(last != null) {
+                                Selector compound = new Selector();
+                                compound.type = Selector.DESCENDANT;
+                                compound.last = last;
+                                compound.current = current;
+                                current = compound;
+                                compoundstate = 0;
+                            }
+                        break;
+                        case 1:
+                            {
+                                Selector compound = new Selector();
+                                compound.type = Selector.CHILD;
+                                compound.last = last;
+                                compound.current = current;
+                                current = compound;
+                                compoundstate = 0;
+                            }
+                        break;
+                        case 2:
+                            {
+                                Selector compound = new Selector();
+                                compound.type = Selector.PRECEDENT;
+                                compound.last = last;
+                                compound.current = current;
+                                current = compound;
+                                compoundstate = 0;
+                            }
+                        break;
+                    }
+                    last = current;
+                }
+            }
+            if(current != null)
+                selectors.add(current);
+        }
+    }
+
+    public CSSStyleDeclaration getStyle()
+    {
+        return style;
+    }
+
+    public String getCssText()
+    {
+        return cssText;
+    }
+
+    public void setCssText(String cssText)
+    {
+        this.cssText = cssText;
+        style = new CSSStyleDeclarationImpl();
+        style.setCssText(cssText);
+    }
+
+    public short getType()
+    {
+        return STYLE_RULE;
+    }
+
+    public CSSStyleSheet getParentStyleSheet()
+    {
+        return styleSheet;
+    }
+
+    public CSSRule getParentRule()
+    {
+        return null;
+    }
+
+    /**
+     * This should probably be elsewhere, in dom.svg
+     */
+    public boolean matches(SVGElement el)
+    {
+        for(Enumeration e = selectors.elements(); e.hasMoreElements(); ) {
+            Selector sel = (Selector)e.nextElement();
+            if(matches(el, sel))
+                return true;
+        }
+        return false;
+    }
+
+    protected boolean matches(SVGElement el, Selector sel)
+    {
+        short type = sel.type;
+        if(el == null)
+            return false;
+        switch(type) {
+            case Selector.ALL:
+                return true;
+//            break;
+            case Selector.ID:
+                return el.getId().equals(sel.value);
+//            break;
+            case Selector.CLASS:
+                return ((SVGStylable)el).getClassName().getBaseVal().equals(sel.value);
+//            break;
+            case Selector.ATTRIBUTE:
+//System.out.println(sel.value + ":" + el.getAttribute(sel.value));
+//                    return el.getAttribute(sel.value);
+            break;
+            case Selector.TAG:
+                return sel.value.equals(el.getTagName());
+//            break;
+            case Selector.TAG_FIRST_CHILD:
+                if(el.getParentNode() != null)
+                    return (el.getParentNode().getFirstChild() == el);
+            break;
+            case Selector.TAG_ID:
+                return sel.value.equals(el.getTagName())
+                        && sel.subValue.equals(el.getId());
+//            break;
+            case Selector.TAG_CLASS:
+                return sel.value.equals(el.getTagName())
+                        && sel.subValue.equals(((SVGStylable)el).getClassName().getBaseVal());
+//            break;
+            case Selector.DESCENDANT:
+                if(el.getParentNode() instanceof SVGElement) {
+                    if(!matches(el, sel.current))
+                        return false;
+                    SVGElement parent = (SVGElement)el.getParentNode();
+                    while(parent != null) {
+                        if(matches(parent, sel.last))
+                            return true;
+                        if(parent.getParentNode() instanceof SVGElement) {
+                            parent = (SVGElement)parent.getParentNode();
+                        } else {
+                            return false;
+                        }
+                    }
+                }
+                return false;
+//            break;
+            case Selector.CHILD:
+                return matches(el, sel.current)
+                        && matches((SVGElement)el.getParentNode(), sel.last);
+//            break;
+            case Selector.PRECEDENT:
+                return matches(el, sel.current)
+                        && matches((SVGElement)el.getPreviousSibling(), sel.last);
+//            break;
+        }
+        return false;
+    }
+}
+
+class Selector {
+       final static short NONE = -1;
+       final static short ALL = 0;
+       final static short ID = 1;
+       final static short CLASS = 2;
+       final static short ATTRIBUTE = 3;
+       final static short TAG = 4;
+       final static short DESCENDANT = 5;
+       final static short CHILD = 6;
+       final static short PRECEDENT = 7;
+       final static short TAG_FIRST_CHILD = 8;
+       final static short TAG_ID = 9;
+       final static short TAG_CLASS = 10;
+       short type = NONE;
+       String value = "";
+       String subValue = "";
+       // pre- simple selector in compound selectors
+       Selector last = null;
+       Selector current = null;
+}
diff --git a/src/org/apache/fop/dom/css/CSSStyleSheetImpl.java b/src/org/apache/fop/dom/css/CSSStyleSheetImpl.java
new file mode 100644 (file)
index 0000000..87c347e
--- /dev/null
@@ -0,0 +1,194 @@
+/*-- $Id$ -- 
+
+ ============================================================================
+                   The Apache Software License, Version 1.1
+ ============================================================================
+    Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
+ Redistribution and use in source and binary forms, with or without modifica-
+ tion, are permitted provided that the following conditions are met:
+ 1. Redistributions of  source code must  retain the above copyright  notice,
+    this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+    this list of conditions and the following disclaimer in the documentation
+    and/or other materials provided with the distribution.
+ 3. The end-user documentation included with the redistribution, if any, must
+    include  the following  acknowledgment:  "This product includes  software
+    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
+    Alternately, this  acknowledgment may  appear in the software itself,  if
+    and wherever such third-party acknowledgments normally appear.
+ 4. The names "FOP" and  "Apache Software Foundation"  must not be used to
+    endorse  or promote  products derived  from this  software without  prior
+    written permission. For written permission, please contact
+    apache@apache.org.
+ 5. Products  derived from this software may not  be called "Apache", nor may
+    "Apache" appear  in their name,  without prior written permission  of the
+    Apache Software Foundation.
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
+ APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
+ DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
+ ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
+ (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ This software  consists of voluntary contributions made  by many individuals
+ on  behalf of the Apache Software  Foundation and was  originally created by
+ James Tauber <jtauber@jtauber.com>. For more  information on the Apache 
+ Software Foundation, please see <http://www.apache.org/>.
+ */
+
+package org.apache.fop.dom.css;
+
+import org.w3c.dom.css.*;
+import org.w3c.dom.*;
+import org.w3c.dom.stylesheets.*;
+
+import java.util.*;
+
+/**
+ *
+ *
+ */
+public class CSSStyleSheetImpl implements CSSStyleSheet {
+    Vector rules = new Vector();
+
+       public CSSStyleSheetImpl(String sheet)
+       {
+               parseSheet(sheet);
+       }
+
+       protected void parseSheet(String str)
+       {
+               // get each rule and insert it
+               // rule ends with }
+               // need to ignore comments
+               String newStr = str;
+               int pos1;
+               int pos2;
+               pos1 = newStr.indexOf("/*");
+               pos2 = newStr.indexOf("*/");
+               while((pos1 != -1) && (pos2 != -1)) {
+                   newStr = newStr.substring(0, pos1) + newStr.substring(pos2 + 2, newStr.length());
+               pos1 = newStr.indexOf("/*");
+               pos2 = newStr.indexOf("*/");
+               }
+               StringTokenizer st = new StringTokenizer(newStr, "}");
+               while(st.hasMoreTokens()) {
+                   String rule = st.nextToken() + "}";
+                   insertRule(rule, rules.size());
+               }
+       }
+
+    public CSSRule getOwnerRule()
+    {
+        // since this is for a style element
+        return null;
+    }
+
+    public CSSRuleList getCssRules()
+    {
+        return new CSSRuleListImpl(rules);
+    }
+
+    public int insertRule(String rule, 
+                          int index)
+                          throws DOMException
+    {
+        CSSRule r = parseRule(rule);
+        if(r != null)
+            rules.addElement(r);
+        return 0;
+    }
+
+    public void deleteRule(int index)
+                           throws DOMException
+    {
+        rules.remove(index);
+    }
+
+    public String getType()
+    {
+        return "text/css";
+    }
+
+    public boolean getDisabled()
+    {
+        return false;
+    }
+
+    public void setDisabled(boolean disabled)
+    {
+    }
+
+    public Node getOwnerNode()
+    {
+        // return the style element
+        return null;
+    }
+
+    public StyleSheet getParentStyleSheet()
+    {
+        return null;
+    }
+
+    public String getHref()
+    {
+        return null;
+    }
+
+    public String getTitle()
+    {
+        return null;
+    }
+
+    public MediaList getMedia()
+    {
+        return null;
+    }
+
+    protected CSSRule parseRule(String str)
+    {
+        // a rule is "selectors {style}"
+        // a list of selectors followed by the style statement in brackets
+        int pos1 = str.indexOf("{");
+        int pos2 = str.indexOf("}");
+        if(pos1 == -1 || pos2 == -1)
+            return null;
+        String sel = str.substring(0, pos1);
+        String style = str.substring(pos1 + 1, pos2);
+        CSSStyleRule rule = new CSSStyleRuleImpl(this);
+        rule.setSelectorText(sel);
+        rule.setCssText(style);
+        return rule;
+    }
+}
+
+class CSSRuleListImpl implements CSSRuleList {
+    Vector rules;
+    CSSRuleListImpl(Vector v)
+    {
+        rules = v;
+    }
+
+    public int getLength()
+    {
+        return rules.size();
+    }
+
+    public CSSRule item(int pos)
+    {
+        return (CSSRule)rules.elementAt(pos);
+    }
+}
diff --git a/src/org/apache/fop/dom/stylesheets/StyleSheetListImpl.java b/src/org/apache/fop/dom/stylesheets/StyleSheetListImpl.java
new file mode 100644 (file)
index 0000000..ebd0ccb
--- /dev/null
@@ -0,0 +1,79 @@
+/*-- $Id$ -- 
+
+ ============================================================================
+                   The Apache Software License, Version 1.1
+ ============================================================================
+    Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
+ Redistribution and use in source and binary forms, with or without modifica-
+ tion, are permitted provided that the following conditions are met:
+ 1. Redistributions of  source code must  retain the above copyright  notice,
+    this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+    this list of conditions and the following disclaimer in the documentation
+    and/or other materials provided with the distribution.
+ 3. The end-user documentation included with the redistribution, if any, must
+    include  the following  acknowledgment:  "This product includes  software
+    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
+    Alternately, this  acknowledgment may  appear in the software itself,  if
+    and wherever such third-party acknowledgments normally appear.
+ 4. The names "FOP" and  "Apache Software Foundation"  must not be used to
+    endorse  or promote  products derived  from this  software without  prior
+    written permission. For written permission, please contact
+    apache@apache.org.
+ 5. Products  derived from this software may not  be called "Apache", nor may
+    "Apache" appear  in their name,  without prior written permission  of the
+    Apache Software Foundation.
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
+ APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
+ DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
+ ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
+ (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ This software  consists of voluntary contributions made  by many individuals
+ on  behalf of the Apache Software  Foundation and was  originally created by
+ James Tauber <jtauber@jtauber.com>. For more  information on the Apache 
+ Software Foundation, please see <http://www.apache.org/>.
+ */
+
+package org.apache.fop.dom.stylesheets;
+
+import org.w3c.dom.stylesheets.*;
+
+import java.util.*;
+
+/**
+ *
+ *
+ */
+public class StyleSheetListImpl implements StyleSheetList {
+    Vector sheets = new Vector();
+
+       public StyleSheetListImpl(Vector sheets)
+       {
+               this.sheets = sheets;
+       }
+
+    public int getLength()
+    {
+        return sheets.size();
+    }
+
+    public StyleSheet item(int pos)
+    {
+        return (StyleSheet)sheets.elementAt(pos);
+    }
+}
diff --git a/src/org/apache/fop/dom/svg/SVGAnimatedStringImpl.java b/src/org/apache/fop/dom/svg/SVGAnimatedStringImpl.java
new file mode 100644 (file)
index 0000000..b65ad99
--- /dev/null
@@ -0,0 +1,78 @@
+/*-- $Id$ -- 
+
+ ============================================================================
+                   The Apache Software License, Version 1.1
+ ============================================================================
+    Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
+ Redistribution and use in source and binary forms, with or without modifica-
+ tion, are permitted provided that the following conditions are met:
+ 1. Redistributions of  source code must  retain the above copyright  notice,
+    this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+    this list of conditions and the following disclaimer in the documentation
+    and/or other materials provided with the distribution.
+ 3. The end-user documentation included with the redistribution, if any, must
+    include  the following  acknowledgment:  "This product includes  software
+    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
+    Alternately, this  acknowledgment may  appear in the software itself,  if
+    and wherever such third-party acknowledgments normally appear.
+ 4. The names "FOP" and  "Apache Software Foundation"  must not be used to
+    endorse  or promote  products derived  from this  software without  prior
+    written permission. For written permission, please contact
+    apache@apache.org.
+ 5. Products  derived from this software may not  be called "Apache", nor may
+    "Apache" appear  in their name,  without prior written permission  of the
+    Apache Software Foundation.
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
+ APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
+ DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
+ ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
+ (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ This software  consists of voluntary contributions made  by many individuals
+ on  behalf of the Apache Software  Foundation and was  originally created by
+ James Tauber <jtauber@jtauber.com>. For more  information on the Apache 
+ Software Foundation, please see <http://www.apache.org/>.
+ */
+
+package org.apache.fop.dom.svg;
+
+import org.w3c.dom.svg.*;
+
+public class SVGAnimatedStringImpl implements SVGAnimatedString {
+    String str = null;
+
+    public SVGAnimatedStringImpl(String l)
+    {
+        str = l;
+    }
+
+  public String getBaseVal( )
+  {
+      return str;
+  }
+
+  public void setBaseVal( String baseVal )
+  {
+      str = baseVal;
+  }
+
+  public String getAnimVal( )
+  {
+      return str;
+  }
+}
index 0c11944870bb619fdb1b8b5c0f8d0796a3d60dae..8a3ee7e71b163201ffb29df063685c2df15d8a2c 100644 (file)
@@ -106,4 +106,9 @@ public class SVGCircleElementImpl extends GraphicElement implements SVGCircleEle
        {
                this.r = r;
        }
+
+    public String getTagName()
+       {
+               return "circle";
+       }
 }
index a1c697b19b89dcd38119267c5e46a893858c247e..6fe052d796d30a9ac8ca793cae1cb425bb2a687c 100644 (file)
  */
 package org.apache.fop.dom.svg;
 
+import org.apache.fop.dom.stylesheets.*;
+import org.apache.fop.dom.css.*;
 import org.apache.fop.datatypes.*;
 import org.apache.fop.dom.ElementImpl;
 
-import org.w3c.dom.css.CSSStyleDeclaration;
-import org.w3c.dom.css.CSSValue;
+import org.w3c.dom.css.*;
 import org.w3c.dom.svg.*;
 import org.w3c.dom.*;
+import org.w3c.dom.stylesheets.*;
 
 import java.util.*;
 
 public abstract class SVGElementImpl extends ElementImpl implements SVGElement {
        String idString = "";
        CSSStyleDeclaration styleDec;
+       SVGSVGElement ownerSvg;
+       SVGAnimatedString className = new SVGAnimatedStringImpl("");
 
        public String getId()
        {
@@ -81,7 +85,7 @@ public abstract class SVGElementImpl extends ElementImpl implements SVGElement {
 
        public SVGSVGElement getOwnerSVGElement( )
        {
-               return null;
+               return ownerSvg;
        }
 
        public SVGElement getViewportElement( )
@@ -91,25 +95,49 @@ public abstract class SVGElementImpl extends ElementImpl implements SVGElement {
 
        public SVGAnimatedString getClassName( )
        {
-               return null;
+               return className;
        }
 
        public void setClassName( SVGAnimatedString className )
        {
+               this.className = className;
        }
 
        public CSSValue getPresentationAttribute ( String name )
        {
                CSSStyleDeclaration style;
+               CSSValue val = null;
+
                style = getStyle();
-               if(style == null) {
-                       return null;
+               if(style != null) {
+                       val = style.getPropertyCSSValue(name);
                }
-               CSSValue val;
-               val = style.getPropertyCSSValue(name);
+
                if(val == null) {
+                       // this checks for the style selector matching
+                       // everytime a property is requested, this is bad, slow
+
                        // get "style" element style for this
                        SVGSVGElement svg = getOwnerSVGElement();
+                       // maybe
+                       // val = svg.getComputedStyle(this, name);
+                       StyleSheetList list = svg.getStyleSheets();
+                       for(int count = 0; count < list.getLength(); count++) {
+                               CSSRuleList rlist = ((CSSStyleSheet)list.item(count)).getCssRules();
+                               for(int c = 0; c < rlist.getLength(); c++) {
+                                       CSSRule rule = rlist.item(c);
+                                       if(rule.getType() == CSSRule.STYLE_RULE) {
+                                               if(((CSSStyleRuleImpl)rule).matches(this)) {
+                                                       style = ((CSSStyleRule)rule).getStyle();
+                                                       val = style.getPropertyCSSValue(name);
+//                                                     break;
+                                               }
+                                       }
+                               }
+//                             if(val != null) {
+//                                     break;
+//                             }
+                       }
                }
                if(val == null) {
                        // get element parents style
@@ -136,134 +164,36 @@ public abstract class SVGElementImpl extends ElementImpl implements SVGElement {
                styleDec = dec;
        }
 
-/*     SVGElement parent = null;
-       public SVGElement getGraphicParent()
-       {
-               return parent;
-       }
-
-       public void setParent(SVGElement graph)
-       {
-               parent = graph;
-       }*/
-
-/*     Hashtable style = null;
-       public void setStyle(Hashtable st)
-       {
-               style = st;
-       }
-
-       public Hashtable oldgetStyle()
-       {
-               Hashtable ret = null;
-               if(parent != null) {
-                       ret = parent.oldgetStyle();
-                       if(ret != null)
-                               ret = (Hashtable)ret.clone();
-               }
-               if(ret == null) {
-                       ret = style;
-               } else {
-                       if(style != null) {
-                               for(Enumeration e = style.keys(); e.hasMoreElements(); ) {
-                                       String str = (String)e.nextElement();
-                                       ret.put(str, style.get(str));
-                               }
-                       }
-               }
-               return ret;
-       }
-
-       Hashtable defs = new Hashtable();
-       public void addDefs(Hashtable table)
+       public SVGAnimatedBoolean getExternalResourcesRequired( )
        {
-               for(Enumeration e = table.keys(); e.hasMoreElements(); ) {
-                       String str = (String)e.nextElement();
-                       defs.put(str, table.get(str));
-               }
+               return null;
        }
 
-       public Hashtable getDefs()
+       public void setExternalResourcesRequired( SVGAnimatedBoolean externalResourcesRequired )
        {
-               Hashtable ret = null;
-               if(parent != null) {
-                       ret = parent.getDefs();
-                       if(ret != null)
-                               ret = (Hashtable)ret.clone();
-               }
-               if(ret == null) {
-                       ret = defs;
-               } else {
-                       if(defs != null) {
-                               for(Enumeration e = defs.keys(); e.hasMoreElements(); ) {
-                                       String str = (String)e.nextElement();
-                                       ret.put(str, defs.get(str));
-                               }
-                       }
-               }
-               return ret;
        }
 
-       public SVGElement locateDef(String str)
+    public Node appendChild(Node newChild)
+                                    throws DOMException
        {
-               Object obj = null;
-               if(defs != null) {
-                       obj = defs.get(str);
+               Node nChild = super.appendChild(newChild);
+               if(newChild instanceof SVGElementImpl) {
+                       SVGElementImpl ele = (SVGElementImpl)newChild;
+                       if(ownerSvg != null)
+                               ele.setOwnerSVG(ownerSvg);
                }
-               if(obj == null) {
-                       NodeList list = getChildNodes();
-                       for(int count = 0; count < list.getLength(); count++) {
-                               Object o = list.item(count);
-                               if(o instanceof SVGElement) {
-                                       String s;
-                                       s = ((SVGElement)o).getId();
-                                       if(str.equals(s)) {
-                                               obj = o;
-                                               break;
-                                       }
-                               }
-                       }
-               }
-               if(obj == null && parent != null) {
-                       obj = parent.locateDef(str);
-               }
-               return (SVGElement)obj;
+               return nChild;
        }
 
-       Vector trans = null;
-       public void setTransform(Vector tr)
+    public void setOwnerSVG(SVGSVGElement owner)
        {
-               trans = tr;
-       }
-
-       public Vector oldgetTransform()
-       {
-               return trans;
-/*             Vector ret = null;
-               if(parent != null) {
-                       ret = parent.oldgetTransform();
-                       if(ret != null)
-                               ret = (Vector)ret.clone();
-               }
-               if(ret == null) {
-                       ret = trans;
-               } else {
-                       if(trans != null) {
-                               for(Enumeration e = trans.elements(); e.hasMoreElements(); ) {
-                                       Object o = e.nextElement();
-                                       ret.addElement(o);
-                               }
+               ownerSvg = owner;
+               NodeList nl = getChildNodes();
+               for(int count = 0; count < nl.getLength(); count++) {
+                       Node n = nl.item(count);
+                       if(n instanceof SVGElementImpl) {
+                               ((SVGElementImpl)n).setOwnerSVG(owner);
                        }
                }
-               return ret;*
-       }
-*/
-       public SVGAnimatedBoolean getExternalResourcesRequired( )
-       {
-               return null;
-       }
-
-       public void setExternalResourcesRequired( SVGAnimatedBoolean externalResourcesRequired )
-       {
        }
 }
index ba0ac2af34e0c1231906b9728f80dbb970bee193..0c5e150c60c8a5049c7d57ed089f05f0409f0b99 100644 (file)
@@ -93,4 +93,9 @@ public class SVGPolygonElementImpl extends GraphicElement implements SVGPolygonE
                rect.setHeight(maxY - minY);
                return rect;
        }
+
+    public String getTagName()
+       {
+               return "polygon";
+       }
 }
index 4f45cd533167adca82c9dba9fc52eecf2d5d087b..c5ace8baa7bc4d0f709d47fb2751a84900739681 100644 (file)
@@ -153,4 +153,9 @@ public class SVGRectElementImpl extends GraphicElement implements SVGRectElement
        {
            this.ry = ry;
        }
+
+    public String getTagName()
+       {
+               return "rect";
+       }
 }
index 9216c858de014ee75d1f01da0621d2aeee2889df..fc1fb3b8f7d59ba5c6ab1fb35b47ea6195095210 100644 (file)
@@ -50,6 +50,7 @@
  */
 package org.apache.fop.dom.svg;
 
+import org.apache.fop.dom.stylesheets.StyleSheetListImpl;
 import org.apache.fop.fo.Property;
 
 import java.util.*;
@@ -59,6 +60,7 @@ import org.w3c.dom.Element;
 import org.w3c.dom.css.RGBColor;
 import org.w3c.dom.css.CSSStyleDeclaration;
 import org.w3c.dom.stylesheets.StyleSheetList;
+import org.w3c.dom.stylesheets.StyleSheet;
 import org.w3c.dom.NodeList;
 import org.w3c.dom.views.DocumentView;
 import org.w3c.dom.svg.*;
@@ -134,7 +136,7 @@ public class SVGSVGElementImpl extends GraphicElement implements SVGSVGElement {
        {
        }
 
-       public CSSValue getPresentationAttribute ( String name )
+/*     public CSSValue getPresentationAttribute ( String name )
        {
                CSSStyleDeclaration style;
                style = getStyle();
@@ -151,7 +153,7 @@ public class SVGSVGElementImpl extends GraphicElement implements SVGSVGElement {
                        }
                }
                return val;
-       }
+       }*/
 
        public SVGPoint getCurrentTranslate( )
        {
@@ -351,7 +353,15 @@ public class SVGSVGElementImpl extends GraphicElement implements SVGSVGElement {
 
        public StyleSheetList getStyleSheets()
        {
-               return null;
+               NodeList nl = getElementsByTagName("style");
+               Vector shs = new Vector();
+               for(int count = 0; count < nl.getLength(); count++) {
+                       Node el = (Node)nl.item(count);
+                       SVGStyleElementImpl sse = (SVGStyleElementImpl)el;
+                       StyleSheet sheet = sse.getStyleSheet();
+                       shs.addElement(sheet);
+               }
+               return new StyleSheetListImpl(shs);
        }
 
        public Event createEvent(String str)
@@ -363,4 +373,28 @@ public class SVGSVGElementImpl extends GraphicElement implements SVGSVGElement {
        {
                return null;
        }
+
+    public Node appendChild(Node newChild)
+                                    throws DOMException
+       {
+               Node nChild = super.appendChild(newChild);
+               if(newChild instanceof SVGElementImpl) {
+                       SVGElementImpl ele = (SVGElementImpl)newChild;
+                       ele.setOwnerSVG(this);
+               }
+               setOwnerSVG(this);
+               return nChild;
+       }
+
+    public void setOwnerSVG(SVGSVGElement owner)
+       {
+               ownerSvg = owner;
+               NodeList nl = getChildNodes();
+               for(int count = 0; count < nl.getLength(); count++) {
+                       Node n = nl.item(count);
+                       if(n instanceof SVGElementImpl) {
+                               ((SVGElementImpl)n).setOwnerSVG(this);
+                       }
+               }
+       }
 }
index 03c8bbb189c70536e1b94ab7514663669eb79288..3fedd5edb1645891d1a30d7746109d7f1b6717bf 100644 (file)
 
 package org.apache.fop.dom.svg;
 
+import org.apache.fop.dom.css.*;
+
 import org.w3c.dom.svg.*;
+import org.w3c.dom.css.*;
+import org.w3c.dom.stylesheets.*;
 
 /**
  *
  */
 public class SVGStyleElementImpl extends GraphicElement implements SVGStyleElement {
        String type;
+       CSSStyleSheet styleSheet;
 
-       public SVGStyleElementImpl()
+       public SVGStyleElementImpl(String str)
        {
+               styleSheet = new CSSStyleSheetImpl(str);
        }
 
        public String getType()
@@ -90,4 +96,14 @@ public class SVGStyleElementImpl extends GraphicElement implements SVGStyleEleme
        public void setTitle( String title )
        {
        }
+
+    public StyleSheet getStyleSheet()
+    {
+        return styleSheet;
+    }
+
+    public String getTagName()
+       {
+               return "style";
+       }
 }