Search in sources :

Example 16 with ObjectConvertMode

use of permafrost.tundra.lang.ObjectConvertMode in project Tundra by Permafrost.

the class zip method compress.

// ---( server methods )---
public static final void compress(IData pipeline) throws ServiceException {
    // --- <<IS-START(compress)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] record:1:optional $contents
    // [i] - field:0:required name
    // [i] - object:0:required content
    // [i] - field:0:optional encoding
    // [i] field:0:optional $mode {"stream","bytes","string","base64"}
    // [o] object:0:optional $contents.zip
    IDataCursor cursor = pipeline.getCursor();
    try {
        IData[] contents = IDataHelper.get(cursor, "$contents", IData[].class);
        ObjectConvertMode mode = IDataHelper.get(cursor, "$mode", ObjectConvertMode.class);
        Object output = ObjectHelper.convert(ZipHelper.compress(ZipEntryWithData.valueOf(contents)), mode);
        IDataHelper.put(cursor, "$contents.zip", output, false);
    } catch (IOException ex) {
        ExceptionHelper.raise(ex);
    } finally {
        cursor.destroy();
    }
// --- <<IS-END>> ---
}
Also used : ObjectConvertMode(permafrost.tundra.lang.ObjectConvertMode) IOException(java.io.IOException)

Example 17 with ObjectConvertMode

use of permafrost.tundra.lang.ObjectConvertMode in project Tundra by Permafrost.

the class document method emit.

public static final void emit(IData pipeline) throws ServiceException {
    // --- <<IS-START(emit)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] record:0:optional $document
    // [i] field:0:optional $encoding
    // [i] field:0:optional $mode {"stream","bytes","string"}
    // [o] object:0:optional $content
    IDataCursor cursor = pipeline.getCursor();
    try {
        IData document = IDataHelper.get(cursor, "$document", IData.class);
        Charset charset = IDataHelper.get(cursor, "$encoding", Charset.class);
        ObjectConvertMode mode = IDataHelper.get(cursor, "$mode", ObjectConvertMode.class);
        if (document != null) {
            IDataHelper.put(cursor, "$content", ObjectHelper.convert(IDataXMLParser.getInstance().emit(document, charset), charset, mode));
        }
    } catch (IOException ex) {
        ExceptionHelper.raise(ex);
    } finally {
        cursor.destroy();
    }
// --- <<IS-END>> ---
}
Also used : CaseInsensitiveIData(permafrost.tundra.data.CaseInsensitiveIData) ImmutableIData(permafrost.tundra.data.ImmutableIData) ObjectConvertMode(permafrost.tundra.lang.ObjectConvertMode) Charset(java.nio.charset.Charset) IOException(java.io.IOException)

Example 18 with ObjectConvertMode

use of permafrost.tundra.lang.ObjectConvertMode in project Tundra by Permafrost.

the class csv method emit.

// ---( server methods )---
public static final void emit(IData pipeline) throws ServiceException {
    // --- <<IS-START(emit)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] record:0:optional $document
    // [i] - record:1:optional recordWithNoID
    // [i] field:0:optional $delimiter
    // [i] field:0:optional $encoding
    // [i] field:0:optional $mode {"stream","bytes","string"}
    // [o] object:0:optional $content
    IDataCursor cursor = pipeline.getCursor();
    try {
        IData document = IDataHelper.get(cursor, "$document", IData.class);
        String delimiter = IDataHelper.get(cursor, "$delimiter", String.class);
        Charset charset = IDataHelper.get(cursor, "$encoding", Charset.class);
        ObjectConvertMode mode = IDataHelper.get(cursor, "$mode", ObjectConvertMode.class);
        if (document != null) {
            IDataHelper.put(cursor, "$content", ObjectHelper.convert(new IDataCSVParser(delimiter).emit(document, charset), charset, mode));
        }
    } catch (IOException ex) {
        ExceptionHelper.raise(ex);
    } finally {
        cursor.destroy();
    }
// --- <<IS-END>> ---
}
Also used : IDataCSVParser(permafrost.tundra.data.IDataCSVParser) ObjectConvertMode(permafrost.tundra.lang.ObjectConvertMode) Charset(java.nio.charset.Charset) IOException(java.io.IOException)

Example 19 with ObjectConvertMode

use of permafrost.tundra.lang.ObjectConvertMode in project Tundra by Permafrost.

the class base64 method decode.

// ---( server methods )---
public static final void decode(IData pipeline) throws ServiceException {
    // --- <<IS-START(decode)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] object:0:optional $base64
    // [i] field:0:optional $encoding
    // [i] field:0:optional $mode {"stream","bytes","string"}
    // [o] object:0:optional $content
    IDataCursor cursor = pipeline.getCursor();
    try {
        Object input = IDataHelper.get(cursor, "$base64");
        Charset charset = IDataHelper.get(cursor, "$encoding", Charset.class);
        ObjectConvertMode mode = IDataHelper.get(cursor, "$mode", ObjectConvertMode.class);
        Object output = ObjectHelper.convert(BytesHelper.base64Decode(StringHelper.normalize(input, charset)), charset, mode);
        IDataHelper.put(cursor, "$content", output, false);
    } catch (IOException ex) {
        ExceptionHelper.raise(ex);
    } finally {
        cursor.destroy();
    }
// --- <<IS-END>> ---
}
Also used : ObjectConvertMode(permafrost.tundra.lang.ObjectConvertMode) Charset(java.nio.charset.Charset) IOException(java.io.IOException)

Example 20 with ObjectConvertMode

use of permafrost.tundra.lang.ObjectConvertMode in project Tundra by Permafrost.

the class base64 method encode.

public static final void encode(IData pipeline) throws ServiceException {
    // --- <<IS-START(encode)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] object:0:optional $content
    // [i] field:0:optional $encoding
    // [i] field:0:optional $mode {"stream","bytes","string"}
    // [o] object:0:optional $base64
    IDataCursor cursor = pipeline.getCursor();
    try {
        Object input = IDataHelper.get(cursor, "$content");
        Charset charset = IDataHelper.get(cursor, "$encoding", Charset.class);
        ObjectConvertMode mode = IDataHelper.get(cursor, "$mode", ObjectConvertMode.class);
        Object output = ObjectHelper.convert(BytesHelper.base64Encode(BytesHelper.normalize(input, charset)), charset, mode);
        IDataHelper.put(cursor, "$base64", output, false);
    } catch (IOException ex) {
        ExceptionHelper.raise(ex);
    } finally {
        cursor.destroy();
    }
// --- <<IS-END>> ---
}
Also used : ObjectConvertMode(permafrost.tundra.lang.ObjectConvertMode) Charset(java.nio.charset.Charset) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)20 ObjectConvertMode (permafrost.tundra.lang.ObjectConvertMode)20 Charset (java.nio.charset.Charset)19 MessageDigest (java.security.MessageDigest)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Map (java.util.Map)1 Node (org.w3c.dom.Node)1 CaseInsensitiveIData (permafrost.tundra.data.CaseInsensitiveIData)1 IDataCSVParser (permafrost.tundra.data.IDataCSVParser)1 IDataJSONParser (permafrost.tundra.data.IDataJSONParser)1 IDataMap (permafrost.tundra.data.IDataMap)1 ImmutableIData (permafrost.tundra.data.ImmutableIData)1 XMLCanonicalizationAlgorithm (permafrost.tundra.xml.XMLCanonicalizationAlgorithm)1 ZipEntryWithData (permafrost.tundra.zip.ZipEntryWithData)1