Search in sources :

Example 1 with TriggerXMLizer

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() + "\" !");
            }
    }
}
Also used : TriggerXMLizer(com.twinsoft.convertigo.engine.parsers.triggers.TriggerXMLizer) ScreenClassTrigger(com.twinsoft.convertigo.engine.parsers.triggers.ScreenClassTrigger) CallFunctionStatement(com.twinsoft.convertigo.beans.statements.CallFunctionStatement) FunctionStatement(com.twinsoft.convertigo.beans.statements.FunctionStatement) ContinueWithSiteClipperStatement(com.twinsoft.convertigo.beans.statements.ContinueWithSiteClipperStatement) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement) SimpleStatement(com.twinsoft.convertigo.beans.statements.SimpleStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) IScreenClassContainer(com.twinsoft.convertigo.beans.core.IScreenClassContainer) ITriggerOwner(com.twinsoft.convertigo.engine.parsers.triggers.ITriggerOwner) PartInitException(org.eclipse.ui.PartInitException) EngineException(com.twinsoft.convertigo.engine.EngineException) AbstractTrigger(com.twinsoft.convertigo.engine.parsers.triggers.AbstractTrigger) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Example 2 with TriggerXMLizer

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() + "\" !");
        }
}
Also used : TriggerXMLizer(com.twinsoft.convertigo.engine.parsers.triggers.TriggerXMLizer) ScreenClassTrigger(com.twinsoft.convertigo.engine.parsers.triggers.ScreenClassTrigger) ContinueWithSiteClipperStatement(com.twinsoft.convertigo.beans.statements.ContinueWithSiteClipperStatement) CallFunctionStatement(com.twinsoft.convertigo.beans.statements.CallFunctionStatement) FunctionStatement(com.twinsoft.convertigo.beans.statements.FunctionStatement) ContinueWithSiteClipperStatement(com.twinsoft.convertigo.beans.statements.ContinueWithSiteClipperStatement) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement) SimpleStatement(com.twinsoft.convertigo.beans.statements.SimpleStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) EngineException(com.twinsoft.convertigo.engine.EngineException) ITriggerOwner(com.twinsoft.convertigo.engine.parsers.triggers.ITriggerOwner) PartInitException(org.eclipse.ui.PartInitException) EngineException(com.twinsoft.convertigo.engine.EngineException) CallFunctionStatement(com.twinsoft.convertigo.beans.statements.CallFunctionStatement) FunctionStatement(com.twinsoft.convertigo.beans.statements.FunctionStatement) SiteClipperConnector(com.twinsoft.convertigo.beans.connectors.SiteClipperConnector) CallFunctionStatement(com.twinsoft.convertigo.beans.statements.CallFunctionStatement) AbstractTrigger(com.twinsoft.convertigo.engine.parsers.triggers.AbstractTrigger) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement)

Example 3 with TriggerXMLizer

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);
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) Status(com.twinsoft.convertigo.engine.AttachmentManager.Status) TriggerXMLizer(com.twinsoft.convertigo.engine.parsers.triggers.TriggerXMLizer) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) EngineException(com.twinsoft.convertigo.engine.EngineException) IOException(java.io.IOException) Document(org.w3c.dom.Document) HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement) IDownloader(com.twinsoft.convertigo.engine.parsers.IDownloader) EngineException(com.twinsoft.convertigo.engine.EngineException) EvaluatorException(org.mozilla.javascript.EvaluatorException) JavaScriptException(org.mozilla.javascript.JavaScriptException) IOException(java.io.IOException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException)

Example 4 with TriggerXMLizer

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()));
}
Also used : TriggerXMLizer(com.twinsoft.convertigo.engine.parsers.triggers.TriggerXMLizer) ScreenClassTrigger(com.twinsoft.convertigo.engine.parsers.triggers.ScreenClassTrigger) XMLVector(com.twinsoft.convertigo.beans.common.XMLVector)

Aggregations

TriggerXMLizer (com.twinsoft.convertigo.engine.parsers.triggers.TriggerXMLizer)4 EngineException (com.twinsoft.convertigo.engine.EngineException)3 ScreenClassTrigger (com.twinsoft.convertigo.engine.parsers.triggers.ScreenClassTrigger)3 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)2 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)2 Statement (com.twinsoft.convertigo.beans.core.Statement)2 CallFunctionStatement (com.twinsoft.convertigo.beans.statements.CallFunctionStatement)2 ContinueWithSiteClipperStatement (com.twinsoft.convertigo.beans.statements.ContinueWithSiteClipperStatement)2 FunctionStatement (com.twinsoft.convertigo.beans.statements.FunctionStatement)2 HandlerStatement (com.twinsoft.convertigo.beans.statements.HandlerStatement)2 ScHandlerStatement (com.twinsoft.convertigo.beans.statements.ScHandlerStatement)2 SimpleStatement (com.twinsoft.convertigo.beans.statements.SimpleStatement)2 AbstractTrigger (com.twinsoft.convertigo.engine.parsers.triggers.AbstractTrigger)2 ITriggerOwner (com.twinsoft.convertigo.engine.parsers.triggers.ITriggerOwner)2 PartInitException (org.eclipse.ui.PartInitException)2 XMLVector (com.twinsoft.convertigo.beans.common.XMLVector)1 HtmlConnector (com.twinsoft.convertigo.beans.connectors.HtmlConnector)1 SiteClipperConnector (com.twinsoft.convertigo.beans.connectors.SiteClipperConnector)1 IScreenClassContainer (com.twinsoft.convertigo.beans.core.IScreenClassContainer)1 HTTPStatement (com.twinsoft.convertigo.beans.statements.HTTPStatement)1