import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.util.ArrayList;
import java.util.Date;
-import java.util.HashMap;
+import java.util.List;
import java.util.Map;
// avalon configuration
import org.apache.fop.layoutmgr.LayoutManagerMaker;
import org.apache.fop.pdf.PDFEncryptionParams;
import org.apache.fop.render.Renderer;
+import org.apache.fop.render.XMLHandlerRegistry;
/**
* The User Agent for fo.
/** Defines the default resolution (72dpi) for FOP */
public static final float DEFAULT_PX2MM = (25.4f / 72); //dpi (=25.4/dpi)
- /** Map containing various default values */
- public Map defaults = new java.util.HashMap();
- /** Map containing XML handlers for various document types */
- public Map handlers = new java.util.HashMap();
+ /** Registry for XML handlers */
+ private XMLHandlerRegistry xmlHandlers = new XMLHandlerRegistry();
private String baseURL;
private PDFEncryptionParams pdfEncryptionParams;
private float px2mm = DEFAULT_PX2MM;
- private HashMap rendererOptions = new java.util.HashMap();
+ private Map rendererOptions = new java.util.HashMap();
private InputHandler inputHandler = null;
private File outputFile = null;
private Renderer rendererOverride = null;
private boolean strictValidation = true;
/* Additional fo.ElementMapping subclasses set by user */
- private ArrayList additionalElementMappings = null;
+ private List additionalElementMappings = null;
/** Producer: Metadata element for the system/software that produces
* the document. (Some renderers can store this in the document.)
*/
public void addElementMapping(ElementMapping elementMapping) {
if (additionalElementMappings == null) {
- additionalElementMappings = new ArrayList();
+ additionalElementMappings = new java.util.ArrayList();
}
additionalElementMappings.add(elementMapping);
}
/**
- * Returns the ArrayList of user-added ElementMapping class names
- * @return ArrayList of Strings holding ElementMapping names.
+ * Returns the List of user-added ElementMapping class names
+ * @return List of Strings holding ElementMapping names.
*/
- public ArrayList getAdditionalElementMappings() {
+ public List getAdditionalElementMappings() {
return additionalElementMappings;
}
* Returns the renderer options
* @return renderer options
*/
- public HashMap getRendererOptions() {
+ public Map getRendererOptions() {
return rendererOptions;
}
/**
* If to create hot links to footnotes and before floats.
- * @return True if hot links dhould be created
+ * @return True if hot links should be created
*/
public boolean linkToFootnotes() {
return true;
}
+ /**
+ * @return the XML handler registry
+ */
+ public XMLHandlerRegistry getXMLHandlerRegistry() {
+ return this.xmlHandlers;
+ }
+
+
}
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.apache.fop.fo;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
import java.io.OutputStream;
-import java.io.Reader;
-import java.util.ArrayList;
-import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.render.RendererFactory;
+import org.apache.fop.util.Service;
import org.apache.fop.fo.ElementMapping.Maker;
import org.apache.fop.fo.pagination.Root;
import org.xml.sax.Attributes;
setupDefaultMappings();
// add additional ElementMappings defined within FOUserAgent
- ArrayList addlEMs = foUserAgent.getAdditionalElementMappings();
+ List addlEMs = foUserAgent.getAdditionalElementMappings();
if (addlEMs != null) {
for (int i = 0; i < addlEMs.size(); i++) {
rootFObj = null;
foEventHandler = null;
}
-}
-
-// code stolen from org.apache.batik.util and modified slightly
-// does what sun.misc.Service probably does, but it cannot be relied on.
-// hopefully will be part of standard jdk sometime.
-
-/**
- * This class loads services present in the class path.
- */
-class Service {
-
- private static Map providerMap = new java.util.Hashtable();
-
- public static synchronized Iterator providers(Class cls) {
- ClassLoader cl = cls.getClassLoader();
- // null if loaded by bootstrap class loader
- if (cl == null) {
- cl = ClassLoader.getSystemClassLoader();
- }
- String serviceFile = "META-INF/services/" + cls.getName();
-
- // log.debug("File: " + serviceFile);
-
- List lst = (List)providerMap.get(serviceFile);
- if (lst != null) {
- return lst.iterator();
- }
-
- lst = new java.util.Vector();
- providerMap.put(serviceFile, lst);
-
- Enumeration e;
- try {
- e = cl.getResources(serviceFile);
- } catch (IOException ioe) {
- return lst.iterator();
- }
-
- while (e.hasMoreElements()) {
- try {
- java.net.URL u = (java.net.URL)e.nextElement();
- //log.debug("URL: " + u);
-
- InputStream is = u.openStream();
- Reader r = new InputStreamReader(is, "UTF-8");
- BufferedReader br = new BufferedReader(r);
-
- String line = br.readLine();
- while (line != null) {
- try {
- // First strip any comment...
- int idx = line.indexOf('#');
- if (idx != -1) {
- line = line.substring(0, idx);
- }
-
- // Trim whitespace.
- line = line.trim();
-
- // If nothing left then loop around...
- if (line.length() == 0) {
- line = br.readLine();
- continue;
- }
- // log.debug("Line: " + line);
-
- // Try and load the class
- // Object obj = cl.loadClass(line).newInstance();
- // stick it into our vector...
- lst.add(line);
- } catch (Exception ex) {
- // Just try the next line
- }
-
- line = br.readLine();
- }
- } catch (Exception ex) {
- // Just try the next file...
- }
-
- }
- return lst.iterator();
- }
}
import java.awt.geom.Rectangle2D;
import java.io.IOException;
import java.io.OutputStream;
-import java.util.Map;
import java.util.List;
import java.util.Iterator;
+import java.util.Set;
// XML
import org.w3c.dom.Document;
*/
protected int containingIPPosition = 0;
+ private Set warnedXMLHandlers;
+
/**
* @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
*/
// Some renderers (ex. Text) don't support foreign objects.
}
- /**
- * Set the default xml handler for the given mime type.
- * @param mime MIME type
- * @param handler XMLHandler to use
- */
- public void setDefaultXMLHandler(FOUserAgent foua, String mime,
- XMLHandler handler) {
- foua.defaults.put(mime, handler);
- }
-
- /**
- * Add an xml handler for the given mime type and xml namespace.
- * @param mime MIME type
- * @param ns Namespace URI
- * @param handler XMLHandler to use
- */
- public void addXMLHandler(FOUserAgent foua, String mime, String ns,
- XMLHandler handler) {
- Map mh = (Map) foua.handlers.get(mime);
- if (mh == null) {
- mh = new java.util.HashMap();
- foua.handlers.put(mime, mh);
- }
- mh.put(ns, handler);
- }
-
/**
* Render the xml document with the given xml namespace.
* The Render Context is by the handle to render into the current
* @param doc DOM Document containing the source document
* @param namespace Namespace URI of the document
*/
- public void renderXML(FOUserAgent foua, RendererContext ctx, Document doc,
+ public void renderXML(RendererContext ctx, Document doc,
String namespace) {
String mime = ctx.getMimeType();
- Map mh = (Map) foua.handlers.get(mime);
- XMLHandler handler = null;
- if (mh != null) {
- handler = (XMLHandler) mh.get(namespace);
- }
- if (handler == null) {
- handler = (XMLHandler) foua.defaults.get(mime);
- }
+ XMLHandler handler = userAgent.getXMLHandlerRegistry().getXMLHandler(
+ mime, namespace);
if (handler != null) {
try {
handler.handleXML(ctx, doc, namespace);
+ "Could not render XML", t);
}
} else {
- // no handler found for document
- getLogger().warn("Some XML content will be ignored. "
- + "No handler defined for XML: " + namespace);
+ if (warnedXMLHandlers == null) {
+ warnedXMLHandlers = new java.util.HashSet();
+ }
+ if (!warnedXMLHandlers.contains(namespace)) {
+ // no handler found for document
+ warnedXMLHandlers.add(namespace);
+ getLogger().warn("Some XML content will be ignored. "
+ + "No handler defined for XML: " + namespace);
+ }
}
}
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
public class RendererContext {
private String mime;
+ private AbstractRenderer renderer;
private FOUserAgent userAgent;
private Map props = new java.util.HashMap();
/**
* Contructor for this class. It takes a MIME type as parameter.
*
+ * @param renderer The current renderer
* @param m The MIME type of the output that's generated.
*/
- public RendererContext(String m) {
- mime = m;
+ public RendererContext(AbstractRenderer renderer, String m) {
+ this.renderer = renderer;
+ this.mime = m;
}
+ /**
+ * @return Returns the renderer.
+ */
+ public AbstractRenderer getRenderer() {
+ return renderer;
+ }
+
/**
* Returns the MIME type associated with this RendererContext.
*
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
public interface XMLHandler {
+ /** Used to indicate that all MIME types or XML namespaces are handled. */
+ String HANDLE_ALL = "*";
+
/**
- * Handle an external xml document inside a Foreign Object Area. <p>
- *
- * This may throw an exception if for some reason it cannot be handled. The
- * caller is expected to deal with this exception.</p>
+ * <p>Handle an external xml document inside a Foreign Object Area.
+ * </p>
+ * <p>This may throw an exception if for some reason it cannot be handled. The
+ * caller is expected to deal with this exception.
+ * </p>
+ * <p>The implementation may convert the XML document internally to another
+ * XML dialect (SVG, for example) and call renderXML() on the AbstractRenderer
+ * again (which can be retrieved through the RendererContext).</p>
*
* @param context The RendererContext (contains the user agent)
* @param doc A DOM containing the foreign object to be
* @param ns The Namespace of the foreign object
* @exception Exception If an error occurs during processing.
*/
- void handleXML(RendererContext context, Document doc, String ns)
- throws Exception;
+ void handleXML(RendererContext context,
+ Document doc, String ns) throws Exception;
+
+ /**
+ * @return the MIME type for which this XMLHandler was written
+ */
+ String getMimeType();
+ /**
+ * @return the XML namespace for the XML dialect this XMLHandler supports,
+ * null if all XML content is handled by this instance.
+ */
+ String getNamespace();
}
--- /dev/null
+/*\r
+ * Copyright 2005 The Apache Software Foundation.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/* $Id$ */\r
+\r
+package org.apache.fop.render;\r
+\r
+import java.util.Iterator;\r
+import java.util.Map;\r
+\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+import org.apache.fop.util.Service;\r
+\r
+/**\r
+ * This class holds references to various XML handlers used by FOP. It also\r
+ * supports automatic discovery of additional XML handlers available through\r
+ * the class path.\r
+ */\r
+public class XMLHandlerRegistry {\r
+\r
+ /** the logger */\r
+ private static Log log = LogFactory.getLog(XMLHandlerRegistry.class);\r
+ \r
+ /** Map containing XML handlers for various document types */\r
+ private Map handlers = new java.util.HashMap();\r
+ \r
+ \r
+ /**\r
+ * Default constructor.\r
+ */\r
+ public XMLHandlerRegistry() {\r
+ discoverXMLHandlers();\r
+ }\r
+ \r
+ /**\r
+ * Set the default XML handler for the given MIME type.\r
+ * @param mime MIME type\r
+ * @param handler XMLHandler to use\r
+ */\r
+ private void setDefaultXMLHandler(String mime,\r
+ XMLHandler handler) {\r
+ addXMLHandler(mime, XMLHandler.HANDLE_ALL, handler);\r
+ }\r
+ \r
+ /**\r
+ * Add an XML handler. The handler itself is inspected to find out what it supports.\r
+ * @param classname the fully qualified class name\r
+ */\r
+ public void addXMLHandler(String classname) {\r
+ try {\r
+ XMLHandler handlerInstance =\r
+ (XMLHandler)Class.forName(classname).newInstance();\r
+ addXMLHandler(handlerInstance);\r
+ } catch (ClassNotFoundException e) {\r
+ throw new IllegalArgumentException("Could not find "\r
+ + classname);\r
+ } catch (InstantiationException e) {\r
+ throw new IllegalArgumentException("Could not instantiate "\r
+ + classname);\r
+ } catch (IllegalAccessException e) {\r
+ throw new IllegalArgumentException("Could not access "\r
+ + classname);\r
+ } catch (ClassCastException e) {\r
+ throw new IllegalArgumentException(classname\r
+ + " is not an ElementMapping");\r
+ }\r
+ }\r
+ \r
+ /**\r
+ * Add an XML handler. The handler itself is inspected to find out what it supports.\r
+ * @param handler the XMLHandler instance\r
+ */\r
+ public void addXMLHandler(XMLHandler handler) {\r
+ String mime = handler.getMimeType();\r
+ String ns = handler.getNamespace();\r
+ if (ns == null) {\r
+ setDefaultXMLHandler(mime, handler);\r
+ } else {\r
+ addXMLHandler(mime, ns, handler);\r
+ }\r
+ }\r
+ \r
+ /**\r
+ * Add an XML handler for the given MIME type and XML namespace.\r
+ * @param mime MIME type\r
+ * @param ns Namespace URI\r
+ * @param handler XMLHandler to use\r
+ */\r
+ private void addXMLHandler(String mime, String ns,\r
+ XMLHandler handler) {\r
+ Map mh = (Map)handlers.get(mime);\r
+ if (mh == null) {\r
+ mh = new java.util.HashMap();\r
+ handlers.put(mime, mh);\r
+ }\r
+ mh.put(ns, handler);\r
+ }\r
+ \r
+ /**\r
+ * Returns an XMLHandler which handles an XML dialect of the given namespace and for\r
+ * a specified output format defined by its MIME type.\r
+ * @param mime the MIME type of the output format\r
+ * @param ns the XML namespace associated with the XML to be rendered\r
+ * @return the XMLHandler responsible for handling the XML or null if none is available\r
+ */\r
+ public XMLHandler getXMLHandler(String mime, String ns) {\r
+ XMLHandler handler = null;\r
+\r
+ Map mh = (Map)handlers.get(mime);\r
+ if (mh != null) {\r
+ handler = (XMLHandler)mh.get(ns);\r
+ if (handler == null) {\r
+ handler = (XMLHandler)mh.get(XMLHandler.HANDLE_ALL);\r
+ }\r
+ }\r
+ if (handler == null) {\r
+ mh = (Map)handlers.get(XMLHandler.HANDLE_ALL);\r
+ if (mh != null) {\r
+ handler = (XMLHandler)mh.get(ns);\r
+ if (handler == null) {\r
+ handler = (XMLHandler)mh.get(XMLHandler.HANDLE_ALL);\r
+ }\r
+ }\r
+ }\r
+ return handler;\r
+ }\r
+ \r
+ \r
+ /**\r
+ * Discovers XMLHandler implementations through the classpath and dynamically\r
+ * registers them.\r
+ */\r
+ private void discoverXMLHandlers() {\r
+ // add mappings from available services\r
+ Iterator providers =\r
+ Service.providers(XMLHandler.class);\r
+ if (providers != null) {\r
+ while (providers.hasNext()) {\r
+ String str = (String)providers.next();\r
+ try {\r
+ if (log.isDebugEnabled()) {\r
+ log.debug("Dynamically adding XMLHandler: " + str);\r
+ }\r
+ addXMLHandler(str);\r
+ } catch (IllegalArgumentException e) {\r
+ log.error("Error while adding XMLHandler", e);\r
+ }\r
+\r
+ }\r
+ }\r
+ }\r
+}\r
import org.apache.batik.bridge.BridgeContext;
import org.apache.batik.bridge.GVTBuilder;
import org.apache.batik.bridge.ViewBox;
+import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.gvt.GraphicsNode;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
public void renderForeignObject(ForeignObject fo, Rectangle2D pos) {
Document doc = fo.getDocument();
String ns = fo.getNameSpace();
- if (ns.equals("http://www.w3.org/2000/svg")) {
+ if (SVGDOMImplementation.SVG_NAMESPACE_URI.equals(ns)) {
renderSVGDocument(doc, pos);
} else {
renderDocument(doc, ns, pos);
*/
public void renderDocument(Document doc, String ns, Rectangle2D pos) {
RendererContext context;
- context = new RendererContext(MIME_TYPE);
+ context = new RendererContext(this, MIME_TYPE);
context.setUserAgent(userAgent);
// TODO implement
/*
int y = currentBPPosition;
RendererContext context;
- context = new RendererContext(MIME_TYPE);
+ context = new RendererContext(this, MIME_TYPE);
context.setUserAgent(userAgent);
SVGUserAgent ua = new SVGUserAgent(context.getUserAgent()
public void setUserAgent(FOUserAgent agent) {
super.setUserAgent(agent);
PDFXMLHandler xmlHandler = new PDFXMLHandler();
- //userAgent.setDefaultXMLHandler(MIME_TYPE, xmlHandler);
- String svg = "http://www.w3.org/2000/svg";
- addXMLHandler(userAgent, MIME_TYPE, svg, xmlHandler);
+ userAgent.getXMLHandlerRegistry().addXMLHandler(xmlHandler);
}
/**
* @param pdf StringBuffer to write the PDF code to, if null, the code is
* written to the current stream.
*/
- private void setColor(Color col, boolean fill, StringBuffer pdf) {
+ protected void setColor(Color col, boolean fill, StringBuffer pdf) {
PDFColor color = new PDFColor(col);
closeText();
*/
public void renderDocument(Document doc, String ns, Rectangle2D pos) {
RendererContext context;
- context = new RendererContext(MIME_TYPE);
+ context = new RendererContext(this, MIME_TYPE);
context.setUserAgent(userAgent);
context.setProperty(PDFXMLHandler.PDF_DOCUMENT, pdfDoc);
new Integer((int) pos.getWidth()));
context.setProperty(PDFXMLHandler.PDF_HEIGHT,
new Integer((int) pos.getHeight()));
- renderXML(userAgent, context, doc, ns);
+ renderXML(context, doc, ns);
}
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.apache.batik.bridge.GVTBuilder;
import org.apache.batik.bridge.BridgeContext;
import org.apache.batik.bridge.ViewBox;
+import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.gvt.GraphicsNode;
import org.w3c.dom.svg.SVGDocument;
import org.w3c.dom.svg.SVGSVGElement;
+import java.awt.Color;
import java.awt.geom.AffineTransform;
/**
public PDFXMLHandler() {
}
- /**
- * Handle the XML.
- * This checks the type of XML and handles appropraitely.
- *
- * @param context the renderer context
- * @param doc the XML document to render
- * @param ns the namespace of the XML document
- * @throws Exception any sort of exception could be thrown and shuld be handled
- */
- public void handleXML(RendererContext context, org.w3c.dom.Document doc,
- String ns) throws Exception {
+ /** @see org.apache.fop.render.XMLHandler */
+ public void handleXML(RendererContext context,
+ org.w3c.dom.Document doc, String ns) throws Exception {
PDFInfo pdfi = getPDFInfo(context);
String svg = "http://www.w3.org/2000/svg";
* Note: To have the svg overlay (under) a text area then use
* an fo:block-container
*/
- pdfInfo.currentStream.add("q\n");
+ PDFRenderer renderer = (PDFRenderer)context.getRenderer();
+ renderer.saveGraphicsState();
+ //pdfInfo.currentStream.add("q\n");
+ renderer.setColor(Color.BLACK, false, null);
+ renderer.setColor(Color.BLACK, true, null);
// transform so that the coordinates (0,0) is from the top left
// and positive is down and to the right. (0,0) is where the
// viewBox puts it.
SVGSVGElement svg = ((SVGDocument)doc).getRootElement();
AffineTransform at = ViewBox.getPreserveAspectRatioTransform(svg, w / 1000f, h / 1000f);
- if (!at.isIdentity()) {
+ if (false && !at.isIdentity()) {
double[] vals = new double[6];
at.getMatrix(vals);
pdfInfo.currentStream.add(PDFNumber.doubleOut(vals[0], 5) + " "
+ e.getMessage(), e);
}
- pdfInfo.currentStream.add("Q\n");
+ //pdfInfo.currentStream.add("Q\n");
+ renderer.restoreGraphicsState();
pdfInfo.pdfState.pop();
}
}
-}
+
+ /** @see org.apache.fop.render.XMLHandler#getMimeType() */
+ public String getMimeType() {
+ return PDFRenderer.MIME_TYPE;
+ }
+ /** @see org.apache.fop.render.XMLHandler#getNamespace() */
+ public String getNamespace() {
+ return SVGDOMImplementation.SVG_NAMESPACE_URI;
+ }
+
+}
\ No newline at end of file
public void setUserAgent(FOUserAgent agent) {
super.setUserAgent(agent);
PSXMLHandler xmlHandler = new PSXMLHandler();
- //userAgent.setDefaultXMLHandler(MIME_TYPE, xmlHandler);
- String svg = "http://www.w3.org/2000/svg";
- addXMLHandler(userAgent, MIME_TYPE, svg, xmlHandler);
+ userAgent.getXMLHandlerRegistry().addXMLHandler(xmlHandler);
}
/**
*/
public void renderDocument(Document doc, String ns, Rectangle2D pos) {
RendererContext context;
- context = new RendererContext(MIME_TYPE);
+ context = new RendererContext(this, MIME_TYPE);
context.setUserAgent(userAgent);
context.setProperty(PSXMLHandler.PS_GENERATOR, this.gen);
new Integer(currentBPPosition + (int) pos.getY()));
//context.setProperty("strokeSVGText", options.get("strokeSVGText"));
- renderXML(userAgent, context, doc, ns);
+ renderXML(context, doc, ns);
}
/** @see org.apache.fop.render.AbstractRenderer */
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.apache.batik.bridge.GVTBuilder;
import org.apache.batik.bridge.BridgeContext;
import org.apache.batik.bridge.ViewBox;
+import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.gvt.GraphicsNode;
// FOP
public PSXMLHandler() {
}
- /**
- * Handle the XML.
- * This checks the type of XML and handles appropraitely.
- *
- * @param context the renderer context
- * @param doc the XML document to render
- * @param ns the namespace of the XML document
- * @throws Exception any sort of exception could be thrown and shuld be handled
- */
- public void handleXML(RendererContext context, org.w3c.dom.Document doc,
- String ns) throws Exception {
+ /** @see org.apache.fop.render.XMLHandler */
+ public void handleXML(RendererContext context,
+ org.w3c.dom.Document doc, String ns) throws Exception {
PSInfo psi = getPSInfo(context);
- String svg = "http://www.w3.org/2000/svg";
- if (svg.equals(ns)) {
+ if (SVGDOMImplementation.SVG_NAMESPACE_URI.equals(ns)) {
SVGHandler svghandler = new SVGHandler();
svghandler.renderSVGDocument(context, doc, psi);
} else {
}
}
}
+
+ /** @see org.apache.fop.render.XMLHandler#getMimeType() */
+ public String getMimeType() {
+ return PSRenderer.MIME_TYPE;
+ }
+
+ /** @see org.apache.fop.render.XMLHandler#getNamespace() */
+ public String getNamespace() {
+ return SVGDOMImplementation.SVG_NAMESPACE_URI;
+ }
+
}
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* Creates a new SVG renderer.
*/
public SVGRenderer() {
- context = new RendererContext(SVG_MIME_TYPE);
+ context = new RendererContext(this, SVG_MIME_TYPE);
}
/**
*/
public void setUserAgent(FOUserAgent agent) {
super.setUserAgent(agent);
- setDefaultXMLHandler(userAgent, SVG_MIME_TYPE, this);
- addXMLHandler(userAgent, SVG_MIME_TYPE, SVG_NAMESPACE, this);
+ userAgent.getXMLHandlerRegistry().addXMLHandler(this);
}
/**
* Method renderForeignObject.
* @param fo the foreign object
*/
- public void renderForeignObject(ForeignObject fo) {
+ public void renderForeignObject(ForeignObject fo, Rectangle2D pos) {
org.w3c.dom.Document doc = fo.getDocument();
String ns = fo.getNameSpace();
- renderXML(userAgent, context, doc, ns);
+ renderXML(context, doc, ns);
}
- /**
- * @see org.apache.fop.render.XMLHandler#handleXML(RendererContext, Document, String)
- */
- public void handleXML(RendererContext context, org.w3c.dom.Document doc,
- String ns) throws Exception {
+ /** @see org.apache.fop.render.XMLHandler */
+ public void handleXML(RendererContext context,
+ org.w3c.dom.Document doc, String ns) throws Exception {
if (SVG_NAMESPACE.equals(ns)) {
if (!(doc instanceof SVGDocument)) {
DOMImplementation impl =
return SVG_MIME_TYPE;
}
+ /** @see org.apache.fop.render.XMLHandler#getNamespace() */
+ public String getNamespace() {
+ return SVG_NAMESPACE;
+ }
+
}
* Creates a new XML renderer.
*/
public XMLRenderer() {
- context = new RendererContext(XML_MIME_TYPE);
+ context = new RendererContext(this, XML_MIME_TYPE);
}
/**
//
//userAgent.addExtensionHandler();
XMLHandler handler = new XMLXMLHandler();
- setDefaultXMLHandler(userAgent, XML_MIME_TYPE, handler);
- String svg = "http://www.w3.org/2000/svg";
- addXMLHandler(userAgent, XML_MIME_TYPE, svg, handler);
+ userAgent.getXMLHandlerRegistry().addXMLHandler(handler);
}
/**
Document doc = fo.getDocument();
String ns = fo.getNameSpace();
context.setProperty(XMLXMLHandler.HANDLER, handler);
- renderXML(userAgent, context, doc, ns);
+ renderXML(context, doc, ns);
endElement("foreignObject");
}
private AttributesImpl atts = new AttributesImpl();
- /**
- * @see org.apache.fop.render.XMLHandler#handleXML(RendererContext, Document, String)
- */
- public void handleXML(RendererContext context, Document doc,
- String ns) throws Exception {
+ /** @see org.apache.fop.render.XMLHandler */
+ public void handleXML(RendererContext context,
+ org.w3c.dom.Document doc, String ns) throws Exception {
TransformerHandler handler = (TransformerHandler) context.getProperty(HANDLER);
- //String svg = "http://www.w3.org/2000/svg";
writeDocument(doc, handler);
}
return result.toString();
}
+ /** @see org.apache.fop.render.XMLHandler#getMimeType() */
+ public String getMimeType() {
+ return XMLRenderer.XML_MIME_TYPE;
+ }
+
+ /** @see org.apache.fop.render.XMLHandler#getNamespace() */
+ public String getNamespace() {
+ return null; //Handle all XML content
+ }
+
}
--- /dev/null
+/*\r
+ * Copyright 1999-2005 The Apache Software Foundation.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/* $Id$ */\r
+\r
+package org.apache.fop.util;\r
+\r
+import java.io.BufferedReader;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.io.InputStreamReader;\r
+import java.io.Reader;\r
+import java.util.Enumeration;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+//code stolen from org.apache.batik.util and modified slightly\r
+//does what sun.misc.Service probably does, but it cannot be relied on.\r
+//hopefully will be part of standard jdk sometime.\r
+\r
+/**\r
+ * This class loads services present in the class path.\r
+ */\r
+public class Service {\r
+\r
+ private static Map providerMap = new java.util.Hashtable();\r
+\r
+ public static synchronized Iterator providers(Class cls) {\r
+ ClassLoader cl = cls.getClassLoader();\r
+ // null if loaded by bootstrap class loader\r
+ if (cl == null) {\r
+ cl = ClassLoader.getSystemClassLoader();\r
+ }\r
+ String serviceFile = "META-INF/services/" + cls.getName();\r
+\r
+ // log.debug("File: " + serviceFile);\r
+\r
+ List lst = (List)providerMap.get(serviceFile);\r
+ if (lst != null) {\r
+ return lst.iterator();\r
+ }\r
+\r
+ lst = new java.util.Vector();\r
+ providerMap.put(serviceFile, lst);\r
+\r
+ Enumeration e;\r
+ try {\r
+ e = cl.getResources(serviceFile);\r
+ } catch (IOException ioe) {\r
+ return lst.iterator();\r
+ }\r
+\r
+ while (e.hasMoreElements()) {\r
+ try {\r
+ java.net.URL u = (java.net.URL)e.nextElement();\r
+ //log.debug("URL: " + u);\r
+\r
+ InputStream is = u.openStream();\r
+ Reader r = new InputStreamReader(is, "UTF-8");\r
+ BufferedReader br = new BufferedReader(r);\r
+\r
+ String line = br.readLine();\r
+ while (line != null) {\r
+ try {\r
+ // First strip any comment...\r
+ int idx = line.indexOf('#');\r
+ if (idx != -1) {\r
+ line = line.substring(0, idx);\r
+ }\r
+\r
+ // Trim whitespace.\r
+ line = line.trim();\r
+\r
+ // If nothing left then loop around...\r
+ if (line.length() == 0) {\r
+ line = br.readLine();\r
+ continue;\r
+ }\r
+ // log.debug("Line: " + line);\r
+\r
+ // Try and load the class\r
+ // Object obj = cl.loadClass(line).newInstance();\r
+ // stick it into our vector...\r
+ lst.add(line);\r
+ } catch (Exception ex) {\r
+ // Just try the next line\r
+ }\r
+\r
+ line = br.readLine();\r
+ }\r
+ } catch (Exception ex) {\r
+ // Just try the next file...\r
+ }\r
+\r
+ }\r
+ return lst.iterator();\r
+ }\r
+\r
+ }
\ No newline at end of file