KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log4j > xml > Log4jEntityResolver


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.log4j.xml;
18
19 import java.io.InputStream JavaDoc;
20 import java.io.ByteArrayOutputStream JavaDoc;
21 import java.io.ByteArrayInputStream JavaDoc;
22 import java.io.IOException JavaDoc;
23
24 import org.xml.sax.EntityResolver JavaDoc;
25 import org.xml.sax.InputSource JavaDoc;
26
27 import org.apache.log4j.helpers.LogLog;
28
29 /**
30  * An {@link EntityResolver} specifically designed to return
31  * <code>log4j.dtd</code> which is embedded within the log4j jar
32  * file.
33  *
34  * @author Paul Austin
35  * */

36 public class Log4jEntityResolver implements EntityResolver JavaDoc {
37
38   public InputSource JavaDoc resolveEntity (String JavaDoc publicId, String JavaDoc systemId) {
39     if (systemId.endsWith("log4j.dtd")) {
40       Class JavaDoc clazz = getClass();
41       InputStream JavaDoc in = clazz.getResourceAsStream("/org/apache/log4j/xml/log4j.dtd");
42       if (in == null) {
43     LogLog.error("Could not find [log4j.dtd]. Used [" + clazz.getClassLoader()
44              + "] class loader in the search.");
45     return null;
46       } else {
47     return new InputSource JavaDoc(in);
48       }
49     } else {
50       return null;
51     }
52   }
53 }
54
Popular Tags