public static void jsFunction_printf()

in src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptablePrintWriter.java [82:123]


    public static void jsFunction_printf(Context cx, Scriptable thisObj,
            Object[] args, Function funObj) {

        if (args.length > 0) {

            // the index of the next argument to consider
            int nextIdx = 0;

            // the local for printf
            Locale locale = null;

            if (args[nextIdx] instanceof Locale) {

                // the Locale is the first argument, use it an increment idx
                locale = (Locale) args[nextIdx];
                nextIdx++;

            } else {

                // get the per-HTTP request local or the default locale
                locale = ((ScriptablePrintWriter) thisObj).getLocale();
            }

            // only continue, if there is at least an other argument
            // containing the format string
            if (args.length > nextIdx) {

                // the format string
                String format = ScriptRuntime.toString(args[nextIdx]);

                // arguments starting after that are formatting arguments
                nextIdx++;
                Object[] formatArgs = new Object[args.length - nextIdx];
                System.arraycopy(args, nextIdx, formatArgs, 0,
                    formatArgs.length);

                // now get the writer and call printf
                PrintWriter writer = ((ScriptablePrintWriter) thisObj).writer;
                writer.printf(locale, format, formatArgs);
            }
        }
    }