Author: ktlili
Date: Thu Jun 21 16:32:13 2007
New Revision: 59
URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D59&repname=3D=
addressbook
Log:
- remove prtinln
- add log4j, less verbose
Modified:
trunk/war/src/java/org/jahia/tools/Tools.java
trunk/war/src/java/org/jahia/tools/db/AddressBookDBServices.java
trunk/war/src/java/org/jahia/tools/files/FileDownload.java
trunk/war/src/java/org/jahia/webapps/addressbook/AddressBookServlet.java
trunk/war/src/java/org/jahia/webapps/util/ActionHandler.java
trunk/war/src/webapp/jsp/edit_form.jsp
Modified: trunk/war/src/java/org/jahia/tools/Tools.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/war/src/java/or=
g/jahia/tools/Tools.java&rev=3D59&repname=3Daddressbook
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/war/src/java/org/jahia/tools/Tools.java (original)
+++ trunk/war/src/java/org/jahia/tools/Tools.java Thu Jun 21 16:32:13 2007
@@ -3,6 +3,8 @@
import java.util.*;
import java.text.*;
=
+import org.apache.log4j.*;
+
/**
* @author Jerome Tamiotti <a href=3D"mailto:[EMAIL PROTECTED]">j=
[EMAIL PROTECTED]</a>
*/
@@ -10,77 +12,74 @@
=
/**
* Class Tools: provides tools like debug printing, date managing...
- *
*/
-public class Tools
-{
-
- // the mask used for date display
- private static String mask =3D "EEE, MMM d, yyyy";
+public class Tools {
+ private static org.apache.log4j.Logger logger =3D
+ org.apache.log4j.Logger.getLogger(Tools.class);
+ // the mask used for date display
+ private static String mask =3D "EEE, MMM d, yyyy";
=
- private static boolean debugInfo =3D true;
+ private static boolean debugInfo =3D true;
=
- /**
+ /**
* Method toConsole: print a debug message into server console
- *
- * @param localisation the current class name followed by the method
n=
ame
- * @param msg the msg to print
- */
- static public void toConsole(String localisation, String msg)
- {
- if (debugInfo) {
- System.out.println(">> " + localisation + "(): " + msg);
- }
+ *
+ * @param localisation the current class name followed by the method n=
ame
+ * @param msg the msg to print
+ */
+ static public void toConsole(String localisation, String msg) {
+ if (debugInfo) {
+ logger.info(">> " + localisation + "(): " + msg);
+ }
}
=
- /**
+ /**
* Method toConsole: print a debug message into server console
- *
- * @param msg the msg to print
+ *
+ * @param msg the msg to print
*/
- static public void toConsole(String msg)
- {
- if (debugInfo) {
- System.out.println(">> " + msg);
- }
- }
- /**
- * Replaces a token in a string with another given String
- *
- * @param str the String to be parsed
- * @param token the token to be found and replaced
- * @param replaceValue the value to insert where token is found
- * @return the new String
- */
- public static String replace(String str, String token,
- String replaceValue) {
-
- String result =3D "";
- int i =3D str.indexOf(token);
- while (i !=3D -1) {
- result +=3D str.substring(0,i) + replaceValue;
- str =3D str.substring(i + token.length(), str.length());
- i =3D str.indexOf(token);
- }
- return result + str;
+ static public void toConsole(String msg) {
+ if (debugInfo) {
+ logger.info(">> " + msg);
}
+ }
=
+ /**
+ * Replaces a token in a string with another given String
+ *
+ * @param str the String to be parsed
+ * @param token the token to be found and replaced
+ * @param replaceValue the value to insert where token is found
+ * @return the new String
+ */
+ public static String replace(String str, String token,
+ String replaceValue) {
=
- /**
+ String result =3D "";
+ int i =3D str.indexOf(token);
+ while (i !=3D -1) {
+ result +=3D str.substring(0, i) + replaceValue;
+ str =3D str.substring(i + token.length(), str.length());
+ i =3D str.indexOf(token);
+ }
+ return result + str;
+ }
+
+
+ /**
* Method replacePattern : replace a pattern in a text with another o=
ne
- *
- * @param str the text to alter
- * @param oldToken the token to replace
- * @param newToken the new text
- *
- * @return the altered text
+ *
+ * @param str the text to alter
+ * @param oldToken the token to replace
+ * @param newToken the new text
+ * @return the altered text
*/
- static public String replacePattern(String str, String oldToken, String
n=
ewToken) {
+ static public String replacePattern(String str, String oldToken, Strin=
g newToken) {
=
String result =3D "";
int i =3D str.indexOf(oldToken);
while (i !=3D -1) {
- result +=3D str.substring(0,i) + newToken;
+ result +=3D str.substring(0, i) + newToken;
str =3D str.substring(i + oldToken.length(), str.length());
i =3D str.indexOf(oldToken);
}
@@ -88,163 +87,149 @@
}
=
=
- /**
+ /**
* Method getDisplayedDate: return the date of today as a string
- *
- * @return the string value of today
+ *
+ * @return the string value of today
*/
- static public String getDisplayedDate()
- {
- Date today =3D new Date();
- SimpleDateFormat formatter =3D new
SimpleDateFormat(mask,Locale.US);
- String datenewformat =3D formatter.format(today);
- return datenewformat;
+ static public String getDisplayedDate() {
+ Date today =3D new Date();
+ SimpleDateFormat formatter =3D new SimpleDateFormat(mask, Locale.U=
S);
+ String datenewformat =3D formatter.format(today);
+ return datenewformat;
}
=
=
- /**
+ /**
* Method getDisplayedDate: return the date represented by time as a s=
tring
- *
- * @return the string value of today
+ *
+ * @return the string value of today
*/
- static public String getDisplayedDate(long time)
- {
- Date today =3D new Date(time);
- SimpleDateFormat formatter =3D new
SimpleDateFormat(mask,Locale.US);
- String datenewformat =3D formatter.format(today);
- return datenewformat;
+ static public String getDisplayedDate(long time) {
+ Date today =3D new Date(time);
+ SimpleDateFormat formatter =3D new SimpleDateFormat(mask, Locale.U=
S);
+ String datenewformat =3D formatter.format(today);
+ return datenewformat;
}
=
=
- /**
+ /**
* Method getCurrentDateInMs: return the date of today as a long value
- *
- * @return the long value of today
+ *
+ * @return the long value of today
*/
- static public long getCurrentDateInMs()
- {
- return System.currentTimeMillis();
+ static public long getCurrentDateInMs() {
+ return System.currentTimeMillis();
}
=
=
- /**
+ /**
* Method getDateInMs: return a long value for the time represented by=
the
- * given year, month and day
+ * given year, month and day
+ *
* @param year
- * @param month (1 to 12)
- * @param day
- *
- * @return the long value of time
- */
- static public long getDateInMs(int year,int month,int day)
- {
- Calendar c =3D Calendar.getInstance();
- // class calendar use monthes from 0 to 11, so decrement
- c.set(year,month-1,day);
- Date d =3D c.getTime();
- return d.getTime();
- }
-
+ * @param month (1 to 12)
+ * @param day
+ * @return the long value of time
+ */
+ static public long getDateInMs(int year, int month, int day) {
+ Calendar c =3D Calendar.getInstance();
+ // class calendar use monthes from 0 to 11, so decrement
+ c.set(year, month - 1, day);
+ Date d =3D c.getTime();
+ return d.getTime();
+ }
=
=
- /**
+ /**
* Method getDayFromMs: from a date in ms from 1970, January 1st, retu=
rn the day
- * @param time
- *
- * @return the day value
- */
- static public int getDayFromMs(long time)
- {
- Calendar c =3D Calendar.getInstance();
- c.setTime(new Date(time));
- return c.get(c.DAY_OF_MONTH);
- }
+ *
+ * @param time
+ * @return the day value
+ */
+ static public int getDayFromMs(long time) {
+ Calendar c =3D Calendar.getInstance();
+ c.setTime(new Date(time));
+ return c.get(c.DAY_OF_MONTH);
+ }
=
=
- /**
+ /**
* Method getMonthFromMs: from a date in ms from 1970, January 1st, re=
turn the month
- * @param time
- *
- * @return the month value
- */
- static public int getMonthFromMs(long time)
- {
- Calendar c =3D Calendar.getInstance();
- c.setTime(new Date(time));
- return c.get(c.MONTH);
- }
+ *
+ * @param time
+ * @return the month value
+ */
+ static public int getMonthFromMs(long time) {
+ Calendar c =3D Calendar.getInstance();
+ c.setTime(new Date(time));
+ return c.get(c.MONTH);
+ }
=
=
- /**
+ /**
* Method getYearFromMs: from a date in ms from 1970, January 1st, ret=
urn the year
- * @param time
- *
- * @return the year value
- */
- static public int getYearFromMs(long time)
- {
- Calendar c =3D Calendar.getInstance();
- c.setTime(new Date(time));
- return c.get(c.YEAR);
- }
-
+ *
+ * @param time
+ * @return the year value
+ */
+ static public int getYearFromMs(long time) {
+ Calendar c =3D Calendar.getInstance();
+ c.setTime(new Date(time));
+ return c.get(c.YEAR);
+ }
=
=
- /**
- * Method Quote
- * Double the quotes in order to be SQL compliant
- *
- * @param input String to filter
- * @return a filtered string
- */
- static public String Quote(String input)
- {
+ /**
+ * Method Quote
+ * Double the quotes in order to be SQL compliant
+ *
+ * @param input String to filter
+ * @return a filtered string
+ */
+ static public String Quote(String input) {
StringBuffer sb =3D new StringBuffer(input);
- for (int i =3D 0; i < sb.length(); i++)
- {
+ for (int i =3D 0; i < sb.length(); i++) {
char c =3D sb.charAt(i);
- if (c =3D=3D '\'')
- {
+ if (c =3D=3D '\'') {
sb.insert(i++, '\'');
}
- }
+ }
return sb.toString();
}
=
=
- /**
+ /**
* Simple <code>int</code> to <code>boolean</code> converter
*
* @param value an integer value
* @return <code>false</code> if <code>0</code>, <code>1</code> if not=
<code>0</code>
*/
- static public boolean int2boolean(int value)
- {
+ static public boolean int2boolean(int value) {
return value !=3D 0;
}
=
=
- /**
+ /**
* Simple <code>boolean</code> to <code>int</code> converter
*
* @param value a <code>boolean</code> value
* @return <code>0</code> if <code>false</code>, <code>1</code> if <co=
de>true</code>
*/
- static public int boolean2int(boolean value)
- {
+ static public int boolean2int(boolean value) {
return value ? 1 : 0;
}
=
- /**
+ /**
* Method inverseVector : inverse the elements contained in a vector
*
- * @param myVector the vector to inverse
- * @return the inversed vector
+ * @param myVector the vector to inverse
+ * @return the inversed vector
*/
static public Vector inverseVector(Vector myVector) {
=
- Vector temp =3D new Vector();
- for(int i =3D myVector.size()-1; i >=3D 0; i--) {
+ Vector temp =3D new Vector();
+ for(int i =3D myVector.size()-1; i >=3D 0; i--) {
=
temp.addElement(myVector.get(i));
}
Modified: trunk/war/src/java/org/jahia/tools/db/AddressBookDBServices.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/war/src/java/or=
g/jahia/tools/db/AddressBookDBServices.java&rev=3D59&repname=3Daddressbook
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/war/src/java/org/jahia/tools/db/AddressBookDBServices.java (origi=
nal)
+++ trunk/war/src/java/org/jahia/tools/db/AddressBookDBServices.java Thu Ju=
n 21 16:32:13 2007
@@ -8,6 +8,8 @@
*/
=
=
+import org.apache.log4j.Logger;
+
import java.util.*;
import java.sql.*;
=
@@ -21,6 +23,8 @@
*/
public class AddressBookDBServices
{
+ private static final Logger logger =3D Logger.getLogger(AddressBookDBS=
ervices.class);
+
private static AddressBookDBServices m_Instance =3D null;
private ConnectionPool m_ConnPool =3D null;
=
@@ -41,7 +45,7 @@
try {
m_ConnPool =3D new ConnectionPool( m_DB_DRIVER, m_DB_URL,
m_DB_USER=
NAME, m_DB_PASSWORD, m_DB_INITIALCONNECTIONS, m_DB_MAXCONNECTIONS, true );
} catch (SQLException se) {
- System.out.println("Error in creation connectionPool : " + se.get=
Message() + "\n" );
+ logger.error("Error in creation connectionPool : " + se.getMessag=
e() + "\n" );
}
}
=
Modified: trunk/war/src/java/org/jahia/tools/files/FileDownload.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/war/src/java/or=
g/jahia/tools/files/FileDownload.java&rev=3D59&repname=3Daddressbook
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/war/src/java/org/jahia/tools/files/FileDownload.java (original)
+++ trunk/war/src/java/org/jahia/tools/files/FileDownload.java Thu Jun 21 1=
6:32:13 2007
@@ -14,6 +14,7 @@
import javax.servlet.http.*;
=
import com.oreilly.servlet.*;
+import org.apache.log4j.Logger;
=
/**
* Class FileDownload.
@@ -34,6 +35,7 @@
=
private int m_BufferSize =3D 4096;
private byte[] m_WriteBuffer =3D new byte[m_BufferSize];
+ private static final Logger logger =3D Logger.getLogger(FileDownload.c=
lass);
=
=
/**
@@ -103,7 +105,6 @@
*
* @param ins An InputStream.
* @param outs An OutputStream.
- * @exception IOException.
*/
private void copyStream(InputStream ins,
OutputStream outs)
@@ -128,7 +129,7 @@
* @param msg any String message to write to the console
*/
public void toConsole(String msg) {
- System.out.println(msg);
+ logger.debug(msg);
}
=
} =
Modified: trunk/war/src/java/org/jahia/webapps/addressbook/AddressBookServl=
et.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/war/src/java/or=
g/jahia/webapps/addressbook/AddressBookServlet.java&rev=3D59&repname=3Daddr=
essbook
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/war/src/java/org/jahia/webapps/addressbook/AddressBookServlet.jav=
a (original)
+++ trunk/war/src/java/org/jahia/webapps/addressbook/AddressBookServlet.jav=
a Thu Jun 21 16:32:13 2007
@@ -14,8 +14,7 @@
import org.apache.ojb.broker.util.ui.AsciiSplash;
import org.odmg.*;
import org.apache.ojb.odmg.*;
-
-
+import org.apache.log4j.Logger;
=
=
import org.jahia.tools.*;
@@ -29,7 +28,7 @@
* @author Jerome Tamiotti <a href=3D"mailto:[EMAIL PROTECTED]">=
[EMAIL PROTECTED]</a>
*/
public class AddressBookServlet extends HttpServlet {
-
+ private static final Logger logger =3D Logger.getLogger(AddressBookSe=
rvlet.class);
/** the external properties file ServletConfig key **/
private final static String SC_KEY_PROPERTIES =3D "properties";
=
@@ -116,7 +115,7 @@
throw new ServletException("error initializing database via OJ=
B", t);
}
} else {
- System.out.println("Error Loading Properties");
+ logger.error("Error Loading Properties");
}
}
=
@@ -183,7 +182,7 @@
//Tools.toConsole("AddressBookServlet: loadProperties", "drive=
r=3D"+m_DB_DRIVER+", url=3D"+m_DB_URL+", username=3D"+m_DB_USERNAME+", max =
connections=3D"+ m_DB_MAXCONNECTIONS);
=
} catch (java.io.IOException ex) {
- ex.printStackTrace();
+ logger.error(ex,ex);
return false;
}
return true;
@@ -288,8 +287,7 @@
Tools.toConsole("AddressBookServlet: doGet", "forward to " + nex=
tPage);
rd.forward(request, response);
} catch (Exception e) {
- Tools.toConsole("AddressBookServlet: doGet","Unable to forward t=
o next page; cause : "+e.toString());
- e.printStackTrace();
+ logger.error("Unable to forward to next page; cause : ",e);
}
=
} else {
@@ -298,7 +296,7 @@
// separated because it needs response and don't forward to a pa=
ge
try {
String filePath =3D AddbookHandler.save(request);
- Tools.toConsole("AddressbookServlet: doGet","File saved: path =
=3D " + filePath);
+ logger.debug("File saved: path =3D " + filePath);
FileDownload fdwn =3D new FileDownload(request,response,"Addre=
ssBook.csv",filePath,"text/csv");
fdwn.writeFileContentToResponse();
// Delete temp file
@@ -331,13 +329,13 @@
rd.include(request,response);
} catch (ServletException se) {
Tools.toConsole("AddressBookServlet: doGet","Unable to forward=
to next page; cause : "+se.toString());
- se.printStackTrace();
+ logger.error(se,se);
if (se.getRootCause() !=3D null) {
- se.getRootCause().printStackTrace();
+ logger.error(se.getCause(),se.getCause());
}
} catch (Exception e) {
Tools.toConsole("AddressBookServlet: doGet","Unable to forward=
to next page; cause : "+e.toString());
- e.printStackTrace();
+ logger.error(e,e);
}
}
}
Modified: trunk/war/src/java/org/jahia/webapps/util/ActionHandler.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/war/src/java/or=
g/jahia/webapps/util/ActionHandler.java&rev=3D59&repname=3Daddressbook
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/war/src/java/org/jahia/webapps/util/ActionHandler.java (original)
+++ trunk/war/src/java/org/jahia/webapps/util/ActionHandler.java Thu Jun 21=
16:32:13 2007
@@ -6,6 +6,7 @@
import javax.servlet.http.*;
=
import org.jahia.tools.*;
+import org.apache.log4j.Logger;
=
=
/**
@@ -17,6 +18,7 @@
* @version 1.1
*/
public class ActionHandler {
+ private static final Logger logger =3D Logger.getLogger(ActionHandler.=
class);
=
/* The class on which to call the methods */
private Class actionClass;
@@ -93,7 +95,7 @@
=
} catch(InvocationTargetException ite) {
Tools.toConsole("ActionHandler-call", ite.toString());
- ite.printStackTrace();
+ logger.error(ite,ite);
throw new NullPointerException();
=
}
Modified: trunk/war/src/webapp/jsp/edit_form.jsp
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/war/src/webapp/=
jsp/edit_form.jsp&rev=3D59&repname=3Daddressbook
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/war/src/webapp/jsp/edit_form.jsp (original)
+++ trunk/war/src/webapp/jsp/edit_form.jsp Thu Jun 21 16:32:13 2007
@@ -37,7 +37,6 @@
<form name=3D"editForm<%=3DcontextId%>" action=3D"<%=3Dresponse.encodeURL(=
servlet)%>" method=3D"post">
<input type=3D"hidden" name=3D"contact_id" value=3D"<%=3Dcontact.getId()%>=
">
<%
- System.out.println("edit_form.jsp>currentAction=3D" + currentAction);
if ( (currentAction.equals("change_contact_form")) ||
(currentAction.equa=
ls("change_contact")) ) {
nextAction =3D "change_contact";
} else {
_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list