001    package railo.commons.lang;
002    
003    import java.io.PrintWriter;
004    import java.util.Date;
005    
006    import railo.runtime.PageContext;
007    import railo.runtime.config.Config;
008    import railo.runtime.engine.ThreadLocalPageContext;
009    
010    public final class SystemOut {
011    
012            public static int OUT=1;
013            public static int ERR=2;
014            
015        /**
016         * logs a value 
017         * @param value
018         */
019        public static void printDate(PrintWriter pw,String value) {
020            long millis=System.currentTimeMillis();
021            pw.write(
022                            new Date(millis)
023                            +"-"
024                            +(millis-(millis/1000*1000))
025                            +" "+value+"\n");
026            pw.flush();
027        }
028        /**
029         * logs a value 
030         * @param value
031         */
032        public static void print(PrintWriter pw,String value) {
033            pw.write(value+"\n");
034            pw.flush();
035        } 
036    
037    
038            public static void printStack(PrintWriter pw) {
039                    new Throwable().printStackTrace(pw);
040            }
041    
042            public static void printStack(int type) {
043                    Config config=ThreadLocalPageContext.getConfig();
044            if(config!=null) {
045                    if(type==ERR)
046                            printStack(config.getErrWriter());
047                    else 
048                            printStack(config.getOutWriter());
049            }
050            else {
051                    printStack(new PrintWriter((type==ERR)?System.err:System.out));
052            }
053            }
054        
055        /**
056         * logs a value 
057         * @param value
058         */
059        public static void printDate(String value) {
060            printDate(value,OUT);
061        }
062        
063        public static void printDate(String value,int type) {
064            printDate(getPrinWriter(type),value);
065        }
066        
067    
068        public static PrintWriter getPrinWriter(int type) {
069            Config config=ThreadLocalPageContext.getConfig();
070            if(config!=null) {
071                    if(type==ERR) return config.getErrWriter();
072                    return config.getOutWriter();
073            }
074            return new PrintWriter((type==ERR)?System.err:System.out);
075        }
076        
077        
078        
079        /**
080         * logs a value 
081         * @param value
082         */
083        
084        public static void print(String value) {
085            print(value, OUT);
086        }
087        
088        public static void print(String value,int type) {
089            PageContext pc=ThreadLocalPageContext.get();
090            if(pc!=null) {
091                    if(type==ERR)
092                            print(pc.getConfig().getErrWriter(),value);
093                    else 
094                            print(pc.getConfig().getOutWriter(),value);
095            }
096            else {
097                    print(new PrintWriter((type==ERR)?System.err:System.out),value);
098            }
099        }
100    
101    }