Properties

Allows scripts to read from .properties files. These files may be distributed over your folder tree. There can be one master xill.properties file in the root of your project and several defaults.properties files in subfolders. If a property is only defined in the defaults.properties, it will be applicable to scripts in that folder and its subfolders. If it is also defined in the xill.properties, that value will take precedence everywhere in the project.

Example

 

#udm
db.name=udm_demo_drupal_aem
udm.identity=demo_drupal_aem

#paths
project.root=/develop/demo_drupal_aem/
project.exportPath=export/
project.tempPath=temp/
project.binaryPath=data/binaries/
project.imagePath=data/images/

#export
source.url=http://drupal-demo.chapp.io/drupal-demo/

#import
target.url=http://localhost:4502
target.user=admin
target.password=

 

To get a property value in a robot, you use Properties.get([property_name]).

Exiftool

Metadata-reading functionality from Exiftool is included in this package. 

Example

Output the mimetype of each file in a folder:  

use ExifTool;
use System;

var result = ExifTool.scanFolder("D:\\temp");

foreach(file in result) {
System.print(file.filePath :: " has mimetype " :: file.mimeType);
}

Database packages

Xill has a number of SQL-based database packages and a Mongo package:

Package name Database type Versions
MySQL MySQL 5.5 and newer
MariaDB MySQL 5.5 and newer
MSSQL Microsoft SQL Server 6.5, 7, 2000, 2005, 2008, 2012
Oracle Oracle Database 11g, 12c
SQLite SQLite  All formats since 2004

Example

Make a testing table in MariaDB, fill one field, update the field and get it back from the database:  

use MariaDB;
use System;

var db_name = "community_test";
MariaDB.connect("jdbc:mariadb://localhost:3306/information_schema?user=root");
MariaDB.query("CREATE DATABASE " :: db_name);
MariaDB.connect("jdbc:mariadb://localhost:3306/" :: db_name :: "?user=root");
MariaDB.query("CREATE TABLE `testable` (
`testfield` INT NULL
)");
MariaDB.storeObject("testable",{"testfield" : 4});
var test = MariaDB.query("UPDATE testable SET testfield = 3*testfield");
System.print(MariaDB.getObject("testable",{}));
MariaDB.query("DROP DATABASE " :: db_name);

Web

This package is for navigation and extraction of web pages.

Example

Load the Google homepage and get the language from the loaded page:  

use System;
use Web;

var page = Web.loadPage("http://www.google.com/");
System.print(getLang(page));

function getLang(page) {
return Web.xPath(page, "/html/@lang");
}

XURL

XURL communicates with the world wide web on a lower level than the Web package functions. The XURL package constructs can do requests like post, get and put.

Example

This example is provided to show the syntax of XURL.post functionality.  

use XURL, System, File;

var filePath = "C:\\tmp\\note.txt";

var response = XURL.post(
    "https://httpbin.org/post",
    {
        "file": {
            "content": filePath,
            "type": "file",
            "contentType": "text/plain"
        },
        "description": {
            "content": "This is an example of a multipart request",
            "type": "text"
        }
    },
    {
        // Make this request a multipart request
        "multipart": true
    }
);

var prettyJson = System.toJSON(response, true);
System.print(prettyJson);

XML

Provides functionality for XML editing and extraction.

Example

Simple xml extraction:  

use System;
use XML;

var xml_string = "<food>
<fruit>Apples</fruit>
<fruit>Bananas</fruit>
</food>";
var xml = XML.fromString(xml_string);
var fruits = XML.xPath(xml, "//fruit/text()");
foreach(fruit in fruits) {
System.print("There's " :: fruit);
}

Excel

This package can read, create and edit Microsoft Excel files (.xls and .xlsx).

Example

Creating a testing Excel document: 

use System;
use Excel;

var temp_path = "D:/temp/exceltest.xlsx";

var workbook = Excel.createWorkbook(temp_path);
var sheet = Excel.createSheet(workbook,"testsheet");
Excel.setCellValue(sheet,"A",1,"yes it works");

System.print(Excel.save(workbook));

Encode and Decode

Constructs from these packages can encode and decode files to/from Base64, characters to/from hexadecimal and strings to/from percent-encoding (url-encoding).

Example

Encoding an image to Base64:   

use Encode, File, Stream;

var extraction_path = "C:/projects/project1/extraction/";
var import_path = "C:/projects/project1/import/";
var file = File.openRead(extraction_path :: "image1.png");
var base64=Encode.toBase64(file);

var target = File.openWrite(import_path :: "image1.png.base64");
Stream.write(base64, target);
// The image is now converted to a string and, for example, can be sent in a REST request to import it in a new CMS