Search in sources :

Example 1 with ObjectConvertMode

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

the class yaml 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] 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(IDataYAMLParser.getInstance().emit(document, charset), charset, mode));
        }
    } 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 2 with ObjectConvertMode

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

the class zip method decompress.

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

Example 3 with ObjectConvertMode

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

the class json 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] - object:1:optional recordWithNoID
    // [i] field:0:optional $encoding
    // [i] field:0:optional $mode {"stream","bytes","string"}
    // [i] field:0:optional $minify? {"false","true"}
    // [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);
        boolean minify = IDataHelper.getOrDefault(cursor, "$minify?", Boolean.class, false);
        if (document != null) {
            IDataJSONParser parser = minify ? new IDataJSONParser(!minify) : IDataJSONParser.getInstance();
            IDataHelper.put(cursor, "$content", ObjectHelper.convert(parser.emit(document, charset), charset, mode));
        }
    } 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) IDataJSONParser(permafrost.tundra.data.IDataJSONParser)

Example 4 with ObjectConvertMode

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

the class object method convert.

public static final void convert(IData pipeline) throws ServiceException {
    // --- <<IS-START(convert)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] object:0:optional $object
    // [i] field:0:optional $mode {"stream","bytes","string"}
    // [i] field:0:optional $encoding
    // [o] object:0:optional $object
    IDataCursor cursor = pipeline.getCursor();
    try {
        Object object = IDataHelper.get(cursor, "$object");
        Charset charset = IDataHelper.get(cursor, "$encoding", Charset.class);
        ObjectConvertMode mode = IDataHelper.get(cursor, "$mode", ObjectConvertMode.class);
        IDataHelper.put(cursor, "$object", ObjectHelper.convert(object, charset, mode), 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 5 with ObjectConvertMode

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

the class pipeline method emit.

public static final void emit(IData pipeline) throws ServiceException {
    // --- <<IS-START(emit)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] field:0:optional $encoding
    // [i] field:0:optional $mode {"stream","bytes","string"}
    // [o] object:0:optional $content
    IDataCursor cursor = pipeline.getCursor();
    try {
        // remove input arguments so that they are not included in serialization of the pipeline
        Charset charset = IDataHelper.remove(cursor, "$encoding", Charset.class);
        ObjectConvertMode mode = IDataHelper.remove(cursor, "$mode", ObjectConvertMode.class);
        IDataHelper.put(cursor, "$content", ObjectHelper.convert(IDataXMLParser.getInstance().emit(pipeline, charset), charset, mode));
    } 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