use of com.twinsoft.convertigo.engine.parsers.triggers.TriggerXMLizer in project convertigo by convertigo.
the class StatementTreeObject method treeObjectRemoved.
@Override
public void treeObjectRemoved(TreeObjectEvent treeObjectEvent) {
super.treeObjectRemoved(treeObjectEvent);
// Avoid the cast between "UnloadedProjectTreeObject" and "DatabaseObjectTreeObject
if (!(treeObjectEvent.getSource() instanceof UnloadedProjectTreeObject)) {
DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) treeObjectEvent.getSource();
DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
Statement statement = getObject();
boolean change = false;
// Case this is a screen class
if (databaseObject instanceof ScreenClass) {
ScreenClassTreeObject sto = (ScreenClassTreeObject) treeObjectEvent.getSource();
String screenClassName = StringUtils.normalize(databaseObject.getName());
// ScreenClass and Statement must have the same connector!
if (statement.getConnector().equals(sto.getConnectorTreeObject().getObject())) {
if (statement instanceof ITriggerOwner) {
ITriggerOwner ito = (ITriggerOwner) statement;
AbstractTrigger atrigger = ito.getTrigger().getTrigger();
if (atrigger instanceof ScreenClassTrigger) {
ScreenClassTrigger sct = (ScreenClassTrigger) atrigger;
List<String> screenClasses = sct.getScreenClasses();
for (int i = 0; i < screenClasses.size(); i++) {
if (screenClasses.get(i).equals(screenClassName)) {
screenClasses.remove(i);
change = true;
}
}
// Add default root screen class if all have been removed
if (screenClasses.isEmpty()) {
IScreenClassContainer<?> iscc = (IScreenClassContainer<?>) sto.getConnectorTreeObject().getObject();
String defaultScreenClassName = StringUtils.normalize(iscc.getDefaultScreenClass().getName());
screenClasses.add(defaultScreenClassName);
change = true;
}
if (change)
ito.setTrigger(new TriggerXMLizer(sct));
}
}
}
}
if (change)
try {
hasBeenModified(true);
ConvertigoPlugin.getDefault().getProjectExplorerView().refreshTreeObject(this);
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could not refresh in tree ScHandlerStatement \"" + statement.getName() + "\" !");
}
}
}
use of com.twinsoft.convertigo.engine.parsers.triggers.TriggerXMLizer in project convertigo by convertigo.
the class StatementTreeObject method handlesBeanNameChanged.
protected void handlesBeanNameChanged(TreeObjectEvent treeObjectEvent) {
DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) treeObjectEvent.getSource();
DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
Object oldValue = treeObjectEvent.oldValue;
Object newValue = treeObjectEvent.newValue;
Statement statement = getObject();
boolean change = false;
if (databaseObject instanceof ScreenClass) {
String oldScreenClassName = StringUtils.normalize((String) oldValue);
String newScreenClassName = StringUtils.normalize((String) newValue);
// ScreenClass and Statement must have the same connector!
if (statement.getConnector().equals(databaseObject.getConnector())) {
// Modify screenclass handlers name
if (statement instanceof ScHandlerStatement) {
ScHandlerStatement scHandlerStatement = (ScHandlerStatement) statement;
if (scHandlerStatement.getNormalizedScreenClassName().equals(oldScreenClassName)) {
String handlerType = scHandlerStatement.getHandlerType();
String beanName = "on" + newScreenClassName + handlerType;
try {
scHandlerStatement.setName(beanName);
scHandlerStatement.setNormalizedScreenClassName(newScreenClassName);
change = true;
} catch (EngineException e) {
ConvertigoPlugin.logWarning(e, "Could not rename ScHandlerStatement from \"" + scHandlerStatement.getName() + "\" to \"" + beanName + "\" !");
}
}
}
if (statement instanceof ITriggerOwner) {
ITriggerOwner ito = (ITriggerOwner) statement;
AbstractTrigger atrigger = ito.getTrigger().getTrigger();
if (atrigger instanceof ScreenClassTrigger) {
ScreenClassTrigger sct = (ScreenClassTrigger) atrigger;
List<String> screenClasses = sct.getScreenClasses();
for (int i = 0; i < screenClasses.size(); i++) if (screenClasses.get(i).equals(oldScreenClassName) && (change = true))
screenClasses.set(i, newScreenClassName);
if (change)
ito.setTrigger(new TriggerXMLizer(sct));
}
}
}
} else // Case of connector rename
if (databaseObject instanceof SiteClipperConnector) {
if (statement instanceof ContinueWithSiteClipperStatement) {
boolean isLocalProject = statement.getProject().equals(databaseObject.getProject());
boolean isSameValue = ((ContinueWithSiteClipperStatement) statement).getSiteClipperConnectorName().equals(oldValue);
if (isSameValue && isLocalProject) {
((ContinueWithSiteClipperStatement) statement).setSiteClipperConnectorName((String) newValue);
hasBeenModified(true);
viewer.refresh();
// refresh editors (e.g labels in combobox)
getDescriptors();
}
}
}
if (statement instanceof CallFunctionStatement && databaseObject.getClass().equals(FunctionStatement.class) && ((FunctionStatement) databaseObject).getParentTransaction().equals(statement.getParentTransaction())) {
CallFunctionStatement callfunction = (CallFunctionStatement) statement;
if (callfunction.getFunctionName().equals(oldValue) && (change = true))
callfunction.setFunctionName(newValue.toString());
}
if (change)
try {
hasBeenModified(true);
ConvertigoPlugin.getDefault().getProjectExplorerView().refreshTreeObject(this);
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could not refresh in tree ScHandlerStatement \"" + statement.getName() + "\" !");
}
}
use of com.twinsoft.convertigo.engine.parsers.triggers.TriggerXMLizer in project convertigo by convertigo.
the class HtmlTransaction method applyUserRequest.
public void applyUserRequest(Object object) throws EngineException {
final HtmlConnector connector = (HtmlConnector) parent;
if (!runningThread.bContinue) {
return;
}
Cookie[] cookies = new Cookie[] {};
final byte[][] httpData = { null };
try {
Document dom = null;
TriggerXMLizer triggerXML = null;
String t = context.statistics.start(EngineStatistics.HTTP_CONNECT);
try {
// Retrieving Data
if (object instanceof HtmlConnector) {
Engine.logBeans.trace("(HtmlTransaction) Retrieving data from connector ...");
httpData[0] = connector.getData(context);
triggerXML = trigger;
}
if (object instanceof HTTPStatement) {
Engine.logBeans.trace("(HtmlTransaction) Retrieving data from http statement ...");
connector.prepareForHTTPStatement(context);
httpData[0] = connector.getData(context);
triggerXML = ((HTTPStatement) object).getTrigger();
}
if (!alreadyConnected)
alreadyConnected = true;
Engine.logBeans.trace("(HtmlTransaction) Data retrieved!");
// Engine.logBeans.trace("(HtmlTransaction) Data html:\n"+ new String(httpData));
} finally {
context.statistics.stop(t);
}
// Retrieve cookies from HttpClient response
if (connector.handleCookie) {
cookies = connector.getCookies();
if (Engine.logBeans.isTraceEnabled()) {
Engine.logBeans.trace("(HtmlTransaction) cookies from HttpClient response :" + Arrays.asList(cookies).toString());
}
}
if (!runningThread.bContinue) {
return;
}
// Parse response : push data into HTML parser
if (!isContentTypeHTML()) {
final String[] filename = { connector.getReferer() };
int id;
if ((id = filename[0].indexOf('?')) != -1) {
filename[0] = filename[0].substring(0, id);
}
if ((id = filename[0].lastIndexOf('/')) != -1) {
filename[0] = filename[0].substring(id + 1);
}
connector.getHtmlParser().downloadRequest(context, new IDownloader() {
public String getUri() {
return connector.getReferer();
}
public String getReferrer() {
return connector.getReferer();
}
public String getFilename() {
return filename[0];
}
public byte[] getData(long timeout, long threshold) {
return httpData[0];
}
public String getContentType() {
return HtmlTransaction.this.getContentType();
}
public void cancel() {
}
public Status getStatus() {
return Status.direct;
}
});
return;
}
dom = connector.parseData(httpData[0], connector.getReferer(), connector.getCharset(), triggerXML.getTrigger());
if (!runningThread.bContinue)
return;
setCurrentXmlDocument(dom);
if (Engine.logBeans.isTraceEnabled())
Engine.logBeans.trace("(HtmlTransaction) Parser result dom:\n" + XMLUtils.prettyPrintDOM(dom));
if (!runningThread.bContinue)
return;
// Modify input document if needed
modifyInputDocument();
} catch (IOException e) {
throw new EngineException("An IO exception occured while trying to connect to the URL.\nURL: " + connector.sUrl + "\nPost query: " + connector.postQuery, e);
} catch (Exception e) {
throw new EngineException("An unexpected exception occured while trying to get the document via HTTP.", e);
}
if (!runningThread.bContinue)
return;
// Applying handler
executeHandler(EVENT_DATA_RETRIEVED, ((RequestableThread) Thread.currentThread()).javascriptContext);
}
use of com.twinsoft.convertigo.engine.parsers.triggers.TriggerXMLizer in project convertigo by convertigo.
the class HttpTriggerScreenClassEditorComposite method getTriggerXMLizer.
public TriggerXMLizer getTriggerXMLizer() {
String[] items = scrClass_list.getSelection();
XMLVector<String> list = new XMLVector<String>();
for (int i = 0; i < items.length; i++) {
list.add(items[i]);
}
return new TriggerXMLizer(new ScreenClassTrigger(list, parent.getTimeout()));
}
Aggregations