/*****************************************************************************
* 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.bridge;
import java.awt.Shape;
import java.io.StringReader;
import org.apache.batik.gvt.ShapeNode;
import org.apache.batik.parser.AWTPolylineProducer;
import org.apache.batik.parser.ParseException;
import org.apache.batik.parser.PointsParser;
import org.w3c.dom.Element;
/**
* Bridge class for the <polyline> element.
*
* @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
* @version $Id: SVGPolylineElementBridge.java,v 1.5 2001/03/30 16:03:31 tkormann Exp $
*/
public class SVGPolylineElementBridge extends SVGDecoratedShapeElementBridge {
/**
* Constructs a new bridge for the <polyline> element.
*/
public SVGPolylineElementBridge() {}
/**
* Constructs a polyline according to the specified parameters.
*
* @param ctx the bridge context to use
* @param e the element that describes a rect element
* @param shapeNode the shape node to initialize
*/
protected void buildShape(BridgeContext ctx,
Element e,
ShapeNode shapeNode) {
String s = e.getAttributeNS(null, SVG_POINTS_ATTRIBUTE);
if (s.length() != 0) {
AWTPolylineProducer app = new AWTPolylineProducer();
app.setWindingRule(CSSUtilities.convertFillRule(e));
try {
PointsParser pp = new PointsParser();
pp.setPointsHandler(app);
pp.parse(new StringReader(s));
} catch (ParseException ex) {
BridgeException bex
= new BridgeException(e, ERR_ATTRIBUTE_VALUE_MALFORMED,
new Object[] {SVG_POINTS_ATTRIBUTE});
bex.setGraphicsNode(shapeNode);
throw bex;
} finally {
shapeNode.setShape(app.getShape());
}
} else {
throw new BridgeException(e, ERR_ATTRIBUTE_MISSING,
new Object[] {SVG_POINTS_ATTRIBUTE});
}
}
}