use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class XMLDateTimeStep method getActionValue.
@Override
protected String getActionValue() throws EngineException {
String nodeValue = super.getActionValue();
if (!nodeValue.equals("")) {
try {
Date date = null;
if (nodeValue.equalsIgnoreCase("now")) {
date = new Date();
} else {
DateFormat dfInput = new SimpleDateFormat(inputFormat, DateUtils.getLocale(inputLocale));
dfInput.setTimeZone(TimeZone.getDefault());
date = dfInput.parse(nodeValue);
}
DateFormat dfOutput = new SimpleDateFormat(outputFormat, DateUtils.getLocale(outputLocale));
dfOutput.setTimeZone(TimeZone.getDefault());
nodeValue = dfOutput.format(date);
} catch (Exception e) {
Engine.logBeans.warn(e.getMessage());
setErrorStatus(true);
}
}
return nodeValue;
}
use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class WriteXMLStep method writeFile.
protected void writeFile(String filePath, NodeList nodeList) throws EngineException {
if (nodeList == null) {
throw new EngineException("Unable to write to xml file: element is Null");
}
String fullPathName = getAbsoluteFilePath(filePath);
synchronized (Engine.theApp.filePropertyManager.getMutex(fullPathName)) {
try {
String encoding = getEncoding();
encoding = encoding.length() > 0 && Charset.isSupported(encoding) ? encoding : "UTF-8";
if (!isReallyAppend(fullPathName)) {
String tTag = defaultRootTagname.length() > 0 ? StringUtils.normalize(defaultRootTagname) : "document";
FileUtils.write(new File(fullPathName), "<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n<" + tTag + "/>", encoding);
}
StringBuffer content = new StringBuffer();
/* do the content, only append child element */
for (int i = 0; i < nodeList.getLength(); i++) {
if (nodeList.item(i).getNodeType() == Node.ELEMENT_NODE) {
content.append(XMLUtils.prettyPrintElement((Element) nodeList.item(i), true, true));
}
}
/* detect current xml encoding */
RandomAccessFile randomAccessFile = null;
try {
randomAccessFile = new RandomAccessFile(fullPathName, "rw");
FileChannel fc = randomAccessFile.getChannel();
ByteBuffer buf = ByteBuffer.allocate(60);
int nb = fc.read(buf);
String sbuf = new String(buf.array(), 0, nb, "ASCII");
String enc = sbuf.replaceFirst("^.*encoding=\"", "").replaceFirst("\"[\\d\\D]*$", "");
if (!Charset.isSupported(enc)) {
enc = encoding;
}
buf.clear();
/* retrieve last header tag*/
long pos = fc.size() - buf.capacity();
if (pos < 0) {
pos = 0;
}
nb = fc.read(buf, pos);
boolean isUTF8 = Charset.forName(enc) == Charset.forName("UTF-8");
if (isUTF8) {
for (int i = 0; i < buf.capacity(); i++) {
sbuf = new String(buf.array(), i, nb - i, enc);
if (!sbuf.startsWith("�")) {
pos += i;
break;
}
}
} else {
sbuf = new String(buf.array(), 0, nb, enc);
}
int lastTagIndex = sbuf.lastIndexOf("</");
if (lastTagIndex == -1) {
int iend = sbuf.lastIndexOf("/>");
if (iend != -1) {
lastTagIndex = sbuf.lastIndexOf("<", iend);
String tagname = sbuf.substring(lastTagIndex + 1, iend);
content = new StringBuffer("<" + tagname + ">\n" + content.toString() + "</" + tagname + ">");
} else {
throw new EngineException("Malformed XML file");
}
} else {
content.append(sbuf.substring(lastTagIndex));
if (isUTF8) {
String before = sbuf.substring(0, lastTagIndex);
lastTagIndex = before.getBytes(enc).length;
}
}
fc.write(ByteBuffer.wrap(content.toString().getBytes(enc)), pos + lastTagIndex);
} finally {
if (randomAccessFile != null) {
randomAccessFile.close();
}
}
} catch (IOException e) {
throw new EngineException("Unable to write to xml file", e);
} finally {
Engine.theApp.filePropertyManager.releaseMutex(fullPathName);
}
}
}
use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class SetResponseStatusStep method createStepNodeValue.
@Override
protected void createStepNodeValue(Document doc, Element stepNode) throws EngineException {
String sCode = (sCode = statusCode.getSingleString(this)) == null ? "" : sCode;
if (sCode != null && sCode.length() > 0) {
String sText = (sText = statusText.getSingleString(this)) == null ? "" : sText;
Integer iCode = -1;
try {
iCode = Integer.parseInt(sCode, 10);
} catch (Exception e) {
throw new EngineException("Unable to set status code", e);
}
getSequence().context.setResponseStatus(iCode, sText);
Element en = (Element) stepNode.appendChild(doc.createElement("code"));
en.setTextContent(sCode);
Element ev = (Element) stepNode.appendChild(doc.createElement("text"));
ev.setTextContent(sText);
}
}
use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class SimpleIteratorStep method stepExecute.
@Override
protected boolean stepExecute(Context javascriptContext, Scriptable scope) throws EngineException {
if (isEnabled()) {
try {
evaluate(javascriptContext, scope, getExpression(), "expression", true);
if (evaluated instanceof org.mozilla.javascript.Undefined) {
throw new Exception("Step " + getName() + " has none expression defined.");
}
} catch (Exception e) {
evaluated = null;
Engine.logBeans.warn(e.getMessage());
}
try {
iterator.init();
} catch (Exception e) {
throw new EngineException("Unable to initialize iterator", e);
}
if (inError()) {
Engine.logBeans.warn("(SimpleIteratorStep) 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;
}
use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class TransactionStep 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() + "\".\nXML data: " + s);
throw ee;
}
try {
if (VersionUtils.compare(version, "6.0.3") < 0) {
String projectName = (String) XMLUtils.findPropertyValue(element, "projectName");
// Handle wrong project name
if (projectName.equals("")) {
projectName = "unknown_project";
}
String connectorName = (String) XMLUtils.findPropertyValue(element, "connectorName");
// If the default connector has been set, find the explicit default connector name
if (connectorName.equals("")) {
NodeList connectorsNodeList = element.getOwnerDocument().getElementsByTagName("connector");
Node connectorNode = XMLUtils.findNodeByAttributeValue(connectorsNodeList, "default", "true");
if (connectorNode != null) {
connectorName = (String) XMLUtils.findPropertyValue((Element) connectorNode, "name");
} else {
throw new EngineException("Unable to find the default connector for the project '" + projectName + "'");
}
}
String transactionName = (String) XMLUtils.findPropertyValue(element, "transactionName");
// If the default transaction has been set, find the explicit default transaction name
if (transactionName.equals("")) {
NodeList connectorsNodeList = element.getOwnerDocument().getElementsByTagName("connector");
int nlLen = connectorsNodeList.getLength();
for (int i = 0; i < nlLen; i++) {
Element connectorElement = (Element) connectorsNodeList.item(i);
String connectorNameElement = (String) XMLUtils.findPropertyValue(connectorElement, "name");
if (connectorName.equals(connectorNameElement)) {
NodeList transactionsNodeList = connectorElement.getElementsByTagName("transaction");
Node transactionNode = XMLUtils.findNodeByAttributeValue(transactionsNodeList, "default", "true");
if (transactionNode != null) {
transactionName = (String) XMLUtils.findPropertyValue((Element) transactionNode, "name");
break;
}
throw new EngineException("Unable to find the default transaction for the connector '" + connectorName + "' from project '" + projectName + "'");
}
}
}
String sourceTransaction = projectName + SequenceStep.SOURCE_SEPARATOR + connectorName + SequenceStep.SOURCE_SEPARATOR + transactionName;
setSourceTransaction(sourceTransaction);
hasChanged = true;
Engine.logBeans.warn("[SequenceStpe] The object \"" + getName() + "\" has been updated to version 6.0.3; source transaction: " + sourceTransaction);
}
} catch (Exception e) {
throw new EngineException("Unable to migrate the source definition for CallTransaction step \"" + getName() + "\".", e);
}
}
Aggregations