* @param ctx the bridge context to use
* @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);
if (imageNode == null) {
return null;
}
// '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();
// try to load an SVG document
DocumentLoader loader = ctx.getDocumentLoader();
URIResolver resolver = new URIResolver(svgDoc, loader);
try {
Node n = resolver.getNode(uriStr, e);
if (n.getNodeType() == n.DOCUMENT_NODE) {
imgDocument = (SVGDocument)n;
node = createSVGImageNode(ctx, e, imgDocument);
}
} catch (BridgeException ex) {
throw ex;
} catch (SecurityException ex) {
throw new BridgeException(e, ERR_URI_UNSECURE,
new Object[] {uriStr});
} catch (Exception ex) {
/* Nothing to do */
}
if (node == null) {
String baseURI = XMLBaseSupport.getCascadedXMLBase(e);
ParsedURL purl;
if (baseURI == null)
purl = new ParsedURL(uriStr);
else
purl = new ParsedURL(baseURI, uriStr);
// 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});
}
imageNode.setImage(node);
// 'image-rendering' and 'color-rendering'
RenderingHints hints = CSSUtilities.convertImageRendering(e, null);
hints = CSSUtilities.convertColorRendering(e, hints);
if (hints != null) {
imageNode.setRenderingHints(hints);
}
return imageNode;
}