use of com.twinsoft.convertigo.beans.connectors.HtmlConnector in project convertigo by convertigo.
the class ReferencesView method handleTransactionSelection.
private void handleTransactionSelection(Object firstElement) {
TransactionTreeObject transactionTreeObject = (TransactionTreeObject) firstElement;
Transaction transaction = transactionTreeObject.getObject();
String transactionName = transactionTreeObject.getName();
// Get the referencing sequence steps
String transactionProjectName = transaction.getProject().getName();
String transactionConnectorName = transaction.getParent().getName();
try {
Project project = null;
List<String> projectNames = Engine.theApp.databaseObjectsManager.getAllProjectNamesList();
ProjectExplorerView projectExplorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
treeViewer.setInput(null);
RootNode root = new RootNode();
TransactionNode transactionFolder = new TransactionNode(root, transactionName, transaction);
root.addChild(transactionFolder);
IsUsedByNode isUsedByNode = new IsUsedByNode(transactionFolder, "Is used by");
RequiresNode requiresNode = new RequiresNode(transactionFolder, "Requires");
ProjectNode projectFolder = null;
// Searching all objects are required transaction selected
Connector connector = transaction.getConnector();
if (connector instanceof HtmlConnector) {
Project proj = ((HtmlConnector) connector).getProject();
ProjectNode projectNode = new ProjectNode(requiresNode, transactionProjectName, proj);
HtmlTransaction htmlTransaction = (HtmlTransaction) transaction;
List<Statement> statements = htmlTransaction.getStatements();
List<ScreenClass> screenClassList = new ArrayList<ScreenClass>();
List<String> siteClipperConnectorNames = new ArrayList<String>();
for (Statement statement : statements) {
if (statement instanceof ScHandlerStatement) {
ScHandlerStatement scHandlerStatement = (ScHandlerStatement) statement;
String screenClassName = scHandlerStatement.getNormalizedScreenClassName();
ScreenClass screenClass = ((HtmlConnector) connector).getScreenClassByName(screenClassName);
if (screenClass != null) {
if (!screenClassList.contains(screenClass)) {
screenClassList.add(screenClass);
requiresNode.addChild(new ScreenClassNode(requiresNode, screenClassName, screenClass));
}
}
}
List<Statement> statementList = ((FunctionStatement) statement).getStatements();
for (Statement st : statementList) {
if (st instanceof ContinueWithSiteClipperStatement) {
ContinueWithSiteClipperStatement continueWithSiteClipperStatement = (ContinueWithSiteClipperStatement) st;
String siteClipperconnectorName = continueWithSiteClipperStatement.getSiteClipperConnectorName();
if (!siteClipperConnectorNames.contains(siteClipperconnectorName)) {
siteClipperConnectorNames.add(siteClipperconnectorName);
Connector siteClipperConnector = proj.getConnectorByName(siteClipperconnectorName);
ConnectorNode connectorSiteClipperNode = new SiteClipperConnectorNode(projectNode, siteClipperconnectorName, siteClipperConnector);
projectNode.addChild(connectorSiteClipperNode);
}
}
}
}
if (projectNode.hasChildren()) {
requiresNode.addChild(projectNode);
}
} else if (connector instanceof JavelinConnector) {
JavelinTransaction javelinTransaction = (JavelinTransaction) transaction;
String handlers = javelinTransaction.handlers;
List<JavelinScreenClass> screenClasses = ((JavelinConnector) connector).getAllScreenClasses();
List<JavelinScreenClass> screenClassList = new ArrayList<JavelinScreenClass>();
for (JavelinScreenClass screenClass : screenClasses) {
if (handlers.indexOf("function on" + screenClass.getName()) != -1) {
if (!screenClassList.contains(screenClass)) {
screenClassList.add(screenClass);
requiresNode.addChild(new ScreenClassNode(requiresNode, screenClass.getName(), screenClass));
}
}
}
}
// Searching all objects are used transaction selected
for (String projectName : projectNames) {
project = getProject(projectName, projectExplorerView);
if (project != null) {
projectFolder = new ProjectNode(isUsedByNode, project.getName(), project);
UrlMapper urlMapper = project.getUrlMapper();
if (urlMapper != null) {
MapperNode mapperNode = new MapperNode(projectFolder, urlMapper.getName(), urlMapper);
List<UrlMapping> mappings = urlMapper.getMappingList();
for (UrlMapping mapping : mappings) {
MappingPathNode pathNode = new MappingPathNode(mapperNode, mapping.getPath(), mapping);
List<UrlMappingOperation> operations = mapping.getOperationList();
for (UrlMappingOperation operation : operations) {
String targetRequestable = operation.getTargetRequestable();
if (targetRequestable.equals(transactionProjectName + "." + transactionConnectorName + "." + transactionName)) {
MappingOperationNode operationNode = new MappingOperationNode(pathNode, operation.getName(), operation);
pathNode.addChild(operationNode);
}
}
if (pathNode.hasChildren()) {
mapperNode.addChild(pathNode);
}
}
if (mapperNode.hasChildren()) {
projectFolder.addChild(mapperNode);
}
}
List<Sequence> sequences = project.getSequencesList();
for (Sequence sequence : sequences) {
List<Step> stepList = sequence.getAllSteps();
SequenceNode sequenceNode = new SequenceNode(projectFolder, sequence.getName(), sequence);
for (Step step : stepList) {
getTransactionReferencing(step, projectExplorerView, sequenceNode, transactionProjectName, transactionConnectorName, transactionName);
}
if (sequenceNode.hasChildren()) {
projectFolder.addChild(sequenceNode);
}
}
if (projectFolder.hasChildren()) {
isUsedByNode.addChild(projectFolder);
}
}
}
if (requiresNode.hasChildren()) {
transactionFolder.addChild(requiresNode);
}
if (isUsedByNode.hasChildren()) {
transactionFolder.addChild(isUsedByNode);
}
if (!transactionFolder.hasChildren()) {
transactionFolder.addChild(new InformationNode(projectFolder, "This transaction is not used in any sequence"));
}
treeViewer.setInput(root);
treeViewer.expandAll();
} catch (EngineException e) {
ConvertigoPlugin.logException(e, "Error while analyzing the projects hierarchy", true);
}
}
use of com.twinsoft.convertigo.beans.connectors.HtmlConnector in project convertigo by convertigo.
the class ReferencesView method handleScreenClassSelection.
private void handleScreenClassSelection(Object firstElement) {
ScreenClassTreeObject screenClassTreeObject = (ScreenClassTreeObject) firstElement;
ScreenClass screenClass = screenClassTreeObject.getObject();
String screenClassName = screenClassTreeObject.getName();
// Get the referencing transactions
Connector connector = screenClass.getConnector();
List<Transaction> transactions = connector.getTransactionsList();
RootNode root = new RootNode();
ScreenClassNode screenClassFolder = new ScreenClassNode(root, screenClassName, screenClass);
root.addChild(screenClassFolder);
IsUsedByNode isUsedByNode = new IsUsedByNode(screenClassFolder, "Is used by");
EntryHandlerNode entryFolder = new EntryHandlerNode(isUsedByNode, "Transaction entry handlers", null);
ExitHandlerNode exitFolder = new ExitHandlerNode(isUsedByNode, "Transaction exit handlers", null);
if (connector instanceof HtmlConnector) {
for (Transaction transaction : transactions) {
HtmlTransaction htmlTransaction = (HtmlTransaction) transaction;
List<Statement> statements = htmlTransaction.getStatements();
for (Statement statement : statements) {
if (statement instanceof ScHandlerStatement) {
ScHandlerStatement scHandlerStatement = (ScHandlerStatement) statement;
if (scHandlerStatement.getNormalizedScreenClassName().equals(screenClassName)) {
if (scHandlerStatement.getName().endsWith("Entry")) {
entryFolder.addChild(new TransactionNode(entryFolder, transaction.getName(), scHandlerStatement));
} else {
exitFolder.addChild(new TransactionNode(exitFolder, transaction.getName(), scHandlerStatement));
}
}
}
}
}
} else if (connector instanceof JavelinConnector) {
for (Transaction transaction : transactions) {
JavelinTransaction javelinTransaction = (JavelinTransaction) transaction;
if (javelinTransaction.handlers.indexOf("function on" + screenClassName + "Entry()") != -1) {
entryFolder.addChild(new TransactionNode(entryFolder, transaction.getName(), transaction));
}
if (javelinTransaction.handlers.indexOf("function on" + screenClassName + "Exit()") != -1) {
exitFolder.addChild(new TransactionNode(exitFolder, transaction.getName(), transaction));
}
}
}
if (entryFolder.hasChildren()) {
isUsedByNode.addChild(entryFolder);
}
if (exitFolder.hasChildren()) {
isUsedByNode.addChild(exitFolder);
}
if (!isUsedByNode.hasChildren()) {
screenClassFolder.addChild(new InformationNode(screenClassFolder, "This screen class is not used in any transaction"));
} else {
screenClassFolder.addChild(isUsedByNode);
}
// Build the treeviewer model
treeViewer.setInput(null);
treeViewer.setInput(root);
treeViewer.expandAll();
}
use of com.twinsoft.convertigo.beans.connectors.HtmlConnector in project convertigo by convertigo.
the class HtmlTransaction method runCore.
@Override
public void runCore() throws EngineException {
try {
HtmlConnector connector = (HtmlConnector) parent;
vExtractionRulesInited = new LinkedList<String>();
if (!runningThread.bContinue) {
return;
}
if (isStateFull() || connector.getHtmlParser().isConnected()) {
alreadyConnected = true;
}
if (!alreadyConnected) {
connector.setCurrentXmlDocument(null);
applyUserRequest(connector);
} else {
setCurrentXmlDocument(connector.getHtmlParser().getDom(context));
}
if (bDispatching) {
applyUserEvents();
}
bNotFirstLoop1 = false;
bNotFirstLoop2 = false;
if (!runningThread.bContinue) {
return;
}
if (isContentTypeHTML()) {
latestCalledHandler = null;
do {
do {
String t = context.statistics.start(EngineStatistics.GET_CURRENT_SCREEN_CLASS);
try {
screenClass = ((HtmlConnector) connector).getCurrentScreenClass();
normalizedScreenClassName = StringUtils.normalize(screenClass.getName());
context.lastDetectedObject = screenClass;
score += 1;
Engine.logBeans.info("Detected screen class: '" + screenClass.getName() + "'");
// We fire engine events only in studio mode.
if (Engine.isStudioMode()) {
Engine.theApp.fireObjectDetected(new EngineEvent(screenClass));
}
} finally {
context.statistics.stop(t, bNotFirstLoop1);
}
// We execute the entry handler for the detected screen class
executeHandler(EVENT_ENTRY_HANDLER, ((RequestableThread) Thread.currentThread()).javascriptContext);
bNotFirstLoop1 = true;
// while re detecting, a new page could be loaded by async client javascript, if this happens,
// we refresh our current dom. Normally this is done by each statement, refreshing the dom here seems to be useless
// except in the case explained above. We rely on the the DOM cache to speed up things as the
// isDirty flag would not be set in most of the cases
setCurrentXmlDocument(connector.getHtmlParser().getDom(context));
} while (runningThread.bContinue && (handlerResult.equalsIgnoreCase(RETURN_REDETECT)));
if (!handlerResult.equalsIgnoreCase(RETURN_SKIP)) {
// We fire engine events only in studio mode.
if (Engine.isStudioMode()) {
// Engine.theApp.fireObjectDetected(new EngineEvent(blockFactory));
}
if (!runningThread.bContinue) {
return;
}
if (currentXmlDocument == null) {
throw new EngineException(alreadyConnected ? "Connector did not reconnect, please verify transaction statefull mode." : "" + " Current document is null. Cannot apply extraction rules.");
}
applyExtractionRules(screenClass, bNotFirstLoop2);
Engine.logBeans.debug("(HtmlTransaction) Extraction rules executed ...");
}
if (!runningThread.bContinue) {
return;
}
// We execute the exit handler for the current screen class
executeHandler(EVENT_EXIT_HANDLER, ((RequestableThread) Thread.currentThread()).javascriptContext);
bNotFirstLoop2 = true;
} while (runningThread.bContinue && (handlerResult.equalsIgnoreCase(RETURN_ACCUMULATE)));
if (!runningThread.bContinue) {
return;
}
} else if (currentXmlDocument != null) {
XMLUtils.copyDocument(currentXmlDocument, context.outputDocument);
} else {
throw new EngineException("Connector doesn't retrieve xmlizable content. Verify your url.");
}
} finally {
alreadyConnected = false;
// restoreVariablesDefinition();
restoreVariables();
if ((runningThread == null) || (!runningThread.bContinue)) {
Engine.logBeans.warn("(HtmlTransaction) The transaction \"" + getName() + "\" has been successfully interrupted.");
} else {
Engine.logBeans.debug("(HtmlTransaction) The transaction \"" + getName() + "\" has successfully finished.");
}
}
}
use of com.twinsoft.convertigo.beans.connectors.HtmlConnector in project convertigo by convertigo.
the class HtmlTransaction method applyUserEvents.
protected void applyUserEvents() throws EngineException {
HtmlConnector connector = (HtmlConnector) parent;
if (!runningThread.bContinue)
return;
try {
Document dom = null;
for (int i = 0; i < wcFields.size(); i++) {
AbstractEvent event = (AbstractEvent) wcFields.get(i);
connector.dispatchEvent(event, context, new WaitTimeTrigger(0, false));
}
String comment = (wcEvent instanceof AbstractEvent) ? ((AbstractEvent) wcEvent).getXPath() : "on browser";
Engine.logBeans.trace("(HtmlTransaction) Dispatch Event: " + comment);
boolean dispatch = connector.dispatchEvent(wcEvent, context, wcTrigger);
dom = connector.getHtmlParser().getDom(context);
Engine.logBeans.trace("(HtmlTransaction) Event: " + comment + (dispatch ? "" : " not") + " dispatched");
setCurrentXmlDocument(dom);
if (Engine.logBeans.isTraceEnabled())
Engine.logBeans.trace("(HtmlTransaction) Parse result dom:\n" + XMLUtils.prettyPrintDOM(dom));
} catch (Exception e) {
throw new EngineException("An unexpected exception occured while trying to get the document via HTTP.", e);
} finally {
bDispatching = false;
}
if (!runningThread.bContinue)
return;
}
use of com.twinsoft.convertigo.beans.connectors.HtmlConnector 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);
}
Aggregations