* @param e the element that describes the graphics node to build
* @return a graphics node that represents the specified element
*/
public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) {
ImageNode imageNode = (ImageNode)super.createGraphicsNode(ctx, e);
// 'xlink:href' attribute - required
String uriStr = XLinkSupport.getXLinkHref(e);
if (uriStr.length() == 0) {
throw new BridgeException(e, ERR_ATTRIBUTE_MISSING,
new Object[] {"xlink:href"});
}
if (uriStr.indexOf('#') != -1) {
throw new BridgeException(e, ERR_ATTRIBUTE_VALUE_MALFORMED,
new Object[] {"xlink:href", uriStr});
}
GraphicsNode node = null;
// try to load the image as an svg document
SVGDocument svgDoc = (SVGDocument)e.getOwnerDocument();
URL baseURL = ((SVGOMDocument)svgDoc).getURLObject();
ParsedURL purl = new ParsedURL(baseURL, uriStr);
// try to load an SVG document
DocumentLoader loader = ctx.getDocumentLoader();
URIResolver resolver = new URIResolver(svgDoc, loader);
try {
Node n = resolver.getNode(purl.toString(), e);
if (n.getNodeType() == n.DOCUMENT_NODE) {
SVGDocument imgDocument = (SVGDocument)n;
node = createSVGImageNode(ctx, e, imgDocument);
}
} catch (BridgeException ex) {
throw ex;
} catch (Exception ex) {
/* Nothing to do */
}
if (node == null) {
// try to load the image as a raster image (JPG or PNG)
node = createRasterImageNode(ctx, e, purl);
}
if (node == null) {
throw new BridgeException(e, ERR_URI_IMAGE_INVALID,
new Object[] {uriStr});
}
// 'image-rendering' and 'color-rendering'
Map imageHints = CSSUtilities.convertImageRendering(e);
Map colorHints = CSSUtilities.convertColorRendering(e);
if (imageHints != null || colorHints != null) {
RenderingHints hints;
if (imageHints == null) {
hints = new RenderingHints(colorHints);
} else if (colorHints == null) {
hints = new RenderingHints(imageHints);
} else {
hints = new RenderingHints(imageHints);
hints.putAll(colorHints);
}
node.setRenderingHints(hints);
}
imageNode.setImage(node);
return imageNode;
}