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;
}
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);
}
}
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");
}
}
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);
}
}
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;
}
Aggregations