Revision 45011
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/ExpressionBuilder.java | ||
---|---|---|
102 | 102 |
public static final String FUNCTION_TOINTEGER = "TOINTEGER"; |
103 | 103 |
public static final String FUNCTION_TOLONG = "TOLONG"; |
104 | 104 |
public static final String FUNCTION_TOSTR = "TOSTR"; |
105 |
public static final String FUNCTION_TOJSON = "TO_JSON"; |
|
105 | 106 |
|
106 | 107 |
public static final String FUNCTION_INCR = "INCR"; |
107 | 108 |
public static final String FUNCTION_DECR = "DECR"; |
... | ... | |
110 | 111 |
public static final String FUNCTION_EVAL = "EVAL"; |
111 | 112 |
public static final String FUNCTION_LIST = "LIST"; |
112 | 113 |
public static final String FUNCTION_TUPLE = "TUPLE"; |
113 |
public static final String FUNCTION_MAP = "MAP";
|
|
114 |
public static final String FUNCTION_DICT = "DICT";
|
|
114 | 115 |
|
115 | 116 |
public static final String FUNCTION_GETATTR = "GETATTR"; |
117 |
public static final String FUNCTION_GETITEM = "GETITEM"; |
|
118 |
public static final String FUNCTION_URLREAD = "URL_READ"; |
|
119 |
public static final String FUNCTION_URLREADBYTES = "URL_READBYTES"; |
|
120 |
public static final String FUNCTION_URL = "URL"; |
|
116 | 121 |
|
117 | 122 |
public static final int PARAMETER_TYPE_CONSTANT = 0; |
118 | 123 |
public static final int PARAMETER_TYPE_VARIABLE = 1; |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/ExpressionEvaluatorLibrary.java | ||
---|---|---|
1 | 1 |
package org.gvsig.expressionevaluator; |
2 | 2 |
|
3 |
import javax.json.JsonArray; |
|
4 |
import javax.json.JsonObject; |
|
3 | 5 |
import org.gvsig.tools.ToolsLibrary; |
4 | 6 |
import org.gvsig.tools.ToolsLocator; |
5 | 7 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
... | ... | |
23 | 25 |
DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager(); |
24 | 26 |
dataTypesManager.addtype(DataTypes.EXPRESSION, "Expression", "Expression", |
25 | 27 |
Expression.class, null); |
28 |
dataTypesManager.addtype(DataTypes.JSONOBJECT, "JsonObject", "JsonObject", |
|
29 |
JsonObject.class, null); |
|
30 |
dataTypesManager.addtype(DataTypes.JSONARRAY, "JsonArray", "JsonArray", |
|
31 |
JsonArray.class, null); |
|
26 | 32 |
|
27 | 33 |
} |
28 | 34 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/spi/formatter/value/BaseFormatter.java | ||
---|---|---|
26 | 26 |
new Timestamp(formatter), |
27 | 27 |
new Extract(formatter), |
28 | 28 |
new Getattr(formatter), |
29 |
new GetItem(formatter), |
|
30 |
new Dict(formatter), |
|
29 | 31 |
new Tuple(formatter) |
30 | 32 |
}; |
31 | 33 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/spi/formatter/value/GetItem.java | ||
---|---|---|
1 |
package org.gvsig.expressionevaluator.spi.formatter.value; |
|
2 |
|
|
3 |
import org.apache.commons.lang3.StringUtils; |
|
4 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
|
5 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_GETATTR; |
|
6 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_GETITEM; |
|
7 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Function; |
|
8 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
|
9 |
import org.gvsig.expressionevaluator.Formatter; |
|
10 |
|
|
11 |
/** |
|
12 |
* |
|
13 |
* @author jjdelcerro |
|
14 |
*/ |
|
15 |
public class GetItem implements Formatter<Value> { |
|
16 |
|
|
17 |
private final Formatter<Value> formatter; |
|
18 |
|
|
19 |
public GetItem(Formatter<Value> formatter) { |
|
20 |
this.formatter = formatter; |
|
21 |
} |
|
22 |
@Override |
|
23 |
public boolean canApply(ExpressionBuilder.Value value) { |
|
24 |
if (value instanceof ExpressionBuilder.Function) { |
|
25 |
return StringUtils.equalsIgnoreCase(FUNCTION_GETITEM, ((Function) value).name()); |
|
26 |
} |
|
27 |
return false; |
|
28 |
} |
|
29 |
|
|
30 |
@Override |
|
31 |
public String format(Value function0) { |
|
32 |
Function function = (Function) function0; |
|
33 |
Value obj = function.parameters().get(0); |
|
34 |
Value attr = function.parameters().get(1); |
|
35 |
return obj.toString(formatter)+"["+ attr.toString(formatter)+"]"; |
|
36 |
} |
|
37 |
|
|
38 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/spi/formatter/value/Dict.java | ||
---|---|---|
1 |
package org.gvsig.expressionevaluator.spi.formatter.value; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
import org.apache.commons.lang3.StringUtils; |
|
5 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
|
6 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_DICT; |
|
7 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Function; |
|
8 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
|
9 |
import org.gvsig.expressionevaluator.Formatter; |
|
10 |
|
|
11 |
/** |
|
12 |
* |
|
13 |
* @author jjdelcerro |
|
14 |
*/ |
|
15 |
public class Dict implements Formatter<Value> { |
|
16 |
|
|
17 |
private final Formatter<Value> formatter; |
|
18 |
|
|
19 |
public Dict(Formatter<Value> formatter) { |
|
20 |
this.formatter = formatter; |
|
21 |
} |
|
22 |
@Override |
|
23 |
public boolean canApply(ExpressionBuilder.Value value) { |
|
24 |
if (value instanceof ExpressionBuilder.Function) { |
|
25 |
return StringUtils.equalsIgnoreCase(FUNCTION_DICT, ((Function) value).name()); |
|
26 |
} |
|
27 |
return false; |
|
28 |
} |
|
29 |
|
|
30 |
@Override |
|
31 |
public String format(Value function0) { |
|
32 |
Function function = (Function) function0; |
|
33 |
List<Value> args = function.parameters(); |
|
34 |
StringBuilder builder = new StringBuilder(); |
|
35 |
builder.append("{ "); |
|
36 |
boolean needcomma = false; |
|
37 |
for (int i_key = 0, i_val = args.size()/2; i_key < args.size()/2; i_key++, i_val++) { |
|
38 |
Value key = args.get(i_key); |
|
39 |
Value value = args.get(i_val); |
|
40 |
if( needcomma ) { |
|
41 |
builder.append(", "); |
|
42 |
} else { |
|
43 |
needcomma = true; |
|
44 |
} |
|
45 |
builder.append(key.toString(formatter)); |
|
46 |
builder.append(":"); |
|
47 |
builder.append(value.toString(formatter)); |
|
48 |
} |
|
49 |
builder.append(" }"); |
|
50 |
return builder.toString(); |
|
51 |
} |
|
52 |
|
|
53 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/spi/AbstractFunction.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.io.File; |
4 | 4 |
import java.io.InputStream; |
5 |
import java.net.MalformedURLException; |
|
5 | 6 |
import java.net.URI; |
6 | 7 |
import java.net.URISyntaxException; |
7 | 8 |
import java.net.URL; |
... | ... | |
20 | 21 |
import org.apache.commons.math.util.MathUtils; |
21 | 22 |
import org.gvsig.expressionevaluator.Code; |
22 | 23 |
import org.gvsig.expressionevaluator.Codes; |
24 |
import org.gvsig.expressionevaluator.ExpressionRuntimeException; |
|
25 |
import org.gvsig.expressionevaluator.Formatter; |
|
23 | 26 |
import org.gvsig.expressionevaluator.Function; |
24 | 27 |
import org.gvsig.expressionevaluator.I18N; |
25 | 28 |
import org.gvsig.expressionevaluator.Interpreter; |
... | ... | |
416 | 419 |
I18N.Expected_XexpectedX_and_found_XfoundX("Temporal/Date",type) |
417 | 420 |
); |
418 | 421 |
} |
422 |
|
|
423 |
public URL getURL(Object[] args, int index) throws MalformedURLException { |
|
424 |
Object obj = getObject(args, index); |
|
425 |
if( obj == null ) { |
|
426 |
return null; |
|
427 |
} |
|
428 |
URL url; |
|
429 |
if( obj instanceof URL ) { |
|
430 |
url = (URL) obj; } else if( obj instanceof CharSequence ) { |
|
431 |
url = new URL(((CharSequence)obj).toString()); |
|
432 |
} else if( obj instanceof File ) { |
|
433 |
url = ((File)obj).toURI().toURL(); |
|
434 |
} else if( obj instanceof URI ) { |
|
435 |
url = ((URI)obj).toURL(); |
|
436 |
} else { |
|
437 |
throw new ExpressionRuntimeException("The "+this.name()+" function require a File, URI or a String and a received a '"+obj.getClass().getSimpleName()+"'."); |
|
438 |
} |
|
439 |
return url; |
|
440 |
} |
|
419 | 441 |
|
420 | 442 |
protected boolean getBoolean(Object args[], int n, Double accuracy) { |
421 | 443 |
if( args.length < n ) { |
... | ... | |
566 | 588 |
} |
567 | 589 |
return r; |
568 | 590 |
} |
569 |
|
|
591 |
|
|
592 |
@Override |
|
593 |
public String toString(Codes args, Formatter<Code> formatter) { |
|
594 |
return null; |
|
595 |
} |
|
596 |
|
|
570 | 597 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/Function.java | ||
---|---|---|
65 | 65 |
*/ |
66 | 66 |
public boolean allowConstantFolding(); |
67 | 67 |
|
68 |
public String toString(Codes args, Formatter<Code> formatter); |
|
69 |
|
|
68 | 70 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/DataTypes.java | ||
---|---|---|
34 | 34 |
public interface DataTypes extends org.gvsig.tools.dataTypes.DataTypes { |
35 | 35 |
|
36 | 36 |
public static final int EXPRESSION = OBJECT + 0x10; |
37 |
public static final int JSONOBJECT = OBJECT + 0x11; |
|
38 |
public static final int JSONARRAY = OBJECT + 0x12; |
|
37 | 39 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/coercion/CoerceJsonObjectToString.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2020 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.expressionevaluator.impl.coercion; |
|
25 |
|
|
26 |
import java.io.StringWriter; |
|
27 |
import java.io.Writer; |
|
28 |
import javax.json.Json; |
|
29 |
import javax.json.JsonObject; |
|
30 |
import javax.json.JsonWriter; |
|
31 |
import org.gvsig.tools.dataTypes.AbstractCoercion; |
|
32 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
33 |
import org.gvsig.tools.dataTypes.CoercionContext; |
|
34 |
|
|
35 |
/** |
|
36 |
* Convert a Expression to String. |
|
37 |
* |
|
38 |
*/ |
|
39 |
public class CoerceJsonObjectToString extends AbstractCoercion { |
|
40 |
|
|
41 |
public CoerceJsonObjectToString() { |
|
42 |
// Do nothing |
|
43 |
} |
|
44 |
|
|
45 |
@Override |
|
46 |
public Object coerce(Object value, CoercionContext context) throws CoercionException { |
|
47 |
if (value == null || value instanceof String) { |
|
48 |
return value; |
|
49 |
} |
|
50 |
try { |
|
51 |
if (value instanceof JsonObject ) { |
|
52 |
Writer sw = new StringWriter(); |
|
53 |
JsonWriter jsonwriter = Json.createWriter(sw); |
|
54 |
jsonwriter.writeObject((JsonObject) value); |
|
55 |
return sw.toString(); |
|
56 |
} |
|
57 |
} catch (Exception e) { |
|
58 |
throw new CoercionException(e); |
|
59 |
} |
|
60 |
throw new CoercionException(); |
|
61 |
} |
|
62 |
|
|
63 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/coercion/CoerceToJson.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2020 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.expressionevaluator.impl.coercion; |
|
25 |
|
|
26 |
import org.gvsig.expressionevaluator.impl.JsonUtils; |
|
27 |
import org.gvsig.tools.dataTypes.AbstractCoercion; |
|
28 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
29 |
import org.gvsig.tools.dataTypes.CoercionContext; |
|
30 |
|
|
31 |
/** |
|
32 |
* Convert a Expression to String. |
|
33 |
* |
|
34 |
*/ |
|
35 |
@SuppressWarnings("UseSpecificCatch") |
|
36 |
public class CoerceToJson { |
|
37 |
|
|
38 |
public static class CoerceToJsonArray extends AbstractCoercion { |
|
39 |
|
|
40 |
public CoerceToJsonArray() { |
|
41 |
// Do nothing |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
public Object coerce(Object value, CoercionContext context) throws CoercionException { |
|
46 |
return JsonUtils.toJsonArray(value); |
|
47 |
} |
|
48 |
} |
|
49 |
|
|
50 |
public static class CoerceToJsonObject extends AbstractCoercion { |
|
51 |
|
|
52 |
public CoerceToJsonObject() { |
|
53 |
// Do nothing |
|
54 |
} |
|
55 |
|
|
56 |
@Override |
|
57 |
public Object coerce(Object value, CoercionContext context) throws CoercionException { |
|
58 |
return JsonUtils.toJsonObject(value); |
|
59 |
} |
|
60 |
} |
|
61 |
|
|
62 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/coercion/CoerceJsonArrayToString.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2020 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.expressionevaluator.impl.coercion; |
|
25 |
|
|
26 |
import java.io.StringWriter; |
|
27 |
import java.io.Writer; |
|
28 |
import javax.json.Json; |
|
29 |
import javax.json.JsonArray; |
|
30 |
import javax.json.JsonObject; |
|
31 |
import javax.json.JsonWriter; |
|
32 |
import org.gvsig.tools.dataTypes.AbstractCoercion; |
|
33 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
34 |
import org.gvsig.tools.dataTypes.CoercionContext; |
|
35 |
|
|
36 |
/** |
|
37 |
* Convert a Expression to String. |
|
38 |
* |
|
39 |
*/ |
|
40 |
public class CoerceJsonArrayToString extends AbstractCoercion { |
|
41 |
|
|
42 |
public CoerceJsonArrayToString() { |
|
43 |
// Do nothing |
|
44 |
} |
|
45 |
|
|
46 |
@Override |
|
47 |
public Object coerce(Object value, CoercionContext context) throws CoercionException { |
|
48 |
if (value == null || value instanceof String) { |
|
49 |
return value; |
|
50 |
} |
|
51 |
try { |
|
52 |
if (value instanceof JsonArray ) { |
|
53 |
Writer sw = new StringWriter(); |
|
54 |
JsonWriter jsonwriter = Json.createWriter(sw); |
|
55 |
jsonwriter.writeArray((JsonArray) value); |
|
56 |
return sw.toString(); |
|
57 |
} |
|
58 |
} catch (Exception e) { |
|
59 |
throw new CoercionException(e); |
|
60 |
} |
|
61 |
throw new CoercionException(); |
|
62 |
} |
|
63 |
|
|
64 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/coercion/CoerceToString.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.expressionevaluator.impl.coercion; |
25 | 25 |
|
26 |
import javax.json.JsonStructure; |
|
26 | 27 |
import org.gvsig.expressionevaluator.Expression; |
28 |
import org.gvsig.expressionevaluator.impl.JsonUtils; |
|
27 | 29 |
import org.gvsig.tools.dataTypes.AbstractCoercion; |
28 | 30 |
import org.gvsig.tools.dataTypes.CoercionException; |
29 | 31 |
import org.gvsig.tools.dataTypes.CoercionContext; |
32 |
import org.json.JSONArray; |
|
33 |
import org.json.JSONObject; |
|
30 | 34 |
|
31 | 35 |
/** |
32 | 36 |
* Convert a Expression to String. |
... | ... | |
47 | 51 |
if (value instanceof Expression) { |
48 | 52 |
return ((Expression) value).getPhrase(); |
49 | 53 |
} |
54 |
if (value instanceof JSONObject ) { |
|
55 |
return ((JSONObject)value).toString(); |
|
56 |
} |
|
57 |
if (value instanceof JSONArray ) { |
|
58 |
return ((JSONArray)value).toString(); |
|
59 |
} |
|
60 |
if (value instanceof JsonStructure ) { |
|
61 |
return JsonUtils.toString((JsonStructure) value); |
|
62 |
} |
|
50 | 63 |
} catch (Exception e) { |
51 | 64 |
throw new CoercionException(e); |
52 | 65 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/DefaultCodeBuilder.java | ||
---|---|---|
53 | 53 |
import org.gvsig.tools.visitor.Visitor; |
54 | 54 |
import static org.gvsig.expressionevaluator.Code.CALLABLE; |
55 | 55 |
import org.gvsig.expressionevaluator.Code.Callable; |
56 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_GETITEM; |
|
56 | 57 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_MOD; |
57 | 58 |
|
58 | 59 |
@SuppressWarnings("UseSpecificCatch") |
... | ... | |
502 | 503 |
break; |
503 | 504 |
case FUNCTION: |
504 | 505 |
default: |
505 |
if( StringUtils.equalsIgnoreCase(this.name(),ExpressionBuilder.FUNCTION_GETATTR) ) { |
|
506 |
Code arg0 = this.parameters().get(0); |
|
507 |
Code arg1 = this.parameters().get(1); |
|
508 |
if( arg0 instanceof Code.Identifier && arg1 instanceof Code.Identifier ) { |
|
509 |
builder.append(arg0.toString(formatter)); |
|
510 |
builder.append("."); |
|
511 |
builder.append(arg1.toString()); |
|
512 |
} else { |
|
506 |
String s = null; |
|
507 |
if( this.function()!=null ) { |
|
508 |
s = this.function().toString(args, formatter); |
|
509 |
} |
|
510 |
if( s == null ) { |
|
513 | 511 |
builder.append(this.name()); |
514 | 512 |
builder.append("("); |
515 |
builder.append(arg0.toString(formatter));
|
|
516 |
builder.append(", ");
|
|
517 |
builder.append(arg1.toString(formatter));
|
|
513 |
if( this.parameters()!=null ) {
|
|
514 |
builder.append(this.parameters().toString(formatter));
|
|
515 |
}
|
|
518 | 516 |
builder.append(")"); |
519 |
} |
|
520 | 517 |
} else { |
521 |
builder.append(this.name()); |
|
522 |
builder.append("("); |
|
523 |
if( this.parameters()!=null ) { |
|
524 |
builder.append(this.parameters().toString(formatter)); |
|
525 |
} |
|
526 |
builder.append(")"); |
|
518 |
builder.append(s); |
|
527 | 519 |
} |
528 | 520 |
} |
529 | 521 |
return builder.toString(); |
... | ... | |
831 | 823 |
BaseCodes args = args(); |
832 | 824 |
args.add(obj); |
833 | 825 |
args.add(index); |
834 |
return function(GetitemFunction.NAME, args);
|
|
826 |
return function(FUNCTION_GETITEM, args);
|
|
835 | 827 |
} |
836 | 828 |
|
837 | 829 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/grammars/BasicGrammarFactory.java | ||
---|---|---|
27 | 27 |
import org.gvsig.expressionevaluator.impl.function.programming.WhileFunction; |
28 | 28 |
import org.gvsig.expressionevaluator.spi.AbstractGrammarFactory; |
29 | 29 |
import org.gvsig.expressionevaluator.Code.Callable; |
30 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_MAP;
|
|
30 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_DICT;
|
|
31 | 31 |
|
32 | 32 |
/** |
33 | 33 |
* |
... | ... | |
349 | 349 |
stmt.code(FUNCTION_EXTRACT,stmt.args_names("FIELD", "EXP")); |
350 | 350 |
theGrammar.addStatement(stmt); |
351 | 351 |
|
352 |
stmt = theGrammar.createStatement("MAP"); |
|
353 |
stmt.addRule(stmt.require_any_token("MAP")); |
|
354 |
stmt.addRule(stmt.require_any_token("(")); |
|
352 |
stmt = theGrammar.createStatement("DICT"); |
|
353 |
stmt.addRule(stmt.require_any_token("{")); |
|
355 | 354 |
stmt.addRule(stmt.repeat() |
356 |
.addRule(stmt.require_identifier().capture_as("NAME#")) |
|
357 |
.addRule(stmt.require_any_token("=")) |
|
355 |
.addRule(stmt.optional_literal_string().capture_as("NAME#") |
|
356 |
.addRuleOnFalse(stmt.require_identifier().capture_as("NAME#")) |
|
357 |
) |
|
358 |
.addRule(stmt.require_any_token(":")) |
|
358 | 359 |
.addRule(stmt.require_expression().capture_as("VALUE#")) |
359 | 360 |
.addRule(stmt.optional_any_token(",") |
360 | 361 |
.addRuleOnFalse(stmt.break_loop()) |
361 | 362 |
) |
362 | 363 |
); |
363 |
stmt.addRule(stmt.require_any_token(")"));
|
|
364 |
stmt.code(FUNCTION_MAP,stmt.args_names("NAME#", "VALUE#"));
|
|
364 |
stmt.addRule(stmt.require_any_token("}"));
|
|
365 |
stmt.code(FUNCTION_DICT,stmt.args_names("NAME#", "VALUE#"));
|
|
365 | 366 |
theGrammar.addStatement(stmt); |
366 | 367 |
|
368 |
stmt = theGrammar.createStatement("LIST"); |
|
369 |
stmt.addRule(stmt.require_any_token("[")); |
|
370 |
stmt.addRule(stmt.repeat() |
|
371 |
.addRule(stmt.require_expression().capture_as("VALUE#")) |
|
372 |
.addRule(stmt.optional_any_token(",") |
|
373 |
.addRuleOnFalse(stmt.break_loop()) |
|
374 |
) |
|
375 |
); |
|
376 |
stmt.addRule(stmt.require_any_token("]")); |
|
377 |
stmt.code(FUNCTION_LIST,stmt.args_names("VALUE#")); |
|
378 |
theGrammar.addStatement(stmt); |
|
379 |
|
|
367 | 380 |
this.grammar = theGrammar; |
368 | 381 |
|
369 | 382 |
stmt = theGrammar.createStatement("PASS"); |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/ExpressionEvaluatorImplLibrary.java | ||
---|---|---|
4 | 4 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLibrary; |
5 | 5 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
6 | 6 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
7 |
import org.gvsig.expressionevaluator.impl.coercion.CoerceJsonArrayToString; |
|
8 |
import org.gvsig.expressionevaluator.impl.coercion.CoerceJsonObjectToString; |
|
7 | 9 |
import org.gvsig.expressionevaluator.impl.coercion.CoerceToExpression; |
10 |
import org.gvsig.expressionevaluator.impl.coercion.CoerceToJson.CoerceToJsonArray; |
|
11 |
import org.gvsig.expressionevaluator.impl.coercion.CoerceToJson.CoerceToJsonObject; |
|
8 | 12 |
import org.gvsig.expressionevaluator.impl.coercion.CoerceToString; |
9 | 13 |
import org.gvsig.expressionevaluator.impl.grammars.BasicGrammarFactory; |
10 | 14 |
import org.gvsig.expressionevaluator.impl.repr.ReprBoolean; |
... | ... | |
58 | 62 |
|
59 | 63 |
dataTypesManager.addCoercion(DataTypes.EXPRESSION, new CoerceToExpression()); |
60 | 64 |
dataTypesManager.addCoercion(DataTypes.STRING,new CoerceToString()); |
65 |
dataTypesManager.addCoercion(DataTypes.STRING,new CoerceJsonObjectToString()); |
|
66 |
dataTypesManager.addCoercion(DataTypes.STRING,new CoerceJsonArrayToString()); |
|
67 |
dataTypesManager.addCoercion(DataTypes.JSONOBJECT, new CoerceToJsonObject()); |
|
68 |
dataTypesManager.addCoercion(DataTypes.JSONARRAY, new CoerceToJsonArray()); |
|
61 | 69 |
|
62 | 70 |
ToolsLocator.registerScriptManager(DefaultExpressionEvaluatorManager.class); |
63 | 71 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/JsonUtils.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2020 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.expressionevaluator.impl; |
|
25 |
|
|
26 |
import java.io.Reader; |
|
27 |
import java.io.StringReader; |
|
28 |
import java.io.StringWriter; |
|
29 |
import java.io.Writer; |
|
30 |
import java.math.BigDecimal; |
|
31 |
import java.math.BigInteger; |
|
32 |
import java.time.format.DateTimeFormatter; |
|
33 |
import java.util.ArrayList; |
|
34 |
import java.util.Date; |
|
35 |
import java.util.List; |
|
36 |
import java.util.Map; |
|
37 |
import javax.json.Json; |
|
38 |
import javax.json.JsonArray; |
|
39 |
import javax.json.JsonArrayBuilder; |
|
40 |
import javax.json.JsonNumber; |
|
41 |
import javax.json.JsonObject; |
|
42 |
import javax.json.JsonObjectBuilder; |
|
43 |
import javax.json.JsonReader; |
|
44 |
import javax.json.JsonStructure; |
|
45 |
import javax.json.JsonValue; |
|
46 |
import javax.json.JsonWriter; |
|
47 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
48 |
import org.gvsig.tools.util.GetItem; |
|
49 |
import org.gvsig.tools.util.GetItem64; |
|
50 |
import org.gvsig.tools.util.GetItemByKey; |
|
51 |
import org.gvsig.tools.util.GetItemWithSize64; |
|
52 |
import org.gvsig.tools.util.GetKeys; |
|
53 |
import org.gvsig.tools.util.Size; |
|
54 |
import org.gvsig.tools.util.Size64; |
|
55 |
import org.json.JSONArray; |
|
56 |
import org.json.JSONObject; |
|
57 |
|
|
58 |
/** |
|
59 |
* Convert a Expression to String. |
|
60 |
* |
|
61 |
*/ |
|
62 |
@SuppressWarnings("UseSpecificCatch") |
|
63 |
public class JsonUtils { |
|
64 |
|
|
65 |
private interface GetItemByKeyWithGetKeys<K,V> extends GetItemByKey<K, V>, GetKeys<K> { |
|
66 |
|
|
67 |
} |
|
68 |
|
|
69 |
private static void add(JsonArrayBuilder builder, Object value) throws CoercionException { |
|
70 |
if( value == null ) { |
|
71 |
builder.addNull(); |
|
72 |
return; |
|
73 |
} |
|
74 |
GetItemWithSize64 value_list = toList(value); |
|
75 |
if (value_list != null) { |
|
76 |
builder.add(toJsonArray(value_list)); |
|
77 |
return; |
|
78 |
} else { |
|
79 |
GetItemByKeyWithGetKeys<String,Object> value_dict = toDict(value); |
|
80 |
if( value_dict!=null ) { |
|
81 |
builder.add(toJsonObject(value_dict)); |
|
82 |
return; |
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
if( value instanceof Integer ) { |
|
87 |
builder.add((int)value); |
|
88 |
} else if( value instanceof Byte ) { |
|
89 |
builder.add((int)value); |
|
90 |
} else if( value instanceof Long ) { |
|
91 |
builder.add((long)value); |
|
92 |
} else if( value instanceof BigDecimal ) { |
|
93 |
builder.add((BigDecimal)value); |
|
94 |
} else if( value instanceof String ) { |
|
95 |
builder.add((String)value); |
|
96 |
} else if( value instanceof Boolean ) { |
|
97 |
builder.add((boolean)value); |
|
98 |
} else if( value instanceof Double ) { |
|
99 |
builder.add((double)value); |
|
100 |
} else if( value instanceof Float ) { |
|
101 |
builder.add((double)value); |
|
102 |
} else if( value instanceof java.sql.Date ) { |
|
103 |
String s = DateTimeFormatter.ISO_DATE.format(new java.util.Date(((Date)value).getTime()).toInstant()); |
|
104 |
builder.add(s); |
|
105 |
} else if( value instanceof java.sql.Time ) { |
|
106 |
String s = DateTimeFormatter.ISO_TIME.format(new java.util.Date(((Date)value).getTime()).toInstant()); |
|
107 |
builder.add(s); |
|
108 |
} else if( value instanceof java.sql.Timestamp ) { |
|
109 |
String s = DateTimeFormatter.ISO_DATE_TIME.format(new java.util.Date(((Date)value).getTime()).toInstant()); |
|
110 |
builder.add(s); |
|
111 |
} else if( value instanceof Date ) { |
|
112 |
String s = DateTimeFormatter.ISO_DATE_TIME.format(new java.util.Date(((Date)value).getTime()).toInstant()); |
|
113 |
builder.add(s); |
|
114 |
} else if( value instanceof JsonValue ) { |
|
115 |
builder.add((JsonValue)value); |
|
116 |
} else if( value instanceof JsonArrayBuilder ) { |
|
117 |
builder.add((JsonArrayBuilder)value); |
|
118 |
} else if( value instanceof JsonObjectBuilder ) { |
|
119 |
builder.add((JsonObjectBuilder)value); |
|
120 |
} else { |
|
121 |
String s = value.toString(); |
|
122 |
builder.add(s); |
|
123 |
} |
|
124 |
} |
|
125 |
|
|
126 |
private static void add(JsonObjectBuilder builder, String name, Object value) throws CoercionException { |
|
127 |
if( value == null ) { |
|
128 |
builder.addNull(name); |
|
129 |
return; |
|
130 |
} |
|
131 |
GetItemWithSize64 value_list = toList(value); |
|
132 |
if (value_list != null) { |
|
133 |
builder.add(name, toJsonArray(value_list)); |
|
134 |
return; |
|
135 |
} else { |
|
136 |
GetItemByKeyWithGetKeys<String,Object> value_dict = toDict(value); |
|
137 |
if( value_dict!=null ) { |
|
138 |
builder.add(name, toJsonObject(value_dict)); |
|
139 |
return; |
|
140 |
} |
|
141 |
} |
|
142 |
if( value instanceof Integer ) { |
|
143 |
builder.add(name, (int)value); |
|
144 |
} else if( value instanceof Byte ) { |
|
145 |
builder.add(name, (int)value); |
|
146 |
} else if( value instanceof Long ) { |
|
147 |
builder.add(name, (long)value); |
|
148 |
} else if( value instanceof BigDecimal ) { |
|
149 |
builder.add(name, (BigDecimal)value); |
|
150 |
} else if( value instanceof String ) { |
|
151 |
builder.add(name, (String)value); |
|
152 |
} else if( value instanceof Boolean ) { |
|
153 |
builder.add(name, (boolean)value); |
|
154 |
} else if( value instanceof Double ) { |
|
155 |
builder.add(name, (double)value); |
|
156 |
} else if( value instanceof Float ) { |
|
157 |
builder.add(name, (double)value); |
|
158 |
} else if( value instanceof java.sql.Date ) { |
|
159 |
String s = DateTimeFormatter.ISO_DATE.format(new java.util.Date(((Date)value).getTime()).toInstant()); |
|
160 |
builder.add(name, s); |
|
161 |
} else if( value instanceof java.sql.Time ) { |
|
162 |
String s = DateTimeFormatter.ISO_TIME.format(new java.util.Date(((Date)value).getTime()).toInstant()); |
|
163 |
builder.add(name, s); |
|
164 |
} else if( value instanceof java.sql.Timestamp ) { |
|
165 |
String s = DateTimeFormatter.ISO_DATE_TIME.format(new java.util.Date(((Date)value).getTime()).toInstant()); |
|
166 |
builder.add(name, s); |
|
167 |
} else if( value instanceof Date ) { |
|
168 |
String s = DateTimeFormatter.ISO_DATE_TIME.format(new java.util.Date(((Date)value).getTime()).toInstant()); |
|
169 |
builder.add(name, s); |
|
170 |
} else if( value instanceof JsonValue ) { |
|
171 |
builder.add(name, (JsonValue)value); |
|
172 |
} else if( value instanceof JsonArrayBuilder ) { |
|
173 |
builder.add(name, (JsonArrayBuilder)value); |
|
174 |
} else if( value instanceof JsonObjectBuilder ) { |
|
175 |
builder.add(name, (JsonObjectBuilder)value); |
|
176 |
} else { |
|
177 |
String s = value.toString(); |
|
178 |
builder.add(name, s); |
|
179 |
} |
|
180 |
} |
|
181 |
|
|
182 |
public static JsonStructure toJson(Object value) throws CoercionException { |
|
183 |
if (value == null) { |
|
184 |
return null; |
|
185 |
} |
|
186 |
if (value instanceof JsonStructure) { |
|
187 |
return (JsonStructure) value; |
|
188 |
} |
|
189 |
JsonStructure r; |
|
190 |
if( value instanceof JSONArray ) { |
|
191 |
r = toJsonArray(value.toString()); |
|
192 |
return r; |
|
193 |
} |
|
194 |
if( value instanceof JSONObject ) { |
|
195 |
r = toJsonObject(value.toString()); |
|
196 |
return r; |
|
197 |
} |
|
198 |
GetItemWithSize64 value_list = toList(value); |
|
199 |
if (value_list != null) { |
|
200 |
return toJsonArray(value_list); |
|
201 |
} else { |
|
202 |
GetItemByKeyWithGetKeys<String,Object> value_dict = toDict(value); |
|
203 |
if( value_dict!=null ) { |
|
204 |
return toJsonObject(value_dict); |
|
205 |
} |
|
206 |
} |
|
207 |
Reader reader = new StringReader(value.toString()); |
|
208 |
JsonReader jsonreader = Json.createReader(reader); |
|
209 |
return jsonreader.read(); |
|
210 |
} |
|
211 |
|
|
212 |
public static JsonArray toJsonArray(Object value) throws CoercionException { |
|
213 |
if (value == null) { |
|
214 |
return null; |
|
215 |
} |
|
216 |
if (value instanceof JsonArray) { |
|
217 |
return (JsonArray) value; |
|
218 |
} |
|
219 |
JsonArray r; |
|
220 |
if( value instanceof JSONArray ) { |
|
221 |
r = toJsonArray(value.toString()); |
|
222 |
return r; |
|
223 |
} |
|
224 |
try { |
|
225 |
GetItemWithSize64 list = toList(value); |
|
226 |
if (list == null) { |
|
227 |
r = toJsonArray(value.toString()); |
|
228 |
} else { |
|
229 |
r = toJsonArray(list); |
|
230 |
} |
|
231 |
return r; |
|
232 |
} catch (Exception e) { |
|
233 |
throw new CoercionException(e); |
|
234 |
} |
|
235 |
} |
|
236 |
|
|
237 |
private static JsonArray toJsonArray(String s) { |
|
238 |
Reader r = new StringReader(s); |
|
239 |
JsonReader jsonreader = Json.createReader(r); |
|
240 |
return jsonreader.readArray(); |
|
241 |
} |
|
242 |
|
|
243 |
private static JsonArray toJsonArray(GetItemWithSize64 list) throws CoercionException { |
|
244 |
JsonArrayBuilder builder = Json.createArrayBuilder(); |
|
245 |
for (long i = 0; i < list.size64(); i++) { |
|
246 |
Object element = list.get64(i); |
|
247 |
add(builder,element); |
|
248 |
} |
|
249 |
return builder.build(); |
|
250 |
} |
|
251 |
|
|
252 |
public static JsonObject toJsonObject(Object value) throws CoercionException { |
|
253 |
if (value == null || value instanceof JsonObject) { |
|
254 |
return (JsonObject) value; |
|
255 |
} |
|
256 |
JsonObject r; |
|
257 |
if( value instanceof JSONObject ) { |
|
258 |
r = toJsonObject(value.toString()); |
|
259 |
return r; |
|
260 |
} |
|
261 |
try { |
|
262 |
GetItemByKeyWithGetKeys<String,Object> dict = toDict(value); |
|
263 |
if (dict == null) { |
|
264 |
r = toJsonObject(value.toString()); |
|
265 |
} else { |
|
266 |
r = toJsonObject(dict); |
|
267 |
} |
|
268 |
return r; |
|
269 |
} catch (Exception e) { |
|
270 |
throw new CoercionException(e); |
|
271 |
} |
|
272 |
} |
|
273 |
|
|
274 |
private static JsonObject toJsonObject(String s) { |
|
275 |
Reader r = new StringReader(s); |
|
276 |
JsonReader jsonreader = Json.createReader(r); |
|
277 |
return jsonreader.readObject(); |
|
278 |
} |
|
279 |
|
|
280 |
private static JsonObject toJsonObject(GetItemByKeyWithGetKeys<String,Object> dict) throws CoercionException { |
|
281 |
JsonObjectBuilder builder = Json.createObjectBuilder(); |
|
282 |
for (String name : dict.getKeys()) { |
|
283 |
if( name == null ) { |
|
284 |
continue; |
|
285 |
} |
|
286 |
Object element = dict.get(name); |
|
287 |
add(builder,name, element); |
|
288 |
} |
|
289 |
return builder.build(); |
|
290 |
} |
|
291 |
|
|
292 |
private static GetItemWithSize64 toList(Object value) { |
|
293 |
GetItemWithSize64 list = null; |
|
294 |
if (value instanceof List) { |
|
295 |
list = new GetItemWithSize64<Object>() { |
|
296 |
@Override |
|
297 |
public long size64() { |
|
298 |
return ((List) value).size(); |
|
299 |
} |
|
300 |
|
|
301 |
@Override |
|
302 |
public Object get64(long index) { |
|
303 |
return ((List) value).get((int) index); |
|
304 |
} |
|
305 |
}; |
|
306 |
} else if (value instanceof Object[]) { |
|
307 |
list = new GetItemWithSize64<Object>() { |
|
308 |
@Override |
|
309 |
public long size64() { |
|
310 |
return ((Object[]) value).length; |
|
311 |
} |
|
312 |
|
|
313 |
@Override |
|
314 |
public Object get64(long index) { |
|
315 |
return ((Object[]) value)[(int) index]; |
|
316 |
} |
|
317 |
}; |
|
318 |
} else if (value instanceof GetItemWithSize64 ) { |
|
319 |
list = (GetItemWithSize64) value; |
|
320 |
|
|
321 |
} else if (value instanceof GetItem && value instanceof Size) { |
|
322 |
list = new GetItemWithSize64<Object>() { |
|
323 |
@Override |
|
324 |
public long size64() { |
|
325 |
return ((Size) value).size(); |
|
326 |
} |
|
327 |
|
|
328 |
@Override |
|
329 |
public Object get64(long index) { |
|
330 |
return ((GetItem) value).get((int) index); |
|
331 |
} |
|
332 |
}; |
|
333 |
} else if (value instanceof GetItem64 && value instanceof Size64) { |
|
334 |
list = new GetItemWithSize64<Object>() { |
|
335 |
@Override |
|
336 |
public long size64() { |
|
337 |
return ((Size64) value).size64(); |
|
338 |
} |
|
339 |
|
|
340 |
@Override |
|
341 |
public Object get64(long index) { |
|
342 |
return ((GetItem64) value).get64((int) index); |
|
343 |
} |
|
344 |
}; |
|
345 |
} |
|
346 |
return list; |
|
347 |
} |
|
348 |
|
|
349 |
private static GetItemByKeyWithGetKeys<String,Object> toDict(Object value) { |
|
350 |
GetItemByKeyWithGetKeys<String,Object> dict = null; |
|
351 |
if( value instanceof Map ) { |
|
352 |
dict = new GetItemByKeyWithGetKeys<String,Object>() { |
|
353 |
@Override |
|
354 |
public Object get(String k) { |
|
355 |
return ((Map)value).get(k); |
|
356 |
} |
|
357 |
@Override |
|
358 |
public List<String> getKeys() { |
|
359 |
return new ArrayList<>(((Map)value).keySet()); |
|
360 |
} |
|
361 |
}; |
|
362 |
} else if( value instanceof GetItemByKey && value instanceof GetKeys ) { |
|
363 |
dict = new GetItemByKeyWithGetKeys<String,Object>() { |
|
364 |
@Override |
|
365 |
public Object get(String k) { |
|
366 |
return ((GetItemByKey<String,Object>)value).get(k); |
|
367 |
} |
|
368 |
@Override |
|
369 |
public List<String> getKeys() { |
|
370 |
return ((GetKeys<String>)value).getKeys(); |
|
371 |
} |
|
372 |
}; |
|
373 |
} |
|
374 |
return dict; |
|
375 |
} |
|
376 |
|
|
377 |
public static Object get(JsonValue jsonvalue) { |
|
378 |
Object value = null; |
|
379 |
switch(jsonvalue.getValueType()) { |
|
380 |
case ARRAY: |
|
381 |
case OBJECT: |
|
382 |
value = jsonvalue; |
|
383 |
break; |
|
384 |
case NULL: |
|
385 |
value = null; |
|
386 |
break; |
|
387 |
case FALSE: |
|
388 |
value = false; |
|
389 |
break; |
|
390 |
case TRUE: |
|
391 |
value = true; |
|
392 |
break; |
|
393 |
case STRING: |
|
394 |
value = jsonvalue.toString(); |
|
395 |
break; |
|
396 |
case NUMBER: |
|
397 |
JsonNumber n = (JsonNumber) jsonvalue; |
|
398 |
if( n.isIntegral() ) { |
|
399 |
BigInteger bi = n.bigIntegerValue(); |
|
400 |
try { |
|
401 |
value = bi.intValueExact(); |
|
402 |
} catch(ArithmeticException ex) { |
|
403 |
try { |
|
404 |
value = bi.longValueExact(); |
|
405 |
} catch(ArithmeticException ex2) { |
|
406 |
value = bi; |
|
407 |
} |
|
408 |
} |
|
409 |
} else { |
|
410 |
try { |
|
411 |
double d = n.doubleValue(); |
|
412 |
if( d == Double.POSITIVE_INFINITY || d == Double.NEGATIVE_INFINITY) { |
|
413 |
value = n.bigDecimalValue(); |
|
414 |
} else { |
|
415 |
value = d; |
|
416 |
} |
|
417 |
} catch(Exception ex) { |
|
418 |
value = n.bigDecimalValue(); |
|
419 |
} |
|
420 |
} |
|
421 |
} |
|
422 |
return value; |
|
423 |
} |
|
424 |
|
|
425 |
public static String toString(JsonStructure jsonstructure) { |
|
426 |
if (jsonstructure instanceof JsonObject ) { |
|
427 |
Writer sw = new StringWriter(); |
|
428 |
JsonWriter jsonwriter = Json.createWriter(sw); |
|
429 |
jsonwriter.writeObject((JsonObject) jsonstructure); |
|
430 |
return sw.toString(); |
|
431 |
} |
|
432 |
if (jsonstructure instanceof JsonArray ) { |
|
433 |
Writer sw = new StringWriter(); |
|
434 |
JsonWriter jsonwriter = Json.createWriter(sw); |
|
435 |
jsonwriter.writeArray((JsonArray) jsonstructure); |
|
436 |
return sw.toString(); |
|
437 |
} |
|
438 |
return null; |
|
439 |
} |
|
440 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/symboltable/SQLSymbolTable.java | ||
---|---|---|
90 | 90 |
import org.gvsig.expressionevaluator.impl.function.typeconversion.ToDoubleFunction; |
91 | 91 |
import org.gvsig.expressionevaluator.impl.function.typeconversion.ToFloatFunction; |
92 | 92 |
import org.gvsig.expressionevaluator.impl.function.typeconversion.ToIntegerFunction; |
93 |
import org.gvsig.expressionevaluator.impl.function.typeconversion.ToJsonFunction; |
|
93 | 94 |
import org.gvsig.expressionevaluator.impl.function.typeconversion.ToLongFunction; |
94 | 95 |
import org.gvsig.expressionevaluator.impl.function.typeconversion.ToStrFunction; |
95 | 96 |
import org.gvsig.expressionevaluator.spi.AbstractSymbolTable; |
... | ... | |
205 | 206 |
|
206 | 207 |
this.addFunction(new ModFunction()); |
207 | 208 |
|
209 |
this.addFunction(new ToJsonFunction()); |
|
208 | 210 |
} |
209 | 211 |
|
210 | 212 |
private void addOperator(Function operator) { |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/symboltable/ProgrammingSymbolTable.java | ||
---|---|---|
17 | 17 |
import org.gvsig.expressionevaluator.impl.function.programming.LenFunction; |
18 | 18 |
import org.gvsig.expressionevaluator.impl.function.programming.LetFunction; |
19 | 19 |
import org.gvsig.expressionevaluator.impl.function.programming.ListFunction; |
20 |
import org.gvsig.expressionevaluator.impl.function.programming.MapFunction;
|
|
20 |
import org.gvsig.expressionevaluator.impl.function.programming.DictFunction;
|
|
21 | 21 |
import org.gvsig.expressionevaluator.impl.function.programming.PassFunction; |
22 | 22 |
import org.gvsig.expressionevaluator.impl.function.programming.PrintFunction; |
23 | 23 |
import org.gvsig.expressionevaluator.impl.function.programming.RangeFunction; |
... | ... | |
25 | 25 |
import org.gvsig.expressionevaluator.impl.function.programming.TryFunction; |
26 | 26 |
import org.gvsig.expressionevaluator.impl.function.programming.TupleFunction; |
27 | 27 |
import org.gvsig.expressionevaluator.impl.function.programming.URLFunction; |
28 |
import org.gvsig.expressionevaluator.impl.function.programming.UrlReadByteArrayFunction; |
|
29 |
import org.gvsig.expressionevaluator.impl.function.programming.UrlReadFunction; |
|
28 | 30 |
import org.gvsig.expressionevaluator.impl.function.programming.UserFunction; |
29 | 31 |
import org.gvsig.expressionevaluator.impl.function.programming.WhileFunction; |
30 | 32 |
import org.gvsig.expressionevaluator.spi.AbstractSymbolTable; |
... | ... | |
66 | 68 |
this.addFunction(new LabeledValueFunction()); |
67 | 69 |
this.addFunction(new EvalFunction()); |
68 | 70 |
this.addFunction(new UserFunction()); |
69 |
this.addFunction(new MapFunction()); |
|
71 |
this.addFunction(new DictFunction()); |
|
72 |
this.addFunction(new UrlReadFunction()); |
|
73 |
this.addFunction(new UrlReadByteArrayFunction()); |
|
70 | 74 |
} |
71 | 75 |
|
72 | 76 |
private void addOperator(Function operator) { |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/programming/MapFunction.java | ||
---|---|---|
1 |
package org.gvsig.expressionevaluator.impl.function.programming; |
|
2 |
|
|
3 |
import java.util.HashMap; |
|
4 |
import java.util.Map; |
|
5 |
import org.apache.commons.lang3.Range; |
|
6 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_MAP; |
|
7 |
import org.gvsig.expressionevaluator.Function; |
|
8 |
import org.gvsig.expressionevaluator.Interpreter; |
|
9 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
|
10 |
|
|
11 |
public class MapFunction extends AbstractFunction { |
|
12 |
|
|
13 |
public MapFunction() { |
|
14 |
super(Function.GROUP_PROGRAMMING, |
|
15 |
FUNCTION_MAP, |
|
16 |
Range.between(0, Integer.MAX_VALUE), |
|
17 |
null, |
|
18 |
"MAP( {{identifier1}} = value1, {{identifier2}} = value2, ...)", |
|
19 |
null, |
|
20 |
"MAP", |
|
21 |
false |
|
22 |
); |
|
23 |
} |
|
24 |
|
|
25 |
@Override |
|
26 |
public boolean allowConstantFolding() { |
|
27 |
return false; |
|
28 |
} |
|
29 |
|
|
30 |
@Override |
|
31 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
32 |
Map<Object,Object> map = new HashMap<>(); |
|
33 |
for (int i_key = 0, i_val = args.length/2; i_key < args.length/2; i_key++, i_val++) { |
|
34 |
Object key = args[i_key]; |
|
35 |
Object value = args[i_val]; |
|
36 |
map.put(key, value); |
|
37 |
} |
|
38 |
return map; |
|
39 |
} |
|
40 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/programming/GetitemFunction.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.util.List; |
4 | 4 |
import java.util.Map; |
5 |
import javax.json.JsonArray; |
|
6 |
import javax.json.JsonObject; |
|
5 | 7 |
import org.apache.commons.lang3.Range; |
8 |
import org.apache.commons.lang3.StringUtils; |
|
9 |
import org.gvsig.expressionevaluator.Code; |
|
10 |
import org.gvsig.expressionevaluator.Codes; |
|
11 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
|
12 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_GETITEM; |
|
6 | 13 |
import org.gvsig.expressionevaluator.ExpressionRuntimeException; |
14 |
import org.gvsig.expressionevaluator.Formatter; |
|
7 | 15 |
import org.gvsig.expressionevaluator.Function; |
8 | 16 |
import org.gvsig.expressionevaluator.Interpreter; |
17 |
import org.gvsig.expressionevaluator.impl.JsonUtils; |
|
9 | 18 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
10 | 19 |
import org.gvsig.tools.util.GetItem; |
11 | 20 |
import org.gvsig.tools.util.GetItem64; |
... | ... | |
14 | 23 |
|
15 | 24 |
public class GetitemFunction extends AbstractFunction { |
16 | 25 |
|
17 |
public static final String NAME = "GETITEM"; |
|
18 |
|
|
19 | 26 |
public GetitemFunction() { |
20 | 27 |
super(Function.GROUP_PROGRAMMING, |
21 |
NAME,
|
|
28 |
FUNCTION_GETITEM,
|
|
22 | 29 |
Range.is(2), |
23 | 30 |
null, |
24 |
"GEIITEM({{object}}, index_or_key)",
|
|
31 |
FUNCTION_GETITEM+"({{object}}, index_or_key)",
|
|
25 | 32 |
null, |
26 | 33 |
"Object", |
27 | 34 |
false |
... | ... | |
38 | 45 |
Object value; |
39 | 46 |
Object obj = getObject(args, 0); |
40 | 47 |
if( obj == null ) { |
41 |
throw new ExpressionRuntimeException("Null is not valid in "+NAME+" function.");
|
|
48 |
throw new ExpressionRuntimeException("Null is not valid in "+FUNCTION_GETITEM+" function.");
|
|
42 | 49 |
} |
43 | 50 |
|
44 | 51 |
if( obj instanceof List ) { |
... | ... | |
69 | 76 |
Object index = getObject(args,1); |
70 | 77 |
value = m.get(index); |
71 | 78 |
|
79 |
} else if( obj instanceof JsonArray ) { |
|
80 |
JsonArray l = ((JsonArray)obj); |
|
81 |
int index = getInt(args,1); |
|
82 |
if( index<0 ) { |
|
83 |
index = l.size() + index; |
|
84 |
} |
|
85 |
value = JsonUtils.get(l.get(index)); |
|
86 |
|
|
87 |
} else if( obj instanceof JsonObject ) { |
|
88 |
JsonObject jsonobj = ((JsonObject)obj); |
|
89 |
String name = getStr(args,1); |
|
90 |
value = JsonUtils.get(jsonobj.get(name)); |
|
91 |
|
|
72 | 92 |
} else if( obj instanceof GetItem ) { |
73 | 93 |
GetItem l = (GetItem)obj; |
74 | 94 |
int index = getInt(args,1); |
... | ... | |
90 | 110 |
value = l.getProperty(propName); |
91 | 111 |
|
92 | 112 |
} else { |
93 |
throw new ExpressionRuntimeException("The "+NAME+" function require a String, List or Map and a received a '"+obj.getClass().getSimpleName()+"'.");
|
|
113 |
throw new ExpressionRuntimeException("The "+FUNCTION_GETITEM+" function require a String, List or Map and a received a '"+obj.getClass().getSimpleName()+"'.");
|
|
94 | 114 |
} |
95 | 115 |
return value; |
96 | 116 |
} |
117 |
|
|
118 |
@Override |
|
119 |
public String toString(Codes args, Formatter<Code> formatter) { |
|
120 |
StringBuilder builder = new StringBuilder(); |
|
121 |
Code arg0 = args.get(0); |
|
122 |
Code arg1 = args.get(1); |
|
123 |
builder.append(arg0.toString(formatter)); |
|
124 |
builder.append("["); |
|
125 |
builder.append(arg1.toString(formatter)); |
|
126 |
builder.append("]"); |
|
127 |
return builder.toString(); |
|
128 |
} |
|
97 | 129 |
|
130 |
|
|
98 | 131 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/programming/UrlReadFunction.java | ||
---|---|---|
1 |
package org.gvsig.expressionevaluator.impl.function.programming; |
|
2 |
|
|
3 |
import java.net.URL; |
|
4 |
import java.security.KeyManagementException; |
|
5 |
import java.security.NoSuchAlgorithmException; |
|
6 |
import java.security.cert.CertificateException; |
|
7 |
import java.security.cert.X509Certificate; |
|
8 |
import javax.net.ssl.HttpsURLConnection; |
|
9 |
import javax.net.ssl.SSLContext; |
|
10 |
import javax.net.ssl.SSLSocketFactory; |
|
11 |
import javax.net.ssl.TrustManager; |
|
12 |
import javax.net.ssl.X509TrustManager; |
|
13 |
import org.apache.commons.io.IOUtils; |
|
14 |
import org.apache.commons.lang3.Range; |
|
15 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_URLREAD; |
|
16 |
import org.gvsig.expressionevaluator.Function; |
|
17 |
import org.gvsig.expressionevaluator.Interpreter; |
|
18 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
|
19 |
|
|
20 |
/** |
|
21 |
* |
|
22 |
* @author jjdelcerro |
|
23 |
*/ |
|
24 |
public class UrlReadFunction extends AbstractFunction { |
|
25 |
|
|
26 |
public static class X509TrustAllManager implements X509TrustManager { |
|
27 |
private static SSLSocketFactory socketFactory = null; |
|
28 |
|
|
29 |
public static void setDefaultSSLSocketFactory() throws NoSuchAlgorithmException, KeyManagementException { |
|
30 |
if( socketFactory == null ) { |
|
31 |
X509TrustAllManager trustAll = new X509TrustAllManager(); |
|
32 |
SSLContext sslContext = SSLContext.getInstance("TLS"); |
|
33 |
sslContext.init(null, new TrustManager[] { trustAll }, new java.security.SecureRandom()); |
|
34 |
socketFactory = sslContext.getSocketFactory(); |
|
35 |
} |
|
36 |
if( HttpsURLConnection.getDefaultSSLSocketFactory()!=socketFactory ) { |
|
37 |
HttpsURLConnection.setDefaultSSLSocketFactory(socketFactory); |
|
38 |
} |
|
39 |
} |
|
40 |
|
|
41 |
@Override |
|
42 |
public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { |
|
43 |
} |
|
44 |
|
|
45 |
@Override |
|
46 |
public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
public X509Certificate[] getAcceptedIssuers() { |
|
51 |
return null; |
|
52 |
} |
|
53 |
|
|
54 |
} |
|
55 |
|
|
56 |
|
|
57 |
public UrlReadFunction() { |
|
58 |
super(Function.GROUP_PROGRAMMING, |
|
59 |
FUNCTION_URLREAD, |
|
60 |
Range.is(1), |
|
61 |
null, |
|
62 |
FUNCTION_URLREAD+"({{expression}})", |
|
63 |
null, |
|
64 |
"String", |
|
65 |
false |
|
66 |
); |
|
67 |
this.addAlias("URLREAD"); |
|
68 |
|
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public boolean allowConstantFolding() { |
|
73 |
return false; |
|
74 |
} |
|
75 |
|
|
76 |
@Override |
|
77 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
78 |
URL url = getURL(args,0); |
|
79 |
X509TrustAllManager.setDefaultSSLSocketFactory(); |
|
80 |
String s = IOUtils.toString(url); |
|
81 |
return s; |
|
82 |
} |
|
83 |
|
|
84 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/programming/URLFunction.java | ||
---|---|---|
4 | 4 |
import java.net.URI; |
5 | 5 |
import java.net.URL; |
6 | 6 |
import org.apache.commons.lang3.Range; |
7 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_URL; |
|
7 | 8 |
import org.gvsig.expressionevaluator.ExpressionRuntimeException; |
8 | 9 |
import org.gvsig.expressionevaluator.Function; |
9 | 10 |
import org.gvsig.expressionevaluator.Interpreter; |
10 | 11 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
11 |
import static org.gvsig.tools.dataTypes.DataTypes.URL; |
|
12 | 12 |
|
13 | 13 |
public class URLFunction extends AbstractFunction { |
14 | 14 |
|
15 |
public static final String NAME = "URL"; |
|
16 | 15 |
|
17 | 16 |
public URLFunction() { |
18 | 17 |
super(Function.GROUP_PROGRAMMING, |
19 |
NAME,
|
|
18 |
FUNCTION_URL,
|
|
20 | 19 |
Range.is(1), |
21 | 20 |
null, |
22 |
NAME+"({{expression}})",
|
|
21 |
FUNCTION_URL+"({{expression}})",
|
|
23 | 22 |
null, |
24 | 23 |
"Object", |
25 | 24 |
false |
... | ... | |
47 | 46 |
} else if( obj instanceof URI ) { |
48 | 47 |
value = ((URI)obj).toURL(); |
49 | 48 |
} else { |
50 |
throw new ExpressionRuntimeException("The "+NAME+" function require a File, URI or a String and a received a '"+obj.getClass().getSimpleName()+"'.");
|
|
49 |
throw new ExpressionRuntimeException("The "+FUNCTION_URL+" function require a File, URI or a String and a received a '"+obj.getClass().getSimpleName()+"'.");
|
|
51 | 50 |
} |
52 | 51 |
return value; |
53 | 52 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/programming/GetattrFunction.java | ||
---|---|---|
3 | 3 |
import java.lang.reflect.Field; |
4 | 4 |
import org.apache.commons.lang3.Range; |
5 | 5 |
import org.gvsig.expressionevaluator.AttributeHandler; |
6 |
import org.gvsig.expressionevaluator.Code; |
|
7 |
import org.gvsig.expressionevaluator.Codes; |
|
6 | 8 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_GETATTR; |
9 |
import org.gvsig.expressionevaluator.Formatter; |
|
7 | 10 |
import org.gvsig.expressionevaluator.Function; |
8 | 11 |
import org.gvsig.expressionevaluator.Interpreter; |
9 | 12 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
10 | 13 |
import org.gvsig.tools.dynobject.DynObject; |
11 |
import org.gvsig.tools.util.GetItemByKey; |
|
12 | 14 |
|
13 | 15 |
public class GetattrFunction extends AbstractFunction { |
14 | 16 |
|
... | ... | |
52 | 54 |
} |
53 | 55 |
return value; |
54 | 56 |
} |
57 |
|
|
58 |
@Override |
|
59 |
public String toString(Codes args, Formatter<Code> formatter) { |
|
60 |
StringBuilder builder = new StringBuilder(); |
|
61 |
Code arg0 = args.get(0); |
|
62 |
Code arg1 = args.get(1); |
|
63 |
if( arg0 instanceof Code.Identifier && arg1 instanceof Code.Identifier ) { |
|
64 |
builder.append(arg0.toString(formatter)); |
|
65 |
builder.append("."); |
|
66 |
builder.append(arg1.toString()); |
|
67 |
} else { |
|
68 |
builder.append(this.name()); |
|
69 |
builder.append("("); |
|
70 |
builder.append(arg0.toString(formatter)); |
|
71 |
builder.append(", "); |
|
72 |
builder.append(arg1.toString(formatter)); |
|
73 |
builder.append(")"); |
|
74 |
} |
|
75 |
return builder.toString(); |
|
76 |
} |
|
55 | 77 |
|
56 | 78 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/programming/ListFunction.java | ||
---|---|---|
4 | 4 |
import java.util.Arrays; |
5 | 5 |
import java.util.List; |
6 | 6 |
import org.apache.commons.lang3.Range; |
7 |
import org.gvsig.expressionevaluator.Code; |
|
8 |
import org.gvsig.expressionevaluator.Codes; |
|
7 | 9 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_LIST; |
10 |
import org.gvsig.expressionevaluator.Formatter; |
|
8 | 11 |
import org.gvsig.expressionevaluator.Function; |
9 | 12 |
import org.gvsig.expressionevaluator.Interpreter; |
10 | 13 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
... | ... | |
34 | 37 |
list.addAll(Arrays.asList(args)); |
35 | 38 |
return list; |
36 | 39 |
} |
40 |
|
|
41 |
@Override |
|
42 |
public String toString(Codes args, Formatter<Code> formatter) { |
|
43 |
StringBuilder builder = new StringBuilder(); |
|
44 |
builder.append("[ "); |
|
45 |
builder.append(args.toString(formatter)); |
|
46 |
builder.append(" ]"); |
|
47 |
return builder.toString(); |
|
48 |
} |
|
49 |
|
|
50 |
|
|
37 | 51 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/programming/UrlReadByteArrayFunction.java | ||
---|---|---|
1 |
package org.gvsig.expressionevaluator.impl.function.programming; |
|
2 |
|
|
3 |
import java.net.URL; |
|
4 |
import org.apache.commons.io.IOUtils; |
|
5 |
import org.apache.commons.lang3.Range; |
|
6 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_URLREADBYTES; |
|
7 |
import org.gvsig.expressionevaluator.Function; |
|
8 |
import org.gvsig.expressionevaluator.Interpreter; |
|
9 |
import org.gvsig.expressionevaluator.impl.function.programming.UrlReadFunction.X509TrustAllManager; |
|
10 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
|
11 |
|
|
12 |
/** |
|
13 |
* |
|
14 |
* @author jjdelcerro |
|
15 |
*/ |
|
16 |
public class UrlReadByteArrayFunction extends AbstractFunction { |
|
17 |
|
|
18 |
public UrlReadByteArrayFunction() { |
|
19 |
super(Function.GROUP_PROGRAMMING, |
|
20 |
FUNCTION_URLREADBYTES, |
|
21 |
Range.is(1), |
|
22 |
null, |
|
23 |
FUNCTION_URLREADBYTES+"({{expression}})", |
|
24 |
null, |
|
25 |
"String", |
|
26 |
false |
|
27 |
); |
|
28 |
this.addAlias("URLREADBYTES"); |
|
29 |
} |
Also available in: Unified diff