Welcome, Guest
Please Login or Register.    Lost Password?

Tips n Tricks in Convertigo
(1 viewing) (1) Guest
Convertigo Products
This is the place to ask questions, request for enhancements and more generally discuss about Convertigo products.
Go to bottomPage: 12
TOPIC: Tips n Tricks in Convertigo
#43
Tips n Tricks in Convertigo 1 Year, 11 Months ago Karma: 1
The purpose of this post is to list examples of code (Java, JavaScript, HTML, XSL,...) or best practices you may have used in Convertigo projects development (XPath, extraction rules, statements, Steps,...). It is a kind of Tips'n'Tricks thread or an How-to section.

gregoV
QA & Support
Convertigo Team
Posts: 15
graphgraph
User Offline Click here to see the profile of this user
Gender: Male Location: Orsay Birthday: 04/04
Last Edit: 2011/02/11 17:45 By gregoV.
The administrator has disabled public write access.
 
#44
Perform a case insensitive Xpath 1 Year, 11 Months ago Karma: 1
Convertigo projects use XPath a lot.
You may need to search if an element contains a particular string.
To perform an insensitive case search use code below :

Code:

//ELEMENT[contains(translate(text(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),"string_to_search")]


It searches for all "ELEMENT" elements that contains "string_to_search" string in lower case.
You can invert letters sequence to perform an upper case search.
You can set "StRiNg_To_SeArCh" value as a transaction variable called myString, for example, and add a Simple Statement in the onTransactionStarted() handler to execute a JavaScript transformation like myString.toLowerCase() or myString.toUpperCase() before using it in a Convertigo Javascript XPath property (HTML statements,...).

Code:

'//ELEMENT[contains(translate(text(), \'ABCDEFGHIJKLMNOPQRSTUVWXYZ\', \'abcdefghijklmnopqrstuvwxyz\'),"'+myString+'")]'
gregoV
QA & Support
Convertigo Team
Posts: 15
graphgraph
User Offline Click here to see the profile of this user
Gender: Male Location: Orsay Birthday: 04/04
Last Edit: 2010/08/04 08:25 By gregoV.
The administrator has disabled public write access.
 
#45
Handling Sequence 'jSource' Step 1 Year, 11 Months ago Karma: 1
In a Convertigo sequence you may need to transform an XML source element from a previous Step into a JavaScript variable to perform some operations on it needed for next Steps.
jSource Step will do the job.
Therefore, it will return you a Java Nodelist, so that you will have to use Java or JS methods before you can retrieve its value.
Once you have set your DOM source in the jSource Step you will have a variable myNodeList in the Convertigo sequence scope.

Here, I will only approach the case of a unique XML element to transform into JS variable :

To have the Nodelist length:
Code:


myNodeList.length;



To have the Nodelist value:
Code:


""+myNodeList.item(0).getFirstChild().getNodeValue();



or

Code:


""+myNodeList.item(0).firstChild.nodeValue;



Don't forget to cast to JS variable with because it is a Java string at the end:
Code:

""+javaString -> JavaScriptString


NB :

myNodeList display in Convertigo (log or jElement Step)
org.apache.xml.dtm.ref.DTMNodeList@xxxx

If you don't cast the Java string you will have the following output:
org.mozilla.javascript.NativeJavaObject@xxxx
gregoV
QA & Support
Convertigo Team
Posts: 15
graphgraph
User Offline Click here to see the profile of this user
Gender: Male Location: Orsay Birthday: 04/04
Last Edit: 2010/08/04 08:27 By gregoV.
The administrator has disabled public write access.
 
#46
[XSL]Transform accentuated characters to no accent 1 Year, 11 Months ago Karma: 1
Here is the kind of xsl code you can use in your xsl file :
Code:

<xsl:variable name="accent" select="'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöùúûüýÿ!@&amp;'"/>
<xsl:variable name="noaccent" select="'AAAAAACEEEEIIIINOOOOOUUUUYaaaaaaceeeeiiiinooooouuuuyy'"/>
<xsl:variable name="ElementNoAccent" select="translate(ElementWithAccent, $accent, $noaccent)"/>



Edit: Notice that 'accent' variable characters !@&amp; have no equivalent in the 'noaccent' variable, meaning they will be purely deleted if found in the element's text to process.
gregoV
QA & Support
Convertigo Team
Posts: 15
graphgraph
User Offline Click here to see the profile of this user
Gender: Male Location: Orsay Birthday: 04/04
Last Edit: 2010/08/04 08:26 By gregoV.
The administrator has disabled public write access.
 
#90
[Studio] Share code between transactions 1 Year, 9 Months ago Karma: 1
To re-use the same code in multiple transactions (via Simple Statement or 'Javascriptable' statements) we can use the context object scope with its get and set methods :

// EXAMPLE //
This example will share a function that writes values to the Engine logs.

'Set' method

1. Create a new transaction (all properties set to default).
2. Add onTransactionStarted handler (set Result property to 'cancel').
3. Add a 'Simple Statement' statement and use the kind of code below :

Code:

var _log = log;
var _context = context;
function bar(p1, p2){
    _log.message("#### p1 value is: "+p1);
    _log.message("#### p2 value is: "+p2);
    _context.set("foo2", p1+":"+p2);
    _log.message("#### p1:p2= "+_context.get("foo2"));
}

context.set("foo", bar);



// OR //

Code:

var _log = log;
var _context = context;
context.set("foo", function(p1, p2){
    _log.message("#### p1 value is: "+p1);
    _log.message("#### p2 value is: "+p2);
    _context.set("foo2", p1+":"+p2);
    _log.message("#### p1:p2= "+_context.get("foo2"));
});



// CALL //

'Get' method

1. Use code below in your other transactions (Simple Statement, JSable statement, ...)

Code:

context.get("foo")("parameter1", 1234567890);


// ENGINE CONSOLE //

Code:

#### p1 value is: parameter1
#### p2 value is: 1234567890
#### p1:p2= parameter1:1234567890



. Note that all Convertigo objects (log, context, etc...) have to be re-defined to JavaScript global variables to be accessible.
. Js functions can be more complex and are not reserved to write logs.
. Scope is limited to project's transactions.
. I would recommend to use one function per set.
gregoV
QA & Support
Convertigo Team
Posts: 15
graphgraph
User Offline Click here to see the profile of this user
Gender: Male Location: Orsay Birthday: 04/04
Last Edit: 2010/08/04 08:13 By gregoV.
The administrator has disabled public write access.
 
#141
HTML tags with double-dots as part of name 1 Year, 3 Months ago Karma: 1
I recently faced an issue with Convertigo Studio in a particular web page.
The page have an HTML tag of type <FOO:BAR>...</FOO:BAR>
Using Connector's view to select an element inside this tag to generate the according xpath ends in an alert error: "Xpath not valid".
The xpath parser is considering the first part of the tag as a namespace and can not resolve it.

To generate an xpath of an element inside that tag, you have to select a parent element and browse down DOM with the DOM's tree view on the left of connector's view.

Some statements (Mouse action, HTML set selected,...) generates an absolute Xpath to execute action on the element. In this case, it also generates an error.

Here are some workarounds:
_ When applicable, you can replace the failing statement by a 'Navigation Bar' statement or an 'Inject JS in browser'.

In my personal case, I replaced the Mouse action (click on a link) by a 'Navigation bar' (goTo action on a full url path) statement.
The 'HTML set selected' has been replaced by an 'Inject JS in browser' statement with this kind of code:
Code:


// Get the <select> by its name and not id because
// the page has several <select> elements with the same id:
var x=document.getElementsByName("selectName")[0];
// For each <option> compare its value with 'val' variable
// If found select the proper index and break loop:
for(var i=0;i<x.length;i++){
if(x.item(i).value==val){
x.selectedIndex=i;
break;
}
}
// submitting the form:
document.getElementsByName("form")[0].submit();



Don't forget to map Convertigo's variables to the internal statement's variables ('Inject JS in browser' 'Variables' property)
gregoV
QA & Support
Convertigo Team
Posts: 15
graphgraph
User Offline Click here to see the profile of this user
Gender: Male Location: Orsay Birthday: 04/04
The administrator has disabled public write access.
 
Go to topPage: 12
Moderators: elodiee