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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations