KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > utils > JahiaConsole


1 /********************************************************************/
2 /* JAHIA */
3 /* Class Name : JahiaConsole */
4 /* Function : Manages Jahia console messages */
5 /* Created : 08-10-2000 */
6 /* Author : Eric Vassalli */
7 /* Interface : */
8 /* print( String ) : prints a message in console */
9 /* println( String ) : prints a message in console with \n */
10 /* startup() : displays cool startup message :) */
11 /* Copyright 2002 Jahia Ltd */
12 /********************************************************************/
13
14 package org.jahia.utils;
15
16 import javax.servlet.GenericServlet JavaDoc;
17
18 public class JahiaConsole {
19
20     private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(JahiaConsole.class);
21
22     /**
23      * Constants for logging levels {
24      */

25     public static final int DEFAULT_LOGGING_LEVEL = 3;
26     public static final int MAX_LOGGING_LEVEL = 10;
27     public static final int CONSOLE_LOGGING_LEVEL = 9;
28     /**
29      * }
30      */

31
32     private static String JavaDoc prefix = "Jahia > ";
33     private static GenericServlet JavaDoc servlet = null;
34     private static int currentLoggingLevel = 0;
35
36
37     /***
38         * constructor
39         * EV 08.10.2000
40         *
41         */

42     private JahiaConsole()
43     {
44         println( "JahiaConsole", "***** Starting Jahia Console" );
45     } // end constructor
46

47
48     public static void setServlet(GenericServlet JavaDoc servletRef) {
49         servlet = servletRef;
50     }
51
52     public static void setLoggingLevel(int level) {
53         currentLoggingLevel = level;
54     }
55
56     /***
57         * print
58         * EV 08.10.2000
59         *
60         */

61     public static void print( String JavaDoc origin, String JavaDoc msg )
62     {
63         logger.debug(origin + " > " + msg);
64
65 /*
66         if (servlet != null) {
67             if (currentLoggingLevel >= DEFAULT_LOGGING_LEVEL) {
68               servlet.log(origin + " > " + msg);
69             }
70         }
71 */

72     } // end print
73

74
75     /***
76         * println
77         * EV 08.10.2000
78         *
79         */

80     public static void println( String JavaDoc origin, String JavaDoc msg )
81     {
82
83         logger.debug(origin + "> " + msg);
84 /*
85         if (servlet != null) {
86             if (currentLoggingLevel >= DEFAULT_LOGGING_LEVEL) {
87                 servlet.log(origin + " > " + msg);
88             }
89             if (currentLoggingLevel >= CONSOLE_LOGGING_LEVEL) {
90                 System.out.println (origin + "> " + msg);
91             }
92         }
93 */

94     } // end println
95

96     /**
97      * Small utility function to print stack trace on the Jahia console.
98      * @param origin a String representing the origin of the message. Recommended
99      * format is class.method
100      * @param t the exception whose stack trace will be dumped into the Jahia
101      * Console.
102      * @author Serge Huber.
103      */

104     public static void printe( String JavaDoc origin, Throwable JavaDoc t ) {
105         logger.debug(origin, t);
106 /*
107         String msg;
108         StringWriter strWriter = new StringWriter();
109         PrintWriter ptrWriter = new PrintWriter(strWriter);
110         t.printStackTrace(ptrWriter);
111         msg = strWriter.toString();
112         if (servlet != null) {
113             if (currentLoggingLevel >= DEFAULT_LOGGING_LEVEL) {
114                 servlet.log(origin + " > " + msg);
115             }
116             if (currentLoggingLevel >= CONSOLE_LOGGING_LEVEL) {
117                 System.out.println (origin + "> " + msg);
118             }
119         }
120 */

121     }
122
123    /**
124     * Prints a message on the console.
125     * THIS METHOD SHOULD BE CALLED ONLY IF YOU WANT YOUR MESSAGE TO BE DISPLAYED IN THE
126     * RELEASE VERSION OF JAHIA. Don't abuse ;-)
127     */

128     public static synchronized void finalPrintln( String JavaDoc origin, String JavaDoc msg )
129     {
130         logger.info(origin + "> " + msg);
131         // System.out.println (origin + "> " + msg);
132
} // end println
133
public static synchronized void finalPrint( String JavaDoc origin, String JavaDoc msg )
134     {
135         logger.info(origin + "> " + msg);
136         // System.out.print (origin + "> " + msg);
137
} // end println
138

139
140
141     /***
142         * startup
143         * EV 08.10.2000
144         *
145         */

146     public static void startup( int buildNumber )
147     {
148         String JavaDoc msg = "";
149         msg += "***********************************\n";
150         msg += " Starting Jahia - Build " + buildNumber + "\n";
151         msg += " \"Today's a great day ! \"\n";
152         msg += "***********************************\n";
153         JahiaConsole.println("JahiaConsole.startup","\n\n" + msg + "\n" );
154         println( "Jahia", "***** Starting Jahia *****" );
155     } // end startup
156

157
158
159     /***
160         * startupWithTrust
161         * AK 20.01.2001
162         *
163         */

164     public static void startupWithTrust( int buildNumber )
165     {
166         Integer JavaDoc buildNumberInteger = new Integer JavaDoc(buildNumber);
167         String JavaDoc buildString = buildNumberInteger.toString();
168         StringBuffer JavaDoc buildBuffer = new StringBuffer JavaDoc();
169
170         for(int i=0; i < buildString.length(); i++) {
171             buildBuffer.append(" ");
172             buildBuffer.append(buildString.substring(i, i+1));
173         }
174
175         StringBuffer JavaDoc msg = new StringBuffer JavaDoc ("\n\n\n\n");
176         msg.append (" ____.\n");
177         msg.append (" __/\\ ______| |__/\\. _______\n");
178         msg.append (" __ .____| | \\ | +----+ \\\n");
179         msg.append (" _______| /--| | | - \\ _ | : - \\_________\n");
180         msg.append (" \\\\______: :---| : : | : | \\________>\n");
181         msg.append (" |__\\---\\_____________:______: :____|____:_____\\\n");
182         msg.append (" /_____|\n");
183         msg.append ("\n");
184         msg.append (" . . . s t a r t i n g j a h i a b u i l d " + buildBuffer.toString() + " . . .\n");
185         msg.append ("\n\n");
186         msg.append (" Copyright 2002-2007 - jahia http://www.jahia.org - all rights reserved\n");
187         msg.append ("\n\n");
188         msg.append (" **************************************************************************\n");
189         msg.append (" * The contents of this file, or the files included with this file, are *\n");
190         msg.append (" * subject to the current version of JAHIA Community Source License for *\n");
191         msg.append (" * the Jahia Portal Server (the \"License\"); You may not use this file *\n");
192         msg.append (" * except in compliance with the License. You may obtain a copy of the *\n");
193         msg.append (" * License at http://www.jahia.org. See the License for the rights, *\n");
194         msg.append (" * obligations and limitations governing use of the contents of the file. *\n");
195         msg.append (" * The Original and Upgraded Code is the Jahia Portal Server. The *\n");
196         msg.append (" * developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA Ltd. *\n");
197         msg.append (" * owns the copyrights in the portions it created. All Rights Reserved. *\n");
198         msg.append (" **************************************************************************\n");
199         msg.append ("\n\n");
200
201         System.out.println (msg.toString());
202         System.out.flush();
203     } // end startupWithTrust
204

205 }
206
Popular Tags