use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class Access method getResponseNavajo.
public Binary getResponseNavajo() throws UserException {
Binary b = new Binary();
if (outputDoc != null) {
try {
OutputStream os = b.getOutputStream();
outputDoc.write(os);
os.close();
} catch (IOException t) {
throw new UserException(-1, t.getMessage(), t);
}
}
return b;
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class DecryptBinary method evaluate.
@Override
public Object evaluate() throws TMLExpressionException {
Binary result = null;
String key = (String) getOperand(0);
String message = (String) getOperand(1);
try {
Security s = new Security(key);
result = s.decryptBinary(message);
} catch (Exception e) {
throw new TMLExpressionException(e.getMessage());
}
return result;
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class GetContextResource method evaluate.
@Override
public Object evaluate() throws TMLExpressionException {
java.io.File contextRoot = DispatcherFactory.getInstance().getNavajoConfig().getContextRoot();
java.io.File res = new java.io.File(contextRoot, "resources");
// input (ArrayList, Object).
if (this.getOperands().size() != 1)
throw new TMLExpressionException("GetContextResource(filename) expected");
Object a = this.getOperands().get(0);
if (!(a instanceof String)) {
throw new TMLExpressionException("GetContextResource(filename) expected");
}
java.io.File result = new java.io.File(res, (String) a);
// Security might be compromised if supplied with path like: ../../../root/somethingsecret
try {
return new Binary(result);
} catch (IOException e) {
throw new TMLExpressionException("Error constructing binary", e);
}
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class File method evaluate.
@Override
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
String fileName = (String) getOperand(0);
try {
java.io.File f = new java.io.File(fileName);
int length = (int) f.length();
byte[] data = new byte[length];
FileInputStream fis = new FileInputStream(f);
int read = 0;
int index = 0;
while ((read = fis.read()) > -1) {
data[index++] = (byte) read;
}
fis.close();
return new Binary(data);
} catch (Throwable e) {
logger.error("Error: ", e);
return null;
}
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class SQLMap method getRecords.
/**
* Get all records from resultset as Binary object (x-separated file)
*
* @return
*/
@Override
public Binary getRecords() throws UserException {
java.io.File tempFile = null;
ResultSet rs = null;
try {
Binary b = null;
rs = getDBResultSet(false);
tempFile = File.createTempFile("sqlmap_records", "navajo");
FileOutputStream fos = new FileOutputStream(tempFile);
OutputStreamWriter fw = new OutputStreamWriter(fos, "UTF-8");
int columns = 0;
ResultSetMetaData meta = null;
try {
meta = rs.getMetaData();
columns = meta.getColumnCount();
if (this.showHeader) {
for (int j = 0; j < columns; j++) {
String column = meta.getColumnLabel(j + 1);
if (j == 0) {
fw.write(column);
} else {
fw.write(this.separator + column);
}
}
fw.write((!dosMode) ? "\n" : "\r\n");
}
} catch (Exception e) {
e.printStackTrace(Access.getConsoleWriter(myAccess));
}
while (rs.next()) {
for (int j = 1; j <= columns; j++) {
String value = (rs.getObject(j) != null ? rs.getString(j) + "" : "");
if (j == 1) {
fw.write(value);
} else {
fw.write(this.separator + value);
}
}
fw.write((!dosMode) ? "\n" : "\r\n");
}
fw.flush();
fw.close();
b = new Binary(tempFile, false);
fos.close();
return b;
} catch (Exception ioe) {
throw new UserException(-1, ioe.getMessage(), ioe);
} finally {
if (rs != null) {
try {
rs.close();
rs = null;
resetAll();
} catch (SQLException e) {
e.printStackTrace(Access.getConsoleWriter(myAccess));
}
}
if (tempFile != null) {
try {
tempFile.delete();
} catch (Exception ioe2) {
ioe2.printStackTrace(Access.getConsoleWriter(myAccess));
}
}
}
}
Aggregations