Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fugerit-org/fj-script-helper
Fugerit Script Helper
https://github.com/fugerit-org/fj-script-helper
Last synced: 13 days ago
JSON representation
Fugerit Script Helper
- Host: GitHub
- URL: https://github.com/fugerit-org/fj-script-helper
- Owner: fugerit-org
- License: mit
- Created: 2024-10-23T09:47:08.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-10-24T20:44:38.000Z (2 months ago)
- Last Synced: 2024-11-06T01:10:10.227Z (2 months ago)
- Language: Java
- Size: 37.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Fugerit Language Script Helper
This project provides just a convenient interface for evaluating scripts with java script engine.
[![Keep a Changelog v1.1.0 badge](https://img.shields.io/badge/changelog-Keep%20a%20Changelog%20v1.1.0-%23E05735)](CHANGELOG.md)
[![Maven Central](https://img.shields.io/maven-central/v/org.fugerit.java/fj-script-helper.svg)](https://central.sonatype.com/artifact/org.fugerit.java/fj-script-helper)
[![javadoc](https://javadoc.io/badge2/org.fugerit.java/fj-script-helper/javadoc.svg)](https://javadoc.io/doc/org.fugerit.java/fj-script-helper)
[![license](https://img.shields.io/badge/License-MIT%20License-teal.svg)](https://opensource.org/license/mit)
[![code of conduct](https://img.shields.io/badge/conduct-Contributor%20Covenant-purple.svg)](https://github.com/fugerit-org/fj-universe/blob/main/CODE_OF_CONDUCT.md)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=fugerit-org_fj-script-helper&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=fugerit-org_fj-script-helper)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=fugerit-org_fj-script-helper&metric=coverage)](https://sonarcloud.io/summary/new_code?id=fugerit-org_fj-script-helper)[![Java runtime version](https://img.shields.io/badge/run%20on-java%208+-%23113366.svg?style=for-the-badge&logo=openjdk&logoColor=white)](https://universe.fugerit.org/src/docs/versions/java11.html)
[![Java build version](https://img.shields.io/badge/build%20on-java%2017+-%23ED8B00.svg?style=for-the-badge&logo=openjdk&logoColor=white)](https://universe.fugerit.org/src/docs/versions/java17.html)
[![Apache Maven](https://img.shields.io/badge/Apache%20Maven-3.9.0+-C71A36?style=for-the-badge&logo=Apache%20Maven&logoColor=white)](https://universe.fugerit.org/src/docs/versions/maven3_9.html)
[![Fugerit Github Project Conventions](https://img.shields.io/badge/Fugerit%20Org-Project%20Conventions-1A36C7?style=for-the-badge&logo=Onlinect%20Playground&logoColor=white)](https://universe.fugerit.org/src/docs/conventions/index.html)## Quickstart
### 1. Add dependency
```xml
org.fugerit.java
fj-script-helper
${fj-script-helper-version}```
### 2. Usage
Sample code :
```java
// this will create a EvalScript instance for :
// kotlin script engine (kts)
// data model will be bound as "data" (if not provided this is the default binding name)
EvalScript evalKts = new EvalScriptWithDataModel( "kts", "data" );
try (Reader reader = [reader on kotlin script]) {
Map dataModel = new HashMap<>();
dataModel.put( "docTitle", "My custom title" );
Object result = evalKts.evalKts( reader, dataModel );
log.info( "my result : {}", result );
}
```It is possible to wrap the EvalScript with some decorators, for instance :
```java
EvalScript evalKts = EvalScriptWithJsonDataModel( new EvalScriptWithDataModel( "kts", "data" ) );
```Will wrap the EvalScript with EvalScriptWithJsonDataModel decorator.
EvalScriptWithJsonDataModel will transform a Map data model to a json data model style. Only getter and setter will be considered and made into basic types :* String
* Number
* Boolean
* Object as Map
* ArrayFor instance this code :
```java
class Vehicle {
private String plate;
private int age;
public Vehicle(int age, String plate) {
this.age = age;
this.plate = plate;
}
public String getPlate() { return plate; }
public int getAge() { return age; }
@Override
public String toString() {
return "Vehicle{age="+age+", plate='"+plate+"'}";
}
}
Map dataModel = new HashMap<>();
dataModel.put( "vehicle", new Vehicle( 10, "AA780BB" ) );
Map jsonStyleDataModel = EvalScriptWithJsonDataModel.defaultDataModelConversion( dataModel );
log.info( "originalDataModel : {}", dataModel );
log.info( "jsonStyleDataModel : {}", jsonStyleDataModel );
```would result in this conversion :
```text
originalDataModel : {vehicle=Vehicle{age=10, plate='AA780BB'}}
jsonStyleDataModel : {vehicle={plate=AA780BB, age=10}}
```