keiron      01/09/13 00:49:32

  Modified:    src/org/apache/fop/fo DirectPropertyListBuilder.java
                        FOTreeBuilder.java
               src/org/apache/fop/svg SVGElement.java
  Added:       src/org/apache/fop/fo UnknownXMLObj.java XMLElement.java
                        XMLObj.java
  Removed:     src/org/apache/fop/svg XMLObj.java
  Log:
  handles foreign namespace elements and unknown elements better
  
  Revision  Changes    Path
  1.2       +2 -2      xml-fop/src/org/apache/fop/fo/DirectPropertyListBuilder.java
  
  Index: DirectPropertyListBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/fo/DirectPropertyListBuilder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DirectPropertyListBuilder.java    2001/09/12 09:28:13     1.1
  +++ DirectPropertyListBuilder.java    2001/09/13 07:49:32     1.2
  @@ -1,5 +1,5 @@
   /*
  - * $Id: DirectPropertyListBuilder.java,v 1.1 2001/09/12 09:28:13 keiron Exp $
  + * $Id: DirectPropertyListBuilder.java,v 1.2 2001/09/13 07:49:32 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -35,7 +35,7 @@
           return ret;
       }
   
  -    public class AttrPropertyList extends PropertyList {
  +    public static class AttrPropertyList extends PropertyList {
           Attributes attributes;
           AttrPropertyList(Attributes attr) {
               super(null, null, null);
  
  
  
  1.28      +15 -2     xml-fop/src/org/apache/fop/fo/FOTreeBuilder.java
  
  Index: FOTreeBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/fo/FOTreeBuilder.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- FOTreeBuilder.java        2001/09/12 09:28:13     1.27
  +++ FOTreeBuilder.java        2001/09/13 07:49:32     1.28
  @@ -1,5 +1,5 @@
   /*
  - * $Id: FOTreeBuilder.java,v 1.27 2001/09/12 09:28:13 keiron Exp $
  + * $Id: FOTreeBuilder.java,v 1.28 2001/09/13 07:49:32 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -27,6 +27,7 @@
   // Java
   import java.util.Hashtable;
   import java.util.Stack;
  +import java.util.Vector;
   import java.io.IOException;
   
   /**
  @@ -48,6 +49,8 @@
        */
       protected Hashtable fobjTable = new Hashtable();
   
  +    protected Vector namespaces = new Vector();
  +
       /**
        * class that builds a property list for each formatting object
        */
  @@ -99,6 +102,7 @@
       public void addMapping(String namespaceURI, String localName,
                              FObj.Maker maker) {
           this.fobjTable.put(namespaceURI + "^" + localName, maker);
  +        this.namespaces.addElement(namespaceURI.intern());
       }
   
       /**
  @@ -215,13 +219,20 @@
           PropertyListBuilder currentListBuilder =
               (PropertyListBuilder)this.propertylistTable.get(uri);
   
  +        boolean foreignXML = false;
           if (fobjMaker == null) {
               if (!this.unknownFOs.containsKey(fullName)) {
                   this.unknownFOs.put(fullName, "");
                   log.error("Unknown formatting object "
                                          + fullName);
  +            }
  +            if(namespaces.contains(uri.intern())) {
  +                // fall back
  +                fobjMaker = new Unknown.Maker();
  +            } else {
  +                fobjMaker = new UnknownXMLObj.Maker(uri, localName);
  +                foreignXML = true;
               }
  -            fobjMaker = new Unknown.Maker();    // fall back
           }
   
           try {
  @@ -231,6 +242,8 @@
                       currentListBuilder.makeList(fullName, attlist,
                                                   (currentFObj == null) ? null
                                                   : currentFObj.properties, 
currentFObj);
  +            } else if(foreignXML) {
  +                list = new DirectPropertyListBuilder.AttrPropertyList(attlist);
               } else {
                   if(currentFObj == null) {
                       throw new FOPException("Invalid XML or missing namespace");
  
  
  
  1.1                  xml-fop/src/org/apache/fop/fo/UnknownXMLObj.java
  
  Index: UnknownXMLObj.java
  ===================================================================
  /*
   * $Id: UnknownXMLObj.java,v 1.1 2001/09/13 07:49:32 keiron Exp $
   * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
   * For details on use and redistribution please refer to the
   * LICENSE file included with these sources.
   */
  
  package org.apache.fop.fo;
  
  import org.apache.fop.fo.*;
  import org.apache.fop.layout.Area;
  import org.apache.fop.layout.FontState;
  import org.apache.fop.layout.inline.*;
  import org.apache.fop.apps.FOPException;
  
  import org.w3c.dom.Element;
  
  public class UnknownXMLObj extends XMLObj {
      String namespace;
  
      /**
       * inner class for making unknown xml objects.
       */
      public static class Maker extends FObj.Maker {
          String space;
          String tag;
  
          Maker(String sp, String t) {
              space = sp;
              tag = t;
          }
  
          /**
           * make an unknown xml object.
           *
           * @param parent the parent formatting object
           * @param propertyList the explicit properties of this object
           *
           * @return the unknown xml object
           */
          public FObj make(FObj parent,
                           PropertyList propertyList) throws FOPException {
              return new UnknownXMLObj(parent, propertyList, space, tag);
          }
      }
  
      /**
       * returns the maker for this object.
       *
       * @return the maker for an unknown xml object
       */
      public static FObj.Maker maker(String space, String tag) {
          return new UnknownXMLObj.Maker(space, tag);
      }
  
      /**
       * constructs an unknown xml object (called by Maker).
       *
       * @param parent the parent formatting object
       * @param propertyList the explicit properties of this object
       */
      protected UnknownXMLObj(FObj parent, PropertyList propertyList, String space, 
String tag) {
          super(parent, propertyList, tag);
          this.namespace = space;
          this.name = this.namespace + ":" + tag;
      }
  
      public String getNameSpace() {
          return this.namespace;
      }
  
      protected void addChild(FONode child) {
          if(doc == null) {
              createBasicDocument();
          }
          super.addChild(child);
      }
  
      protected void addCharacters(char data[], int start, int length) {
          if(doc == null) {
              createBasicDocument();
          }
          super.addCharacters(data, start, length);
      }
  
      public Status layout(Area area) throws FOPException {
          //if (!(area instanceof ForeignObjectArea)) {
              // this is an error
              //throw new FOPException("Foreign XML not in 
fo:instream-foreign-object");
          //}
          log.error("no handler defined for " + this.name + " foreign xml");
  
          /* return status */
          return new Status(Status.OK);
      }
  }
  
  
  
  
  1.1                  xml-fop/src/org/apache/fop/fo/XMLElement.java
  
  Index: XMLElement.java
  ===================================================================
  /*
   * $Id: XMLElement.java,v 1.1 2001/09/13 07:49:32 keiron Exp $
   * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
   * For details on use and redistribution please refer to the
   * LICENSE file included with these sources.
   */
  
  package org.apache.fop.fo;
  
  // FOP
  import org.apache.fop.fo.properties.*;
  import org.apache.fop.layout.Area;
  import org.apache.fop.layout.inline.*;
  import org.apache.fop.apps.FOPException;
  
  /**
   * class representing svg:svg pseudo flow object.
   */
  public class XMLElement extends XMLObj {
      String namespace = "";
  
      /**
       * inner class for making XML objects.
       */
      public static class Maker extends FObj.Maker {
          String tag;
  
          Maker(String t) {
              tag = t;
          }
  
          /**
           * make an XML object.
           *
           * @param parent the parent formatting object
           * @param propertyList the explicit properties of this object
           *
           * @return the XML object
           */
          public FObj make(FObj parent,
                           PropertyList propertyList) throws FOPException {
              return new XMLElement(parent, propertyList, tag);
          }
      }
  
      /**
       * returns the maker for this object.
       *
       * @return the maker for XML objects
       */
      public static FObj.Maker maker(String tag) {
          return new XMLElement.Maker(tag);
      }
  
      /**
       * constructs an XML object (called by Maker).
       *
       * @param parent the parent formatting object
       * @param propertyList the explicit properties of this object
       */
      public XMLElement(FObj parent, PropertyList propertyList, String tag) {
          super(parent, propertyList, tag);
          init();
      }
  
      /**
       * layout this formatting object.
       *
       * @param area the area to layout the object into
       *
       * @return the status of the layout
       */
      public Status layout(final Area area) throws FOPException {
  
          if (!(area instanceof ForeignObjectArea)) {
              // this is an error
              throw new FOPException("XML not in fo:instream-foreign-object");
          }
  
          /* return status */
          return new Status(Status.OK);
      }
  
      private void init() {
          createBasicDocument();
      }
  
      public String getNameSpace() {
          return namespace;
      }
  }
  
  
  
  1.1                  xml-fop/src/org/apache/fop/fo/XMLObj.java
  
  Index: XMLObj.java
  ===================================================================
  /*
   * $Id: XMLObj.java,v 1.1 2001/09/13 07:49:32 keiron Exp $
   * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
   * For details on use and redistribution please refer to the
   * LICENSE file included with these sources.
   */
  
  package org.apache.fop.fo;
  
  // FOP
  import org.apache.fop.fo.*;
  import org.apache.fop.layout.Area;
  import org.apache.fop.layout.FontState;
  import org.apache.fop.apps.FOPException;
  import org.apache.fop.layout.LinkSet;
  import org.apache.fop.datatypes.IDReferences;
  
  import org.w3c.dom.*;
  import org.xml.sax.Attributes;
  
  import java.util.*;
  
  /**
   * Since SVG objects are not layed out then this class checks
   * that this element is not being layed out inside some incorrect
   * element.
   */
  public abstract class XMLObj extends FObj {
  
      protected String tagName = "";
  
      protected Element element;
      protected Document doc;
  
      /**
       *
       * @param parent the parent formatting object
       * @param propertyList the explicit properties of this object
       */
      public XMLObj(FObj parent, PropertyList propertyList, String tag) {
          super(parent, propertyList);
          tagName = tag;
      }
  
      public abstract String getNameSpace();
  
      protected static Hashtable ns = new Hashtable();
  
      public void addGraphic(Document doc, Element parent) {
          this.doc = doc;
          element = doc.createElementNS(getNameSpace(), tagName);
  
          if(this.properties instanceof DirectPropertyListBuilder.AttrPropertyList) {
              Attributes attr = 
((DirectPropertyListBuilder.AttrPropertyList)this.properties).getAttributes();
              for (int count = 0; count < attr.getLength(); count++) {
                  String rf = attr.getValue(count);
                  String qname = attr.getQName(count);
                  if (qname.indexOf(":") == -1) {
                      element.setAttribute(qname, rf);
                  } else {
                      String pref =
                          qname.substring(0, qname.indexOf(":"));
                      if (pref.equals("xmlns")) {
                          ns.put(qname.substring(qname.indexOf(":")
                                                        + 1), rf);
                      }
                      ns.put("xlink", "http://www.w3.org/1999/xlink";);
                      element.setAttributeNS((String)ns.get(pref),
                                             qname, rf);
                  }
              }
          } else {
          }
  
          parent.appendChild(element);
      }
  
      public void buildTopLevel(Document doc, Element svgRoot) {
          // build up the info for the top level element
          if(this.properties instanceof DirectPropertyListBuilder.AttrPropertyList) {
              Attributes attr = 
((DirectPropertyListBuilder.AttrPropertyList)this.properties).getAttributes();
              for (int count = 0; count < attr.getLength(); count++) {
                  String rf = attr.getValue(count);
                  String qname = attr.getQName(count);
                  if (qname.indexOf(":") == -1) {
                      element.setAttribute(qname, rf);
                  } else {
                      String pref =
                         qname.substring(0, qname.indexOf(":"));
                      if (pref.equals("xmlns")) {
                          ns.put(qname.substring(qname.indexOf(":")
                                                        + 1), rf);
                      }
                      ns.put("xlink", "http://www.w3.org/1999/xlink";);
                      element.setAttributeNS((String)ns.get(pref),
                                             qname, rf);
                  }
              }
          } else {
          }
      }
  
      public Document createBasicDocument() {
          doc = null;
  
          element = null;
          try {
              // DOMImplementation impl = 
javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
              // String ns = GraphElementMapping.URI;
              // doc = impl.createDocument(ns, "graph", null);
              doc =
                  
javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
              Element el = doc.createElement("graph");
              doc.appendChild(el);
  
              element = doc.getDocumentElement();
              buildTopLevel(doc, element);
          } catch (Exception e) {
              e.printStackTrace();
          }
          return doc;
      }
  
      protected void addChild(FONode child) {
          if (child instanceof XMLObj) {
              ((XMLObj)child).addGraphic(doc, element);
          }
      }
  
      protected void addCharacters(char data[], int start, int length) {
          String str = new String(data, start, length - start);
          org.w3c.dom.Text text = doc.createTextNode(str);
          element.appendChild(text);
      }
  
      /**
       * layout this formatting object.
       *
       * @param area the area to layout the object into
       * @return the status of the layout
       */
      public Status layout(Area area) throws FOPException {
          /* generate a warning */
          log.error("" + this.name + " outside foreign xml");
  
          /* return status */
          return new Status(Status.OK);
      }
  
      public void removeID(IDReferences idReferences) {}
  
      /**
       * These method overrides prevent problems with the different types.
       */
      public void setIsInTableCell() {}
  
      public void forceStartOffset(int offset) {}
  
      public void forceWidth(int width) {}
  
      public void resetMarker() {}
  
      public void setLinkSet(LinkSet linkSet) {}
  
      public Vector getMarkerSnapshot(Vector snapshot) {
          return snapshot;
      }
  
      public void rollback(Vector snapshot) {}
  
  }
  
  
  
  
  1.10      +4 -3      xml-fop/src/org/apache/fop/svg/SVGElement.java
  
  Index: SVGElement.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/SVGElement.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SVGElement.java   2001/09/12 09:28:13     1.9
  +++ SVGElement.java   2001/09/13 07:49:32     1.10
  @@ -1,5 +1,5 @@
   /*
  - * $Id: SVGElement.java,v 1.9 2001/09/12 09:28:13 keiron Exp $
  + * $Id: SVGElement.java,v 1.10 2001/09/13 07:49:32 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -96,6 +96,7 @@
               this.marker = 0;
           }
   
  +        final Element svgRoot = element;
           /* create an SVG area */
           /* if width and height are zero, get the bounds of the content. */
           DefaultSVGContext dc = new DefaultSVGContext() {
  @@ -105,7 +106,7 @@
               }
   
               public float getViewportWidth(Element e) throws IllegalStateException {
  -                if(e == element) {
  +                if(e == svgRoot) {
                       ForeignObjectArea foa = (ForeignObjectArea)area;
                       if(!foa.isContentWidthAuto()) {
                           return foa.getContentWidth();
  @@ -115,7 +116,7 @@
               }
   
               public float getViewportHeight(Element e) throws IllegalStateException {
  -                if(e == element) {
  +                if(e == svgRoot) {
                       ForeignObjectArea foa = (ForeignObjectArea)area;
                       if(!foa.isContentHeightAuto()) {
                           return foa.getContentHeight();
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to