<< Overview |
Contents
Records, Page ContentsRecord, RecordsRecord RECORDRecord currently openedList<Value> values = RECORD.getValues(); Or: Record record = RECORD;List<Value> values = record.getValues(); List<Record> RECORDSRecords of current view// Records in loopList<Record> records = RECORDS; for(Record record : records) { } ValuesRead valuesReading the values of a records (visible values in table or all values)// Visible columns/valuesList<Value> values = record.getValues(); for(Value value : values) { String name = value.getName(); // Technical Name String text = value.getText(); // Display Text String obj = value.getObject(); // Java-Object (String, Long, Double, Date, Boolean) }More contents:// All columns/values List<Value> values = record.getValuesAll(); // Single value Value value = record.getValue("country"); String color = record.getBackgroundColor(); List<Annotation> annotations = record.getAnnotations(); // Subtables (Contents: tables.title, tables.records, tables.columns) List<Table> tables = record.getTables(); // Attachments List<Attachment> attachments = record.getAttachments(); Grouping, PageGrouping of pageList<Group> groups = PAGE.getGroups();for(Group group : groups) { // Also Title/Level/Count: group.title, group.level, group.count List<Column> columns = group.getColumns(); List<Record> records = group.getRecords(); for(Column column : columns) { String name = column.getName(); String label = column.getLabel(); } } Current pagePAGE.isView: Is view with recordsPAGE.isRecord: Is record opened PAGE.isWebserver: Application is running in Webserver PAGE.title: Title of current pageif (PAGE.isRecord) { } if (PAGE.isView) { } if (PAGE.isWebserver) { } String title = PAGE.title; HelperTemplates/ReturnRead templateAllows to read a text file, useful if content should be added to a existing file. Templates are read from:scripts/templates/ (Predefined or your own application)// Read template String templateContent = TEMPLATE.read("HTML_Template1.html"); // Perform replacements (Example) String page = templateContent.replace("%CONTENT%", "MY CONTENT").replace("%PAGE_TITLE%", PAGE.title); Return value// Script provides a return valueRESULT.set("Sum for year: xx"); // Append text to return value; set() not necessary for append() RESULT.append("\nSum for month: xx"); Escape/FormatEscape for special characters// Replaces special characters e.g. <, >ESCAPE.forHtml(String text) ESCAPE.forXml(String text) ESCAPE.forJson(String text) ESCAPE.forJava(String text) HTML-Output// Creates HTML-Code for the parameters (also images)HTML.toHtml(Value value) HTML.toHtml(String text) HTML.toHtml(List<Annotation> annotationsList) HTML.toHtml(Annotation annotation) HTML.toHtml(Attachment attachment) Object InformationtoString() for objects and variablesObjects and variables provide information to the content and available methods using toString()// Examples for toString()String summary = ""; summary += RECORD.toString()+"\n"; summary += RECORDS.toString()+"\n"; summary += PAGE.toString()+"\n"; summary += TEMPLATE.toString()+"\n"; summary += RESULT.toString()+"\n"; summary += READ.toString()+"\n"; summary += WRITE.toString()+"\n"; summary += UPLOADS.toString()+"\n"; summary += FILE.toString()+"\n"; RESULT.set(summary); Read/WriteRead/ChangeReading records// Reads all records of the table named by the parameter// The records only contain values, no further details (Annotations, Subtables, ...) List<Record> recordsWithValues = READ.getRecords(String tablename); Change values// Apply new valueWRITE.setValue(Record record, String fieldname, String newValue); Create/DeleteInsert empty record// Add new recordRecord newRecord = WRITE.insertNewRecord(String tablename); Insert record// Add new recordString tablename = "..."; Record record = new Record(tablename); record.setValue("firstname", "theodora"); WRITE.insertRecord(record); Delete record// Delete a recordRecord myrecord = RECORD; WRITE.deleteRecord(myrecord); WRITE.deleteRecordLogical(myrecord); // Delete LogicalOr:// Delete record, set using Tablename, ID String tablename = "..."; Long id = 1122; Record record = new Record(tablename, id); WRITE.deleteRecord(record); FilesFields, UploadsFields// Read bytes of field valuebyte[] bytes = FILE.readBytes(Value value); // Read bytes of upload byte[] bytes = FILE.readBytes("file.txt"); // Read multiple files List<byte[]> filesBytes = FILE.readBytesList(Value value); Add UploadsUPLOADS.add("file.txt", String text);UPLOADS.add("file.bin", byte[] bytes); File AccessTemp-Files, Open/Edit// Temp FilesFile tmp = FILE.temp(); File tmp = FILE.temp(String ending); File tmp = FILE.temp(String ending, String prefix); // Open/Edit/Browse in Operating System (not Webserver) FILE.open(File file); FILE.edit(File file); FILE.browse(String url); File SystemFILE.write(File file, String text);FILE.write(File file, byte[] bytes); String filetext = FILE.read(File file); byte[] bytes = FILE.readBytes(File file); AdvancedJava-ClassesClasses in scriptsScripts allow to define own classes.Variablen to use in scripts are only available outside of Java-Classes. Because of this they need to be provided in the constructor, an example:// Variables PAGE, ESCAPE, UTIL, RESULT, ... are only available outside classes // Solution: Use variable SCRIPT as parameter, it contains all other variables new Demo(SCRIPT); public class Demo { private Script s; public Demo(Script script) { this.s = script; // Now available: // s.PAGE // s.ESCAPE // s.UTIL // s.RESULT // s.RECORD // s.RECORDS // ... execute(); } private void execute() { s.RESULT.set("My Result"); } }Variables: RECORD, RECORDS, PAGE, ESCAPE, UTIL, TEMPLATE, FILE, HTML, READ, WRITE, RESULT, UPLOADS Template-ExampleRead template, fill content and write to fileFills a new template and writes it to a temporary file. Then the file is opened in the system.// Read template and replace placeholders String content = "MY CONTENT"; String templateContent = TEMPLATE.read("TEMPLATE_HERE.html"); String page = templateContent.replace("%CONTENT%", content).replace("%PAGE_TITLE%", PAGE.title); // Temp File File file = FILE.temp(".html"); // Write to file FILE.write(file, page); // Open file in System FILE.open(file); |