Search in sources :

Example 61 with Binary

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;
}
Also used : OutputStream(java.io.OutputStream) Binary(com.dexels.navajo.document.types.Binary) IOException(java.io.IOException)

Example 62 with Binary

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;
}
Also used : Binary(com.dexels.navajo.document.types.Binary) Security(com.dexels.navajo.functions.security.Security) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 63 with Binary

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);
    }
}
Also used : Binary(com.dexels.navajo.document.types.Binary) IOException(java.io.IOException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 64 with Binary

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;
    }
}
Also used : Binary(com.dexels.navajo.document.types.Binary) FileInputStream(java.io.FileInputStream)

Example 65 with Binary

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));
            }
        }
    }
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) SQLException(java.sql.SQLException) FileOutputStream(java.io.FileOutputStream) ResultSet(java.sql.ResultSet) OutputStreamWriter(java.io.OutputStreamWriter) Binary(com.dexels.navajo.document.types.Binary) UserException(com.dexels.navajo.script.api.UserException) File(java.io.File) NavajoException(com.dexels.navajo.document.NavajoException) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException) SQLException(java.sql.SQLException)

Aggregations

Binary (com.dexels.navajo.document.types.Binary)139 Test (org.junit.Test)38 IOException (java.io.IOException)32 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)26 File (java.io.File)25 Ignore (org.junit.Ignore)17 Property (com.dexels.navajo.document.Property)16 URL (java.net.URL)16 UserException (com.dexels.navajo.script.api.UserException)14 OutputStream (java.io.OutputStream)13 FileOutputStream (java.io.FileOutputStream)12 Navajo (com.dexels.navajo.document.Navajo)11 MappableException (com.dexels.navajo.script.api.MappableException)11 FileInputStream (java.io.FileInputStream)9 InputStream (java.io.InputStream)9 Message (com.dexels.navajo.document.Message)8 StringWriter (java.io.StringWriter)8 OutputStreamWriter (java.io.OutputStreamWriter)7 NavajoException (com.dexels.navajo.document.NavajoException)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6