use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class AttachResource method saveResourceInstances.
@Override
public void saveResourceInstances(ResourceDataBean bean) throws ApsSystemException {
try {
String fileName = this.getNewInstanceFileName(bean.getFileName());
String subPath = this.getDiskSubFolder() + fileName;
this.getStorageManager().saveFile(subPath, this.isProtectedResource(), bean.getInputStream());
ResourceInstance instance = new ResourceInstance();
instance.setSize(0);
instance.setFileName(fileName);
String mimeType = bean.getMimeType();
instance.setMimeType(mimeType);
instance.setFileLength(bean.getFileSize() + " Kb");
this.addInstance(instance);
} catch (Throwable t) {
_logger.error("Error on saving attach resource instances", t);
throw new ApsSystemException("Error on saving attach resource instances", t);
}
}
use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class AbstractImageResizer method saveResizedImage.
@Override
public ResourceInstance saveResizedImage(String subPath, boolean isProtectedResource, ImageIcon imageIcon, ImageResourceDimension dimension) throws ApsSystemException {
ResourceInstance resizedInstance = new ResourceInstance();
resizedInstance.setSize(dimension.getIdDim());
BufferedImage outImage = this.getResizedImage(imageIcon, dimension.getDimx(), dimension.getDimy());
String filename = subPath.substring(subPath.lastIndexOf("/") + 1);
resizedInstance.setFileName(filename);
String tempFilePath = System.getProperty("java.io.tmpdir") + File.separator + "temp_" + filename;
try {
File tempFile = new File(tempFilePath);
ImageIO.write(outImage, this.getFileExtension(tempFilePath), tempFile);
this.getStorageManager().saveFile(subPath, isProtectedResource, new FileInputStream(tempFile));
// resizedInstance.setMimeType(bean.getMimeType());
long realLength = tempFile.length() / 1000;
resizedInstance.setFileLength(String.valueOf(realLength) + " Kb");
tempFile.delete();
} catch (Throwable t) {
_logger.error("Error creating resized Image", t);
String msg = "Error creating resigned Image";
// ApsSystemUtils.logThrowable(t, this, "saveImageResized", msg);
throw new ApsSystemException(msg, t);
}
String mimeType = URLConnection.guessContentTypeFromName(filename);
resizedInstance.setMimeType(mimeType);
return resizedInstance;
}
use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class DefaultImageResizer method saveResizedImage.
@Override
@Deprecated
public void saveResizedImage(ImageIcon imageIcon, String filePath, ImageResourceDimension dimension) throws ApsSystemException {
BufferedImage outImage = this.getResizedImage(imageIcon, dimension.getDimx(), dimension.getDimy());
try {
File file = new File(filePath);
ImageIO.write(outImage, this.getFileExtension(filePath), file);
} catch (Throwable t) {
_logger.error("Error creating resized Image", t);
// ApsSystemUtils.logThrowable(t, this, "saveImageResized", msg);
throw new ApsSystemException("Error creating resized Image", t);
}
}
use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class PNGImageResizer method hasAlpha.
protected boolean hasAlpha(Image image) throws ApsSystemException {
// If buffered image, the color model is readily available
if (image instanceof BufferedImage) {
BufferedImage bimage = (BufferedImage) image;
return bimage.getColorModel().hasAlpha();
}
// Use a pixel grabber to retrieve the image's color model;
// grabbing a single pixel is usually sufficient
PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
try {
pg.grabPixels();
} catch (InterruptedException e) {
throw new ApsSystemException("Error grabbing a single pixel", e);
}
// Get the image's color model
ColorModel cm = pg.getColorModel();
return cm.hasAlpha();
}
use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class IndexerDAO method add.
@Override
public synchronized void add(IApsEntity entity) throws ApsSystemException {
IndexWriter writer = null;
try {
writer = new IndexWriter(this._dir, this.getIndexWriterConfig());
Document document = this.createDocument(entity);
writer.addDocument(document);
} catch (Throwable t) {
_logger.error("Errore saving entity {}", entity.getId(), t);
throw new ApsSystemException("Error saving entity", t);
} finally {
if (null != writer) {
try {
writer.close();
} catch (IOException ex) {
_logger.error("Error closing IndexWriter", ex);
}
}
}
}
Aggregations