return ret;
}
- public class AttrPropertyList extends PropertyList {
+ public static class AttrPropertyList extends PropertyList {
Attributes attributes;
AttrPropertyList(Attributes attr) {
super(null, null, null);
// Java
import java.util.Hashtable;
import java.util.Stack;
+import java.util.Vector;
import java.io.IOException;
/**
*/
protected Hashtable fobjTable = new Hashtable();
+ protected Vector namespaces = new Vector();
+
/**
* class that builds a property list for each formatting object
*/
public void addMapping(String namespaceURI, String localName,
FObj.Maker maker) {
this.fobjTable.put(namespaceURI + "^" + localName, maker);
+ this.namespaces.addElement(namespaceURI.intern());
}
/**
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 {
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");
--- /dev/null
+/*
+ * $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);
+ }
+}
+
--- /dev/null
+/*
+ * $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;
+ }
+}
--- /dev/null
+/*
+ * $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.*;
+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) {}
+
+}
+
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() {
}
public float getViewportWidth(Element e) throws IllegalStateException {
- if(e == element) {
+ if(e == svgRoot) {
ForeignObjectArea foa = (ForeignObjectArea)area;
if(!foa.isContentWidthAuto()) {
return foa.getContentWidth();
}
public float getViewportHeight(Element e) throws IllegalStateException {
- if(e == element) {
+ if(e == svgRoot) {
ForeignObjectArea foa = (ForeignObjectArea)area;
if(!foa.isContentHeightAuto()) {
return foa.getContentHeight();
+++ /dev/null
-/*
- * $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.svg;
-
-// 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.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);
- }
-
- /**
- * 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) {}
-
-}
-