You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Henri Biestro (Jira)" <ji...@apache.org> on 2022/08/21 08:31:00 UTC
[jira] [Updated] (JEXL-379) Allow new to use class identifier
[ https://issues.apache.org/jira/browse/JEXL-379?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Henri Biestro updated JEXL-379:
-------------------------------
Description:
WHAT:
The Java syntax for new is easier/nicer to use than the current JEXL one that forces to use a fully qualified class name (FQCN) to instantiate an object. The improvement will allow using the Java new syntax using either an FQCN (as identifier) or just an identifier.
HOW:
The grammar is augmented to allow the 'new qualified_class_name(<args>)' syntax. Provision is to be made to allow an 'import'-like mechanism so class identifiers can be resolved (JexlContext extension).
Canonical example is:
{code}
//-------------------------------------------------------------------
// send a POST Request
//-------------------------------------------------------------------
#pragma jexl.import java.net
#pragma jexl.import java.io
{
"execute" : (sURL, jsonData) -> {
let url = new URL(sURL);
let con = url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Accept", "application/json");
// send data
if (jsonData != null) {
con.setRequestProperty("Content-Type", "application/json; utf-8");
con.setDoOutput(true);
let outputStream = con.getOutputStream();
let input = jsonData.getBytes("utf-8");
outputStream.write(input, 0, size(input));
}
// read response
let responseCode = con.getResponseCode();
let inputStream = con.getInputStream();
let response = new StringBuffer();
if (inputStream != null) {
let in = new BufferedReader(new InputStreamReader(inputStream));
var inputLine = "";
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
}
response.toString();
}
}
{code}
was:
WHAT:
The Java syntax for new is easier/nicer to use than the current JEXL one that forces to use a fully qualified class name (FQCN) to instantiate an object. The improvement will allow using the Java new syntax using either an FQCN (as identifier) or just an identifier.
HOW:
The grammar is augmented to allow the 'new qualified_class_name(<args>)' syntax. Provision is to be made to allow an 'import'-like mechanism so class identifiers can be resolved (JexlContext extension).
> Allow new to use class identifier
> ---------------------------------
>
> Key: JEXL-379
> URL: https://issues.apache.org/jira/browse/JEXL-379
> Project: Commons JEXL
> Issue Type: Improvement
> Affects Versions: 3.2.1
> Reporter: Henri Biestro
> Assignee: Henri Biestro
> Priority: Major
> Fix For: 3.3
>
>
> WHAT:
> The Java syntax for new is easier/nicer to use than the current JEXL one that forces to use a fully qualified class name (FQCN) to instantiate an object. The improvement will allow using the Java new syntax using either an FQCN (as identifier) or just an identifier.
> HOW:
> The grammar is augmented to allow the 'new qualified_class_name(<args>)' syntax. Provision is to be made to allow an 'import'-like mechanism so class identifiers can be resolved (JexlContext extension).
> Canonical example is:
> {code}
> //-------------------------------------------------------------------
> // send a POST Request
> //-------------------------------------------------------------------
> #pragma jexl.import java.net
> #pragma jexl.import java.io
> {
> "execute" : (sURL, jsonData) -> {
> let url = new URL(sURL);
> let con = url.openConnection();
> con.setRequestMethod("POST");
> con.setRequestProperty("Accept", "application/json");
> // send data
> if (jsonData != null) {
> con.setRequestProperty("Content-Type", "application/json; utf-8");
> con.setDoOutput(true);
> let outputStream = con.getOutputStream();
> let input = jsonData.getBytes("utf-8");
> outputStream.write(input, 0, size(input));
> }
> // read response
> let responseCode = con.getResponseCode();
> let inputStream = con.getInputStream();
> let response = new StringBuffer();
> if (inputStream != null) {
> let in = new BufferedReader(new InputStreamReader(inputStream));
> var inputLine = "";
> while ((inputLine = in.readLine()) != null) {
> response.append(inputLine);
> }
> in.close();
> }
> response.toString();
> }
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)