use of org.apache.batik.util.ParsedURL in project elki by elki-project.
the class CloneInlineImages method cloneNode.
@Override
public Node cloneNode(Document doc, Node eold) {
Node enew = null;
if (eold instanceof Element) {
Element e = (Element) eold;
if (e.getTagName().equals(SVGConstants.SVG_IMAGE_TAG)) {
String url = e.getAttributeNS(SVGConstants.XLINK_NAMESPACE_URI, SVGConstants.XLINK_HREF_ATTRIBUTE);
ParsedURL urldata = new ParsedURL(url);
if (ThumbnailRegistryEntry.isCompatibleURLStatic(urldata)) {
enew = inlineThumbnail(doc, urldata, eold);
} else if ("file".equals(urldata.getProtocol())) {
enew = inlineExternal(doc, urldata, eold);
}
}
}
if (enew != null) {
return enew;
}
return super.cloneNode(doc, eold);
}
use of org.apache.batik.util.ParsedURL in project opencast by opencast.
the class CoverImageServiceOsgiImpl method activate.
/**
* OSGi activation callback
*
* @param cc
* the OSGi component context
*/
@Override
public void activate(ComponentContext cc) {
super.activate(cc);
// See
// http://www.stichlberger.com/software/workaround-for-batiks-noclassdeffounderrorclassnotfoundexception-truncatedfileexception/
// ---------------
// add this code before you use batik (make sure is runs only once)
// via the lower priority this subclass is registered before JPEGRegistryEntry
// and prevents JPEGRegistryEntry.handleStream from breaking when used on a non Sun/Oracle JDK
JPEGRegistryEntry entry = new JPEGRegistryEntry() {
@Override
public float getPriority() {
// higher than that of JPEGRegistryEntry (which is 1000)
return 500;
}
/**
* Decode the Stream into a RenderableImage
*
* @param inIS
* The input stream that contains the image.
* @param origURL
* The original URL, if any, for documentation purposes only. This may be null.
* @param needRawData
* If true the image returned should not have any default color correction the file may specify applied.
*/
@Override
public Filter handleStream(InputStream inIS, ParsedURL origURL, boolean needRawData) {
// Code from org.apache.batik.ext.awt.image.codec.jpeg.JPEGRegistryEntry#handleStream
// Reading image with ImageIO to prevent NoClassDefFoundError on OpenJDK
final DeferRable dr = new DeferRable();
final InputStream is = inIS;
final String errCode;
final Object[] errParam;
if (origURL != null) {
errCode = ERR_URL_FORMAT_UNREADABLE;
errParam = new Object[] { "JPEG", origURL };
} else {
errCode = ERR_STREAM_FORMAT_UNREADABLE;
errParam = new Object[] { "JPEG" };
}
Thread t = new Thread() {
@Override
public void run() {
Filter filt;
try {
BufferedImage image;
image = ImageIO.read(is);
dr.setBounds(new Rectangle2D.Double(0, 0, image.getWidth(), image.getHeight()));
CachableRed cr;
cr = GraphicsUtil.wrap(image);
cr = new Any2sRGBRed(cr);
cr = new FormatRed(cr, GraphicsUtil.sRGB_Unpre);
WritableRaster wr = (WritableRaster) cr.getData();
ColorModel cm = cr.getColorModel();
image = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
cr = GraphicsUtil.wrap(image);
filt = new RedRable(cr);
} catch (IOException ioe) {
// Something bad happened here...
filt = ImageTagRegistry.getBrokenLinkImage(this, errCode, errParam);
} catch (ThreadDeath td) {
filt = ImageTagRegistry.getBrokenLinkImage(this, errCode, errParam);
dr.setSource(filt);
throw td;
} catch (Throwable t) {
filt = ImageTagRegistry.getBrokenLinkImage(this, errCode, errParam);
}
dr.setSource(filt);
}
};
t.start();
return dr;
}
};
ImageTagRegistry.getRegistry().register(entry);
logger.info("Cover image service activated");
}
Aggregations