Browse Source

增加授权插件的编写示例

pull/3/head
richie 6 years ago
parent
commit
55ce7b22af
  1. 2
      plugin-function/build.xml
  2. 0
      plugin-function/lib/report/.gitkeep
  3. 1
      plugin-function/plugin.xml
  4. 17
      plugin-function/src/main/java/com/fr/plugin/MyAbs.java

2
plugin-function/build.xml

@ -5,7 +5,7 @@
<property name="libs" value="${basedir}/lib"/>
<property name="publicLibs" value=""/>
<property name="reportLibs" value="lib/report"/>
<property name="reportLibs" value="${basedir}/../webroot/WEB-INF/lib"/>
<property name="destLoc" value="."/>
<property name="classes" value="classes"/>
<xmlproperty file="${basedir}/plugin.xml"/>

0
plugin-function/lib/report/.gitkeep

1
plugin-function/plugin.xml

@ -15,4 +15,5 @@
<FunctionDefineProvider class="com.fr.plugin.MyAbs" name="MyAbs" description="求绝对值,支持数组。"/>
<LocaleFinder class="com.fr.plugin.MyLocaleFinder"/>
</extra-core>
<function-recorder class="com.fr.plugin.MyAbs"/>
</plugin>

17
plugin-function/src/main/java/com/fr/plugin/MyAbs.java

@ -24,13 +24,24 @@ public class MyAbs extends AbstractFunction {
if (len == 0) {
return Primitive.ERROR_VALUE;
} else if (len == 1) {
return Math.abs(GeneralUtils.objectToNumber(args[0]).doubleValue());
Object one = args[0];
if (one instanceof FArray) {
FArray data = (FArray)one;
FArray<Double> result = new FArray<Double>();
for (Object el : data) {
result.add(Math.abs(GeneralUtils.objectToNumber(el).doubleValue()));
}
return result;
} else {
return Math.abs(GeneralUtils.objectToNumber(one).doubleValue());
}
} else {
FArray<Double> result = new FArray<Double>();
for (Object arg : args) {
result.add(GeneralUtils.objectToNumber(arg).doubleValue());
result.add(Math.abs(GeneralUtils.objectToNumber(arg).doubleValue()));
}
return result;
}
return Primitive.ERROR_VALUE;
}
}

Loading…
Cancel
Save