use of com.dexels.navajo.document.types.BinaryDigest in project navajo by Dexels.
the class BinaryStoreValue method evaluate.
@Override
public Object evaluate() {
String tenant = super.getInstance();
String resourceName = getStringOperand(0);
BinaryDigest binaryDigest = getBinaryDigestOperand(1);
BinaryStore os = BinaryStoreFactory.getInstance().getBinaryStore(resourceName, tenant);
return os.resolve(binaryDigest);
}
use of com.dexels.navajo.document.types.BinaryDigest in project navajo by Dexels.
the class BasePropertyImpl method getTypedValue.
/**
* Get the value of a property as a Java object.
*
* @return
*/
@Override
public final Object getTypedValue() {
if (getType().equals(Property.STRING_PROPERTY)) {
return getValue();
}
if (getType().equals(Property.BOOLEAN_PROPERTY)) {
if (getValue() != null && !getValue().equals("")) {
return Boolean.valueOf(getValue().equalsIgnoreCase("true"));
} else {
return null;
}
}
if (getType().equals(EXPRESSION_LITERAL_PROPERTY)) {
if (getValue() != null && !getValue().equals("")) {
return new NavajoExpression(getValue());
} else {
return null;
}
}
if (getType().equals(EXPRESSION_PROPERTY)) {
if (evaluatedValue == null) {
evaluatedValue = getEvaluatedValue();
return evaluatedValue;
} else {
return evaluatedValue;
}
}
if (getType().equals(Property.PERCENTAGE_PROPERTY)) {
if (getValue() != null) {
return new Percentage(getValue());
} else {
return null;
}
}
if (getType().equals(Property.MONEY_PROPERTY)) {
if (getValue() == null || "".equals(getValue())) {
return new Money((Double) null, getSubType());
}
String val = getValue();
NumberFormat fn = NumberFormat.getNumberInstance(Locale.US);
Number parse;
try {
parse = fn.parse(val);
} catch (ParseException e) {
return null;
}
return new Money(parse.doubleValue(), getSubType());
} else if (getType().equals(Property.CLOCKTIME_PROPERTY)) {
if (getValue() == null || getValue().equals("")) {
return null;
}
try {
return new ClockTime(getValue(), getSubType());
} catch (Exception e) {
logger.error("Error: ", e);
}
} else if (getType().equals(Property.STOPWATCHTIME_PROPERTY)) {
try {
return new StopwatchTime(getValue(), getSubType());
} catch (Exception e) {
logger.error("Error: ", e);
}
} else if (getType().equals(Property.DATE_PROPERTY) || getType().equals(Property.TIMESTAMP_PROPERTY)) {
if (getValue() == null || getValue().equals("") || getValue().equals("null")) {
return null;
}
if (myDate != null) {
return myDate;
}
// Try in order from most specific to least specific
try {
return timestampFormat.get().parse(getValue());
} catch (Exception ex) {
try {
return dateFormat4.get().parse(getValue());
} catch (Exception ex2) {
try {
return dateFormat1.get().parse(getValue());
} catch (Exception ex3) {
try {
return dateFormat2.get().parse(getValue());
} catch (Exception ex4) {
try {
Long l = Long.parseLong(getValue());
Date d = new java.util.Date();
d.setTime(l);
return d;
} catch (Exception e5) {
logger.info("Sorry I really can't parse that date: {}", getValue());
return null;
}
}
}
}
}
} else if (getType().equals(Property.INTEGER_PROPERTY)) {
if (getValue() == null || getValue().equals("") || getValue().trim().equals("null")) {
return null;
}
try {
return Integer.valueOf(Integer.parseInt(getValue().trim()));
} catch (NumberFormatException ex3) {
logger.info("Numberformat exception...: {}", getValue().trim());
return null;
}
} else if (getType().equals(Property.LONG_PROPERTY)) {
if (getValue() == null || getValue().equals("")) {
return null;
}
try {
// Added a trim. Frank.
return Long.valueOf(Long.parseLong(getValue().trim()));
} catch (NumberFormatException ex3) {
logger.info("Numberformat exception...");
return null;
}
} else if (getType().equals(Property.FLOAT_PROPERTY)) {
if (getValue() == null || getValue().equals("")) {
return null;
}
String v = getValue();
String w = v;
// Sometimes the number formatting creates
if (v.indexOf(',') != -1) {
w = v.replaceAll(",", "");
}
Double d;
try {
d = Double.valueOf(Double.parseDouble(w));
} catch (NumberFormatException ex) {
logger.info("Can not format double with: {}", w);
return null;
}
return d;
} else if (getType().equals(Property.BINARY_PROPERTY)) {
try {
return myBinary;
} catch (Exception e) {
logger.error("Error: ", e);
}
} else if (getType().equals(Property.SELECTION_PROPERTY)) {
return getAllSelectedSelections();
} else if (getType().equals(Property.TIPI_PROPERTY)) {
return tipiProperty;
} else if (getType().equals(Property.LIST_PROPERTY)) {
if (tipiProperty != null || myValue == null) {
return tipiProperty;
}
try {
if (myValue.indexOf('[') == 0) {
// Parse back into a list
String stripped = myValue.substring(1, myValue.length() - 1);
tipiProperty = Arrays.asList(stripped.split(", "));
return tipiProperty;
} else if (myValue.length() > 0) {
logger.info("Failed to parse {} as a list!", myValue);
}
} catch (Exception e) {
logger.warn("Exception on parsing {} as a list!", myValue, e);
}
return null;
} else if (getType().equals(Property.BINARY_DIGEST_PROPERTY)) {
return new BinaryDigest(getValue());
} else if (getType().equals(Property.COORDINATE_PROPERTY)) {
try {
return new Coordinate(myValue);
} catch (Exception e) {
logger.error("Cannot create Coordinate Property: ", e);
}
}
return getValue();
}
use of com.dexels.navajo.document.types.BinaryDigest 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;
}
Aggregations