use of com.twinsoft.convertigo.beans.statements.ScEntryHandlerStatement in project convertigo by convertigo.
the class CreateHandlerDialogComposite method generateStatementHandler.
public void generateStatementHandler() throws EngineException {
String normalizedScreenClassName, handlerName = "";
if (jCheckBoxTransactionStarted.getSelection()) {
handlerName = "on" + Transaction.EVENT_TRANSACTION_STARTED;
if (((HtmlTransaction) transaction).getHandlerStatement(handlerName) == null) {
HandlerStatement statement = new HandlerStatement(HandlerStatement.EVENT_TRANSACTION_STARTED, "");
addElement(statement, handlerName);
} else
Beep();
}
if (jCheckBoxXmlGenerated.getSelection()) {
handlerName = "on" + Transaction.EVENT_XML_GENERATED;
if (((HtmlTransaction) transaction).getHandlerStatement(handlerName) == null) {
HandlerStatement statement = new HandlerStatement(HandlerStatement.EVENT_XML_GENERATED, "");
addElement(statement, handlerName);
} else
Beep();
}
if (jCheckBoxTransactionDefaultHandlerEntry.getSelection()) {
handlerName = "onTransactionDefaultHandlerEntry";
if (((HtmlTransaction) transaction).getHandlerStatement(handlerName) == null) {
ScEntryDefaultHandlerStatement statement = new ScEntryDefaultHandlerStatement();
addElement(statement, handlerName);
} else
Beep();
}
if (jCheckBoxTransactionDefaultHandlerExit.getSelection()) {
handlerName = "onTransactionDefaultHandlerExit";
if (((HtmlTransaction) transaction).getHandlerStatement(handlerName) == null) {
ScExitDefaultHandlerStatement statement = new ScExitDefaultHandlerStatement();
addElement(statement, handlerName);
} else
Beep();
}
if (jCheckBoxEntry.getSelection() || jCheckBoxExit.getSelection()) {
TreeItem[] treeItems = tree.getSelection();
for (int i = 0; i < treeItems.length; i++) {
String selectedScreenClass = treeItems[i].getText();
normalizedScreenClassName = StringUtils.normalize(selectedScreenClass);
if (jCheckBoxEntry.getSelection()) {
handlerName = "on" + normalizedScreenClassName + "Entry";
if (((HtmlTransaction) transaction).getHandlerStatement(handlerName) == null) {
ScEntryHandlerStatement statement = new ScEntryHandlerStatement(normalizedScreenClassName);
addElement(statement, handlerName);
} else
Beep();
}
if (jCheckBoxExit.getSelection()) {
handlerName = "on" + normalizedScreenClassName + "Exit";
if (((HtmlTransaction) transaction).getHandlerStatement(handlerName) == null) {
ScExitHandlerStatement statement = new ScExitHandlerStatement(normalizedScreenClassName);
addElement(statement, handlerName);
} else
Beep();
}
}
}
}
use of com.twinsoft.convertigo.beans.statements.ScEntryHandlerStatement in project convertigo by convertigo.
the class ChangeToScEntryHandlerStatementAction method run.
/* (non-Javadoc)
* @see com.twinsoft.convertigo.eclipse.popup.actions.MyAbstractAction#run()
*/
@Override
public void run() {
Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = getParentShell();
shell.setCursor(waitCursor);
try {
ProjectExplorerView explorerView = getProjectExplorerView();
if (explorerView != null) {
DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) explorerView.getFirstSelectedTreeObject();
DatabaseObject databaseObject = treeObject.getObject();
// For ScExitHandler statement
if ((databaseObject != null) && (databaseObject instanceof ScExitHandlerStatement || databaseObject instanceof ScExitDefaultHandlerStatement)) {
HandlerStatement scExitHandlerStatement = (HandlerStatement) databaseObject;
DatabaseObjectTreeObject parentTreeObject = treeObject.getOwnerDatabaseObjectTreeObject();
if (parentTreeObject != null) {
// New ScEntryHandler statement
HandlerStatement scEntryHandlerStatement = databaseObject instanceof ScExitHandlerStatement ? new ScEntryHandlerStatement() : new ScEntryDefaultHandlerStatement();
// Set properties
String handlerResult = scExitHandlerStatement.getHandlerResult();
if (ScHandlerStatement.RETURN_ACCUMULATE.equals(handlerResult)) {
handlerResult = ScHandlerStatement.RETURN_REDETECT;
}
scEntryHandlerStatement.setHandlerResult(handlerResult);
scEntryHandlerStatement.setComment(scExitHandlerStatement.getComment());
scEntryHandlerStatement.setEnabled(scExitHandlerStatement.isEnabled());
scEntryHandlerStatement.setPreventFromLoops(scExitHandlerStatement.preventFromLoops());
scEntryHandlerStatement.setParent(scExitHandlerStatement.getParent());
scEntryHandlerStatement.setReturnedValue(scExitHandlerStatement.getReturnedValue());
scEntryHandlerStatement.setVersion(scExitHandlerStatement.getVersion());
if (databaseObject instanceof ScExitHandlerStatement) {
ScExitHandlerStatement scExit = (ScExitHandlerStatement) scExitHandlerStatement;
ScEntryHandlerStatement scEntry = (ScEntryHandlerStatement) scEntryHandlerStatement;
scEntry.setNormalizedScreenClassName(scExit.getNormalizedScreenClassName());
scEntry.setName("on" + scExit.getNormalizedScreenClassName() + "Entry");
}
// Change status of ScEntryHandler statement
scEntryHandlerStatement.bNew = true;
scEntryHandlerStatement.hasChanged = true;
// Add new ScEntryHandler statement to parent
DatabaseObject parentDbo = scEntryHandlerStatement.getParent();
parentDbo.add(scEntryHandlerStatement);
for (Statement statement : scExitHandlerStatement.getStatements()) {
scEntryHandlerStatement.addStatement(statement);
}
// Delete ScExitHandler statement
scExitHandlerStatement.delete();
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
DatabaseObjectTreeObject newTreeObject = parentTreeObject.findDatabaseObjectTreeObjectChild(scEntryHandlerStatement);
explorerView.setSelectedTreeObject(newTreeObject);
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to change screen class exit handler statement to screen class entry handler statement!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.statements.ScEntryHandlerStatement in project convertigo by convertigo.
the class ChangeToScExitHandlerStatementAction method run.
/* (non-Javadoc)
* @see com.twinsoft.convertigo.eclipse.popup.actions.MyAbstractAction#run()
*/
@Override
public void run() {
Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = getParentShell();
shell.setCursor(waitCursor);
try {
ProjectExplorerView explorerView = getProjectExplorerView();
if (explorerView != null) {
DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) explorerView.getFirstSelectedTreeObject();
DatabaseObject databaseObject = treeObject.getObject();
// For ScEntryHandler statement
if ((databaseObject != null) && (databaseObject instanceof ScEntryHandlerStatement || databaseObject instanceof ScEntryDefaultHandlerStatement)) {
HandlerStatement scEntryHandlerStatement = (HandlerStatement) databaseObject;
DatabaseObjectTreeObject parentTreeObject = treeObject.getOwnerDatabaseObjectTreeObject();
if (parentTreeObject != null) {
// New ScExitHandler statement
HandlerStatement scExitHandlerStatement = databaseObject instanceof ScEntryHandlerStatement ? new ScExitHandlerStatement() : new ScExitDefaultHandlerStatement();
// Set properties
String handlerResult = scEntryHandlerStatement.getHandlerResult();
if (ScHandlerStatement.RETURN_REDETECT.equals(handlerResult)) {
handlerResult = ScHandlerStatement.RETURN_ACCUMULATE;
} else if (ScHandlerStatement.RETURN_SKIP.equals(handlerResult)) {
handlerResult = "";
}
scExitHandlerStatement.setHandlerResult(handlerResult);
scExitHandlerStatement.setComment(scEntryHandlerStatement.getComment());
scExitHandlerStatement.setEnabled(scEntryHandlerStatement.isEnabled());
scExitHandlerStatement.setPreventFromLoops(scEntryHandlerStatement.preventFromLoops());
scExitHandlerStatement.setParent(scEntryHandlerStatement.getParent());
scExitHandlerStatement.setReturnedValue(scEntryHandlerStatement.getReturnedValue());
scExitHandlerStatement.setVersion(scEntryHandlerStatement.getVersion());
if (databaseObject instanceof ScEntryHandlerStatement) {
ScExitHandlerStatement scExit = (ScExitHandlerStatement) scExitHandlerStatement;
ScEntryHandlerStatement scEntry = (ScEntryHandlerStatement) scEntryHandlerStatement;
scExit.setNormalizedScreenClassName(scEntry.getNormalizedScreenClassName());
scExit.setName("on" + scEntry.getNormalizedScreenClassName() + "Exit");
}
// Change status of scExitHanlder statement
scExitHandlerStatement.bNew = true;
scExitHandlerStatement.hasChanged = true;
// Add new ScExitHandler statement to parent
DatabaseObject parentDbo = scEntryHandlerStatement.getParent();
parentDbo.add(scExitHandlerStatement);
// Add new ScExitHandler statement in Tree
StatementTreeObject statementTreeObject = new StatementTreeObject(explorerView.viewer, scExitHandlerStatement);
parentTreeObject.addChild(statementTreeObject);
for (Statement statement : scEntryHandlerStatement.getStatements()) {
scExitHandlerStatement.addStatement(statement);
}
// Delete ScEntryHandler statement
scEntryHandlerStatement.delete();
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
DatabaseObjectTreeObject newTreeObject = parentTreeObject.findDatabaseObjectTreeObjectChild(scExitHandlerStatement);
explorerView.setSelectedTreeObject(newTreeObject);
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to change screen class entry handler statement to screen class exit handler statement!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.statements.ScEntryHandlerStatement in project convertigo by convertigo.
the class HtmlConnectorDesignComposite method modelChanged.
public void modelChanged(HttpProxyEvent event) {
if (!checkProxySource(event)) {
return;
}
String requestString = event.getRequest();
String responseString = event.getResponse();
boolean https = event.isHttps();
int status = Integer.parseInt(event.getStatus());
// do not record client redirection
if ((status == HttpStatus.SC_MOVED_TEMPORARILY) || (status == HttpStatus.SC_MOVED_PERMANENTLY) || (status == HttpStatus.SC_SEE_OTHER) || (status == HttpStatus.SC_TEMPORARY_REDIRECT)) {
return;
}
/*if (requestString.indexOf(getServer()) == -1) {
return;
}*/
Map<String, String> headers = parseResponseString(responseString);
String contentType = headers.get(HeaderName.ContentType.value().toLowerCase());
// record only text/html or null Content-Type ...
if (contentType == null) {
return;
}
if (MimeType.Html.is(contentType) && MimeType.Plain.is(contentType)) {
return;
}
ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) Learning statement...");
try {
String url, method, handlerName, transactionName, statementName, scHandlerName;
String normalizedScreenClassName, screenClassName;
HtmlTransaction htmlTransaction = null;
HTTPStatement httpStatement = null;
HtmlScreenClass htmlScreenClass = null;
HandlerStatement handlerStatement = null;
ScHandlerStatement scHandlerStatement = null;
// Document dom = null;
// Log log = null;
int size, index1;
boolean bContinue;
index1 = 0;
bContinue = true;
normalizedScreenClassName = "Unknown";
htmlTransaction = (HtmlTransaction) htmlConnector.getLearningTransaction();
synchronized (htmlConnector) {
// dom = htmlConnector.getCurrentXmlDocument();
htmlScreenClass = htmlConnector.getCurrentScreenClass();
}
screenClassName = htmlScreenClass.getName();
normalizedScreenClassName = StringUtils.normalize(htmlScreenClass.getName());
ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) current screen class is '" + screenClassName + "'");
if (htmlTransaction != null) {
transactionName = htmlTransaction.getName();
ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) creating new HTTPStatement");
ConvertigoPlugin.logDebug2(requestString);
httpStatement = parseRequestString(requestString);
httpStatement.setHttps(https);
httpStatement.setPort(https ? 443 : 80);
method = httpStatement.getMethod().toLowerCase();
// size = httpStatement.getVariablesDefinitionSize();
size = httpStatement.numberOfVariables();
url = httpStatement.getUrl(htmlConnector.isHttps(), htmlConnector.getServer(), htmlConnector.getPort());
while (bContinue) {
statementName = method + ((index1 == 0) ? " " : " " + index1) + " (" + url + " - " + size + ")";
statementName = StringUtils.normalize(statementName);
httpStatement.setName(statementName);
httpStatement.hasChanged = true;
httpStatement.bNew = true;
if (htmlScreenClass == null) {
try {
httpStatement.priority = 0;
htmlTransaction.addStatement(httpStatement);
ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) added new HTTPStatement to default transaction '" + transactionName + "'");
fireObjectChanged(new CompositeEvent(htmlTransaction));
Engine.theApp.fireObjectDetected(new EngineEvent(httpStatement));
bContinue = false;
} catch (ObjectWithSameNameException owsne) {
index1++;
}
} else {
if (htmlConnector.isAccumulating())
handlerName = "on" + normalizedScreenClassName + "Exit";
else
handlerName = "on" + normalizedScreenClassName + "Entry";
handlerStatement = htmlTransaction.getHandlerStatement(handlerName);
if (handlerStatement != null) {
try {
handlerStatement.addStatement(httpStatement);
ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) added new HTTPStatement to handler '" + handlerName + "' of transaction '" + transactionName + "'");
fireObjectChanged(new CompositeEvent(handlerStatement));
Engine.theApp.fireObjectDetected(new EngineEvent(httpStatement));
bContinue = false;
} catch (ObjectWithSameNameException owsne) {
index1++;
}
} else {
try {
if (htmlConnector.isAccumulating())
scHandlerStatement = new ScExitHandlerStatement(normalizedScreenClassName);
else
scHandlerStatement = new ScEntryHandlerStatement(normalizedScreenClassName);
scHandlerName = scHandlerStatement.getName();
scHandlerStatement.setName(scHandlerName);
scHandlerStatement.hasChanged = true;
scHandlerStatement.bNew = true;
scHandlerStatement.priority = 0;
htmlTransaction.addStatement(scHandlerStatement);
ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) added new ScExitHandlerStatement '" + handlerName + "' of transaction '" + transactionName + "'");
try {
scHandlerStatement.addStatement(httpStatement);
ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) added new HTTPStatement '" + statementName + "' to ScExitHandlerStatement '" + handlerName + "'");
fireObjectChanged(new CompositeEvent(htmlTransaction));
Engine.theApp.fireObjectDetected(new EngineEvent(httpStatement));
bContinue = false;
} catch (ObjectWithSameNameException owsne) {
index1++;
}
}// Should not append
catch (ObjectWithSameNameException owsne) {
throw new EngineException(owsne.getMessage());
}
}
}
}
} else {
throw new EngineException("Found none learning transaction");
}
} catch (EngineException e) {
ConvertigoPlugin.logException(e, "An exception occured while learning");
}
}
Aggregations