You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by cj...@apache.org on 2001/04/02 15:36:18 UTC
cvs commit: xml-batik/sources/org/apache/batik/svggen DefaultErrorHandler.java ErrorHandler.java SVGGraphics2DIOException.java SVGGraphics2DRuntimeException.java AbstractImageHandlerEncoder.java AbstractSVGConverter.java AbstractSVGFilterConverter.java DOMGroupManager.java DOMTreeManager.java DefaultImageHandler.java ImageHandlerBase64Encoder.java ImageHandlerJPEGEncoder.java ImageHandlerPNGEncoder.java SVGClipDescriptor.java SVGFilterConverter.java SVGFontDescriptor.java SVGGeneratorContext.java SVGGraphicContext.java SVGGraphicContextConverter.java SVGGraphicObjectConverter.java SVGGraphics2D.java SVGHintsDescriptor.java SVGLookupOp.java SVGRescaleOp.java SVGStrokeDescriptor.java XmlWriter.java
cjolif 01/04/02 06:36:18
Modified: sources/org/apache/batik/svggen
AbstractImageHandlerEncoder.java
AbstractSVGConverter.java
AbstractSVGFilterConverter.java
DOMGroupManager.java DOMTreeManager.java
DefaultImageHandler.java
ImageHandlerBase64Encoder.java
ImageHandlerJPEGEncoder.java
ImageHandlerPNGEncoder.java SVGClipDescriptor.java
SVGFilterConverter.java SVGFontDescriptor.java
SVGGeneratorContext.java SVGGraphicContext.java
SVGGraphicContextConverter.java
SVGGraphicObjectConverter.java SVGGraphics2D.java
SVGHintsDescriptor.java SVGLookupOp.java
SVGRescaleOp.java SVGStrokeDescriptor.java
XmlWriter.java
Added: sources/org/apache/batik/svggen DefaultErrorHandler.java
ErrorHandler.java SVGGraphics2DIOException.java
SVGGraphics2DRuntimeException.java
Log:
try to better match the error handling guidelines: still some work to be done i18n...
little optim by avoiding instanceof calls in xml writer
Revision Changes Path
1.8 +22 -22 xml-batik/sources/org/apache/batik/svggen/AbstractImageHandlerEncoder.java
Index: AbstractImageHandlerEncoder.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/AbstractImageHandlerEncoder.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- AbstractImageHandlerEncoder.java 2001/03/23 17:23:09 1.7
+++ AbstractImageHandlerEncoder.java 2001/04/02 13:36:02 1.8
@@ -17,7 +17,6 @@
import org.w3c.dom.Element;
-import org.apache.batik.dom.util.XLinkSupport;
import org.apache.batik.ext.awt.RenderingHintsKeyExt;
/**
@@ -29,19 +28,12 @@
* of the file created by this handler.
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: AbstractImageHandlerEncoder.java,v 1.7 2001/03/23 17:23:09 cjolif Exp $
+ * @version $Id: AbstractImageHandlerEncoder.java,v 1.8 2001/04/02 13:36:02 cjolif Exp $
* @see org.apache.batik.svggen.SVGGraphics2D
* @see org.apache.batik.svggen.ImageHandlerJPEGEncoder
* @see org.apache.batik.svggen.ImageHandlerPNGEncoder
*/
public abstract class AbstractImageHandlerEncoder extends DefaultImageHandler {
- private static final String ERROR_NULL_INPUT =
- "imageDir should not be null";
- private static final String ERROR_IMAGE_DIR_DOES_NOT_EXIST =
- "imageDir does not exist";
- private static final String ERROR_CANNOT_USE_IMAGE_DIR_AS_URL =
- "cannot convert imageDir to a URL value : ";
-
private static final AffineTransform IDENTITY = new AffineTransform();
/**
@@ -57,18 +49,19 @@
/**
* @param generatorContext the context in which the handler will work.
* @param imageDir directory where this handler should generate images.
- * If null, an IllegalArgumentException is thrown.
+ * If null, an SVGGraphics2DRuntimeException is thrown.
* @param urlRoot root for the urls that point to images created by this
* image handler. If null, then the url corresponding to imageDir
* is used.
*/
- public AbstractImageHandlerEncoder(String imageDir, String urlRoot) {
+ public AbstractImageHandlerEncoder(String imageDir, String urlRoot)
+ throws SVGGraphics2DIOException {
if (imageDir == null)
- throw new IllegalArgumentException(ERROR_NULL_INPUT);
+ throw new SVGGraphics2DRuntimeException(ERR_IMAGE_DIR_NULL);
File imageDirFile = new File(imageDir);
if (!imageDirFile.exists())
- throw new IllegalArgumentException(ERROR_IMAGE_DIR_DOES_NOT_EXIST);
+ throw new SVGGraphics2DRuntimeException(ERR_IMAGE_DIR_DOES_NOT_EXIST);
this.imageDir = imageDir;
if (urlRoot != null)
@@ -76,8 +69,10 @@
else {
try{
this.urlRoot = imageDirFile.toURL().toString();
- } catch(MalformedURLException e) {
- throw new IllegalArgumentException(ERROR_CANNOT_USE_IMAGE_DIR_AS_URL + e.getMessage());
+ } catch (MalformedURLException e) {
+ throw new SVGGraphics2DIOException(ERR_CANNOT_USE_IMAGE_DIR+
+ e.getMessage(),
+ e);
}
}
}
@@ -87,7 +82,8 @@
* Element parameter
*/
protected void handleHREF(Image image, Element imageElement,
- SVGGeneratorContext generatorContext){
+ SVGGeneratorContext generatorContext)
+ throws SVGGraphics2DIOException {
// Create an buffered image where the image will be drawn
Dimension size = new Dimension(image.getWidth(null),
image.getHeight(null));
@@ -109,7 +105,8 @@
* Element parameter
*/
protected void handleHREF(RenderedImage image, Element imageElement,
- SVGGeneratorContext generatorContext){
+ SVGGeneratorContext generatorContext)
+ throws SVGGraphics2DIOException {
// Create an buffered image where the image will be drawn
Dimension size = new Dimension(image.getWidth(), image.getHeight());
BufferedImage buf = buildBufferedImage(size);
@@ -132,7 +129,8 @@
* Element parameter
*/
protected void handleHREF(RenderableImage image, Element imageElement,
- SVGGeneratorContext generatorContext){
+ SVGGeneratorContext generatorContext)
+ throws SVGGraphics2DIOException {
// Create an buffered image where the image will be drawn
Dimension size = new Dimension((int)Math.ceil(image.getWidth()),
(int)Math.ceil(image.getHeight()));
@@ -153,9 +151,10 @@
private void saveBufferedImageToFile(Element imageElement,
BufferedImage buf,
- SVGGeneratorContext generatorContext) {
+ SVGGeneratorContext generatorContext)
+ throws SVGGraphics2DIOException {
if (generatorContext == null)
- throw new IllegalArgumentException(ERROR_CONTEXT_NULL);
+ throw new SVGGraphics2DRuntimeException(ERR_CONTEXT_NULL);
// Create a new file in image directory
File imageFile = null;
@@ -173,7 +172,7 @@
encodeImage(buf, imageFile);
// Update HREF
- imageElement.setAttributeNS(XLinkSupport.XLINK_NAMESPACE_URI,
+ imageElement.setAttributeNS(XLINK_NAMESPACE_URI,
ATTR_XLINK_HREF, urlRoot + "/" +
imageFile.getName());
}
@@ -194,7 +193,8 @@
* Derived classes should implement this method and encode the input
* BufferedImage as needed
*/
- public abstract void encodeImage(BufferedImage buf, File imageFile);
+ public abstract void encodeImage(BufferedImage buf, File imageFile)
+ throws SVGGraphics2DIOException;
/**
* This method creates a BufferedImage of the right size and type
1.3 +3 -6 xml-batik/sources/org/apache/batik/svggen/AbstractSVGConverter.java
Index: AbstractSVGConverter.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/AbstractSVGConverter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractSVGConverter.java 2001/03/21 14:35:30 1.2
+++ AbstractSVGConverter.java 2001/04/02 13:36:02 1.3
@@ -24,13 +24,10 @@
* values.
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: AbstractSVGConverter.java,v 1.2 2001/03/21 14:35:30 cjolif Exp $
+ * @version $Id: AbstractSVGConverter.java,v 1.3 2001/04/02 13:36:02 cjolif Exp $
*/
-public abstract class AbstractSVGConverter implements SVGConverter {
- private static final String ERROR_CONTEXT_NULL =
- "generatorContext should not be null";
-
+public abstract class AbstractSVGConverter implements SVGConverter, ErrorConstants {
/**
* Used by converters to create Elements and other DOM objects
*/
@@ -54,7 +51,7 @@
*/
public AbstractSVGConverter(SVGGeneratorContext generatorContext) {
if (generatorContext == null)
- throw new IllegalArgumentException(ERROR_CONTEXT_NULL);
+ throw new SVGGraphics2DRuntimeException(ERR_CONTEXT_NULL);
this.generatorContext = generatorContext;
}
1.3 +4 -6 xml-batik/sources/org/apache/batik/svggen/AbstractSVGFilterConverter.java
Index: AbstractSVGFilterConverter.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/AbstractSVGFilterConverter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractSVGFilterConverter.java 2001/03/21 14:35:32 1.2
+++ AbstractSVGFilterConverter.java 2001/04/02 13:36:02 1.3
@@ -24,12 +24,10 @@
* values.
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: AbstractSVGFilterConverter.java,v 1.2 2001/03/21 14:35:32 cjolif Exp $
+ * @version $Id: AbstractSVGFilterConverter.java,v 1.3 2001/04/02 13:36:02 cjolif Exp $
*/
-public abstract class AbstractSVGFilterConverter implements SVGFilterConverter {
- private static final String ERROR_CONTEXT_NULL =
- "generatorContext should not be null";
-
+public abstract class AbstractSVGFilterConverter
+ implements SVGFilterConverter, ErrorConstants {
/**
* Used by converters to create Elements and other DOM objects
*/
@@ -53,7 +51,7 @@
*/
public AbstractSVGFilterConverter(SVGGeneratorContext generatorContext) {
if (generatorContext == null)
- throw new IllegalArgumentException(ERROR_CONTEXT_NULL);
+ throw new SVGGraphics2DRuntimeException(ERR_CONTEXT_NULL);
this.generatorContext = generatorContext;
}
1.9 +4 -8 xml-batik/sources/org/apache/batik/svggen/DOMGroupManager.java
Index: DOMGroupManager.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/DOMGroupManager.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- DOMGroupManager.java 2001/03/27 14:46:08 1.8
+++ DOMGroupManager.java 2001/04/02 13:36:03 1.9
@@ -48,13 +48,9 @@
*
* @author <a href="mailto:cjolif@ilog.fr">Christophe Jolif</a>
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: DOMGroupManager.java,v 1.8 2001/03/27 14:46:08 cjolif Exp $
+ * @version $Id: DOMGroupManager.java,v 1.9 2001/04/02 13:36:03 cjolif Exp $
*/
-public class DOMGroupManager implements SVGSyntax {
- private static final String ERROR_GC_NULL = "gc should not be null";
- private static final String ERROR_DOMTREEMANAGER_NULL =
- "domTreeManager should not be null";
-
+public class DOMGroupManager implements SVGSyntax, ErrorConstants {
public final static short DRAW = 0x01;
public final static short FILL = 0x10;
@@ -88,10 +84,10 @@
*/
public DOMGroupManager(GraphicContext gc, DOMTreeManager domTreeManager) {
if (gc == null)
- throw new IllegalArgumentException(ERROR_GC_NULL);
+ throw new SVGGraphics2DRuntimeException(ERR_GC_NULL);
if (domTreeManager == null)
- throw new IllegalArgumentException(ERROR_DOMTREEMANAGER_NULL);
+ throw new SVGGraphics2DRuntimeException(ERR_DOMTREEMANAGER_NULL);
this.gc = gc;
this.domTreeManager = domTreeManager;
1.10 +8 -24 xml-batik/sources/org/apache/batik/svggen/DOMTreeManager.java
Index: DOMTreeManager.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/DOMTreeManager.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- DOMTreeManager.java 2001/03/27 14:46:08 1.9
+++ DOMTreeManager.java 2001/04/02 13:36:03 1.10
@@ -45,26 +45,10 @@
*
* @author <a href="mailto:cjolif">Christophe Jolif</a>
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: DOMTreeManager.java,v 1.9 2001/03/27 14:46:08 cjolif Exp $
+ * @version $Id: DOMTreeManager.java,v 1.10 2001/04/02 13:36:03 cjolif Exp $
*/
-public class DOMTreeManager implements SVGSyntax {
+public class DOMTreeManager implements SVGSyntax, ErrorConstants {
/**
- * Error messages.
- */
- private static final String ERROR_GC_NULL = "gc should not be null";
- private static final String ERROR_MAXGCOVERRIDES_OUTOFRANGE =
- "maxGcOverrides should be greater than zero";
- private static final String ERROR_TOP_LEVEL_GROUP_NULL =
- "topLevelGroup should not be null";
- private static final String ERROR_TOP_LEVEL_GROUP_NOT_G =
- "topLevelGroup should be a group <g>";
- private static final String ERROR_CONTEXT_NULL =
- "generatorContext should not be null";
-
- public static String GENERATOR_COMMENT =
- "Generated by the Batik Graphics2D SVG Generator";
-
- /**
* Maximum of Graphic Context attributes overrides
* in children of the current group.
*/
@@ -127,13 +111,13 @@
SVGGeneratorContext generatorContext,
int maxGCOverrides){
if (gc == null)
- throw new IllegalArgumentException(ERROR_GC_NULL);
+ throw new SVGGraphics2DRuntimeException(ERR_GC_NULL);
if (maxGCOverrides <= 0)
- throw new IllegalArgumentException(ERROR_MAXGCOVERRIDES_OUTOFRANGE);
+ throw new SVGGraphics2DRuntimeException(ERR_MAXGCOVERRIDES_OUTOFRANGE);
if (generatorContext == null)
- throw new IllegalArgumentException(ERROR_CONTEXT_NULL);
+ throw new SVGGraphics2DRuntimeException(ERR_CONTEXT_NULL);
this.generatorContext = generatorContext;
this.maxGCOverrides = maxGCOverrides;
@@ -219,10 +203,10 @@
*/
public void setTopLevelGroup(Element topLevelGroup){
if(topLevelGroup == null)
- throw new IllegalArgumentException(ERROR_TOP_LEVEL_GROUP_NULL);
+ throw new SVGGraphics2DRuntimeException(ERR_TOP_LEVEL_GROUP_NULL);
if(!SVG_G_TAG.equalsIgnoreCase(topLevelGroup.getTagName()))
- throw new IllegalArgumentException(ERROR_TOP_LEVEL_GROUP_NOT_G);
+ throw new SVGGraphics2DRuntimeException(ERR_TOP_LEVEL_GROUP_NOT_G);
recycleTopLevelGroup(false);
this.topLevelGroup = topLevelGroup;
@@ -243,7 +227,7 @@
(null, SVG_ENABLE_BACKGROUND_ATTRIBUTE, SVG_NEW_VALUE);
Comment generatorComment = generatorContext.domFactory.
- createComment(GENERATOR_COMMENT);
+ createComment(generatorContext.generatorComment);
svg.appendChild(generatorComment);
// Set default rendering context attributes in node
1.6 +50 -18 xml-batik/sources/org/apache/batik/svggen/DefaultImageHandler.java
Index: DefaultImageHandler.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/DefaultImageHandler.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DefaultImageHandler.java 2001/03/23 17:23:10 1.5
+++ DefaultImageHandler.java 2001/04/02 13:36:04 1.6
@@ -14,26 +14,24 @@
import org.w3c.dom.Element;
-import org.apache.batik.dom.util.XLinkSupport;
-
/**
* This interface default implementation of the ImageHandler
* interface simply puts a place holder in the xlink:href
* attribute and sets the width and height of the element.
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: DefaultImageHandler.java,v 1.5 2001/03/23 17:23:10 cjolif Exp $
+ * @version $Id: DefaultImageHandler.java,v 1.6 2001/04/02 13:36:04 cjolif Exp $
* @see org.apache.batik.svggen.SVGGraphics2D
*/
-public class DefaultImageHandler implements ImageHandler {
- static final String ERROR_CONTEXT_NULL =
- "generatorContext should not be null";
+public class DefaultImageHandler implements ImageHandler, ErrorConstants {
+ // reducing the dependency on dom package by doing this only once:
+ static final String XLINK_NAMESPACE_URI =
+ org.apache.batik.dom.util.XLinkSupport.XLINK_NAMESPACE_URI;
/**
* Build a <code>DefaultImageHandler</code>.
*/
- public DefaultImageHandler() {
- }
+ public DefaultImageHandler() {}
/**
* The handler should set the xlink:href tag and the width and
@@ -52,7 +50,17 @@
//
// Now, set the href
//
- handleHREF(image, imageElement, generatorContext);
+ try {
+ handleHREF(image, imageElement, generatorContext);
+ } catch (SVGGraphics2DIOException e) {
+ try {
+ generatorContext.errorHandler.handleError(e);
+ } catch (SVGGraphics2DIOException io) {
+ // we need a runtime exception because
+ // java.awt.Graphics2D method doesn't throw exceptions..
+ throw new SVGGraphics2DRuntimeException(io);
+ }
+ }
}
/**
@@ -72,7 +80,17 @@
//
// Now, set the href
//
- handleHREF(image, imageElement, generatorContext);
+ try {
+ handleHREF(image, imageElement, generatorContext);
+ } catch (SVGGraphics2DIOException e) {
+ try {
+ generatorContext.errorHandler.handleError(e);
+ } catch (SVGGraphics2DIOException io) {
+ // we need a runtime exception because
+ // java.awt.Graphics2D method doesn't throw exceptions..
+ throw new SVGGraphics2DRuntimeException(io);
+ }
+ }
}
/**
@@ -80,7 +98,8 @@
* height attributes.
*/
public void handleImage(RenderableImage image, Element imageElement,
- SVGGeneratorContext generatorContext) {
+ SVGGeneratorContext generatorContext)
+ throws SVGGraphics2DIOException {
//
// First, set the image width and height
//
@@ -92,7 +111,17 @@
//
// Now, set the href
//
- handleHREF(image, imageElement, generatorContext);
+ try {
+ handleHREF(image, imageElement, generatorContext);
+ } catch (SVGGraphics2DIOException e) {
+ try {
+ generatorContext.errorHandler.handleError(e);
+ } catch (SVGGraphics2DIOException io) {
+ // we need a runtime exception because
+ // java.awt.Graphics2D method doesn't throw exceptions..
+ throw new SVGGraphics2DRuntimeException(io);
+ }
+ }
}
/**
@@ -100,9 +129,10 @@
* Element parameter
*/
protected void handleHREF(Image image, Element imageElement,
- SVGGeneratorContext generatorContext) {
+ SVGGeneratorContext generatorContext)
+ throws SVGGraphics2DIOException {
// Simply write a placeholder
- imageElement.setAttributeNS(XLinkSupport.XLINK_NAMESPACE_URI,
+ imageElement.setAttributeNS(XLINK_NAMESPACE_URI,
ATTR_XLINK_HREF, image.toString());
}
@@ -111,9 +141,10 @@
* Element parameter
*/
protected void handleHREF(RenderedImage image, Element imageElement,
- SVGGeneratorContext generatorContext) {
+ SVGGeneratorContext generatorContext)
+ throws SVGGraphics2DIOException {
// Simply write a placeholder
- imageElement.setAttributeNS(XLinkSupport.XLINK_NAMESPACE_URI,
+ imageElement.setAttributeNS(XLINK_NAMESPACE_URI,
ATTR_XLINK_HREF, image.toString());
}
@@ -122,9 +153,10 @@
* Element parameter
*/
protected void handleHREF(RenderableImage image, Element imageElement,
- SVGGeneratorContext generatorContext) {
+ SVGGeneratorContext generatorContext)
+ throws SVGGraphics2DIOException {
// Simply write a placeholder
- imageElement.setAttributeNS(XLinkSupport.XLINK_NAMESPACE_URI,
+ imageElement.setAttributeNS(XLINK_NAMESPACE_URI,
ATTR_XLINK_HREF, image.toString());
}
}
1.11 +20 -18 xml-batik/sources/org/apache/batik/svggen/ImageHandlerBase64Encoder.java
Index: ImageHandlerBase64Encoder.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/ImageHandlerBase64Encoder.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ImageHandlerBase64Encoder.java 2001/03/23 17:23:11 1.10
+++ ImageHandlerBase64Encoder.java 2001/04/02 13:36:04 1.11
@@ -15,7 +15,6 @@
import java.io.*;
import java.net.*;
-import org.apache.batik.dom.util.XLinkSupport;
import org.apache.batik.util.Base64Encoder;
import org.apache.batik.ext.awt.image.codec.ImageEncoder;
import org.apache.batik.ext.awt.image.codec.PNGImageEncoder;
@@ -29,7 +28,7 @@
* the data protocol.
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: ImageHandlerBase64Encoder.java,v 1.10 2001/03/23 17:23:11 cjolif Exp $
+ * @version $Id: ImageHandlerBase64Encoder.java,v 1.11 2001/04/02 13:36:04 cjolif Exp $
* @see org.apache.batik.svggen.SVGGraphics2D
* @see org.apache.batik.svggen.ImageHandler
*/
@@ -49,18 +48,18 @@
* height attributes.
*/
protected void handleHREF(Image image, Element imageElement,
- SVGGeneratorContext generatorContext) {
- if (image == null) {
- throw new IllegalArgumentException();
- }
+ SVGGeneratorContext generatorContext)
+ throws SVGGraphics2DIOException {
+ if (image == null)
+ throw new SVGGraphics2DRuntimeException(ERR_IMAGE_NULL);
int width = image.getWidth(null);
int height = image.getHeight(null);
- if(width==0 || height==0){
+ if (width==0 || height==0) {
handleEmptyImage(imageElement);
- } else{
- if(image instanceof RenderedImage) {
+ } else {
+ if (image instanceof RenderedImage) {
handleHREF((RenderedImage)image, imageElement,
generatorContext);
} else {
@@ -82,9 +81,10 @@
* height attributes.
*/
protected void handleHREF(RenderableImage image, Element imageElement,
- SVGGeneratorContext generatorContext) {
+ SVGGeneratorContext generatorContext)
+ throws SVGGraphics2DIOException {
if (image == null){
- throw new IllegalArgumentException();
+ throw new SVGGraphics2DRuntimeException(ERR_IMAGE_NULL);
}
RenderedImage r = image.createDefaultRendering();
@@ -96,7 +96,7 @@
}
protected void handleEmptyImage(Element imageElement) {
- imageElement.setAttributeNS(XLinkSupport.XLINK_NAMESPACE_URI,
+ imageElement.setAttributeNS(XLINK_NAMESPACE_URI,
ATTR_XLINK_HREF, DATA_PROTOCOL_PNG_PREFIX);
imageElement.setAttributeNS(null, SVG_WIDTH_ATTRIBUTE, "0");
imageElement.setAttributeNS(null, SVG_HEIGHT_ATTRIBUTE, "0");
@@ -109,7 +109,8 @@
* input imageElement, using the data: protocol.
*/
protected void handleHREF(RenderedImage image, Element imageElement,
- SVGGeneratorContext generatorContext) {
+ SVGGeneratorContext generatorContext)
+ throws SVGGraphics2DIOException {
//
// First, encode the input image in PNG
//
@@ -124,22 +125,23 @@
try {
b64Encoder.encodeBuffer(new ByteArrayInputStream(pngBytes),
os);
- } catch(IOException e) {
+ } catch (IOException e) {
// Should not happen because we are doing in-memory processing
- throw new Error();
+ throw new SVGGraphics2DIOException(ERR_UNEXPECTED, e);
}
//
// Finally, write out url
//
- imageElement.setAttributeNS(XLinkSupport.XLINK_NAMESPACE_URI,
+ imageElement.setAttributeNS(XLINK_NAMESPACE_URI,
ATTR_XLINK_HREF,
DATA_PROTOCOL_PNG_PREFIX +
os.toString());
}
- public byte[] encodeImage(RenderedImage buf){
+ public byte[] encodeImage(RenderedImage buf)
+ throws SVGGraphics2DIOException {
try{
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageEncoder encoder = new PNGImageEncoder(os, null);
@@ -149,7 +151,7 @@
return os.toByteArray();
} catch(IOException e) {
// We are doing in-memory processing. This should not happen.
- throw new Error();
+ throw new SVGGraphics2DIOException(ERR_UNEXPECTED);
}
}
1.7 +9 -7 xml-batik/sources/org/apache/batik/svggen/ImageHandlerJPEGEncoder.java
Index: ImageHandlerJPEGEncoder.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/ImageHandlerJPEGEncoder.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ImageHandlerJPEGEncoder.java 2001/03/23 17:23:12 1.6
+++ ImageHandlerJPEGEncoder.java 2001/04/02 13:36:05 1.7
@@ -26,7 +26,7 @@
* image elements it handles.
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: ImageHandlerJPEGEncoder.java,v 1.6 2001/03/23 17:23:12 cjolif Exp $
+ * @version $Id: ImageHandlerJPEGEncoder.java,v 1.7 2001/04/02 13:36:05 cjolif Exp $
* @see org.apache.batik.svggen.SVGGraphics2D
* @see org.apache.batik.svggen.ImageHandlerJPEGEncoder
* @see org.apache.batik.svggen.ImageHandlerPNGEncoder
@@ -39,7 +39,8 @@
* image handler. If null, then the url corresponding to imageDir
* is used.
*/
- public ImageHandlerJPEGEncoder(String imageDir, String urlRoot) {
+ public ImageHandlerJPEGEncoder(String imageDir, String urlRoot)
+ throws SVGGraphics2DIOException {
super(imageDir, urlRoot);
}
@@ -47,7 +48,7 @@
* @return the suffix used by this encoder. E.g., ".jpg" for
* ImageHandlerJPEGEncoder
*/
- public final String getSuffix(){
+ public final String getSuffix() {
return ".jpg";
}
@@ -55,7 +56,7 @@
* @return the prefix used by this encoder. E.g., "jpegImage" for
* ImageHandlerJPEGEncoder
*/
- public final String getPrefix(){
+ public final String getPrefix() {
return "jpegImage";
}
@@ -63,7 +64,8 @@
* Derived classes should implement this method and encode the input
* BufferedImage as needed
*/
- public void encodeImage(BufferedImage buf, File imageFile) {
+ public void encodeImage(BufferedImage buf, File imageFile)
+ throws SVGGraphics2DIOException {
try{
OutputStream os = new FileOutputStream(imageFile);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os);
@@ -72,8 +74,8 @@
encoder.encode(buf, param);
os.flush();
os.close();
- }catch(IOException e){
- throw new Error("Could not write imageFile: " + imageFile.getName());
+ } catch(IOException e) {
+ throw new SVGGraphics2DIOException(ERR_WRITE+imageFile.getName());
}
}
1.7 +8 -6 xml-batik/sources/org/apache/batik/svggen/ImageHandlerPNGEncoder.java
Index: ImageHandlerPNGEncoder.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/ImageHandlerPNGEncoder.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ImageHandlerPNGEncoder.java 2001/03/23 17:23:12 1.6
+++ ImageHandlerPNGEncoder.java 2001/04/02 13:36:05 1.7
@@ -27,7 +27,7 @@
* image elements it handles.
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: ImageHandlerPNGEncoder.java,v 1.6 2001/03/23 17:23:12 cjolif Exp $
+ * @version $Id: ImageHandlerPNGEncoder.java,v 1.7 2001/04/02 13:36:05 cjolif Exp $
* @see org.apache.batik.svggen.SVGGraphics2D
* @see org.apache.batik.svggen.ImageHandlerJPEGEncoder
* @see org.apache.batik.svggen.ImageHandlerPNGEncoder
@@ -40,7 +40,8 @@
* image handler. If null, then the url corresponding to imageDir
* is used.
*/
- public ImageHandlerPNGEncoder(String imageDir, String urlRoot) {
+ public ImageHandlerPNGEncoder(String imageDir, String urlRoot)
+ throws SVGGraphics2DIOException {
super(imageDir, urlRoot);
}
@@ -64,15 +65,16 @@
* Derived classes should implement this method and encode the input
* BufferedImage as needed
*/
- public void encodeImage(BufferedImage buf, File imageFile){
- try{
+ public void encodeImage(BufferedImage buf, File imageFile)
+ throws SVGGraphics2DIOException {
+ try {
OutputStream os = new FileOutputStream(imageFile);
ImageEncoder encoder = new PNGImageEncoder(os, null);
encoder.encode(buf);
os.flush();
os.close();
- }catch(IOException e){
- throw new Error("Could not write imageFile: " + imageFile.getName());
+ } catch (IOException e) {
+ throw new SVGGraphics2DIOException(ERR_WRITE+imageFile.getName());
}
}
1.3 +3 -5 xml-batik/sources/org/apache/batik/svggen/SVGClipDescriptor.java
Index: SVGClipDescriptor.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/SVGClipDescriptor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SVGClipDescriptor.java 2001/03/19 11:22:28 1.2
+++ SVGClipDescriptor.java 2001/04/02 13:36:05 1.3
@@ -19,13 +19,11 @@
* Describes an SVG clip
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: SVGClipDescriptor.java,v 1.2 2001/03/19 11:22:28 cjolif Exp $
+ * @version $Id: SVGClipDescriptor.java,v 1.3 2001/04/02 13:36:05 cjolif Exp $
* @see org.apache.batik.ext.awt.g2d.GraphicContext
* @see org.apache.batik.svggen.SVGDescriptor
*/
public class SVGClipDescriptor implements SVGDescriptor, SVGSyntax{
- public static final String ERROR_NULL_INPUT = "clipPathValue should not be null";
-
private String clipPathValue;
private Element clipPathDef;
@@ -34,8 +32,8 @@
* @param attribute value referencing clipPathDef
*/
public SVGClipDescriptor(String clipPathValue, Element clipPathDef){
- if(clipPathValue == null)
- throw new IllegalArgumentException(ERROR_NULL_INPUT);
+ if (clipPathValue == null)
+ throw new SVGGraphics2DRuntimeException(ErrorConstants.ERR_CLIP_NULL);
this.clipPathValue = clipPathValue;
this.clipPathDef = clipPathDef;
1.3 +2 -2 xml-batik/sources/org/apache/batik/svggen/SVGFilterConverter.java
Index: SVGFilterConverter.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/SVGFilterConverter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SVGFilterConverter.java 2001/03/21 14:36:00 1.2
+++ SVGFilterConverter.java 2001/04/02 13:36:06 1.3
@@ -17,10 +17,10 @@
* a BufferedImageOp filter.
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: SVGFilterConverter.java,v 1.2 2001/03/21 14:36:00 cjolif Exp $
+ * @version $Id: SVGFilterConverter.java,v 1.3 2001/04/02 13:36:06 cjolif Exp $
* @see org.apache.batik.svggen.SVGFilterDescriptor
*/
-public interface SVGFilterConverter extends SVGSyntax{
+public interface SVGFilterConverter extends SVGSyntax {
/**
* Converts a Java 2D API BufferedImageOp into
* a set of attribute/value pairs and related definitions
1.2 +6 -8 xml-batik/sources/org/apache/batik/svggen/SVGFontDescriptor.java
Index: SVGFontDescriptor.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/SVGFontDescriptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SVGFontDescriptor.java 2001/01/23 17:12:25 1.1
+++ SVGFontDescriptor.java 2001/04/02 13:36:06 1.2
@@ -19,12 +19,10 @@
* Describes an SVG font
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: SVGFontDescriptor.java,v 1.1 2001/01/23 17:12:25 tkormann Exp $
+ * @version $Id: SVGFontDescriptor.java,v 1.2 2001/04/02 13:36:06 cjolif Exp $
* @see org.apache.batik.svggen.SVGFont
*/
public class SVGFontDescriptor implements SVGDescriptor, SVGSyntax {
- public static final String ERROR_NULL_INPUT = "none of the input arguments should be null";
-
private String fontSize;
private String fontWeight;
private String fontStyle;
@@ -37,11 +35,11 @@
String fontWeight,
String fontStyle,
String fontFamily){
- if(fontSize == null ||
- fontWeight == null ||
- fontStyle == null ||
- fontFamily == null)
- throw new IllegalArgumentException(ERROR_NULL_INPUT);
+ if (fontSize == null ||
+ fontWeight == null ||
+ fontStyle == null ||
+ fontFamily == null)
+ throw new SVGGraphics2DRuntimeException(ErrorConstants.ERR_FONT_NULL);
this.fontSize = fontSize;
this.fontWeight = fontWeight;
1.5 +51 -21 xml-batik/sources/org/apache/batik/svggen/SVGGeneratorContext.java
Index: SVGGeneratorContext.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/SVGGeneratorContext.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SVGGeneratorContext.java 2001/03/27 14:46:08 1.4
+++ SVGGeneratorContext.java 2001/04/02 13:36:06 1.5
@@ -18,23 +18,9 @@
*
* @see org.apache.batik.svggen.SVGGraphics2D#SVGGraphics2D(SVGGeneratorContext,boolean)
* @author <a href="mailto:cjolif@ilog.fr>Christophe Jolif</a>
- * @version $Id: SVGGeneratorContext.java,v 1.4 2001/03/27 14:46:08 cjolif Exp $
+ * @version $Id: SVGGeneratorContext.java,v 1.5 2001/04/02 13:36:06 cjolif Exp $
*/
-public class SVGGeneratorContext {
- /**
- * Error messages.
- */
- private static final String ERROR_DOM_FACTORY_NULL =
- "domFactory should not be null";
- private static final String ERROR_IMAGE_HANDLER_NULL =
- "imageHandler should not be null";
- private static final String ERROR_EXTENSION_HANDLER_NULL =
- "extensionHandler should not be null";
- private static final String ERROR_ID_GENERATOR_NULL =
- "idGenerator should not be null";
- private static final String ERROR_STYLE_HANDLER_NULL =
- "styleHandler should not be null";
-
+public class SVGGeneratorContext implements ErrorConstants {
// this fields are package access for read-only purpose
/**
@@ -70,6 +56,16 @@
StyleHandler styleHandler;
/**
+ * The comment to insert at generation time.
+ */
+ String generatorComment;
+
+ /**
+ * The error handler.
+ */
+ ErrorHandler errorHandler;
+
+ /**
* Builds an instance of <code>SVGGeneratorContext</code> with the given
* <code>domFactory</code> but let the user set later the other contextual
* information.
@@ -95,6 +91,7 @@
ctx.setExtensionHandler(new DefaultExtensionHandler());
ctx.setImageHandler(new ImageHandlerBase64Encoder());
ctx.setStyleHandler(new DefaultStyleHandler());
+ ctx.setComment("Generated by the Batik Graphics2D SVG Generator");
return ctx;
}
@@ -112,7 +109,7 @@
*/
final protected void setIDGenerator(SVGIDGenerator idGenerator) {
if (idGenerator == null)
- throw new IllegalArgumentException(ERROR_ID_GENERATOR_NULL);
+ throw new SVGGraphics2DRuntimeException(ERR_ID_GENERATOR_NULL);
this.idGenerator = idGenerator;
}
@@ -130,7 +127,7 @@
*/
final protected void setDOMFactory(Document domFactory) {
if (domFactory == null)
- throw new IllegalArgumentException(ERROR_DOM_FACTORY_NULL);
+ throw new SVGGraphics2DRuntimeException(ERR_DOM_FACTORY_NULL);
this.domFactory = domFactory;
}
@@ -148,7 +145,7 @@
*/
final protected void setExtensionHandler(ExtensionHandler extensionHandler) {
if (extensionHandler == null)
- throw new IllegalArgumentException(ERROR_EXTENSION_HANDLER_NULL);
+ throw new SVGGraphics2DRuntimeException(ERR_EXTENSION_HANDLER_NULL);
this.extensionHandler = extensionHandler;
}
@@ -166,7 +163,7 @@
*/
final protected void setImageHandler(ImageHandler imageHandler) {
if (imageHandler == null)
- throw new IllegalArgumentException(ERROR_IMAGE_HANDLER_NULL);
+ throw new SVGGraphics2DRuntimeException(ERR_IMAGE_HANDLER_NULL);
this.imageHandler = imageHandler;
}
@@ -184,7 +181,40 @@
*/
final protected void setStyleHandler(StyleHandler styleHandler) {
if (styleHandler == null)
- throw new IllegalArgumentException(ERROR_STYLE_HANDLER_NULL);
+ throw new SVGGraphics2DRuntimeException(ERR_STYLE_HANDLER_NULL);
this.styleHandler = styleHandler;
+ }
+
+ /**
+ * Returns the comment to be generated in the SVG file.
+ */
+ final public String getComment() {
+ return generatorComment;
+ }
+
+ /**
+ * Sets the comment to be used. It can be <code>null</code> if you
+ * want to disable it.
+ */
+ final protected void setComment(String generatorComment) {
+ this.generatorComment = generatorComment;
+ }
+
+ /**
+ * Returns the {@link org.apache.batik.svggen.ErrorHandler} that
+ * has been set.
+ */
+ final public ErrorHandler getErrorHandler() {
+ return errorHandler;
+ }
+
+ /**
+ * Sets the {@link org.apache.batik.svggen.Errorhandler}
+ * to be used. It should not be <code>null</code>.
+ */
+ final protected void setErrorHandler(ErrorHandler errorHandler) {
+ if (errorHandler == null)
+ throw new SVGGraphics2DRuntimeException(ERR_ERROR_HANDLER_NULL);
+ this.errorHandler = errorHandler;
}
}
1.4 +10 -11 xml-batik/sources/org/apache/batik/svggen/SVGGraphicContext.java
Index: SVGGraphicContext.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/SVGGraphicContext.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SVGGraphicContext.java 2001/03/27 14:46:08 1.3
+++ SVGGraphicContext.java 2001/04/02 13:36:06 1.4
@@ -22,12 +22,9 @@
* context attribute.
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: SVGGraphicContext.java,v 1.3 2001/03/27 14:46:08 cjolif Exp $
+ * @version $Id: SVGGraphicContext.java,v 1.4 2001/04/02 13:36:06 cjolif Exp $
*/
-public class SVGGraphicContext implements SVGConstants {
- private static final String ERROR_NULL_INPUT =
- "arguments should not be null";
-
+public class SVGGraphicContext implements SVGConstants, ErrorConstants {
// this properties can only be set of leaf nodes =>
// if they have default values they can be ignored
private static final String leafOnlyAttributes[] = {
@@ -54,9 +51,10 @@
*/
public SVGGraphicContext(Map context,
TransformStackElement transformStack[]) {
- if (context == null ||
- transformStack == null)
- throw new IllegalArgumentException(ERROR_NULL_INPUT);
+ if (context == null)
+ throw new SVGGraphics2DRuntimeException(ERR_MAP_NULL);
+ if (transformStack == null)
+ throw new SVGGraphics2DRuntimeException(ERR_TRANS_NULL);
this.context = context;
this.transformStack = transformStack;
computeGroupAndGraphicElementContext();
@@ -71,9 +69,10 @@
*/
public SVGGraphicContext(Map groupContext, Map graphicElementContext,
TransformStackElement transformStack[]) {
- if (groupContext == null || graphicElementContext == null ||
- transformStack == null)
- throw new IllegalArgumentException(ERROR_NULL_INPUT);
+ if (groupContext == null || graphicElementContext == null)
+ throw new SVGGraphics2DRuntimeException(ERR_MAP_NULL);
+ if (transformStack == null)
+ throw new SVGGraphics2DRuntimeException(ERR_TRANS_NULL);
this.groupContext = groupContext;
this.graphicElementContext = graphicElementContext;
1.8 +2 -5 xml-batik/sources/org/apache/batik/svggen/SVGGraphicContextConverter.java
Index: SVGGraphicContextConverter.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/SVGGraphicContextConverter.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- SVGGraphicContextConverter.java 2001/03/27 14:46:08 1.7
+++ SVGGraphicContextConverter.java 2001/04/02 13:36:07 1.8
@@ -25,12 +25,9 @@
* SVG attributes.
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: SVGGraphicContextConverter.java,v 1.7 2001/03/27 14:46:08 cjolif Exp $
+ * @version $Id: SVGGraphicContextConverter.java,v 1.8 2001/04/02 13:36:07 cjolif Exp $
*/
public class SVGGraphicContextConverter {
- private static final String ERROR_CONTEXT_NULL =
- "generatorContext should not be null";
-
private static final int GRAPHIC_CONTEXT_CONVERTER_COUNT = 6;
private SVGTransform transformConverter;
@@ -57,7 +54,7 @@
*/
public SVGGraphicContextConverter(SVGGeneratorContext generatorContext) {
if (generatorContext == null)
- throw new IllegalArgumentException(ERROR_CONTEXT_NULL);
+ throw new SVGGraphics2DRuntimeException(ErrorConstants.ERR_CONTEXT_NULL);
transformConverter = new SVGTransform();
paintConverter = new SVGPaint(generatorContext);
1.3 +2 -5 xml-batik/sources/org/apache/batik/svggen/SVGGraphicObjectConverter.java
Index: SVGGraphicObjectConverter.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/SVGGraphicObjectConverter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SVGGraphicObjectConverter.java 2001/03/21 14:36:05 1.2
+++ SVGGraphicObjectConverter.java 2001/04/02 13:36:07 1.3
@@ -18,12 +18,9 @@
/**
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: SVGGraphicObjectConverter.java,v 1.2 2001/03/21 14:36:05 cjolif Exp $
+ * @version $Id: SVGGraphicObjectConverter.java,v 1.3 2001/04/02 13:36:07 cjolif Exp $
*/
public abstract class SVGGraphicObjectConverter implements SVGSyntax {
- private static final String ERROR_CONTEXT_NULL =
- "generatorContext should not be null";
-
/**
* Used by converters to create Elements and other DOM objects.
*/
@@ -35,7 +32,7 @@
*/
public SVGGraphicObjectConverter(SVGGeneratorContext generatorContext) {
if (generatorContext == null)
- throw new IllegalArgumentException(ERROR_CONTEXT_NULL);
+ throw new SVGGraphics2DRuntimeException(ErrorConstants.ERR_CONTEXT_NULL);
this.generatorContext = generatorContext;
}
1.12 +82 -71 xml-batik/sources/org/apache/batik/svggen/SVGGraphics2D.java
Index: SVGGraphics2D.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/SVGGraphics2D.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- SVGGraphics2D.java 2001/03/27 14:46:08 1.11
+++ SVGGraphics2D.java 2001/04/02 13:36:07 1.12
@@ -44,7 +44,7 @@
*
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: SVGGraphics2D.java,v 1.11 2001/03/27 14:46:08 cjolif Exp $
+ * @version $Id: SVGGraphics2D.java,v 1.12 2001/04/02 13:36:07 cjolif Exp $
* @see org.apache.batik.ext.awt.g2d.GraphicContext
* @see org.apache.batik.svggen.DOMTreeManager
* @see org.apache.batik.svggen.DOMGroupManager
@@ -53,16 +53,8 @@
* @see org.w3c.dom.Document
*/
public class SVGGraphics2D extends AbstractGraphics2D
- implements Cloneable, SVGSyntax {
+ implements Cloneable, SVGSyntax, ErrorConstants {
/*
- * Error messages
- */
- private static final String ERROR_CANVAS_SIZE_NULL =
- "canvas size should not be null";
- private static final String ERROR_CONTEXT_NULL =
- "generatorContext should not be null";
-
- /*
* Constants definitions
*/
public static final String DEFAULT_XML_ENCODING = "ISO-8859-1";
@@ -136,9 +128,10 @@
/**
* @param SVG Canvas size
*/
- public final void setSVGCanvasSize(Dimension svgCanvasSize){
- if(svgCanvasSize == null)
- throw new IllegalArgumentException(ERROR_CANVAS_SIZE_NULL);
+ public final void setSVGCanvasSize(Dimension svgCanvasSize) {
+ if (svgCanvasSize == null)
+ generatorCtx.errorHandler.
+ handleError(new SVGGraphics2DRuntimeException(ERR_CANVAS_SIZE_NULL));
this.svgCanvasSize = new Dimension(svgCanvasSize);
}
@@ -189,7 +182,7 @@
/**
* @param domFactory Factory which will produce Elements for the DOM tree
* this Graphics2D generates.
- * @exception IllegalArgumentException if domFactory is null.
+ * @exception SVGGraphics2DRuntimeException if domFactory is null.
*/
public SVGGraphics2D(Document domFactory) {
this(SVGGeneratorContext.createDefault(domFactory), false);
@@ -205,7 +198,7 @@
* @param textAsShapes if true, all text is turned into SVG shapes in the
* convertion. No SVG text is output.
*
- * @exception IllegalArgumentException if domFactory is null.
+ * @exception SVGGraphics2DRuntimeException if domFactory is null.
*/
public SVGGraphics2D(Document domFactory,
ImageHandler imageHandler,
@@ -221,13 +214,16 @@
* that will provide all useful information to the generator.
* @param textAsShapes if true, all text is turned into SVG shapes in the
* convertion. No SVG text is output.
+ *
+ * @exception SVGGraphics2DRuntimeException if generatorContext is null.
*/
public SVGGraphics2D(SVGGeneratorContext generatorCtx,
boolean textAsShapes) {
super(textAsShapes);
if (generatorCtx == null)
- throw new IllegalArgumentException(ERROR_CONTEXT_NULL);
+ // not error handler here as we don't have the ctx...
+ throw new SVGGraphics2DRuntimeException(ERR_CONTEXT_NULL);
this.generatorCtx = generatorCtx;
@@ -260,7 +256,7 @@
* @param svgFileName name of the file where SVG content
* should be written
*/
- public void stream(String svgFileName) throws IOException {
+ public void stream(String svgFileName) throws SVGGraphics2DIOException {
stream(svgFileName, false);
}
@@ -270,19 +266,25 @@
* @param useCss defines whether the output SVG should use CSS style
* properties as opposed to plain attributes.
*/
- public void stream(String svgFileName, boolean useCss) throws IOException {
- OutputStreamWriter writer =
- new OutputStreamWriter(new FileOutputStream(svgFileName),
- DEFAULT_XML_ENCODING);
- stream(writer, useCss);
- writer.flush();
- writer.close();
+ public void stream(String svgFileName, boolean useCss)
+ throws SVGGraphics2DIOException {
+ try {
+ OutputStreamWriter writer =
+ new OutputStreamWriter(new FileOutputStream(svgFileName),
+ DEFAULT_XML_ENCODING);
+ stream(writer, useCss);
+ writer.flush();
+ writer.close();
+ } catch (IOException e) {
+ generatorCtx.errorHandler.
+ handleError(new SVGGraphics2DIOException(e));
+ }
}
/**
* @param writer used to writer out the SVG content
*/
- public void stream(Writer writer) throws IOException {
+ public void stream(Writer writer) throws SVGGraphics2DIOException {
stream(writer, false);
}
@@ -291,7 +293,8 @@
* @param useCss defines whether the output SVG should use CSS
* style properties as opposed to plain attributes.
*/
- public void stream(Writer writer, boolean useCss) throws IOException {
+ public void stream(Writer writer, boolean useCss)
+ throws SVGGraphics2DIOException {
Element svgRoot = getRoot();
stream(svgRoot, writer, useCss);
}
@@ -299,7 +302,8 @@
/**
* @param svgRoot root element to stream out
*/
- public void stream(Element svgRoot, Writer writer) throws IOException{
+ public void stream(Element svgRoot, Writer writer)
+ throws SVGGraphics2DIOException {
stream(svgRoot, writer, false);
}
@@ -310,27 +314,35 @@
* properties as opposed to plain attributes.
*/
public void stream(Element svgRoot, Writer writer, boolean useCss)
- throws IOException {
- PrintWriter out = new PrintWriter(writer);
- DocumentFragment svgDocument =
- svgRoot.getOwnerDocument().createDocumentFragment();
- svgDocument.appendChild(svgRoot);
-
- /*if(useCss){
- Node svgCssDocument = svgDocument;
- SVGCSSStyler.style(svgCssDocument);
- XmlWriter.writeXml(svgCssDocument, writer);
- writer.flush();
- }
- else{
- XmlWriter.writeXml(svgDocument, writer);
- writer.flush();
- }*/
- if(useCss)
- SVGCSSStyler.style(svgDocument);
-
- XmlWriter.writeXml(svgDocument, writer);
- writer.flush();
+ throws SVGGraphics2DIOException {
+ try {
+ PrintWriter out = new PrintWriter(writer);
+ DocumentFragment svgDocument =
+ svgRoot.getOwnerDocument().createDocumentFragment();
+ svgDocument.appendChild(svgRoot);
+
+ /*if(useCss){
+ Node svgCssDocument = svgDocument;
+ SVGCSSStyler.style(svgCssDocument);
+ XmlWriter.writeXml(svgCssDocument, writer);
+ writer.flush();
+ }
+ else{
+ XmlWriter.writeXml(svgDocument, writer);
+ writer.flush();
+ }*/
+ if (useCss)
+ SVGCSSStyler.style(svgDocument);
+
+ XmlWriter.writeXml(svgDocument, writer);
+ writer.flush();
+ } catch (IOException io) {
+ generatorCtx.errorHandler.
+ handleError(new SVGGraphics2DIOException(io));
+ } catch (SVGGraphics2DIOException e) {
+ generatorCtx.errorHandler.
+ handleError(e);
+ }
}
/**
@@ -416,8 +428,9 @@
* drawn twice, then all pixels are restored to their original values.
* @param c1 the XOR alternation color
*/
- public void setXORMode(Color c1){
- throw new Error("XOR Mode is not supported by Graphics2D SVG Generator");
+ public void setXORMode(Color c1) {
+ generatorCtx.errorHandler.
+ handleError(new SVGGraphics2DRuntimeException(ERR_XOR));
}
/**
@@ -481,13 +494,13 @@
* @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
*/
public boolean drawImage(Image img, int x, int y,
- ImageObserver observer){
+ ImageObserver observer) {
Element imageElement =
getDOMFactory().createElementNS(SVG_NAMESPACE_URI, SVG_IMAGE_TAG);
imageElement.setAttributeNS(null, SVG_X_ATTRIBUTE, Integer.toString(x));
imageElement.setAttributeNS(null, SVG_Y_ATTRIBUTE, Integer.toString(y));
imageElement.setAttributeNS(null, SVG_WIDTH_ATTRIBUTE,
- Integer.toString(img.getWidth(null)));
+ Integer.toString(img.getWidth(null)));
imageElement.setAttributeNS(null, SVG_HEIGHT_ATTRIBUTE,
Integer.toString(img.getHeight(null)));
getImageHandler().handleImage(img, imageElement, generatorCtx);
@@ -572,7 +585,7 @@
* @see java.awt.Component#getGraphics
* @see java.awt.Graphics#create
*/
- public void dispose(){
+ public void dispose() {
this.domTreeManager.removeGroupManager(this.domGroupManager);
}
@@ -644,16 +657,15 @@
try{
inverseTransform = xform.createInverse();
} catch(NoninvertibleTransformException e){
- // Should never happen since we checked the
- // matrix determinant
- throw new Error();
+ // Should never happen since we checked the
+ // matrix determinant
+ throw new SVGGraphics2DRuntimeException(ERR_UNEXPECTED);
}
gc.transform(xform);
retVal = drawImage(img, 0, 0, null);
gc.transform(inverseTransform);
- }
- else{
+ } else {
AffineTransform savTransform = new AffineTransform(gc.getTransform());
gc.transform(xform);
retVal = drawImage(img, 0, 0, null);
@@ -713,7 +725,7 @@
}catch(NoninvertibleTransformException e){
// This should never happen since we checked the
// matrix determinant
- throw new Error();
+ throw new SVGGraphics2DRuntimeException(ERR_UNEXPECTED);
}
gc.transform(transform);
drawImage(img, x, y, null);
@@ -825,15 +837,14 @@
try{
inverseTransform = xform.createInverse();
}catch(NoninvertibleTransformException e){
- // This should never happen since we checked
- // the matrix determinant
- throw new Error();
+ // This should never happen since we checked
+ // the matrix determinant
+ throw new SVGGraphics2DRuntimeException(ERR_UNEXPECTED);
}
gc.transform(xform);
domGroupManager.addElement(image);
gc.transform(inverseTransform);
- }
- else{
+ } else {
AffineTransform savTransform = new AffineTransform(gc.getTransform());
gc.transform(xform);
domGroupManager.addElement(image);
@@ -891,15 +902,14 @@
try{
inverseTransform = xform.createInverse();
}catch(NoninvertibleTransformException e){
- // This should never happen because we checked the
- // matrix determinant
- throw new Error();
+ // This should never happen because we checked the
+ // matrix determinant
+ throw new SVGGraphics2DRuntimeException(ERR_UNEXPECTED);
}
gc.transform(xform);
domGroupManager.addElement(image);
gc.transform(inverseTransform);
- }
- else{
+ } else {
AffineTransform savTransform = new AffineTransform(gc.getTransform());
gc.transform(xform);
domGroupManager.addElement(image);
@@ -970,8 +980,9 @@
* @see #setClip
*/
public void drawString(AttributedCharacterIterator iterator,
- float x, float y){
- throw new Error("AttributedCharacterIterator not supported yet");
+ float x, float y) {
+ generatorCtx.errorHandler.
+ handleError(new SVGGraphics2DRuntimeException(ERR_ACI));
}
1.3 +2 -2 xml-batik/sources/org/apache/batik/svggen/SVGHintsDescriptor.java
Index: SVGHintsDescriptor.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/SVGHintsDescriptor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SVGHintsDescriptor.java 2001/03/26 09:45:14 1.2
+++ SVGHintsDescriptor.java 2001/04/02 13:36:08 1.3
@@ -19,7 +19,7 @@
* Describes a set of SVG hints
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: SVGHintsDescriptor.java,v 1.2 2001/03/26 09:45:14 tkormann Exp $
+ * @version $Id: SVGHintsDescriptor.java,v 1.3 2001/04/02 13:36:08 cjolif Exp $
* @see org.apache.batik.svggen.SVGRenderingHints
*/
public class SVGHintsDescriptor implements SVGDescriptor, SVGSyntax {
@@ -44,7 +44,7 @@
textRendering == null ||
shapeRendering == null ||
imageRendering == null)
- throw new IllegalArgumentException(ERROR_NULL_INPUT);
+ throw new SVGGraphics2DRuntimeException(ErrorConstants.ERR_HINT_NULL);
this.colorInterpolation = colorInterpolation;
this.colorRendering = colorRendering;
1.10 +2 -5 xml-batik/sources/org/apache/batik/svggen/SVGLookupOp.java
Index: SVGLookupOp.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/SVGLookupOp.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- SVGLookupOp.java 2001/04/01 18:05:11 1.9
+++ SVGLookupOp.java 2001/04/02 13:36:08 1.10
@@ -27,13 +27,10 @@
* of the lookup table.
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: SVGLookupOp.java,v 1.9 2001/04/01 18:05:11 hillion Exp $
+ * @version $Id: SVGLookupOp.java,v 1.10 2001/04/02 13:36:08 cjolif Exp $
* @see org.apache.batik.svggen.SVGBufferedImageOp
*/
public class SVGLookupOp extends AbstractSVGFilterConverter {
- private static final String ERROR_ILLEGAL_BUFFERED_IMAGE_LOOKUP_OP =
- "BufferedImage LookupOp should have 1, 3 or 4 lookup arrays";
-
/**
* Gamma for linear to sRGB convertion
*/
@@ -213,7 +210,7 @@
int nComponents = lookupTable.getNumComponents();
if((nComponents != 1) && (nComponents != 3) && (nComponents != 4))
- throw new IllegalArgumentException(ERROR_ILLEGAL_BUFFERED_IMAGE_LOOKUP_OP);
+ throw new SVGGraphics2DRuntimeException(ERR_ILLEGAL_BUFFERED_IMAGE_LOOKUP_OP);
StringBuffer lookupTableBuf[] = new StringBuffer[nComponents];
for(int i=0; i<nComponents; i++)
1.9 +3 -7 xml-batik/sources/org/apache/batik/svggen/SVGRescaleOp.java
Index: SVGRescaleOp.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/SVGRescaleOp.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- SVGRescaleOp.java 2001/04/01 18:05:11 1.8
+++ SVGRescaleOp.java 2001/04/02 13:36:09 1.9
@@ -28,14 +28,10 @@
* offsets.
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: SVGRescaleOp.java,v 1.8 2001/04/01 18:05:11 hillion Exp $
+ * @version $Id: SVGRescaleOp.java,v 1.9 2001/04/02 13:36:09 cjolif Exp $
* @see org.apache.batik.svggen.SVGBufferedImageOp
*/
public class SVGRescaleOp extends AbstractSVGFilterConverter {
- public static final String ERROR_SCALE_FACTORS_AND_OFFSETS_MISMATCH =
- "RescapeOp offsets and scaleFactor array lenght do not match";
- public static final String ERROR_ILLEGAL_BUFFERED_IMAGE_RESCALE_OP =
- "BufferedImage RescaleOp should have 1, 3 or 4 scale factors";
/**
* @param generatorContext used to build Elements
@@ -101,12 +97,12 @@
float offsets[] = rescaleOp.getOffsets(null);
float scaleFactors[] = rescaleOp.getScaleFactors(null);
if(offsets.length != scaleFactors.length)
- throw new IllegalArgumentException(ERROR_SCALE_FACTORS_AND_OFFSETS_MISMATCH);
+ throw new SVGGraphics2DRuntimeException(ERR_SCALE_FACTORS_AND_OFFSETS_MISMATCH);
if(offsets.length != 1 &&
offsets.length != 3 &&
offsets.length != 4)
- throw new IllegalArgumentException(ERROR_ILLEGAL_BUFFERED_IMAGE_RESCALE_OP);
+ throw new SVGGraphics2DRuntimeException(ERR_ILLEGAL_BUFFERED_IMAGE_RESCALE_OP);
Element feFuncR = domFactory.createElementNS(SVG_NAMESPACE_URI,
SVG_FE_FUNC_R_TAG);
1.3 +5 -6 xml-batik/sources/org/apache/batik/svggen/SVGStrokeDescriptor.java
Index: SVGStrokeDescriptor.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/SVGStrokeDescriptor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SVGStrokeDescriptor.java 2001/03/26 09:45:16 1.2
+++ SVGStrokeDescriptor.java 2001/04/02 13:36:09 1.3
@@ -20,11 +20,9 @@
* to values: an SVG paint value and an SVG opacity value
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: SVGStrokeDescriptor.java,v 1.2 2001/03/26 09:45:16 tkormann Exp $
+ * @version $Id: SVGStrokeDescriptor.java,v 1.3 2001/04/02 13:36:09 cjolif Exp $
*/
public class SVGStrokeDescriptor implements SVGDescriptor, SVGSyntax{
- public static final String ERROR_NULL_ARGUMENT = "None of the stroke attribute values should be null";
-
private String strokeWidth;
private String capStyle;
private String joinStyle;
@@ -33,15 +31,16 @@
private String dashOffset;
- public SVGStrokeDescriptor(String strokeWidth, String capStyle, String joinStyle,
- String miterLimit, String dashArray, String dashOffset){
+ public SVGStrokeDescriptor(String strokeWidth, String capStyle,
+ String joinStyle, String miterLimit,
+ String dashArray, String dashOffset){
if(strokeWidth == null ||
capStyle == null ||
joinStyle == null ||
miterLimit == null ||
dashArray == null ||
dashOffset == null)
- throw new IllegalArgumentException(ERROR_NULL_ARGUMENT);
+ throw new SVGGraphics2DRuntimeException(ErrorConstants.ERR_STROKE_NULL);
this.strokeWidth = strokeWidth;
this.capStyle = capStyle;
1.5 +71 -49 xml-batik/sources/org/apache/batik/svggen/XmlWriter.java
Index: XmlWriter.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/XmlWriter.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XmlWriter.java 2001/03/19 09:26:28 1.4
+++ XmlWriter.java 2001/04/02 13:36:09 1.5
@@ -21,14 +21,15 @@
* for Sun's Project X by David Brownell.
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: XmlWriter.java,v 1.4 2001/03/19 09:26:28 cjolif Exp $
+ * @version $Id: XmlWriter.java,v 1.5 2001/04/02 13:36:09 cjolif Exp $
*/
class XmlWriter implements SVGConstants {
- static private String EOL;
- static private String TAG_END = " />";
- static private String TAG_START = "</";
- static private String SPACE = " ";
+ static private String EOL;
+ static private final String TAG_END = " />";
+ static private final String TAG_START = "</";
+ static private final String SPACE = " ";
+
static {
String temp;
try { temp = System.getProperty ("line.separator", "\n"); }
@@ -41,11 +42,8 @@
private int indentLevel;
public IndentWriter(Writer proxied){
- if(proxied == null)
- throw new IllegalArgumentException();
-
- // if(proxied instanceof OutputStreamWriter)
- // System.out.println("Encoding : " + ((OutputStreamWriter)proxied).getEncoding());
+ if (proxied == null)
+ throw new SVGGraphics2DRuntimeException(ErrorConstants.ERR_PROXY);
this.proxied = proxied;
}
@@ -111,7 +109,8 @@
/**
* Writes the attribute's value.
*/
- private static void writeChildrenXml(Attr attr, IndentWriter out) throws IOException{
+ private static void writeChildrenXml(Attr attr, IndentWriter out)
+ throws IOException {
String value = attr.getValue();
for (int i = 0; i < value.length (); i++) {
int c = value.charAt (i);
@@ -131,7 +130,8 @@
* prevent illegal comments: between consecutive dashes ("--")
* or if the last character of the comment is a dash.
*/
- private static void writeXml(Comment comment, IndentWriter out) throws IOException {
+ private static void writeXml(Comment comment, IndentWriter out)
+ throws IOException {
char data[] = comment.getData().toCharArray();
out.write ("<!--");
if (data != null) {
@@ -158,7 +158,8 @@
out.write ("-->");
}
- private static void writeXml(Text text, IndentWriter out) throws IOException{
+ private static void writeXml(Text text, IndentWriter out)
+ throws IOException {
char data[] = text.getData().toCharArray();
int start = 0, last = 0;
@@ -196,7 +197,8 @@
out.write (data, start, last - start);
}
- private static void writeXml(CDATASection cdataSection, IndentWriter out) throws IOException{
+ private static void writeXml(CDATASection cdataSection, IndentWriter out)
+ throws IOException {
char[] data = cdataSection.getData().toCharArray();
out.write ("<![CDATA[");
for (int i = 0; i < data.length; i++) {
@@ -217,7 +219,8 @@
out.write ("]]>");
}
- private static void writeXml(Element element, IndentWriter out) throws IOException{
+ private static void writeXml(Element element, IndentWriter out)
+ throws IOException, SVGGraphics2DIOException {
out.write (TAG_START, 0, 1); // "<"
out.write (element.getTagName());
@@ -248,7 +251,8 @@
}
}
- private static void writeChildrenXml(Element element, IndentWriter out) throws IOException {
+ private static void writeChildrenXml(Element element, IndentWriter out)
+ throws IOException, SVGGraphics2DIOException {
NodeList children = element.getChildNodes();
if (children == null)
return;
@@ -275,11 +279,13 @@
}
}
- private static void writeDocumentHeader(IndentWriter out) throws IOException {
+ private static void writeDocumentHeader(IndentWriter out)
+ throws IOException {
String encoding = null;
- if(out.getProxied() instanceof OutputStreamWriter)
- encoding = java2std (((OutputStreamWriter)out.getProxied()).getEncoding ());
+ if (out.getProxied() instanceof OutputStreamWriter)
+ encoding =
+ java2std(((OutputStreamWriter)out.getProxied()).getEncoding());
out.write ("<?xml version=\"1.0\"");
if (encoding != null) {
@@ -302,13 +308,15 @@
out.write (EOL);
}
- private static void writeXml (Document document, IndentWriter out) throws IOException{
+ private static void writeXml(Document document, IndentWriter out)
+ throws IOException, SVGGraphics2DIOException {
writeDocumentHeader(out);
NodeList childList = document.getChildNodes();
writeXml(childList, out);
}
- private static void writeXml(NodeList childList, IndentWriter out) throws IOException{
+ private static void writeXml(NodeList childList, IndentWriter out)
+ throws IOException, SVGGraphics2DIOException {
int length = childList.getLength ();
if (length == 0)
@@ -320,7 +328,7 @@
}
}
- static String java2std (String encodingName){
+ static String java2std(String encodingName) {
if (encodingName == null)
return null;
@@ -364,33 +372,47 @@
return encodingName;
}
- public static void writeXml(Node node, Writer writer) throws IOException {
- // System.out.println("Writing class: " + node.getClass().getName());
- IndentWriter out = null;
- if(writer instanceof IndentWriter)
- out = (IndentWriter)writer;
- else
- out = new IndentWriter(writer);
-
- if(node instanceof Attr)
- writeXml((Attr)node, out);
- else if(node instanceof Comment)
- writeXml((Comment)node, out);
- else if(node instanceof Text)
- writeXml((Text)node, out);
- else if(node instanceof CDATASection)
- writeXml((CDATASection)node, out);
- else if(node instanceof Document)
- writeXml((Document)node, out);
- else if(node instanceof DocumentFragment){
- writeDocumentHeader(out);
- NodeList childList = node.getChildNodes();
- writeXml(childList, out);
- }
- else if(node instanceof Element)
- writeXml((Element)node, out);
- else {
- System.err.println("Unable to write node of type: " + node.getClass().getName());
+ public static void writeXml(Node node, Writer writer)
+ throws SVGGraphics2DIOException {
+ try {
+ IndentWriter out = null;
+ if (writer instanceof IndentWriter)
+ out = (IndentWriter)writer;
+ else
+ out = new IndentWriter(writer);
+
+ switch (node.getNodeType()) {
+ case Node.ATTRIBUTE_NODE:
+ writeXml((Attr)node, out);
+ break;
+ case Node.COMMENT_NODE:
+ writeXml((Comment)node, out);
+ break;
+ case Node.TEXT_NODE:
+ writeXml((Text)node, out);
+ break;
+ case Node.CDATA_SECTION_NODE:
+ writeXml((CDATASection)node, out);
+ break;
+ case Node.DOCUMENT_NODE:
+ writeXml((Document)node, out);
+ break;
+ case Node.DOCUMENT_FRAGMENT_NODE:
+ writeDocumentHeader(out);
+ NodeList childList = node.getChildNodes();
+ writeXml(childList, out);
+ break;
+ case Node.ELEMENT_NODE:
+ writeXml((Element)node, out);
+ break;
+ default:
+ throw
+ new SVGGraphics2DRuntimeException(ErrorConstants.INVALID_NODE+
+ node.getClass().
+ getName());
+ }
+ } catch (IOException io) {
+ throw new SVGGraphics2DIOException(io);
}
}
}
1.1 xml-batik/sources/org/apache/batik/svggen/DefaultErrorHandler.java
Index: DefaultErrorHandler.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.batik.svggen;
/**
* The <code>ErrorHandler</code> interface allows you to specialize
* how the error will be set on an SVG <code>Element</code>.
*
* @author <a href="mailto:cjolif@ilog.fr">Christophe Jolif</a>
* @version $Id: DefaultErrorHandler.java,v 1.1 2001/04/02 13:36:04 cjolif Exp $
*/
public class DefaultErrorHandler implements ErrorHandler {
/**
* This method handles the <code>SVGGraphics2DIOException</code>. The default
* implementation re-throws the exception.
*/
public void handleError(SVGGraphics2DIOException ex)
throws SVGGraphics2DIOException {
throw ex;
}
/**
* This method handles the <code>SVGGraphics2DRuntimeException</code>.
* The default implementation print the exception message.
*/
public void handleError(SVGGraphics2DRuntimeException ex)
throws SVGGraphics2DRuntimeException {
System.err.println(ex.getMessage());
}
}
1.1 xml-batik/sources/org/apache/batik/svggen/ErrorHandler.java
Index: ErrorHandler.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.batik.svggen;
/**
* The <code>ErrorHandler</code> interface allows you to specialize
* how the error will be set on an SVG <code>Element</code>.
*
* @author <a href="mailto:cjolif@ilog.fr">Christophe Jolif</a>
* @version $Id: ErrorHandler.java,v 1.1 2001/04/02 13:36:04 cjolif Exp $
*/
public interface ErrorHandler {
/**
* This method handles the <code>SVGGraphics2DIOException</code>.
*/
public void handleError(SVGGraphics2DIOException ex)
throws SVGGraphics2DIOException;
/**
* This method handles the <code>SVGGraphics2DRuntimeException</code>.
*/
public void handleError(SVGGraphics2DRuntimeException ex)
throws SVGGraphics2DRuntimeException;
}
1.1 xml-batik/sources/org/apache/batik/svggen/SVGGraphics2DIOException.java
Index: SVGGraphics2DIOException.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.batik.svggen;
import java.io.IOException;
/**
* Thrown when an SVG Generator method receives an illegal argument in parameter.
*
* @author <a href="mailto:cjolif@ilog.fr">Christophe Jolif</a>
* @version $Id: SVGGraphics2DIOException.java,v 1.1 2001/04/02 13:36:08 cjolif Exp $
*/
public class SVGGraphics2DIOException extends Exception {
/** The enclosed exception. */
private IOException embedded;
/**
* Constructs a new <code>SVGGraphics2DIOException</code> with the
* specified detail message.
* @param s the detail message of this exception
*/
public SVGGraphics2DIOException(String s) {
this(s, null);
}
/**
* Constructs a new <code>SVGGraphics2DIOException</code> with the
* specified detail message.
* @param ex the enclosed exception
*/
public SVGGraphics2DIOException(IOException ex) {
this(null, ex);
}
/**
* Constructs a new <code>SVGGraphics2DIOException</code> with the
* specified detail message.
* @param s the detail message of this exception
* @param ex the original exception
*/
public SVGGraphics2DIOException(String s,
IOException ex) {
super(s);
embedded = ex;
}
/**
* Returns the message of this exception. If an error message has
* been specified, returns that one. Otherwise, return the error message
* of enclosed exception or null if any.
*/
public String getMessage() {
String msg = super.getMessage();
if (msg != null) {
return msg;
} else if (embedded != null) {
return embedded.getMessage();
} else {
return null;
}
}
/**
* Returns the original enclosed exception or null if any.
*/
public IOException getException() {
return embedded;
}
}
1.1 xml-batik/sources/org/apache/batik/svggen/SVGGraphics2DRuntimeException.java
Index: SVGGraphics2DRuntimeException.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.batik.svggen;
/**
* Thrown when an SVG Generator method receives an illegal argument in parameter.
*
* @author <a href="mailto:cjolif@ilog.fr">Christophe Jolif</a>
* @version $Id: SVGGraphics2DRuntimeException.java,v 1.1 2001/04/02 13:36:08 cjolif Exp $
*/
public class SVGGraphics2DRuntimeException extends RuntimeException {
/** The enclosed exception. */
private Exception embedded;
/**
* Constructs a new <code>SVGGraphics2DRuntimeException</code> with the
* specified detail message.
* @param s the detail message of this exception
*/
public SVGGraphics2DRuntimeException(String s) {
this(s, null);
}
/**
* Constructs a new <code>SVGGraphics2DRuntimeException</code> with the
* specified detail message.
* @param ex the enclosed exception
*/
public SVGGraphics2DRuntimeException(Exception ex) {
this(null, ex);
}
/**
* Constructs a new <code>SVGGraphics2DRuntimeException</code> with the
* specified detail message.
* @param s the detail message of this exception
* @param ex the original exception
*/
public SVGGraphics2DRuntimeException(String s, Exception ex) {
super(s);
embedded = ex;
}
/**
* Returns the message of this exception. If an error message has
* been specified, returns that one. Otherwise, return the error message
* of enclosed exception or null if any.
*/
public String getMessage() {
String msg = super.getMessage();
if (msg != null) {
return msg;
} else if (embedded != null) {
return embedded.getMessage();
} else {
return null;
}
}
/**
* Returns the original enclosed exception or null if any.
*/
public Exception getException() {
return embedded;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org