use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class MD5Sum method evaluate.
@Override
public final Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
String output = "unknown";
if (getOperand(0) == null) {
return Integer.valueOf(0);
}
if (getOperand(0) instanceof Binary) {
Binary binaryFile = (Binary) getOperand(0);
return binaryFile.getHexDigest();
}
MessageDigest md5 = null;
try {
md5 = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
if (getOperand(0) instanceof Message) {
Message m = (Message) getOperand(0);
StringWriter sw = new StringWriter();
m.write(sw);
md5.update(sw.toString().getBytes());
} else {
md5.update((getOperand(0) + "").getBytes());
}
byte[] array = md5.digest();
if (getOperands().size() > 1 && getOperand(1) instanceof Boolean && (boolean) getOperand(1)) {
// return hex representation
return new BinaryDigest(array).hex();
}
BigInteger bigInt = new BigInteger(1, array);
output = bigInt.toString(16);
return output;
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class StoreBinary method evaluate.
@Override
public Object evaluate() throws TMLExpressionException {
if (getOperands().size() != 2) {
throw new TMLExpressionException(this, "Invalid number of operands");
}
if (!(getOperand(0) instanceof String)) {
throw new TMLExpressionException(this, "Invalid operand: " + getOperand(0));
}
if (!(getOperand(1) instanceof Binary)) {
throw new TMLExpressionException(this, "Invalid operand: " + getOperand(1));
}
String id = (String) getOperand(0);
Binary n = (Binary) getOperand(1);
SharedStoreInterface mss = SharedStoreFactory.getInstance();
try {
OutputStream os = mss.getOutputStream(getAccess().getTenant(), GetBinary.PARENT_LOCATION, id, false);
n.write(os);
os.close();
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new TMLExpressionException(this, e.getMessage());
}
return id;
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class ScaleImageCentered method evaluate.
/*
* (non-Javadoc)
* @see com.dexels.navajo.parser.FunctionInterface#evaluate()
*/
@Override
public Object evaluate() throws TMLExpressionException {
if (getOperands().size() < 3) {
throw new TMLExpressionException(this, "Three operands expected. ");
}
Binary b = (Binary) getOperand(0);
Integer width = (Integer) getOperand(1);
Integer height = (Integer) getOperand(2);
String imageType = "png";
if (getOperands().size() == 4 && (String) getOperand(3) != null) {
imageType = (String) getOperand(3);
}
try {
Binary res = ImageScaler.scaleCentered(b, width.intValue(), height.intValue(), imageType);
return res;
} catch (IOException e) {
return null;
}
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class ScaleImageFree method evaluate.
/* (non-Javadoc)
* @see com.dexels.navajo.parser.FunctionInterface#evaluate()
*/
@Override
public Object evaluate() throws TMLExpressionException {
if (getOperands().size() < 3) {
throw new TMLExpressionException(this, "Three operands expected. ");
}
Binary b = (Binary) getOperand(0);
Integer width = (Integer) getOperand(1);
Integer height = (Integer) getOperand(2);
String imageType = "png";
if (getOperands().size() == 4 && (String) getOperand(3) != null) {
imageType = (String) getOperand(3);
}
try {
Binary res = ImageScaler.scaleFree(b, width.intValue(), height.intValue(), imageType);
return res;
} catch (IOException e) {
logger.error("Error: ", e);
return null;
}
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class ScaleImageMin method evaluate.
/* (non-Javadoc)
* @see com.dexels.navajo.parser.FunctionInterface#evaluate()
*/
@Override
public Object evaluate() throws TMLExpressionException {
if (getOperands().size() < 3) {
throw new TMLExpressionException(this, "Three operands expected. ");
}
Binary b = (Binary) getOperand(0);
Integer width = (Integer) getOperand(1);
Integer height = (Integer) getOperand(2);
String imageType = "png";
if (getOperands().size() == 4 && (String) getOperand(3) != null) {
imageType = (String) getOperand(3);
}
try {
Binary res = ImageScaler.scaleToMin(b, width.intValue(), height.intValue(), imageType);
return res;
} catch (IOException e) {
logger.error("Scaling problem: ", e);
return null;
}
}
Aggregations