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
The package for using SQL-based databases. It is a connector for MySQL, MSSQL, Oracle DB and SQLite.
Example
Make a testing table in MySQL, fill one field, update the field and get it back from the database:
use Database; use System; var db_name = "community_test"; var con1 = Database.connect("localhost:3306/information_schema", "mysql","root"); Database.rawQuery("CREATE DATABASE " :: db_name, 50, con1); Database.connect("localhost:3306/" :: db_name, "mysql","root"); Database.query("CREATE TABLE `testable` ( `testfield` INT NULL )"); Database.storeObject("testable",{"testfield" : 4}); var test = Database.query("UPDATE testable SET testfield = 3*testfield"); System.print(Database.getObject("testable",{})); Database.rawQuery("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"); }
REST
REST communicates with the world wide web on a lower level than the Web package functions. The REST package constructs can do requests like post, get and put.
Example
This example is provided to show the syntax of REST.post functionality. It does not actually post anything to an existing website.
use System; use REST; use XML; var bodyStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <test name=\"xillio\">content</test>"; var body = XML.fromString(bodyStr); var response = REST.post("http://somesite.com/uri", {"timeout" : 3000}, body); System.print(response);
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; //set this path to your choice var filePath = "C:\\tmp\\test.xlsx"; //create a workbook with a sheet, and then fill a cell var myFirstWorkbook = Excel.createWorkbook(filePath); var myFirstSheet = Excel.createSheet(myFirstWorkbook,"Hi"); Excel.setCell(myFirstSheet,"A",1,"Hello World!"); Excel.setCell(myFirstSheet,"A",2,"Hi Earth!"); //now save the sheet System.print(Excel.save(myFirstWorkbook)); //to demonstrate the reading functions, let's read the written cell back from disk and log the contents var workBookFromDisk = Excel.loadWorkbook(filePath); var sheetFromDisk = Excel.loadSheet(workBookFromDisk,"Hi"); var upperLeftCell = Excel.getCell(sheetFromDisk,"A",1); System.print(upperLeftCell);
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; var extraction_path = "C:/projects/project1/extraction/"; var import_path = "C:/projects/project1/import/"; Encode.fileToBase64(extraction_path :: "image1.png", import_path :: "image1.png.base64"); // 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