krysalis-version/src/java/org/krysalis/version/util SystemUtils.java,NONE,1.1 DebugUtils.java,NONE,1.1
Nick Chalko <[email protected]> Tue, 09 Nov 2004 06:40:29 +0000
| Newsgroups | gmane.comp.krysalis.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/krysalis/krysalis-version/src/java/org/krysalis/version/util
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20857/src/java/org/krysalis/version/util
Added Files:
SystemUtils.java DebugUtils.java
Log Message:
Mucho Refactoring.
--- NEW FILE: DebugUtils.java ---
/*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.krysalis.version.util;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Hashtable;
/**
* @version $Revision: 1.1 $
*/
public class DebugUtils {
private static Hashtable l_indents = new Hashtable();
private static boolean l_verbose = false;
public static void enableXercesParser() {
// SAX ...
System.setProperty(
"org.xml.sax.driver",
"org.apache.xerces.parsers.SAXParser");
// DOM...
//:TODO:
//javax.xml.parsers.DocumentBuilderFactory
}
public static void enableCommonsLogging() {
System.setProperty(
"org.apache.commons.logging.Log",
"org.apache.commons.logging.impl.SimpleLog");
System.setProperty(
"org.apache.commons.logging.simplelog.showdatetime",
"true");
}
public static void enableHttpClientDebug() {
enableCommonsLogging();
System.setProperty(
"org.apache.commons.logging.simplelog.log.httpclient.wire",
"debug");
System.setProperty(
"org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient",
"debug");
}
public static void enableVerboseDumps() {
l_verbose = true;
}
public static void indent(PrintWriter out, int x) {
for (int i = 0; i < x; ++i) {
out.print(" ");
}
}
public static String getIndent(int x) {
String idstr = (String) l_indents.get(new Integer(x));
if (null == idstr) {
StringBuffer indent = new StringBuffer();
for (int i = 0; i < x; ++i)
indent.append(" ");
idstr = indent.toString();
l_indents.put(new Integer(x), idstr);
}
return idstr;
}
public static String getDump(Throwable t) {
return getDump(t, l_verbose);
}
public static String getDump(Throwable t, boolean verbose) {
if (verbose) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw, true);
t.printStackTrace(pw);
pw.flush();
return sw.toString();
}
return t.getLocalizedMessage();
}
public static void printSeparator() {
printSeparator(SystemUtils.getSystemOut(), 0);
}
public static void printSeparator(PrintWriter out, int depth) {
out.print(DebugUtils.getIndent(depth));
out.println(
"--------------------------------------------------------------");
}
}
--- NEW FILE: SystemUtils.java ---
/*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.krysalis.version.util;
import java.io.File;
import java.io.PrintWriter;
/**
* @author ajack
*/
public class SystemUtils {
public static final String g_pathSeparator;
static {
// :TODO: --- BTW: Add forceLog --- to stderr if not logging..
g_pathSeparator = getSystemProperty("path.separator");
}
public static File getCWD() {
File cwd = null;
try {
cwd = new File(getSystemProperty("user.dir"));
}
catch (Exception e) {
// World of hurt...
// :TODO:
}
return cwd;
}
public static String getSystemProperty(String key) {
String value = null;
try {
value = System.getProperty(key);
}
catch (SecurityException se) {
// World of hurt...
// :TODO:
}
return value;
}
public static String getShortName(Object obj) {
return getShortName(obj.getClass().getName());
}
public static String getShortName(Class clazz) {
return getShortName(clazz.getName());
}
public static String getShortName(String name) {
String shortName = null;
int periodPos = name.lastIndexOf('.');
if (-1 != periodPos)
shortName = name.substring(periodPos + 1);
else
shortName = name;
return shortName;
}
public static PrintWriter getSystemOut() {
//:TODO: Singleton?
return new PrintWriter(System.out, true);
}
public static PrintWriter getSystemErr() {
//:TODO: Singleton?
return new PrintWriter(System.err, true);
}
}
-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click