001: /*
002: * Copyright 1999-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.tomcat.util.compat;
018:
019: import java.io.File;
020: import java.io.IOException;
021: import java.net.MalformedURLException;
022: import java.net.URL;
023: import java.util.Locale;
024: import java.text.MessageFormat;
025:
026: import org.apache.commons.logging.Log;
027: import org.apache.commons.logging.LogFactory;
028:
029: /**
030: * See JdkCompat. This is an extension of that class for Jdk1.4 support.
031: *
032: * @author Tim Funk
033: * @author Remy Maucherat
034: */
035: public class Jdk14Compat extends JdkCompat {
036: // -------------------------------------------------------------- Constants
037:
038: // ------------------------------------------------------- Static Variables
039: static Log logger = LogFactory.getLog(Jdk14Compat.class);
040:
041: // ----------------------------------------------------------- Constructors
042: /**
043: * Default no-arg constructor
044: */
045: protected Jdk14Compat() {
046: }
047:
048: // --------------------------------------------------------- Public Methods
049:
050: /**
051: * Return the URI for the given file. Originally created for
052: * o.a.c.loader.WebappClassLoader
053: *
054: * @param File to wrap into URI
055: * @return A URI as a URL
056: */
057: public URL getURI(File file) throws MalformedURLException {
058:
059: File realFile = file;
060: try {
061: realFile = realFile.getCanonicalFile();
062: } catch (IOException e) {
063: // Ignore
064: }
065:
066: return realFile.toURI().toURL();
067: }
068:
069: /**
070: * Return the maximum amount of memory the JVM will attempt to use.
071: */
072: public long getMaxMemory() {
073: return Runtime.getRuntime().maxMemory();
074: }
075:
076: /**
077: * Print out a partial servlet stack trace (truncating at the last
078: * occurrence of javax.servlet.).
079: */
080: public String getPartialServletStackTrace(Throwable t) {
081: StringBuffer trace = new StringBuffer();
082: trace.append(t.toString()).append('\n');
083: StackTraceElement[] elements = t.getStackTrace();
084: int pos = elements.length;
085: for (int i = 0; i < elements.length; i++) {
086: if ((elements[i].getClassName()
087: .startsWith("org.apache.catalina.core.ApplicationFilterChain"))
088: && (elements[i].getMethodName()
089: .equals("internalDoFilter"))) {
090: pos = i;
091: }
092: }
093: for (int i = 0; i < pos; i++) {
094: if (!(elements[i].getClassName()
095: .startsWith("org.apache.catalina.core."))) {
096: trace.append('\t').append(elements[i].toString())
097: .append('\n');
098: }
099: }
100: return trace.toString();
101: }
102:
103: public String[] split(String path, String pat) {
104: return path.split(pat);
105: }
106:
107: /**
108: * Chains the <tt>wrapped</tt> throwable to the <tt>wrapper</tt> throwable.
109: *
110: * @param wrapper The wrapper throwable
111: * @param wrapped The throwable to be wrapped
112: */
113: public void chainException(Throwable wrapper, Throwable wrapped) {
114: wrapper.initCause(wrapped);
115: }
116:
117: }
|