Search in sources :

Example 1 with OutputFilter

use of com.twinsoft.convertigo.beans.core.Sequence.OutputFilter in project convertigo by convertigo.

the class WriteFileStep method stepExecute.

@Override
protected boolean stepExecute(Context javascriptContext, Scriptable scope) throws EngineException {
    if (isEnabled()) {
        filePath = null;
        try {
            StepSource stepSource = getSource();
            if (!stepSource.inError()) {
                filePath = evaluateDataFileName(javascriptContext, scope);
                // Retrieve a view based on context nodes (prevent to modify context nodes, output usefull nodes only)
                OutputFilter outputFilter = sequence.new OutputFilter(writeOutputFalse ? OutputOption.UsefullOnly : OutputOption.VisibleOnly);
                NodeList nl = Sequence.ouputDomView(stepSource.getContextOutputNodes(), outputFilter);
                writeFile(filePath, nl);
                filePath = getAbsoluteFilePath(filePath);
            }
        } catch (Exception e) {
            setErrorStatus(true);
            Engine.logBeans.error("An error occured while writing to file", e);
        }
        return super.stepExecute(javascriptContext, scope);
    }
    return false;
}
Also used : StepSource(com.twinsoft.convertigo.beans.core.StepSource) OutputFilter(com.twinsoft.convertigo.beans.core.Sequence.OutputFilter) NodeList(org.w3c.dom.NodeList) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 2 with OutputFilter

use of com.twinsoft.convertigo.beans.core.Sequence.OutputFilter in project convertigo by convertigo.

the class SessionSetObjectStep method createStepNodeValue.

@Override
protected void createStepNodeValue(Document doc, Element stepNode) throws EngineException {
    stepNode.setAttribute("key", key.isEmpty() ? "empty_key" : StringUtils.normalize(key));
    if (!key.isEmpty()) {
        Object object = value.getObject(this);
        if (object != null) {
            if ((object instanceof NodeList) && value.isUseSource()) {
                OutputFilter outputFilter = sequence.new OutputFilter(OutputOption.UsefullOnly);
                object = Sequence.ouputDomView((NodeList) object, outputFilter);
            }
            getSequence().context.httpSession.setAttribute(key, object);
            // Simple objects
            if ((object instanceof Boolean) || (object instanceof Integer) || (object instanceof Double) || (object instanceof Float) || (object instanceof Character) || (object instanceof Long) || (object instanceof Short) || (object instanceof Byte) || (object instanceof String)) {
                stepNode.setTextContent(ParameterUtils.toString(object));
            } else // Complex objects
            {
                CDATASection cDATASection = doc.createCDATASection(ParameterUtils.toString(object));
                stepNode.appendChild(cDATASection);
            }
        }
    }
}
Also used : OutputFilter(com.twinsoft.convertigo.beans.core.Sequence.OutputFilter) NodeList(org.w3c.dom.NodeList) CDATASection(org.w3c.dom.CDATASection)

Aggregations

OutputFilter (com.twinsoft.convertigo.beans.core.Sequence.OutputFilter)2 NodeList (org.w3c.dom.NodeList)2 StepSource (com.twinsoft.convertigo.beans.core.StepSource)1 EngineException (com.twinsoft.convertigo.engine.EngineException)1 CDATASection (org.w3c.dom.CDATASection)1