Search in sources :

Example 6 with HtmlTransaction

use of com.twinsoft.convertigo.beans.transactions.HtmlTransaction in project convertigo by convertigo.

the class TransactionTreeObject 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;
    if (databaseObject instanceof ScreenClass) {
        String oldName = StringUtils.normalize((String) oldValue);
        String newName = StringUtils.normalize((String) newValue);
        Transaction transaction = getObject();
        // Modify Screenclass name in Transaction handlers
        if (!(transaction instanceof HtmlTransaction)) {
            // ScreenClass and Transaction must have the same connector!
            if (transaction.getConnector().equals(databaseObject.getConnector())) {
                String oldHandlerPrefix = "on" + StringUtils.normalize(oldName);
                String newHandlerPrefix = "on" + StringUtils.normalize(newName);
                if (transaction.handlers.indexOf(oldHandlerPrefix) != -1) {
                    StringEx sx = new StringEx(transaction.handlers);
                    // Updating comments
                    sx.replaceAll("handler for screen class \"" + oldName + "\"", "handler for screen class \"" + newName + "\"");
                    // Updating functions def & calls
                    sx.replaceAll(oldHandlerPrefix + "Entry", newHandlerPrefix + "Entry");
                    sx.replaceAll(oldHandlerPrefix + "Exit", newHandlerPrefix + "Exit");
                    String newHandlers = sx.toString();
                    if (!newHandlers.equals(transaction.handlers)) {
                        transaction.handlers = newHandlers;
                        hasBeenModified(true);
                    }
                    // Update the opened handlers editor if any
                    JScriptEditorInput jsinput = ConvertigoPlugin.getDefault().getJScriptEditorInput(transaction);
                    if (jsinput != null) {
                        jsinput.reload();
                    }
                    try {
                        getProjectExplorerView().reloadTreeObject(this);
                    } catch (Exception e) {
                        ConvertigoPlugin.logWarning(e, "Could not reload in tree Transaction \"" + databaseObject.getName() + "\" !");
                    }
                }
            }
        }
    }
    if (databaseObject instanceof Variable) {
        String oldVariableName = oldValue.toString();
        String newVariableName = newValue.toString();
        // A variable of this transaction has been renamed
        if (getObject().equals(databaseObject.getParent())) {
            if (getObject() instanceof AbstractHttpTransaction) {
                AbstractHttpTransaction httpTransaction = (AbstractHttpTransaction) getObject();
                try {
                    // Check for variables to be renamed in SubDir property
                    String transactionSubDir = httpTransaction.getSubDir();
                    List<String> pathVariableList = AbstractHttpTransaction.getPathVariableList(transactionSubDir);
                    if (pathVariableList.contains(oldVariableName)) {
                        transactionSubDir = transactionSubDir.replaceAll("\\{" + oldVariableName + "\\}", "{" + newVariableName + "}");
                        httpTransaction.setSubDir(transactionSubDir);
                        httpTransaction.hasChanged = true;
                    }
                    getProjectExplorerView().refreshTreeObject(this);
                } catch (Exception e) {
                    ConvertigoPlugin.logWarning(e, "Could not reload in tree Transaction \"" + databaseObject.getName() + "\" !");
                }
            }
        }
    }
    // Case of this transaction rename : update transaction's schema
    if (treeObject.equals(this)) {
        String path = Project.XSD_FOLDER_NAME + "/" + Project.XSD_INTERNAL_FOLDER_NAME + "/" + getConnectorTreeObject().getName();
        String oldPath = path + "/" + (String) oldValue + ".xsd";
        String newPath = path + "/" + (String) newValue + ".xsd";
        IFile file = getProjectTreeObject().getFile(oldPath);
        try {
            file.getParent().refreshLocal(IResource.DEPTH_ONE, null);
            if (file.exists()) {
                // rename file (xsd/internal/connector/transaction.xsd)
                file.move(new Path((String) newValue + ".xsd"), true, null);
                // make replacements in schema files
                List<Replacement> replacements = new ArrayList<Replacement>();
                replacements.add(new Replacement("__" + (String) oldValue, "__" + (String) newValue));
                IFile newFile = file.getParent().getFile(new Path((String) newValue + ".xsd"));
                String newFilePath = newFile.getLocation().makeAbsolute().toString();
                try {
                    ProjectUtils.makeReplacementsInFile(replacements, newFilePath);
                } catch (Exception e) {
                    ConvertigoPlugin.logWarning(e, "Could not rename \"" + oldValue + "\" to \"" + newValue + "\" in schema file \"" + newPath + "\" !");
                }
                // refresh file
                file.refreshLocal(IResource.DEPTH_ZERO, null);
                Engine.theApp.schemaManager.clearCache(getProjectTreeObject().getName());
            }
        } catch (Exception e) {
            ConvertigoPlugin.logWarning(e, "Could not rename schema file from \"" + oldPath + "\" to \"" + newPath + "\" !");
        }
    }
}
Also used : JScriptEditorInput(com.twinsoft.convertigo.eclipse.editors.jscript.JScriptEditorInput) Path(org.eclipse.core.runtime.Path) RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable) Variable(com.twinsoft.convertigo.beans.core.Variable) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) IFile(org.eclipse.core.resources.IFile) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) ArrayList(java.util.ArrayList) Replacement(com.twinsoft.convertigo.engine.util.Replacement) PartInitException(org.eclipse.ui.PartInitException) EngineException(com.twinsoft.convertigo.engine.EngineException) AbstractHttpTransaction(com.twinsoft.convertigo.beans.transactions.AbstractHttpTransaction) AbstractHttpTransaction(com.twinsoft.convertigo.beans.transactions.AbstractHttpTransaction) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) SqlTransaction(com.twinsoft.convertigo.beans.transactions.SqlTransaction) Transaction(com.twinsoft.convertigo.beans.core.Transaction) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) StringEx(com.twinsoft.util.StringEx)

Example 7 with HtmlTransaction

use of com.twinsoft.convertigo.beans.transactions.HtmlTransaction in project convertigo by convertigo.

the class BrowserPropertyChangeStatement method execute.

@Override
public boolean execute(Context javascriptContext, Scriptable scope) throws EngineException {
    if (isEnabled()) {
        if (super.execute(javascriptContext, scope)) {
            if (convertigoMode == ConvertigoMode.both || convertigoMode == ConvertigoMode.studio && Engine.isStudioMode() || convertigoMode == ConvertigoMode.engine && Engine.isEngineMode()) {
                HtmlTransaction htmlTransaction = (HtmlTransaction) getParentTransaction();
                HtmlConnector htmlConnector = (HtmlConnector) htmlTransaction.getParent();
                HtmlParser htmlParser = htmlConnector.getHtmlParser();
                if (javascriptMode == JavascriptMode.forceOn)
                    htmlParser.setAllowJavascript(htmlTransaction.context, true);
                else if (javascriptMode == JavascriptMode.forceOff)
                    htmlParser.setAllowJavascript(htmlTransaction.context, false);
                if (imageMode == ImageMode.forceOn)
                    htmlParser.setAllowImage(htmlTransaction.context, true);
                else if (imageMode == ImageMode.forceOff)
                    htmlParser.setAllowImage(htmlTransaction.context, false);
                if (pluginMode == PluginMode.forceOn)
                    htmlParser.setAllowPlugin(htmlTransaction.context, true);
                else if (pluginMode == PluginMode.forceOff)
                    htmlParser.setAllowPlugin(htmlTransaction.context, false);
                if (attachmentMode == AttachmentMode.forceOn)
                    htmlParser.setAllowAttachment(htmlTransaction.context, true);
                else if (attachmentMode == AttachmentMode.forceOff)
                    htmlParser.setAllowAttachment(htmlTransaction.context, false);
                if (windowOpenMode == WindowOpenMode.forceOnNewWindow)
                    htmlParser.setWindowOpenState(htmlTransaction.context, IWebViewer.windowOpenNewWindow);
                else if (windowOpenMode == WindowOpenMode.forceOnSameWindow)
                    htmlParser.setWindowOpenState(htmlTransaction.context, IWebViewer.windowOpenSameWindow);
                else if (windowOpenMode == WindowOpenMode.forceOff)
                    htmlParser.setWindowOpenState(htmlTransaction.context, IWebViewer.windowOpenCancel);
                if (bClearCookies) {
                    htmlConnector.resetHttpState(htmlTransaction.context);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : HtmlParser(com.twinsoft.convertigo.engine.parsers.HtmlParser) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction)

Example 8 with HtmlTransaction

use of com.twinsoft.convertigo.beans.transactions.HtmlTransaction in project convertigo by convertigo.

the class TransactionCreateHandlerAction method run.

@Override
public void run() {
    Display display = Display.getDefault();
    Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
    Shell shell = getParentShell();
    shell.setCursor(waitCursor);
    Statement lastStatement = null;
    try {
        ProjectExplorerView explorerView = getProjectExplorerView();
        if (explorerView != null) {
            TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
            if (treeObject != null) {
                Transaction transaction = null;
                if (treeObject instanceof TransactionTreeObject) {
                    transaction = (Transaction) treeObject.getObject();
                } else if (treeObject instanceof ObjectsFolderTreeObject) {
                    transaction = (Transaction) treeObject.getParent().getObject();
                }
                if (transaction != null) {
                    CreateHandlerDialog createHandlerDialog = new CreateHandlerDialog(shell, transaction);
                    createHandlerDialog.open();
                    if (createHandlerDialog.getReturnCode() != Window.CANCEL) {
                        List<?> result = createHandlerDialog.result;
                        if (result != null) {
                            int len = result.size();
                            if (len > 0) {
                                if (transaction instanceof HtmlTransaction) {
                                    HtmlTransaction htmlTransaction = (HtmlTransaction) transaction;
                                    Statement statement = null;
                                    for (int i = 0; i < len; i++) {
                                        statement = (Statement) result.get(i);
                                        htmlTransaction.addStatement(statement);
                                    }
                                    lastStatement = statement;
                                } else {
                                    String handler = null;
                                    for (int i = 0; i < len; i++) {
                                        handler = (String) result.get(i);
                                        transaction.handlers += handler;
                                        transaction.hasChanged = true;
                                    }
                                    // Update the opened handlers editor if any
                                    JScriptEditorInput jsinput = ConvertigoPlugin.getDefault().getJScriptEditorInput(transaction);
                                    if (jsinput != null) {
                                        jsinput.reload();
                                    }
                                }
                                // Reload transaction in tree and select last created Statement.
                                try {
                                    ProjectExplorerView projectExplorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
                                    projectExplorerView.reloadDatabaseObject(transaction);
                                    if (transaction instanceof HtmlTransaction) {
                                        if (lastStatement != null) {
                                            projectExplorerView.objectSelected(new CompositeEvent(lastStatement));
                                        }
                                    } else {
                                        projectExplorerView.objectSelected(new CompositeEvent(transaction));
                                    }
                                } catch (IOException e) {
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to create new handler for transaction!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : JScriptEditorInput(com.twinsoft.convertigo.eclipse.editors.jscript.JScriptEditorInput) TransactionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TransactionTreeObject) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) Statement(com.twinsoft.convertigo.beans.core.Statement) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) CreateHandlerDialog(com.twinsoft.convertigo.eclipse.dialogs.CreateHandlerDialog) IOException(java.io.IOException) Cursor(org.eclipse.swt.graphics.Cursor) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) Shell(org.eclipse.swt.widgets.Shell) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) Transaction(com.twinsoft.convertigo.beans.core.Transaction) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) TransactionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TransactionTreeObject) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) Display(org.eclipse.swt.widgets.Display)

Example 9 with HtmlTransaction

use of com.twinsoft.convertigo.beans.transactions.HtmlTransaction in project convertigo by convertigo.

the class HTTPStatement method execute.

@Override
public boolean execute(Context javascriptContext, Scriptable scope) throws EngineException {
    if (isEnabled()) {
        if (super.execute(javascriptContext, scope)) {
            this.javascriptContext = javascriptContext;
            this.scope = scope;
            HtmlTransaction htmlTransaction = getParentTransaction();
            HttpMethodType exVerb = htmlTransaction.getHttpVerb();
            String exCustomVerb = htmlTransaction.getCustomHttpVerb();
            long exTimeout = htmlTransaction.getResponseTimeout();
            try {
                htmlTransaction.setHttpVerb(getHttpVerb());
                htmlTransaction.setCustomHttpVerb(getCustomHttpVerb());
                try {
                    htmlTransaction.setResponseTimeout(getTrigger().getTrigger().getTimeout() / 1000);
                } finally {
                }
                htmlTransaction.applyUserRequest(this);
                return true;
            } finally {
                htmlTransaction.setHttpVerb(exVerb);
                htmlTransaction.setCustomHttpVerb(exCustomVerb);
                htmlTransaction.setResponseTimeout(exTimeout);
            }
        }
    }
    return false;
}
Also used : HttpMethodType(com.twinsoft.convertigo.engine.enums.HttpMethodType) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction)

Example 10 with HtmlTransaction

use of com.twinsoft.convertigo.beans.transactions.HtmlTransaction in project convertigo by convertigo.

the class TabManagementStatement method execute.

@Override
public boolean execute(Context javascriptContext, Scriptable scope) throws EngineException {
    if (isEnabled()) {
        if (super.execute(javascriptContext, scope)) {
            HtmlTransaction htmlTransaction = (HtmlTransaction) getParentTransaction();
            HtmlConnector htmlConnector = (HtmlConnector) htmlTransaction.getParent();
            TabManagementEvent evt;
            if (action.equalsIgnoreCase(TabManagementEvent.ACTION_SETINDEX)) {
                try {
                    evaluate(javascriptContext, scope, jsIndex, "jsIndex", false);
                    int index = (int) Double.parseDouble(evaluated.toString());
                    evt = new TabManagementEvent(action, index);
                } catch (Exception e) {
                    throw new EngineException("Tab index value isn't good.", e);
                }
            } else {
                evt = new TabManagementEvent(action);
            }
            HtmlParser htmlParser = htmlConnector.getHtmlParser();
            boolean success = htmlParser.dispatchEvent(evt, htmlTransaction.context, null);
            if (!success)
                Engine.logBeans.debug("NavigationBarStatement has failed");
            else {
                if (action.equalsIgnoreCase(TabManagementEvent.ACTION_GETINDEX)) {
                    String code = getIndexVarname + "=" + evt.getIndex();
                    evaluate(javascriptContext, scope, code, "ContextGet", true);
                } else if (action.equalsIgnoreCase(TabManagementEvent.ACTION_GETNBTAB)) {
                    String code = getIndexVarname + "=" + evt.getNbTab();
                    evaluate(javascriptContext, scope, code, "ContextGet", true);
                }
            }
            success = true;
            return success;
        }
    }
    return false;
}
Also used : HtmlParser(com.twinsoft.convertigo.engine.parsers.HtmlParser) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) TabManagementEvent(com.twinsoft.convertigo.engine.parsers.events.TabManagementEvent) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) EngineException(com.twinsoft.convertigo.engine.EngineException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Aggregations

HtmlTransaction (com.twinsoft.convertigo.beans.transactions.HtmlTransaction)28 HtmlConnector (com.twinsoft.convertigo.beans.connectors.HtmlConnector)14 EngineException (com.twinsoft.convertigo.engine.EngineException)13 Transaction (com.twinsoft.convertigo.beans.core.Transaction)11 Statement (com.twinsoft.convertigo.beans.core.Statement)10 Connector (com.twinsoft.convertigo.beans.core.Connector)8 JavelinConnector (com.twinsoft.convertigo.beans.connectors.JavelinConnector)6 SiteClipperConnector (com.twinsoft.convertigo.beans.connectors.SiteClipperConnector)6 SqlConnector (com.twinsoft.convertigo.beans.connectors.SqlConnector)6 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)6 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)6 Sequence (com.twinsoft.convertigo.beans.core.Sequence)6 Step (com.twinsoft.convertigo.beans.core.Step)6 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)6 CicsConnector (com.twinsoft.convertigo.beans.connectors.CicsConnector)5 HttpConnector (com.twinsoft.convertigo.beans.connectors.HttpConnector)5 JavelinScreenClass (com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass)5 HTTPStatement (com.twinsoft.convertigo.beans.statements.HTTPStatement)5 JavelinTransaction (com.twinsoft.convertigo.beans.transactions.JavelinTransaction)5 ScHandlerStatement (com.twinsoft.convertigo.beans.statements.ScHandlerStatement)4