Search in sources :

Example 21 with HtmlConnector

use of com.twinsoft.convertigo.beans.connectors.HtmlConnector in project convertigo by convertigo.

the class IfXpathExistsStatement method execute.

@Override
public boolean execute(Context javascriptContext, Scriptable scope) throws EngineException {
    if (isEnabled()) {
        if (super.execute(javascriptContext, scope)) {
            HtmlConnector htmlConnector = getConnector();
            Document xmlDocument = htmlConnector.getCurrentXmlDocument();
            TwsCachedXPathAPI xpathApi = htmlConnector.context.getXpathApi();
            if ((xmlDocument == null) || (xpathApi == null)) {
                Engine.logBeans.warn((xmlDocument == null) ? "(XPath) Current DOM of HtmlConnector is Null!" : "TwsCachedXPathAPI of HtmlConnector is Null!");
                return false;
            }
            evaluate(javascriptContext, scope, getCondition(), "xpath", false);
            String jsXpath = evaluated.toString();
            NodeList nodeList = null;
            try {
                nodeList = xpathApi.selectNodeList(xmlDocument, jsXpath);
            } catch (TransformerException e) {
                return false;
            } catch (ClassCastException e) {
                return false;
            }
            if (nodeList == null)
                return false;
            if (nodeList.getLength() == 0)
                return false;
            return executeNextStatement(javascriptContext, scope);
        }
    }
    return false;
}
Also used : HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) TransformerException(javax.xml.transform.TransformerException) TwsCachedXPathAPI(com.twinsoft.convertigo.engine.util.TwsCachedXPathAPI)

Example 22 with HtmlConnector

use of com.twinsoft.convertigo.beans.connectors.HtmlConnector in project convertigo by convertigo.

the class IfXpathExistsThenElseStatement method execute.

@Override
public boolean execute(Context javascriptContext, Scriptable scope) throws EngineException {
    if (isEnabled()) {
        if (super.execute(javascriptContext, scope)) {
            HtmlConnector htmlConnector = getConnector();
            Document xmlDocument = htmlConnector.getCurrentXmlDocument();
            TwsCachedXPathAPI xpathApi = htmlConnector.context.getXpathApi();
            if ((xmlDocument == null) || (xpathApi == null)) {
                Engine.logBeans.warn((xmlDocument == null) ? "(XPath) Current DOM of HtmlConnector is Null!" : "TwsCachedXPathAPI of HtmlConnector is Null!");
                return false;
            }
            evaluate(javascriptContext, scope, getCondition(), "xpath", false);
            String jsXpath = evaluated.toString();
            NodeList nodeList = null;
            try {
                nodeList = xpathApi.selectNodeList(xmlDocument, jsXpath);
            } catch (TransformerException e) {
                return false;
            } catch (ClassCastException e) {
                return false;
            }
            if (nodeList == null) {
                return false;
            }
            if (nodeList.getLength() == 0) {
                elseStatement = getElseStatement();
                if (elseStatement != null) {
                    elseStatement.execute(javascriptContext, scope);
                }
                return false;
            }
            thenStatement = getThenStatement();
            if (thenStatement != null) {
                thenStatement.execute(javascriptContext, scope);
                return true;
            }
            return false;
        }
    }
    return false;
}
Also used : HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) TransformerException(javax.xml.transform.TransformerException) TwsCachedXPathAPI(com.twinsoft.convertigo.engine.util.TwsCachedXPathAPI)

Example 23 with HtmlConnector

use of com.twinsoft.convertigo.beans.connectors.HtmlConnector in project convertigo by convertigo.

the class CredentialsStatement method execute.

@Override
public boolean execute(Context javascriptContext, Scriptable scope) throws EngineException {
    String _user = null;
    String _password = null;
    if (isEnabled()) {
        if (super.execute(javascriptContext, scope)) {
            if (user != null && user.length() != 0) {
                // evaluate user
                evaluate(javascriptContext, scope, user, "user", true);
                try {
                    _user = evaluated.toString();
                } catch (Exception e) {
                    EngineException ee = new EngineException("Invalid user.\n" + "CredentialsStatement: \"" + getName() + "\"", e);
                    throw ee;
                }
            }
            if (password != null && password.length() != 0) {
                // evaluate password
                evaluate(javascriptContext, scope, password, "password", true);
                try {
                    _password = evaluated.toString();
                } catch (Exception e) {
                    EngineException ee = new EngineException("Invalid password.\n" + "CredentialsStatement: \"" + getName() + "\"", e);
                    throw ee;
                }
            }
            // Set basic credentials on connector
            HtmlConnector htmlConnector = (HtmlConnector) getParentTransaction().getParent();
            htmlConnector.setGivenAuthUser(_user);
            Engine.logBeans.debug("(CredentialsStatement) User '" + _user + "' has been set on http connector.");
            htmlConnector.setGivenAuthPassword(_password);
            Engine.logBeans.debug("(CredentialsStatement) Password '******' has been set on http connector.");
            htmlConnector.getHtmlParser().setCredentials(htmlConnector.context, _user, _password, forceBasic);
            return true;
        }
    }
    return false;
}
Also used : HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) EngineException(com.twinsoft.convertigo.engine.EngineException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 24 with HtmlConnector

use of com.twinsoft.convertigo.beans.connectors.HtmlConnector 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 25 with HtmlConnector

use of com.twinsoft.convertigo.beans.connectors.HtmlConnector in project convertigo by convertigo.

the class Get method createCategories.

private void createCategories(Document document, DatabaseObject dbo, Class<? extends DatabaseObject> databaseObjectClass, Element root) throws Exception {
    Element response = document.createElement("response");
    try {
        List<String> defaultDboList = new ArrayList<>();
        Class<? extends DatabaseObject> parentObjectClass = dbo.getClass();
        Map<String, DboCategoryData> categoryNameToDboCategory = new HashMap<>();
        DboExplorerManager manager = Engine.theApp.getDboExplorerManager();
        for (DboGroup group : manager.getGroups()) {
            for (DboCategory category : group.getCategories()) {
                for (DboBeans beansCategory : category.getBeans()) {
                    for (DboBean bean : beansCategory.getBeans()) {
                        // Skip if bean is disabled
                        if (!bean.isEnable()) {
                            continue;
                        }
                        String className = bean.getClassName();
                        try {
                            Class<DatabaseObject> beanClass = GenericUtils.cast(Class.forName(className));
                            DboCategoryInfo dboCategoryInfo = DatabaseObject.getDboGroupInfo(beanClass);
                            if (dboCategoryInfo == null) {
                                continue;
                            }
                            // If one of these cases, do not add the category
                            if (dbo instanceof ScreenClass) {
                                ScreenClass sc = (ScreenClass) dbo;
                                // Do not show Criteria category if it is the default Screen Class
                                if (sc.getDepth() == 0 && dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Criteria.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof CicsConnector) {
                                // Do not show Pool category
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Pool.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof JavelinConnector) {
                                // Do not show ScreenClass category
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(ScreenClass.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof SqlConnector) {
                                // Do not show Pool category
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Pool.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof HtmlConnector) {
                                // Do not show Pool and ScreenClass categories
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Pool.class)) || dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(ScreenClass.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof HttpConnector) {
                                // Do not show Pool category
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Pool.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof SiteClipperConnector) {
                                // Do not show Pool and ScreenClass categories
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Pool.class)) || dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(ScreenClass.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof Transaction) {
                                // Do not show Statement category
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Statement.class))) {
                                    continue;
                                }
                            }
                            if (bean.isDefault()) {
                                defaultDboList.add(className);
                            }
                            // The bean should derived from
                            // DatabaseObject...
                            boolean isDatabaseObject = (DatabaseObject.class.isAssignableFrom(beanClass));
                            if (isDatabaseObject) {
                                // ... and should derived from the specified class
                                boolean isFromSpecifiedClass = (databaseObjectClass == null || (databaseObjectClass != null && databaseObjectClass.isAssignableFrom(beanClass)));
                                if (isFromSpecifiedClass) {
                                    // Check parent
                                    boolean bFound = DatabaseObjectsManager.checkParent(parentObjectClass, bean);
                                    if (bFound) {
                                        String technology = DboUtils.getTechnology(dbo, beanClass);
                                        // Check technology if needed
                                        if (technology != null) {
                                            Collection<String> acceptedTechnologies = bean.getEmulatorTechnologies();
                                            if (!acceptedTechnologies.isEmpty() && !acceptedTechnologies.contains(technology)) {
                                                continue;
                                            }
                                        }
                                        String beanInfoClassName = className + "BeanInfo";
                                        Class<BeanInfo> beanInfoClass = GenericUtils.cast(Class.forName(beanInfoClassName));
                                        if (beanInfoClass != null) {
                                            String categoryName = dboCategoryInfo.getCategoryName();
                                            // Create category
                                            DboCategoryData dboCategoryData = categoryNameToDboCategory.get(categoryName);
                                            if (dboCategoryData == null) {
                                                dboCategoryData = new DboCategoryData(dboCategoryInfo.getCategoryId(), categoryName, dboCategoryInfo.getIconClassCSS());
                                                categoryNameToDboCategory.put(categoryName, dboCategoryData);
                                            }
                                            // Beans name
                                            String beansName = beansCategory.getName();
                                            if (beansName.length() == 0) {
                                                beansName = categoryName;
                                            }
                                            // Create beans
                                            DboBeansData dboBeansData = dboCategoryData.getDboBeans(beansName);
                                            if (dboBeansData == null) {
                                                dboBeansData = new DboBeansData(beansName);
                                                dboCategoryData.addDboBeans(beansName, dboBeansData);
                                            }
                                            // Create bean
                                            DboBeanData dboBeanData = new DboBeanData(beanInfoClass.getConstructor().newInstance());
                                            dboBeansData.addDboBean(dboBeanData);
                                        } else {
                                            String message = java.text.MessageFormat.format("The \"{0}\" does not exist.", new Object[] { beanInfoClassName });
                                            throw new Exception(message);
                                        }
                                    }
                                }
                            } else {
                                String message = java.text.MessageFormat.format("The \"{0}\" class is not a Convertigo database object.", new Object[] { className });
                                throw new Exception(message);
                            }
                        } catch (ClassNotFoundException e) {
                            String message = java.text.MessageFormat.format("Unable to analyze the \"{0}\" class.\n\nClass not found: {1}", new Object[] { className, e.getMessage() });
                            throw new Exception(message);
                        } catch (Throwable e) {
                            String message = java.text.MessageFormat.format("Unable to analyze the \"{0}\" Convertigo database object.", new Object[] { className });
                            throw new Exception(message);
                        }
                    }
                }
            }
        }
        // Find the default selected bean for each categories
        for (DboCategoryData dboCategory : categoryNameToDboCategory.values()) {
            boolean defaultDboFound = false;
            List<DboBeanData> dboBeansList = dboCategory.getAllDboBean(true);
            // By default, we chose the first bean as default selected bean
            DboBeanData defaultSelectedBean = dboBeansList.get(0);
            // Find the default selected bean
            for (int i = 0; i < dboBeansList.size() && !defaultDboFound; ++i) {
                Class<DatabaseObject> beanClass = dboBeansList.get(i).getBeanClass();
                // Another bean is set as default selected bean
                if (defaultDboFound = defaultDboList.contains(beanClass.getName())) {
                    defaultSelectedBean = dboBeansList.get(i);
                }
            }
            defaultSelectedBean.setSelectedByDefault(true);
        }
        // XmlLize
        for (DboCategoryData dboCategory : categoryNameToDboCategory.values()) {
            response.appendChild(dboCategory.toXml(document));
        }
    } catch (Exception e) {
        throw new Exception("Unable to load database objects properties.");
    }
    root.appendChild(response);
}
Also used : HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) HashMap(java.util.HashMap) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) Element(org.w3c.dom.Element) BeanInfo(java.beans.BeanInfo) ArrayList(java.util.ArrayList) DboCategory(com.twinsoft.convertigo.engine.dbo_explorer.DboCategory) DboBeansData(com.twinsoft.convertigo.beans.dbo_explorer.DboBeansData) DboBeanData(com.twinsoft.convertigo.beans.dbo_explorer.DboBeanData) SqlConnector(com.twinsoft.convertigo.beans.connectors.SqlConnector) DboCategoryInfo(com.twinsoft.convertigo.beans.core.DatabaseObject.DboCategoryInfo) SiteClipperConnector(com.twinsoft.convertigo.beans.connectors.SiteClipperConnector) DboCategoryData(com.twinsoft.convertigo.beans.dbo_explorer.DboCategoryData) DboGroup(com.twinsoft.convertigo.engine.dbo_explorer.DboGroup) DboExplorerManager(com.twinsoft.convertigo.engine.dbo_explorer.DboExplorerManager) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DboBeans(com.twinsoft.convertigo.engine.dbo_explorer.DboBeans) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) Transaction(com.twinsoft.convertigo.beans.core.Transaction) CicsConnector(com.twinsoft.convertigo.beans.connectors.CicsConnector) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DboBean(com.twinsoft.convertigo.engine.dbo_explorer.DboBean)

Aggregations

HtmlConnector (com.twinsoft.convertigo.beans.connectors.HtmlConnector)42 HtmlTransaction (com.twinsoft.convertigo.beans.transactions.HtmlTransaction)14 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)13 EngineException (com.twinsoft.convertigo.engine.EngineException)13 JavelinConnector (com.twinsoft.convertigo.beans.connectors.JavelinConnector)12 Connector (com.twinsoft.convertigo.beans.core.Connector)12 Transaction (com.twinsoft.convertigo.beans.core.Transaction)10 HttpConnector (com.twinsoft.convertigo.beans.connectors.HttpConnector)8 SqlConnector (com.twinsoft.convertigo.beans.connectors.SqlConnector)8 SiteClipperConnector (com.twinsoft.convertigo.beans.connectors.SiteClipperConnector)7 Statement (com.twinsoft.convertigo.beans.core.Statement)7 Document (org.w3c.dom.Document)7 CicsConnector (com.twinsoft.convertigo.beans.connectors.CicsConnector)6 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)6 HandlerStatement (com.twinsoft.convertigo.beans.statements.HandlerStatement)6 List (java.util.List)6 HtmlScreenClass (com.twinsoft.convertigo.beans.screenclasses.HtmlScreenClass)5 ScHandlerStatement (com.twinsoft.convertigo.beans.statements.ScHandlerStatement)5 IOException (java.io.IOException)5 TransformerException (javax.xml.transform.TransformerException)5