Search in sources :

Example 91 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class GetBinary method evaluate.

@Override
public Object evaluate() throws TMLExpressionException {
    if (getOperands().size() != 1) {
        throw new TMLExpressionException(this, "Invalid number of operands");
    }
    if (!(getOperand(0) instanceof String)) {
        throw new TMLExpressionException(this, "Invalid operand: " + getOperand(0));
    }
    Binary b = null;
    String id = (String) getOperand(0);
    SharedStoreInterface mss = SharedStoreFactory.getInstance();
    try {
        InputStream is = mss.getStream(PARENT_LOCATION, id);
        b = new Binary(is);
        is.close();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new TMLExpressionException(this, e.getMessage());
    }
    return b;
}
Also used : InputStream(java.io.InputStream) SharedStoreInterface(com.dexels.navajo.sharedstore.SharedStoreInterface) Binary(com.dexels.navajo.document.types.Binary) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 92 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class DecryptBinary method main.

public static void main(String[] args) throws Exception {
    String s = "34PIf6+W/rTMIaGjBHVI4Q==";
    DecryptBinary e = new DecryptBinary();
    e.reset();
    e.insertStringOperand("BBFW06E");
    e.insertStringOperand(s);
    Binary result = (Binary) e.evaluate();
    System.err.println("result: " + new String(result.getData()));
}
Also used : Binary(com.dexels.navajo.document.types.Binary)

Example 93 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class GetReportFile method evaluate.

@Override
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
    String script = DispatcherFactory.getInstance().getNavajoConfig().getScriptPath();
    String reportName = getStringOperand(0);
    java.io.File scriptDir = new java.io.File(script);
    java.io.File report = new java.io.File(scriptDir, reportName + ".rptdesign");
    try {
        Binary b = new Binary(report);
        return b;
    } catch (Exception e) {
        logger.error("File issue: {}", report.getAbsolutePath());
        logger.error("Error resolving report: " + reportName + " from script path: " + script, e);
        throw new TMLExpressionException("Wrapping: " + script, e);
    }
}
Also used : Binary(com.dexels.navajo.document.types.Binary) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 94 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class IsValidXMLFile method evaluate.

@Override
public Object evaluate() throws TMLExpressionException {
    if (getOperands().size() != 1) {
        throw new TMLExpressionException(this, "One operand expected. ");
    }
    Object o = getOperand(0);
    if (!(o instanceof Binary)) {
        return Boolean.FALSE;
    }
    Binary b = (Binary) getOperand(0);
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setValidating(false);
        factory.setNamespaceAware(true);
        DocumentBuilder builder = factory.newDocumentBuilder();
        // the "parse" method also validates XML, will throw an exception if misformatted
        @SuppressWarnings("unused") Document document = builder.parse(new InputSource(b.getDataAsStream()));
        return Boolean.TRUE;
    } catch (Throwable e) {
        logger.info("Invalid XML file", e);
        return Boolean.FALSE;
    }
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Binary(com.dexels.navajo.document.types.Binary) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Document(org.w3c.dom.Document)

Example 95 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class IsValidXMLFile method main.

public static void main(String[] args) throws Exception {
    // FileInputStream fs = new FileInputStream((new File("c:/users/erik/appdata/local/temp/_aaacamt.xml")));
    FileInputStream fs = new FileInputStream((new File("/home/chris/camt.xml")));
    Binary b = new Binary(fs);
    fs.close();
    IsValidXMLFile i = new IsValidXMLFile();
    i.reset();
    i.insertBinaryOperand(b);
    Object o = i.evaluate();
    System.err.println("result valid xml file = " + o);
}
Also used : Binary(com.dexels.navajo.document.types.Binary) File(java.io.File) FileInputStream(java.io.FileInputStream)

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