Search in sources :

Example 76 with EngineException

use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.

the class JsonToXmlStep method createStepNode.

@Override
protected Node createStepNode() throws EngineException {
    Document doc = getOutputDocument();
    Element elt = doc.createElement("e");
    try {
        Object o;
        if (jsonSource.startsWith("{")) {
            o = new JSONObject(jsonSource);
        } else if (jsonSource.startsWith("[")) {
            o = new JSONArray(jsonSource);
        } else {
            o = RhinoUtils.jsonParse(jsonSource);
        }
        XMLUtils.jsonToXml(o, getStepNodeName(), elt, true, false, "item");
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }
    elt = (Element) elt.getFirstChild();
    elt.setAttribute("originalKeyName", key.getSingleString(this));
    return elt;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) Element(org.w3c.dom.Element) JSONArray(org.codehaus.jettison.json.JSONArray) JSONObject(org.codehaus.jettison.json.JSONObject) Document(org.w3c.dom.Document) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 77 with EngineException

use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.

the class ListDirStep method createStepNodeValue.

@Override
protected void createStepNodeValue(Document doc, Element stepNode) throws EngineException {
    try {
        // Command line string
        if (evaluated instanceof org.mozilla.javascript.Undefined)
            throw new EngineException("Source directory path is empty.");
        String path = Engine.theApp.filePropertyManager.getFilepathFromProperty(evaluated.toString(), getProject().getName());
        File fDir = new File(path);
        File[] files = fDir.listFiles();
        if (files == null)
            throw new EngineException("Source path \"" + path + "\" isn't a directory.");
        if (fileSortByPolicy.equals(FileSortByPolicy.fileLastModified)) {
            Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR);
        } else if (fileSortByPolicy.equals(FileSortByPolicy.fileSize)) {
            Arrays.sort(files, SizeFileComparator.SIZE_COMPARATOR);
        } else {
            Arrays.sort(files, NameFileComparator.NAME_SYSTEM_COMPARATOR);
        }
        String fileName, fileLastModified, fileSize;
        Element element;
        File file;
        for (int i = 0; i < files.length; i++) {
            file = files[i];
            if (file.isFile() && !file.isHidden()) {
                fileName = file.getName();
                fileSize = String.valueOf(file.length());
                fileLastModified = String.valueOf(file.lastModified());
                element = doc.createElement("file");
                element.appendChild(doc.createTextNode(fileName));
                element.setAttribute("lastModified", fileLastModified);
                element.setAttribute("size", fileSize);
                stepNode.appendChild(element);
            }
        }
    } catch (Exception e) {
        setErrorStatus(true);
        Engine.logBeans.warn("An error occured while listing directory.", e);
    }
}
Also used : XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) Element(org.w3c.dom.Element) EngineException(com.twinsoft.convertigo.engine.EngineException) File(java.io.File) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 78 with EngineException

use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.

the class ReadFileStep method configure.

@Override
public void configure(Element element) throws Exception {
    super.configure(element);
    String version = element.getAttribute("version");
    if (version == null) {
        String s = XMLUtils.prettyPrintDOM(element);
        EngineException ee = new EngineException("Unable to find version number for the database object \"" + getName() + "\".\n" + "XML data: " + s);
        throw ee;
    }
    if (VersionUtils.compareMigrationVersion(version, ".m003") < 0) {
        if (!dataFile.equals(""))
            dataFile = "'" + dataFile + "'";
        hasChanged = true;
        Engine.logBeans.warn("[ReadFileStep] The object \"" + getName() + "\" has been updated to .m003 version");
    }
}
Also used : EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 79 with EngineException

use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.

the class PdfFormStep method replaceField.

/**
 * name is the field's name data is his value doc is the pdf you're working on
 * Put values in the field
 *
 * @param name
 * @param data
 * @param doc
 */
private void replaceField(String name, String data, PDDocument doc) {
    acroForm = doc.getDocumentCatalog().getAcroForm();
    PDField field = acroForm.getField(name);
    try {
        Engine.logBeans.debug("(PdfFormStep) replaceField: replacing field - " + field);
        if (field != null) {
            Engine.logBeans.debug("(PdfFormStep) replaceField: - field is not null");
            if (field.isReadOnly()) {
                field.setReadOnly(false);
                Engine.logBeans.debug("(PdfFormStep) replaceField: - field read only is false");
            }
            // return the type of the field
            String fieldType = field.getClass().getSimpleName();
            Engine.logBeans.debug("(PdfFormStep) Field type = " + fieldType);
            switch(fieldType) {
                case "PDTextField":
                    field.setValue(data);
                    Engine.logBeans.debug("(PdfFormStep) replaceField - PDTextField value set " + data);
                    break;
                case "PDCheckBox":
                    if (data.equals("On") || data.equals("True") || data.equals("Yes")) {
                        ((PDCheckBox) field).check();
                        Engine.logBeans.debug("(PdfFormStep) replaceField - PDFCheckBox value set " + data);
                    } else {
                        ((PDCheckBox) field).unCheck();
                        Engine.logBeans.debug("(PdfFormStep) replaceField - PDFCheckBox value unset " + data);
                    }
                    break;
                // We handle pushButtons as a placeholder for images
                case "PDPushButton":
                    try {
                        String imgPath = getAbsoluteFilePath(data);
                        handleImages(name, imgPath, doc);
                    } catch (EngineException e) {
                        Engine.logBeans.error("(PdfFormStep) Source image file not found", e);
                    }
                    Engine.logBeans.debug("(PdfFormStep) replaceField - PDPushButton value set");
                    break;
                default:
                    Engine.logBeans.error("(PdfFormStep) UNKNOWN field " + field.getClass().getSimpleName());
                    setErrorStatus(true);
                    break;
            }
            field.setReadOnly(true);
        } else {
            Engine.logBeans.error("(PdfFormStep) No field found with name:" + name);
            setErrorStatus(true);
        }
    } catch (IOException e) {
        Engine.logBeans.error("(PdfFormStep) replaceField FAILED", e);
    }
}
Also used : PDField(org.apache.pdfbox.pdmodel.interactive.form.PDField) PDCheckBox(org.apache.pdfbox.pdmodel.interactive.form.PDCheckBox) EngineException(com.twinsoft.convertigo.engine.EngineException) IOException(java.io.IOException)

Example 80 with EngineException

use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.

the class IteratorStep method stepExecute.

@Override
protected boolean stepExecute(Context javascriptContext, Scriptable scope) throws EngineException {
    if (isEnabled()) {
        try {
            iterator.init();
        } catch (TransformerException e) {
            throw new EngineException("Unable to initialize iterator", e);
        }
        if (inError()) {
            Engine.logBeans.warn("(IteratorStep) Skipping step " + this + " (" + hashCode() + ") because its source is in error");
            return true;
        }
        long start = getLoopStartIndex(javascriptContext, scope);
        for (int i = 0; i < iterator.size(); i++) {
            if (bContinue && sequence.isRunning()) {
                int index = iterator.numberOfIterations();
                Scriptable jsIndex = org.mozilla.javascript.Context.toObject(index, scope);
                scope.put("index", scope, jsIndex);
                Object item = iterator.nextElement();
                Scriptable jsItem = org.mozilla.javascript.Context.toObject(item, scope);
                scope.put("item", scope, jsItem);
                start = start < 0 ? 0 : start;
                if (start > index) {
                    doLoop(javascriptContext, scope);
                    continue;
                }
                if (!super.stepExecute(javascriptContext, scope))
                    break;
            } else
                break;
        }
        return true;
    }
    return false;
}
Also used : EngineException(com.twinsoft.convertigo.engine.EngineException) Scriptable(org.mozilla.javascript.Scriptable) TransformerException(javax.xml.transform.TransformerException)

Aggregations

EngineException (com.twinsoft.convertigo.engine.EngineException)426 IOException (java.io.IOException)155 File (java.io.File)117 Element (org.w3c.dom.Element)84 NodeList (org.w3c.dom.NodeList)64 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)62 Document (org.w3c.dom.Document)43 JSONObject (org.codehaus.jettison.json.JSONObject)41 Node (org.w3c.dom.Node)40 Project (com.twinsoft.convertigo.beans.core.Project)35 ArrayList (java.util.ArrayList)35 JSONException (org.codehaus.jettison.json.JSONException)33 Sequence (com.twinsoft.convertigo.beans.core.Sequence)31 RequestableVariable (com.twinsoft.convertigo.beans.variables.RequestableVariable)29 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)27 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)25 Connector (com.twinsoft.convertigo.beans.core.Connector)24 HashMap (java.util.HashMap)23 Transaction (com.twinsoft.convertigo.beans.core.Transaction)21 ObjectWithSameNameException (com.twinsoft.convertigo.engine.ObjectWithSameNameException)20