private static boolean isNull( Object ArgList ) { return isNull( new Object[] { ArgList }, new int[] { 0 } ); }
public static Object fileExists( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext ) { try { if ( ArgList.length == 1 && !isNull( ArgList[0] ) && !isUndefined( ArgList[0] ) ) { if ( ArgList[0].equals( null ) ) { return null; } File file = new File( (String) ArgList[0] ); return Boolean.valueOf( file.isFile() ); } else { throw new RuntimeException( "The function call fileExists requires 1 valid argument." ); } } catch ( Exception e ) { throw new RuntimeException( e.toString() ); } }
public static void appendToFile( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext ) { if ( !isNull( ArgList ) && !isUndefined( ArgList ) ) { try { FileOutputStream file = new FileOutputStream( (String) ArgList[0], true ); DataOutputStream out = new DataOutputStream( file ); out.writeBytes( (String) ArgList[1] ); out.flush(); out.close(); } catch ( Exception er ) { throw new RuntimeException( er.toString() ); } } else { throw new RuntimeException( "The function call appendToFile requires arguments." ); } }
public static void touch( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext ) { try { if ( ArgList.length == 1 && !isNull( ArgList[0] ) && !isUndefined( ArgList[0] ) ) { File file = new File( (String) ArgList[0] ); boolean success = file.createNewFile(); if ( !success ) { file.setLastModified( System.currentTimeMillis() ); } } else { throw new RuntimeException( "The function call touch requires 1 valid argument." ); } } catch ( Exception e ) { throw new RuntimeException( e.toString() ); } }
public static int indexOf( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext ) { int returnIndex = -1; if ( ArgList.length == 2 || ArgList.length == 3 ) { if ( !isNull( ArgList ) && !isUndefined( ArgList ) ) { String string = (String) ArgList[0]; String subString = (String) ArgList[1]; int fromIndex = 0; if ( ArgList.length == 3 ) { fromIndex = (int) Math.round( (Double) ArgList[2] ); } returnIndex = string.indexOf( subString, fromIndex ); } } else { throw new RuntimeException( "The function call indexOf requires 2 or 3 arguments" ); } return returnIndex; }
public static String ltrim( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext ) { try { if ( ArgList.length == 1 ) { if ( isNull( ArgList[0] ) ) { return null; } else if ( isUndefined( ArgList[0] ) ) { return (String) undefinedValue; } String strValueToTrim = (String) ArgList[0]; return strValueToTrim.replaceAll( "^\\s+", "" ); } else { throw new RuntimeException( "The function call ltrim requires 1 argument." ); } } catch ( Exception e ) { throw new RuntimeException( "The function call ltrim is not valid : " + e.getMessage() ); } }
public static Object abs( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext ) { if ( ArgList.length == 1 ) { try { if ( isNull( ArgList[0] ) ) { return new Double( Double.NaN ); } else if ( isUndefined( ArgList[0] ) ) { return undefinedValue; } else { return new Double( Math.abs( (Double) ArgList[0] ) ); } } catch ( Exception e ) { return null; } } else { throw new RuntimeException( "The function call abs requires 1 argument." ); } }
public static Object isDate( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext ) { if ( ArgList.length == 1 ) { try { if ( isNull( ArgList[0] ) ) { return null; } else if ( isUndefined( ArgList[0] ) ) { return undefinedValue; } /* java.util.Date d = (java.util.Date) */ return Boolean.TRUE; } catch ( Exception e ) { return Boolean.FALSE; } } else { throw new RuntimeException( "The function call isDate requires 1 argument." ); } }
public static Object ceil( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext ) { if ( ArgList.length == 1 ) { try { if ( isNull( ArgList[0] ) ) { return new Double( Double.NaN ); } else if ( isUndefined( ArgList[0] ) ) { return undefinedValue; } else { return new Double( Math.ceil( (Double) ArgList[0] ) ); } } catch ( Exception e ) { return null; } } else { throw new RuntimeException( "The function call ceil requires 1 argument." ); } }
public static String rtrim( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext ) { try { if ( ArgList.length == 1 ) { if ( isNull( ArgList[0] ) ) { return null; } else if ( isUndefined( ArgList[0] ) ) { return (String) undefinedValue; } String strValueToTrim = (String) ArgList[0]; return strValueToTrim.replaceAll( "\\s+$", "" ); } else { throw new RuntimeException( "The function call rtrim requires 1 argument." ); } } catch ( Exception e ) { throw new RuntimeException( "The function call rtrim is not valid : " + e.getMessage() ); } }
public static Object floor( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext ) { if ( ArgList.length == 1 ) { try { if ( isNull( ArgList[0] ) ) { return new Double( Double.NaN ); } else if ( isUndefined( ArgList[0] ) ) { return undefinedValue; } else { return new Double( Math.floor( (Double) ArgList[0] ) ); } } catch ( Exception e ) { return null; // throw new RuntimeException(e.toString()); } } else { throw new RuntimeException( "The function call floor requires 1 argument." ); } }
public static Object month( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext ) { try { if ( ArgList.length == 1 ) { if ( isNull( ArgList[0] ) ) { return new Double( Double.NaN ); } else if ( isUndefined( ArgList[0] ) ) { return undefinedValue; } java.util.Date dArg1 = (java.util.Date) ArgList[0]; Calendar cal = Calendar.getInstance(); cal.setTime( dArg1 ); return new Double( cal.get( Calendar.MONTH ) ); } else { throw new RuntimeException( "The function call month requires 1 argument." ); } } catch ( Exception e ) { throw new RuntimeException( e.toString() ); } }
public static String upper( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext ) { String sRC = ""; if ( ArgList.length == 1 ) { try { if ( isNull( ArgList[0] ) ) { return null; } else if ( isUndefined( ArgList[0] ) ) { return (String) undefinedValue; } sRC = (String) ArgList[0]; sRC = sRC.toUpperCase(); } catch ( Exception e ) { throw new RuntimeException( "The function call upper is not valid : " + e.getMessage() ); } } else { throw new RuntimeException( "The function call upper requires 1 argument." ); } return sRC; }
public static Object isRegExp( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext ) { if ( ArgList.length >= 2 ) { if ( isNull( ArgList, new int[] { 0, 1 } ) ) { return null; } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) { return undefinedValue; } String strToMatch = (String) ArgList[0]; for ( int i = 1; i < ArgList.length; i++ ) { Pattern p = Pattern.compile( (String) ArgList[i] ); Matcher m = p.matcher( strToMatch ); if ( m.matches() ) { return new Double( i ); } } } return new Double( -1 ); }
public static String rpad( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext ) { try { if ( ArgList.length == 3 ) { if ( isNull( ArgList, new int[] { 0, 1, 2 } ) ) { return null; } else if ( isUndefined( ArgList, new int[] { 0, 1, 2 } ) ) { return (String) undefinedValue; } String valueToPad = (String) ArgList[0]; String filler = (String) ArgList[1]; int size = (Integer) ArgList[2]; while ( valueToPad.length() < size ) { valueToPad = valueToPad + filler; } return valueToPad; } } catch ( Exception e ) { throw new RuntimeException( "The function call rpad requires 3 arguments." ); } return null; }
public static Object year( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext ) { try { if ( ArgList.length == 1 ) { if ( isNull( ArgList[0] ) ) { return new Double( Double.NaN ); } else if ( isUndefined( ArgList[0] ) ) { return undefinedValue; } java.util.Date dArg1 = (java.util.Date) ArgList[0]; Calendar cal = Calendar.getInstance(); cal.setTime( dArg1 ); return new Double( cal.get( Calendar.YEAR ) ); } else { throw new RuntimeException( "The function call year requires 1 argument." ); } } catch ( Exception e ) { throw new RuntimeException( e.toString() ); } }
public static Object week( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext ) { try { if ( ArgList.length == 1 ) { if ( isNull( ArgList[0] ) ) { return new Double( Double.NaN ); } else if ( isUndefined( ArgList[0] ) ) { return undefinedValue; } java.util.Date dArg1 = (java.util.Date) ArgList[0]; Calendar cal = Calendar.getInstance(); cal.setTime( dArg1 ); return new Double( cal.get( Calendar.WEEK_OF_YEAR ) ); } else { throw new RuntimeException( "The function call week requires 1 argument." ); } } catch ( Exception e ) { throw new RuntimeException( e.toString() ); } }
public static String lower( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext ) { String sRC = ""; if ( ArgList.length == 1 ) { try { if ( isNull( ArgList[0] ) ) { return null; } else if ( isUndefined( ArgList[0] ) ) { return (String) undefinedValue; } sRC = (String) ArgList[0]; sRC = sRC.toLowerCase(); } catch ( Exception e ) { throw new RuntimeException( "The function call lower is not valid : " + e.getMessage() ); } } else { throw new RuntimeException( "The function call lower requires 1 argument." ); } return sRC; }
public static String replace( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext ) { try { if ( ArgList.length >= 2 && ( ArgList.length - 1 ) % 2 == 0 ) { if ( isNull( ArgList, new int[] { 0, 1 } ) ) { return null; } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) { return (String) undefinedValue; } String objForReplace = (String) ArgList[0]; for ( int i = 1; i < ArgList.length - 1; i = i + 2 ) { objForReplace = objForReplace.replaceAll( (String) ArgList[i], (String) ArgList[i + 1] ); } return objForReplace; } else { throw new RuntimeException( "The function call replace is not valid (wrong number of arguments)" ); } } catch ( Exception e ) { throw new RuntimeException( "Function call replace is not valid : " + e.getMessage() ); } }
public static String trim( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext ) { String sRC = ""; if ( ArgList.length == 1 ) { try { if ( isNull( ArgList[0] ) ) { return null; } else if ( isUndefined( ArgList[0] ) ) { return (String) undefinedValue; } sRC = (String) ArgList[0]; sRC = Const.trim( sRC ); } catch ( Exception e ) { throw new RuntimeException( "The function call trim is not valid : " + e.getMessage() ); } } else { throw new RuntimeException( "The function call trim requires 1 argument." ); } return sRC; }