static VariableScope getVariableScope( String codeOfScope ) { switch ( codeOfScope ) { case "s": return VariableScope.SYSTEM; case "r": return VariableScope.ROOT; case "p": return VariableScope.PARENT; case "g": return VariableScope.GRAND_PARENT; default: throw Context.reportRuntimeError( "The argument type of function call " + "setVariable should either be \"s\", \"r\", \"p\", or \"g\"." ); } }
public static void setEnvironmentVar( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { String sArg1 = ""; String sArg2 = ""; if ( ArgList.length == 2 ) { try { sArg1 = Context.toString( ArgList[0] ); sArg2 = Context.toString( ArgList[1] ); System.setProperty( sArg1, sArg2 ); } catch ( Exception e ) { throw Context.reportRuntimeError( e.toString() ); } } else { throw Context.reportRuntimeError( "The function call setEnvironmentVar requires 2 arguments." ); } }
public static void touch( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { try { if ( ArgList.length == 1 && !isNull( ArgList[0] ) && !isUndefined( ArgList[0] ) ) { File file = new File( Context.toString( ArgList[0] ) ); boolean success = file.createNewFile(); if ( !success ) { file.setLastModified( System.currentTimeMillis() ); } } else { throw Context.reportRuntimeError( "The function call touch requires 1 valid argument." ); } } catch ( Exception e ) { throw Context.reportRuntimeError( e.toString() ); } }
public static Object fileExists( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { try { if ( ArgList.length == 1 && !isNull( ArgList[0] ) && !isUndefined( ArgList[0] ) ) { if ( ArgList[0].equals( null ) ) { return null; } File file = new File( Context.toString( ArgList[0] ) ); return Boolean.valueOf( file.isFile() ); } else { throw Context.reportRuntimeError( "The function call fileExists requires 1 valid argument." ); } } catch ( Exception e ) { throw Context.reportRuntimeError( e.toString() ); } }
public static Object getTransformationName( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { try { Object objTranName = Context.toString( actualObject.get( "_TransformationName_", actualObject ) ); return objTranName; } catch ( Exception e ) { throw Context.reportRuntimeError( e.toString() ); } }
public static void appendToFile( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { if ( !isNull( ArgList ) && !isUndefined( ArgList ) ) { try { FileOutputStream file = new FileOutputStream( Context.toString( ArgList[0] ), true ); DataOutputStream out = new DataOutputStream( file ); out.writeBytes( Context.toString( ArgList[1] ) ); out.flush(); out.close(); } catch ( Exception er ) { throw Context.reportRuntimeError( er.toString() ); } } else { throw Context.reportRuntimeError( "The function call appendToFile requires arguments." ); } }
public static Object[] createRowCopy( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { if ( ArgList.length == 1 ) { try { int newSize = (int) Math.round( Context.toNumber( ArgList[0] ) ); Object scmO = actualObject.get( "row", actualObject ); Object[] row = (Object[]) Context.jsToJava( scmO, ( new Object[] {} ).getClass() ); return RowDataUtil.createResizedCopy( row, newSize ); } catch ( Exception e ) { throw Context.reportRuntimeError( "Unable to create a row copy: " + Const.CR + e.toString() ); } } else { throw Context .reportRuntimeError( "The function call createRowCopy requires a single arguments : the new size of the row" ); } }
public static String unEscapeXml( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { if ( ArgList.length == 1 ) { return Const.unEscapeXml( Context.toString( ArgList[0] ) ); } else { throw Context.reportRuntimeError( "The function call unEscapeXml requires 1 argument." ); } }
public static String escapeSQL( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { if ( ArgList.length == 1 ) { return Const.escapeSQL( Context.toString( ArgList[0] ) ); } else { throw Context.reportRuntimeError( "The function call escapeSQL requires 1 argument." ); } }
public static String removeDigits( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { if ( ArgList.length == 1 ) { return Const.removeDigits( Context.toString( ArgList[0] ) ); } else { throw Context.reportRuntimeError( "The function call removeDigits requires 1 argument." ); } }
public static String unEscapeHtml( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { if ( ArgList.length == 1 ) { return Const.unEscapeHtml( Context.toString( ArgList[0] ) ); } else { throw Context.reportRuntimeError( "The function call unEscapeHtml requires 1 argument." ); } }
public static String protectXMLCDATA( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { if ( ArgList.length == 1 ) { return Const.protectXMLCDATA( Context.toString( ArgList[0] ) ); } else { throw Context.reportRuntimeError( "The function call protectXMLCDATA requires 1 argument." ); } }
public static String escapeXml( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { if ( ArgList.length == 1 ) { return Const.escapeXML( Context.toString( ArgList[0] ) ); } else { throw Context.reportRuntimeError( "The function call escapeXml requires 1 argument." ); } }
public static String getDigitsOnly( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { if ( ArgList.length == 1 ) { return Const.getDigitsOnly( Context.toString( ArgList[0] ) ); } else { throw Context.reportRuntimeError( "The function call getDigitsOnly requires 1 argument." ); } }
public static String escapeHtml( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { if ( ArgList.length == 1 ) { return Const.escapeHtml( Context.toString( ArgList[0] ) ); } else { throw Context.reportRuntimeError( "The function call escapeHtml requires 1 argument." ); } }
public static String initCap( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { if ( ArgList.length == 1 ) { return Const.initCap( Context.toString( ArgList[0] ) ); } else { throw Context.reportRuntimeError( "The function call initCap requires 1 argument." ); } }
public static String ltrim( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { try { if ( ArgList.length == 1 ) { if ( isNull( ArgList[0] ) ) { return null; } else if ( isUndefined( ArgList[0] ) ) { return (String) Context.getUndefinedValue(); } String strValueToTrim = Context.toString( ArgList[0] ); return strValueToTrim.replaceAll( "^\\s+", "" ); } else { throw Context.reportRuntimeError( "The function call ltrim requires 1 argument." ); } } catch ( Exception e ) { throw Context.reportRuntimeError( "The function call ltrim is not valid : " + e.getMessage() ); } }
public static String rtrim( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { try { if ( ArgList.length == 1 ) { if ( isNull( ArgList[0] ) ) { return null; } else if ( isUndefined( ArgList[0] ) ) { return (String) Context.getUndefinedValue(); } String strValueToTrim = Context.toString( ArgList[0] ); return strValueToTrim.replaceAll( "\\s+$", "" ); } else { throw Context.reportRuntimeError( "The function call rtrim requires 1 argument." ); } } catch ( Exception e ) { throw Context.reportRuntimeError( "The function call rtrim is not valid : " + e.getMessage() ); } }
public static Object abs( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { if ( ArgList.length == 1 ) { try { if ( isNull( ArgList[0] ) ) { return new Double( Double.NaN ); } else if ( isUndefined( ArgList[0] ) ) { return Context.getUndefinedValue(); } else { return new Double( Math.abs( Context.toNumber( ArgList[0] ) ) ); } } catch ( Exception e ) { return null; } } else { throw Context.reportRuntimeError( "The function call abs requires 1 argument." ); } }
public static String removeCRLF( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { if ( ArgList.length == 1 ) { try { if ( isNull( ArgList[0] ) ) { return null; } else if ( isUndefined( ArgList[0] ) ) { return (String) Context.getUndefinedValue(); } return Const.removeCRLF( Context.toString( ArgList[0] ) ); } catch ( Exception e ) { throw Context.reportRuntimeError( "The function call removeCRLF is not valid" ); } } else { throw Context.reportRuntimeError( "The function call removeCRLF is not valid" ); } } }