aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeiron Liddle <keiron@apache.org>2001-09-13 07:49:32 +0000
committerKeiron Liddle <keiron@apache.org>2001-09-13 07:49:32 +0000
commitf6534eb8c512ac95b224f2c27c3e88f67a29d3ed (patch)
tree797e28371d5628ef2ee0fea61a4aae515942f79e
parentfdabc4dd38c3903f8d141ca5e0cfdb241b400771 (diff)
downloadxmlgraphics-fop-f6534eb8c512ac95b224f2c27c3e88f67a29d3ed.tar.gz
xmlgraphics-fop-f6534eb8c512ac95b224f2c27c3e88f67a29d3ed.zip
handles foreign namespace elements and unknown elements better
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194462 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/org/apache/fop/fo/DirectPropertyListBuilder.java2
-rw-r--r--src/org/apache/fop/fo/FOTreeBuilder.java15
-rw-r--r--src/org/apache/fop/fo/UnknownXMLObj.java97
-rw-r--r--src/org/apache/fop/fo/XMLElement.java91
-rw-r--r--src/org/apache/fop/fo/XMLObj.java (renamed from src/org/apache/fop/svg/XMLObj.java)5
-rw-r--r--src/org/apache/fop/svg/SVGElement.java5
6 files changed, 210 insertions, 5 deletions
diff --git a/src/org/apache/fop/fo/DirectPropertyListBuilder.java b/src/org/apache/fop/fo/DirectPropertyListBuilder.java
index e039b3731..7c6b6f6e4 100644
--- a/src/org/apache/fop/fo/DirectPropertyListBuilder.java
+++ b/src/org/apache/fop/fo/DirectPropertyListBuilder.java
@@ -35,7 +35,7 @@ public class DirectPropertyListBuilder extends PropertyListBuilder {
return ret;
}
- public class AttrPropertyList extends PropertyList {
+ public static class AttrPropertyList extends PropertyList {
Attributes attributes;
AttrPropertyList(Attributes attr) {
super(null, null, null);
diff --git a/src/org/apache/fop/fo/FOTreeBuilder.java b/src/org/apache/fop/fo/FOTreeBuilder.java
index 359ca6fbc..ae67d2d91 100644
--- a/src/org/apache/fop/fo/FOTreeBuilder.java
+++ b/src/org/apache/fop/fo/FOTreeBuilder.java
@@ -27,6 +27,7 @@ import org.xml.sax.Attributes;
// Java
import java.util.Hashtable;
import java.util.Stack;
+import java.util.Vector;
import java.io.IOException;
/**
@@ -48,6 +49,8 @@ public class FOTreeBuilder extends DefaultHandler implements TreeBuilder {
*/
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 class FOTreeBuilder extends DefaultHandler implements TreeBuilder {
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 @@ public class FOTreeBuilder extends DefaultHandler implements TreeBuilder {
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);
}
- fobjMaker = new Unknown.Maker(); // fall back
+ if(namespaces.contains(uri.intern())) {
+ // fall back
+ fobjMaker = new Unknown.Maker();
+ } else {
+ fobjMaker = new UnknownXMLObj.Maker(uri, localName);
+ foreignXML = true;
+ }
}
try {
@@ -231,6 +242,8 @@ public class FOTreeBuilder extends DefaultHandler implements TreeBuilder {
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");
diff --git a/src/org/apache/fop/fo/UnknownXMLObj.java b/src/org/apache/fop/fo/UnknownXMLObj.java
new file mode 100644
index 000000000..5c734aaed
--- /dev/null
+++ b/src/org/apache/fop/fo/UnknownXMLObj.java
@@ -0,0 +1,97 @@
+/*
+ * $Id$
+ * 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);
+ }
+}
+
diff --git a/src/org/apache/fop/fo/XMLElement.java b/src/org/apache/fop/fo/XMLElement.java
new file mode 100644
index 000000000..dc8586414
--- /dev/null
+++ b/src/org/apache/fop/fo/XMLElement.java
@@ -0,0 +1,91 @@
+/*
+ * $Id$
+ * 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;
+ }
+}
diff --git a/src/org/apache/fop/svg/XMLObj.java b/src/org/apache/fop/fo/XMLObj.java
index 383005b02..1b17bf21f 100644
--- a/src/org/apache/fop/svg/XMLObj.java
+++ b/src/org/apache/fop/fo/XMLObj.java
@@ -5,7 +5,7 @@
* LICENSE file included with these sources.
*/
-package org.apache.fop.svg;
+package org.apache.fop.fo;
// FOP
import org.apache.fop.fo.*;
@@ -13,6 +13,7 @@ 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;
@@ -146,6 +147,8 @@ public abstract class XMLObj extends FObj {
return new Status(Status.OK);
}
+ public void removeID(IDReferences idReferences) {}
+
/**
* These method overrides prevent problems with the different types.
*/
diff --git a/src/org/apache/fop/svg/SVGElement.java b/src/org/apache/fop/svg/SVGElement.java
index 211178803..e500f6d2f 100644
--- a/src/org/apache/fop/svg/SVGElement.java
+++ b/src/org/apache/fop/svg/SVGElement.java
@@ -96,6 +96,7 @@ public class SVGElement extends SVGObj {
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 class SVGElement extends SVGObj {
}
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 class SVGElement extends SVGObj {
}
public float getViewportHeight(Element e) throws IllegalStateException {
- if(e == element) {
+ if(e == svgRoot) {
ForeignObjectArea foa = (ForeignObjectArea)area;
if(!foa.isContentHeightAuto()) {
return foa.getContentHeight();