use of com.twinsoft.convertigo.beans.screenclasses.SiteClipperScreenClass in project convertigo by convertigo.
the class SiteClipperConnector method clone.
@Override
public SiteClipperConnector clone() throws CloneNotSupportedException {
SiteClipperConnector siteClipperConnector = (SiteClipperConnector) super.clone();
siteClipperConnector.screenClassHelper = new ScreenClassHelper<SiteClipperScreenClass>(siteClipperConnector);
siteClipperConnector.domainsFilter = new DomainsFilterHelper(siteClipperConnector);
siteClipperConnector.givenAuthPassword = null;
siteClipperConnector.givenAuthUser = null;
siteClipperConnector.givenAuthMode = null;
siteClipperConnector.certificateManager = new CertificateManager();
siteClipperConnector.siteClipperRequestObjectsPerThread = Collections.synchronizedMap(new HashMap<Thread, Shuttle>());
return siteClipperConnector;
}
use of com.twinsoft.convertigo.beans.screenclasses.SiteClipperScreenClass in project convertigo by convertigo.
the class SiteClipperConnector method doProcessRequest.
private void doProcessRequest(Shuttle shuttle) throws IOException, ServletException, EngineException {
shuttle.statisticsTaskID = context.statistics.start(EngineStatistics.GET_DOCUMENT);
try {
shuttle.sharedScope = context.getSharedScope();
String domain = shuttle.getRequest(QueryPart.host) + shuttle.getRequest(QueryPart.port);
Engine.logSiteClipper.trace("(SiteClipperConnector) Prepare the request for the domain " + domain);
if (!shouldRewrite(domain)) {
Engine.logSiteClipper.info("(SiteClipperConnector) The domain " + domain + " is not allowed with this connector");
shuttle.response.sendError(HttpServletResponse.SC_FORBIDDEN, "The domain " + domain + " is not allowed with this connector");
return;
}
String uri = shuttle.getRequest(QueryPart.uri);
Engine.logSiteClipper.info("Preparing " + shuttle.request.getMethod() + " " + shuttle.getRequestUrl());
HttpMethod httpMethod = null;
XulRecorder xulRecorder = context.getXulRecorder();
if (xulRecorder != null) {
httpMethod = shuttle.httpMethod = xulRecorder.getRecord(shuttle.getRequestUrlAndQuery());
}
if (httpMethod == null) {
try {
switch(shuttle.getRequestHttpMethodType()) {
case GET:
httpMethod = new GetMethod(uri);
break;
case POST:
httpMethod = new PostMethod(uri);
((PostMethod) httpMethod).setRequestEntity(new InputStreamRequestEntity(shuttle.request.getInputStream()));
break;
case PUT:
httpMethod = new PutMethod(uri);
((PutMethod) httpMethod).setRequestEntity(new InputStreamRequestEntity(shuttle.request.getInputStream()));
break;
case DELETE:
httpMethod = new DeleteMethod(uri);
break;
case HEAD:
httpMethod = new HeadMethod(uri);
break;
case OPTIONS:
httpMethod = new OptionsMethod(uri);
break;
case TRACE:
httpMethod = new TraceMethod(uri);
break;
default:
throw new ServletException("(SiteClipperConnector) unknown http method " + shuttle.request.getMethod());
}
httpMethod.setFollowRedirects(false);
} catch (Exception e) {
throw new ServletException("(SiteClipperConnector) unexpected exception will building the http method : " + e.getMessage());
}
shuttle.httpMethod = httpMethod;
SiteClipperScreenClass screenClass = getCurrentScreenClass();
Engine.logSiteClipper.info("Request screen class: " + screenClass.getName());
for (String name : Collections.list(GenericUtils.<Enumeration<String>>cast(shuttle.request.getHeaderNames()))) {
if (requestHeadersToIgnore.contains(HeaderName.parse(name))) {
Engine.logSiteClipper.trace("(SiteClipperConnector) Ignoring request header " + name);
} else {
String value = shuttle.request.getHeader(name);
Engine.logSiteClipper.trace("(SiteClipperConnector) Copying request header " + name + "=" + value);
shuttle.setRequestCustomHeader(name, value);
}
}
Engine.logSiteClipper.debug("(SiteClipperConnector) applying request rules for the screenclass " + screenClass.getName());
for (IRequestRule rule : screenClass.getRequestRules()) {
if (rule.isEnabled()) {
Engine.logSiteClipper.trace("(SiteClipperConnector) applying request rule " + rule.getName());
rule.fireEvents();
boolean done = rule.applyOnRequest(shuttle);
Engine.logSiteClipper.debug("(SiteClipperConnector) the request rule " + rule.getName() + " is " + (done ? "well" : "not") + " applied");
} else {
Engine.logSiteClipper.trace("(SiteClipperConnector) skip the disabled request rule " + rule.getName());
}
}
for (Entry<String, String> header : shuttle.requestCustomHeaders.entrySet()) {
Engine.logSiteClipper.trace("(SiteClipperConnector) Push request header " + header.getKey() + "=" + header.getValue());
httpMethod.addRequestHeader(header.getKey(), header.getValue());
}
String queryString = shuttle.request.getQueryString();
if (queryString != null) {
try {
// Fake test in order to check query string validity
new URI("http://localhost/index?" + queryString, true, httpMethod.getParams().getUriCharset());
} catch (URIException e) {
// Bugfix #2103
StringBuffer newQuery = new StringBuffer();
for (String part : RegexpUtils.pattern_and.split(queryString)) {
String[] pair = RegexpUtils.pattern_equals.split(part, 2);
try {
newQuery.append('&').append(URLEncoder.encode(URLDecoder.decode(pair[0], "UTF-8"), "UTF-8"));
if (pair.length > 1) {
newQuery.append('=').append(URLEncoder.encode(URLDecoder.decode(pair[1], "UTF-8"), "UTF-8"));
}
} catch (UnsupportedEncodingException ee) {
Engine.logSiteClipper.trace("(SiteClipperConnector) failed to encode query part : " + part);
}
}
queryString = newQuery.length() > 0 ? newQuery.substring(1) : newQuery.toString();
Engine.logSiteClipper.trace("(SiteClipperConnector) re-encode query : " + queryString);
}
}
Engine.logSiteClipper.debug("(SiteClipperConnector) Copying the query string : " + queryString);
httpMethod.setQueryString(queryString);
// if (context.httpState == null) {
// Engine.logSiteClipper.debug("(SiteClipperConnector) Creating new HttpState for context id " + context.contextID);
// context.httpState = new HttpState();
// } else {
// Engine.logSiteClipper.debug("(SiteClipperConnector) Using HttpState of context id " + context.contextID);
// }
getHttpState(shuttle);
HostConfiguration hostConfiguration = getHostConfiguration(shuttle);
HttpMethodParams httpMethodParams = httpMethod.getParams();
httpMethodParams.setBooleanParameter("http.connection.stalecheck", true);
httpMethodParams.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, true));
Engine.logSiteClipper.info("Requesting " + httpMethod.getName() + " " + hostConfiguration.getHostURL() + httpMethod.getURI().toString());
HttpClient httpClient = context.getHttpClient3(shuttle.getHttpPool());
HttpUtils.logCurrentHttpConnection(httpClient, hostConfiguration, shuttle.getHttpPool());
httpClient.executeMethod(hostConfiguration, httpMethod, context.httpState);
} else {
Engine.logSiteClipper.info("Retrieve recorded response from Context");
}
int status = httpMethod.getStatusCode();
shuttle.processState = ProcessState.response;
Engine.logSiteClipper.info("Request terminated with status " + status);
shuttle.response.setStatus(status);
if (Engine.isStudioMode() && status == HttpServletResponse.SC_OK && shuttle.getResponseMimeType().startsWith("text/")) {
fireDataChanged(new ConnectorEvent(this, shuttle.getResponseAsString()));
}
SiteClipperScreenClass screenClass = getCurrentScreenClass();
Engine.logSiteClipper.info("Response screen class: " + screenClass.getName());
if (Engine.isStudioMode()) {
Engine.theApp.fireObjectDetected(new EngineEvent(screenClass));
}
for (Header header : httpMethod.getResponseHeaders()) {
String name = header.getName();
if (responseHeadersToIgnore.contains(HeaderName.parse(name))) {
Engine.logSiteClipper.trace("(SiteClipperConnector) Ignoring response header " + name);
} else {
String value = header.getValue();
Engine.logSiteClipper.trace("(SiteClipperConnector) Copying response header " + name + "=" + value);
shuttle.responseCustomHeaders.put(name, value);
}
}
String contentLength = HeaderName.ContentLength.getResponseHeader(httpMethod);
Engine.logSiteClipper.debug("(SiteClipperConnector) applying response rules for the screenclass " + screenClass.getName());
for (IResponseRule rule : screenClass.getResponseRules()) {
if (rule.isEnabled()) {
Engine.logSiteClipper.trace("(SiteClipperConnector) applying response rule " + rule.getName());
rule.fireEvents();
boolean done = rule.applyOnResponse(shuttle);
Engine.logSiteClipper.debug("(SiteClipperConnector) the response rule " + rule.getName() + " is " + (done ? "well" : "not") + " applied");
} else {
Engine.logSiteClipper.trace("(SiteClipperConnector) skip the disabled response rule " + rule.getName());
}
}
for (Entry<String, String> header : shuttle.responseCustomHeaders.entrySet()) {
Engine.logSiteClipper.trace("(SiteClipperConnector) Push request header " + header.getKey() + "=" + header.getValue());
shuttle.response.addHeader(header.getKey(), header.getValue());
}
if (shuttle.postInstructions != null) {
JSONArray instructions = new JSONArray();
for (IClientInstruction instruction : shuttle.postInstructions) {
try {
instructions.put(instruction.getInstruction());
} catch (JSONException e) {
Engine.logSiteClipper.error("(SiteClipperConnector) Failed to add a post instruction due to a JSONException", e);
}
}
String codeToInject = "<script>C8O_postInstructions = " + instructions.toString() + "</script>\n" + "<script src=\"" + shuttle.getRequest(QueryPart.full_convertigo_path) + "/scripts/jquery.min.js\"></script>\n" + "<script src=\"" + shuttle.getRequest(QueryPart.full_convertigo_path) + "/scripts/siteclipper.js\"></script>\n";
String content = shuttle.getResponseAsString();
Matcher matcher = HtmlLocation.head_top.matcher(content);
String newContent = RegexpUtils.inject(matcher, codeToInject);
if (newContent == null) {
matcher = HtmlLocation.body_top.matcher(content);
newContent = RegexpUtils.inject(matcher, codeToInject);
}
if (newContent != null) {
shuttle.setResponseAsString(newContent);
} else {
Engine.logSiteClipper.info("(SiteClipperConnector) Failed to find a head or body tag in the response content");
Engine.logSiteClipper.trace("(SiteClipperConnector) Response content : \"" + content + "\"");
}
}
long nbBytes = 0L;
String responseContentLength = HeaderName.ContentLength.getHeader(shuttle.response);
if (shuttle.responseAsString != null && shuttle.responseAsString.hashCode() != shuttle.responseAsStringOriginal.hashCode()) {
OutputStream os = shuttle.response.getOutputStream();
shuttle.responseAsByte = shuttle.responseAsString.getBytes(shuttle.getResponseCharset());
nbBytes = shuttle.responseAsByte.length;
switch(shuttle.getResponseContentEncoding()) {
case gzip:
os = new GZIPOutputStream(os);
break;
case deflate:
os = new DeflaterOutputStream(os, new Deflater(Deflater.DEFAULT_COMPRESSION | Deflater.DEFAULT_STRATEGY, true));
break;
default:
if (responseContentLength == null) {
HeaderName.ContentLength.setHeader(shuttle.response, "" + nbBytes);
}
break;
}
IOUtils.write(shuttle.responseAsByte, os);
os.close();
} else {
InputStream is;
if (shuttle.responseAsByte == null) {
if (responseContentLength == null && contentLength != null) {
HeaderName.ContentLength.setHeader(shuttle.response, contentLength);
}
is = httpMethod.getResponseBodyAsStream();
} else {
if (responseContentLength == null) {
HeaderName.ContentLength.setHeader(shuttle.response, "" + shuttle.responseAsByte.length);
}
is = new ByteArrayInputStream(shuttle.responseAsByte);
}
if (is != null) {
nbBytes = StreamUtils.copyAutoFlush(is, shuttle.response.getOutputStream());
Engine.logSiteClipper.trace("(SiteClipperConnector) Response body copyied (" + nbBytes + " bytes)");
}
}
shuttle.response.getOutputStream().close();
shuttle.score = getScore(nbBytes);
Engine.logSiteClipper.debug("(SiteClipperConnector) Request terminated with a score of " + shuttle.score);
} finally {
long duration = context.statistics.stop(shuttle.statisticsTaskID);
if (context.requestedObject != null) {
try {
Engine.theApp.billingManager.insertBilling(context, Long.valueOf(duration), Long.valueOf(shuttle.score));
} catch (Exception e) {
Engine.logContext.warn("Unable to insert billing ticket (the billing is thus ignored): [" + e.getClass().getName() + "] " + e.getMessage());
}
}
}
}
use of com.twinsoft.convertigo.beans.screenclasses.SiteClipperScreenClass in project convertigo by convertigo.
the class ProjectUtils method getStatByProject.
public static Map<String, String> getStatByProject(Project project) throws Exception {
final Map<String, String> result = new HashMap<String, String>();
try {
if (project != null) {
try {
new WalkHelper() {
String displayString = "";
@SuppressWarnings("unused")
int depth = 0;
int sequenceJavascriptLines;
int sequenceJavascriptFunction;
int connectorCount = 0;
int httpConnectorCount = 0;
int httpsConnectorCount = 0;
int htmlConnectorCount = 0;
int cicsConnectorCount = 0;
int siteClipperConnectorCount = 0;
int sqlConnectorCount = 0;
int javelinConnectorCount = 0;
int htmlScreenclassCount = 0;
int htmlCriteriaCount = 0;
int siteClipperScreenclassCount = 0;
int siteClipperCriteriaCount = 0;
int htmlExtractionRuleCount = 0;
int htmlTransactionVariableCount = 0;
int sqlTransactionVariableCount = 0;
int javelinTransactionVariableCount = 0;
int javelinScreenclassCount = 0;
int javelinCriteriaCount = 0;
int javelinExtractionRuleCount = 0;
int javelinEntryHandlerCount = 0;
int javelinExitHandlerCount = 0;
int javelinHandlerCount = 0;
int javelinJavascriptLines = 0;
int statementCount = 0;
int poolCount = 0;
int handlerstatementCount = 0;
@SuppressWarnings("unused")
int reqVariableCount = 0;
int sequenceVariableCount = 0;
@SuppressWarnings("unused")
int transactionVariableCount = 0;
int testcaseVariableCount = 0;
int testcaseCount = 0;
int sequenceCount = 0;
int stepCount = 0;
int sheetCount = 0;
int referenceCount = 0;
int selectInQueryCount = 0;
/*
* transaction counters
*/
@SuppressWarnings("unused")
int transactionCount = 0;
@SuppressWarnings("unused")
int transactionWithVariablesCount = 0;
int htmltransactionCount = 0;
int httpTransactionCount = 0;
int httpsTransactionCount = 0;
int xmlHttpTransactionCount = 0;
int xmlHttpsTransactionCount = 0;
int jsonHttpTransactionCount = 0;
int jsonHttpsTransactionCount = 0;
int proxyTransactionCount = 0;
int siteClipperTransactionCount = 0;
int javelinTransactionCount = 0;
int sqlTransactionCount = 0;
int totalC8oObjects = 0;
public void go(DatabaseObject project) {
try {
String projectName = project.getName();
init(project);
connectorCount = htmlConnectorCount + httpConnectorCount + httpsConnectorCount + cicsConnectorCount + siteClipperConnectorCount + sqlConnectorCount + javelinConnectorCount;
totalC8oObjects = 1 + // connectors
connectorCount + htmlScreenclassCount + htmlCriteriaCount + htmlExtractionRuleCount + htmlTransactionVariableCount + handlerstatementCount + statementCount + javelinScreenclassCount + javelinCriteriaCount + javelinExtractionRuleCount + javelinTransactionCount + javelinEntryHandlerCount + javelinExitHandlerCount + javelinHandlerCount + javelinTransactionVariableCount + sqlTransactionCount + sqlTransactionVariableCount + sheetCount + jsonHttpTransactionCount + jsonHttpsTransactionCount + xmlHttpTransactionCount + xmlHttpsTransactionCount + httpTransactionCount + httpsTransactionCount + proxyTransactionCount + siteClipperTransactionCount + siteClipperScreenclassCount + siteClipperCriteriaCount + sequenceCount + stepCount + sequenceVariableCount + sequenceJavascriptFunction + poolCount + referenceCount + testcaseCount + testcaseVariableCount;
displayString = // ok
totalC8oObjects + " object(s)<br/>" + connectorCount + // ok
" connector(s)";
result.put(projectName, displayString);
if (htmltransactionCount > 0) {
displayString = // ok
(htmlScreenclassCount > 0 ? " screenclassCount = " + htmlScreenclassCount + "<br/>" : "") + (htmlCriteriaCount > 0 ? " criteriaCount = " + htmlCriteriaCount + "<br/>" : "") + (htmlExtractionRuleCount > 0 ? " extractionRuleCount = " + htmlExtractionRuleCount + "<br/>" : "") + " transactionCount = " + htmltransactionCount + // ok
"<br/>" + (htmlTransactionVariableCount > 0 ? " transactionVariableCount = " + htmlTransactionVariableCount + "<br/>" : "") + " statementCount (handlers=" + handlerstatementCount + ", statements=" + statementCount + ", total=" + (int) (handlerstatementCount + statementCount) + ")";
result.put("HTML connector", displayString);
}
/*
* javelin connector
*/
if (javelinScreenclassCount > 0) {
displayString = // ok
" screenclassCount = " + javelinScreenclassCount + "<br/>" + (javelinCriteriaCount > 0 ? " criteriaCount = " + javelinCriteriaCount + "<br/>" : "") + (javelinExtractionRuleCount > 0 ? " extractionRuleCount = " + javelinExtractionRuleCount + "<br/>" : "") + // ok
(javelinTransactionCount > 0 ? " transactionCount = " + javelinTransactionCount + "<br/>" : "") + " handlerCount (Entry = " + javelinEntryHandlerCount + ", Exit = " + javelinExitHandlerCount + ", Screenclass = " + javelinHandlerCount + "), total = " + (int) (javelinEntryHandlerCount + javelinExitHandlerCount + javelinHandlerCount) + " in " + javelinJavascriptLines + " lines<br/>" + (javelinTransactionVariableCount > 0 ? " variableCount = " + javelinTransactionVariableCount : "");
result.put("Javelin connector", displayString);
}
/*
* SQL connector
*/
if (sqlTransactionCount > 0) {
displayString = // ok
" sqltransactionCount = " + sqlTransactionCount + "<br/>" + // ok
(selectInQueryCount > 0 ? " selectInQueryCount = " + selectInQueryCount + "<br/>" : "") + (sqlTransactionVariableCount > 0 ? " transactionVariableCount = " + sqlTransactionVariableCount : "");
if (sheetCount > 0) {
displayString += "<br/>Sheets<br/>" + " sheetCount = " + sheetCount;
}
result.put("SQL connector", displayString);
}
/*
* Http connector
*/
if (httpConnectorCount > 0) {
displayString = " connectorCount = " + httpConnectorCount + "<br/>";
}
if (jsonHttpTransactionCount > 0) {
displayString += // ok
" JSONTransactionCount = " + jsonHttpTransactionCount + "<br/>" + // ok
(xmlHttpTransactionCount > 0 ? " XmlTransactionCount = " + xmlHttpTransactionCount + "<br/>" : "") + (httpTransactionCount > 0 ? " HTTPtransactionCount = " + httpTransactionCount : "");
result.put("HTTP connector", displayString);
}
/*
* Https connector
*/
if (httpsConnectorCount > 0) {
displayString = " connectorCount = " + httpsConnectorCount + "<br/>" + // ok
(jsonHttpsTransactionCount > 0 ? " JSONTransactionCount = " + jsonHttpsTransactionCount + "<br/>" : "") + // ok
(xmlHttpsTransactionCount > 0 ? " XmlTransactionCount = " + xmlHttpsTransactionCount + "<br/>" : "") + // ok
(httpsTransactionCount > 0 ? " HTTPStransactionCount = " + httpsTransactionCount : "");
result.put("HTTPS connector", displayString);
}
/*
* Proxy connector
*/
if (proxyTransactionCount > 0) {
displayString = " TransactionCount = " + proxyTransactionCount;
result.put("Proxy connector", displayString);
}
/*
* Siteclipper connector
*/
if (siteClipperTransactionCount > 0) {
displayString = // ok
" TransactionCount = " + siteClipperTransactionCount + "<br/>" + // ok
(siteClipperScreenclassCount > 0 ? " screenclassCount = " + siteClipperScreenclassCount + "<br/>" : "") + (siteClipperCriteriaCount > 0 ? " criteriaCount = " + siteClipperCriteriaCount : "");
result.put("SiteClipper connector", displayString);
}
/*
* Sequencer
*/
if (sequenceCount > 0) {
displayString = // ok
" sequenceCount = " + sequenceCount + "<br/>" + // ok
(stepCount > 0 ? " stepCount = " + stepCount + "<br/>" : "") + (sequenceVariableCount > 0 ? " variableCount = " + sequenceVariableCount + "<br/>" : "") + " javascriptCode = " + sequenceJavascriptFunction + " functions in " + sequenceJavascriptLines + " lines" + ((boolean) (sequenceJavascriptFunction == 0) ? " (declarations or so)" : "");
result.put("Sequencer", displayString);
}
if (poolCount > 0) {
displayString = " poolCount = " + poolCount;
result.put("Pools", displayString);
}
if (referenceCount > 0) {
displayString = " referenceCount = " + referenceCount;
result.put("References", displayString);
}
if (testcaseCount > 0) {
displayString = " testcaseCount = " + testcaseCount + "<br/>" + (testcaseVariableCount > 0 ? " testcaseVariableCount = " + testcaseVariableCount : "");
result.put("Test cases", displayString);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void walk(DatabaseObject databaseObject) throws Exception {
depth++;
// deal with connectors
if (databaseObject instanceof Connector) {
if (databaseObject instanceof HtmlConnector) {
htmlConnectorCount++;
} else if (databaseObject instanceof HttpConnector) {
if (((HttpConnector) databaseObject).isHttps())
httpsConnectorCount++;
else
httpConnectorCount++;
} else if (databaseObject instanceof CicsConnector) {
cicsConnectorCount++;
} else if (databaseObject instanceof SiteClipperConnector) {
siteClipperConnectorCount++;
} else if (databaseObject instanceof SqlConnector) {
sqlConnectorCount++;
} else if (databaseObject instanceof JavelinConnector) {
javelinConnectorCount++;
}
} else // deal with screenclasses
if (databaseObject instanceof ScreenClass) {
if (databaseObject instanceof JavelinScreenClass) {
// deal with javelinScreenClasses
javelinScreenclassCount++;
} else if (databaseObject instanceof SiteClipperScreenClass) {
// deal with siteClipperScreenClasses
siteClipperScreenclassCount++;
} else {
// deal with html ScreenClasses
htmlScreenclassCount++;
}
} else if (databaseObject instanceof Criteria) {
if (databaseObject.getParent() instanceof JavelinScreenClass) {
javelinCriteriaCount++;
} else if (databaseObject.getParent() instanceof SiteClipperScreenClass) {
siteClipperCriteriaCount++;
} else {
htmlCriteriaCount++;
}
} else if (databaseObject instanceof ExtractionRule) {
if (databaseObject.getParent() instanceof JavelinScreenClass) {
javelinExtractionRuleCount++;
} else {
htmlExtractionRuleCount++;
}
} else if (databaseObject instanceof Transaction) {
if (databaseObject instanceof TransactionWithVariables) {
if (databaseObject instanceof HtmlTransaction) {
htmltransactionCount++;
} else if (databaseObject instanceof JsonHttpTransaction) {
if (((HttpConnector) databaseObject.getParent()).isHttps())
jsonHttpsTransactionCount++;
else
jsonHttpTransactionCount++;
} else if (databaseObject instanceof HttpTransaction) {
if (((HttpConnector) databaseObject.getParent()).isHttps())
httpsTransactionCount++;
else
httpTransactionCount++;
} else if (databaseObject instanceof XmlHttpTransaction) {
if (((HttpConnector) databaseObject.getParent()).isHttps())
xmlHttpsTransactionCount++;
else
xmlHttpTransactionCount++;
} else if (databaseObject instanceof ProxyTransaction) {
proxyTransactionCount++;
} else if (databaseObject instanceof SiteClipperTransaction) {
siteClipperTransactionCount++;
} else if (databaseObject instanceof JavelinTransaction) {
JavelinTransaction javelinTransaction = (JavelinTransaction) databaseObject;
// Functions
String line;
int lineNumber = 0;
BufferedReader br = new BufferedReader(new StringReader(javelinTransaction.handlers));
while ((line = br.readLine()) != null) {
line = line.trim();
lineNumber++;
if (line.startsWith("function ")) {
try {
String functionName = line.substring(9, line.indexOf(')') + 1);
if (functionName.endsWith(JavelinTransaction.EVENT_ENTRY_HANDLER + "()")) {
// TYPE_FUNCTION_SCREEN_CLASS_ENTRY
javelinEntryHandlerCount++;
} else if (functionName.endsWith(JavelinTransaction.EVENT_EXIT_HANDLER + "()")) {
// TYPE_FUNCTION_SCREEN_CLASS_EXIT
javelinExitHandlerCount++;
} else {
// TYPE_OTHER
javelinHandlerCount++;
}
} catch (StringIndexOutOfBoundsException e) {
// Ignore
}
}
}
// compute total number of lines of javascript
javelinJavascriptLines += lineNumber;
javelinTransactionCount++;
} else if (databaseObject instanceof SqlTransaction) {
SqlTransaction sqlTransaction = (SqlTransaction) databaseObject;
/*
* count the number of SELECT
*/
String query = sqlTransaction.getSqlQuery();
if (query != null) {
query = query.toLowerCase();
String pattern = "select";
int lastIndex = 0;
while (lastIndex != -1) {
lastIndex = query.indexOf(pattern, lastIndex);
if (lastIndex != -1) {
selectInQueryCount++;
lastIndex += pattern.length();
}
}
}
sqlTransactionCount++;
}
transactionWithVariablesCount++;
} else {
// transaction with no variables
transactionCount++;
}
} else // deal with statements
if (databaseObject instanceof Statement) {
// System.out.println(databaseObject.getClass().getName() + "\r\n");
if (databaseObject instanceof HandlerStatement) {
handlerstatementCount++;
} else {
statementCount++;
}
} else // deal with variables
if (databaseObject instanceof Variable) {
if (databaseObject.getParent() instanceof Transaction) {
if (databaseObject.getParent() instanceof JavelinTransaction) {
javelinTransactionVariableCount++;
} else if (databaseObject.getParent() instanceof HtmlTransaction) {
htmlTransactionVariableCount++;
} else if (databaseObject.getParent() instanceof SqlTransaction) {
sqlTransactionVariableCount++;
} else {
// should be zero
transactionVariableCount++;
}
} else if (databaseObject.getParent() instanceof Sequence) {
sequenceVariableCount++;
} else if (databaseObject.getParent() instanceof TestCase) {
testcaseVariableCount++;
}
} else if (databaseObject instanceof TestCase) {
testcaseCount++;
} else if (databaseObject instanceof Sequence) {
sequenceCount++;
} else if (databaseObject instanceof Step) {
if (databaseObject instanceof SimpleStep) {
SimpleStep simpleStep = (SimpleStep) databaseObject;
// Functions
String line;
int lineNumber = 0;
BufferedReader br = new BufferedReader(new StringReader(simpleStep.getExpression()));
while ((line = br.readLine()) != null) {
line = line.trim();
lineNumber++;
if (line.startsWith("function ")) {
try {
sequenceJavascriptFunction++;
} catch (StringIndexOutOfBoundsException e) {
// Ignore
}
}
}
sequenceJavascriptLines += lineNumber;
stepCount++;
} else
stepCount++;
} else if (databaseObject instanceof Sheet) {
sheetCount++;
} else if (databaseObject instanceof Pool) {
poolCount++;
}
super.walk(databaseObject);
}
}.go(project);
} catch (Exception e) {
// Just ignore, should never happen
}
}
} catch (Throwable e) {
throw new Exception("Unable to compute statistics of the project!: \n" + e.getMessage());
} finally {
}
return result;
}
use of com.twinsoft.convertigo.beans.screenclasses.SiteClipperScreenClass in project convertigo by convertigo.
the class Connector method setupConnector.
public static void setupConnector(DatabaseObject connector) throws EngineException {
if (connector instanceof JavelinConnector) {
JavelinConnector javelinConnector = (JavelinConnector) connector;
JavelinScreenClass defaultScreenClass = new JavelinScreenClass();
defaultScreenClass.setName("Default_screen_class");
defaultScreenClass.hasChanged = true;
defaultScreenClass.bNew = true;
javelinConnector.setDefaultScreenClass(defaultScreenClass);
DefaultBlockFactory blockFactory = new DefaultBlockFactory();
blockFactory.setName("Block_factory");
blockFactory.hasChanged = true;
blockFactory.bNew = true;
defaultScreenClass.setBlockFactory(blockFactory);
EmulatorTechnology emulatorTechnology = new EmulatorTechnology();
emulatorTechnology.hasChanged = true;
emulatorTechnology.bNew = true;
emulatorTechnology.setName("Emulator_technology");
defaultScreenClass.add(emulatorTechnology);
JavelinTransaction transaction = new JavelinTransaction();
transaction.hasChanged = true;
transaction.bNew = true;
transaction.setName("XMLize");
javelinConnector.add(transaction);
javelinConnector.setDefaultTransaction(transaction);
} else if (connector instanceof HtmlConnector) {
HtmlConnector htmlConnector = (HtmlConnector) connector;
htmlConnector.setServer("www.convertigo.com");
HtmlScreenClass defaultScreenClass = new HtmlScreenClass();
defaultScreenClass.setName("Default_screen_class");
defaultScreenClass.hasChanged = true;
defaultScreenClass.bNew = true;
htmlConnector.setDefaultScreenClass(defaultScreenClass);
HtmlTransaction transaction = new HtmlTransaction();
transaction.hasChanged = true;
transaction.bNew = true;
transaction.setName("XMLize");
htmlConnector.add(transaction);
htmlConnector.setDefaultTransaction(transaction);
} else if (connector instanceof HttpConnector) {
HttpConnector httpConnector = (HttpConnector) connector;
HttpTransaction transaction = new HttpTransaction();
transaction.hasChanged = true;
transaction.bNew = true;
transaction.setName("Default_transaction");
httpConnector.add(transaction);
httpConnector.setDefaultTransaction(transaction);
} else if (connector instanceof SapJcoConnector) {
SapJcoConnector sapConnector = (SapJcoConnector) connector;
SapJcoLogonTransaction sapLogon = new SapJcoLogonTransaction();
sapLogon.hasChanged = true;
sapLogon.bNew = true;
sapLogon.setName("Logon");
sapLogon.addCredentialsVariables();
sapConnector.add(sapLogon);
sapConnector.setDefaultTransaction(sapLogon);
SapJcoTransaction transaction = new SapJcoTransaction();
transaction.hasChanged = true;
transaction.bNew = true;
transaction.setName("RFC_FUNCTION_SEARCH");
transaction.setBapiName("RFC_FUNCTION_SEARCH");
RequestableVariable variable = new RequestableVariable();
variable.hasChanged = true;
variable.bNew = true;
variable.setName("FUNCNAME");
variable.setValueOrNull("BAPI_*");
transaction.add(variable);
sapConnector.add(transaction);
} else if (connector instanceof SqlConnector) {
SqlConnector sqlConnector = (SqlConnector) connector;
sqlConnector.setJdbcDriverClassName("org.hsqldb.jdbcDriver");
SqlTransaction transaction = new SqlTransaction();
transaction.hasChanged = true;
transaction.bNew = true;
transaction.setName("Default_transaction");
sqlConnector.add(transaction);
sqlConnector.setDefaultTransaction(transaction);
} else if (connector instanceof CicsConnector) {
CicsConnector cicsConnector = (CicsConnector) connector;
CicsTransaction transaction = new CicsTransaction();
transaction.hasChanged = true;
transaction.bNew = true;
transaction.setName("Default_transaction");
cicsConnector.add(transaction);
cicsConnector.setDefaultTransaction(transaction);
} else if (connector instanceof SiteClipperConnector) {
SiteClipperConnector siteClipperConnector = (SiteClipperConnector) connector;
SiteClipperScreenClass defaultScreenClass = new SiteClipperScreenClass();
defaultScreenClass.setName("Default_screen_class");
defaultScreenClass.hasChanged = true;
defaultScreenClass.bNew = true;
siteClipperConnector.setDefaultScreenClass(defaultScreenClass);
SiteClipperTransaction transaction = new SiteClipperTransaction();
transaction.hasChanged = true;
transaction.bNew = true;
transaction.setName("Default_transaction");
siteClipperConnector.add(transaction);
siteClipperConnector.setDefaultTransaction(transaction);
} else if (connector instanceof CouchDbConnector) {
CouchDbConnector couchDbConnector = (CouchDbConnector) connector;
String couchDbXsdPath = AbstractCouchDbTransaction.COUCHDB_XSD_LOCATION;
boolean existReference = false;
for (Reference reference : couchDbConnector.getProject().getReferenceList()) {
if (reference instanceof XsdSchemaReference) {
String urlPath = ((XsdSchemaReference) reference).getUrlpath();
if (urlPath.equals(couchDbXsdPath)) {
existReference = true;
break;
}
}
}
if (!existReference) {
ImportXsdSchemaReference reference = new ImportXsdSchemaReference();
reference.setName("CouchDb_schema");
reference.setUrlpath(couchDbXsdPath);
couchDbConnector.getProject().add(reference);
}
GetServerInfoTransaction transaction = new GetServerInfoTransaction();
couchDbConnector.add(transaction);
couchDbConnector.setDefaultTransaction(transaction);
}
}
Aggregations