Skip to content
This repository was archived by the owner on Feb 21, 2025. It is now read-only.

Commit 8bbc810

Browse files
committed
Import from Tomcat 6.0.39
1 parent 730baf5 commit 8bbc810

File tree

2 files changed

+192
-1
lines changed

2 files changed

+192
-1
lines changed

pom.xml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,33 @@
44

55
<groupId>com.zigarn</groupId>
66
<artifactId>tomcat-extra-properties</artifactId>
7-
<version>0.0.1-SNAPSHOT</version>
7+
<version>6.0.39</version>
88
<packaging>jar</packaging>
99

1010
<properties>
1111
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1212
</properties>
1313

14+
<build>
15+
<plugins>
16+
<plugin>
17+
<groupId>org.apache.maven.plugins</groupId>
18+
<artifactId>maven-compiler-plugin</artifactId>
19+
<version>3.1</version>
20+
<configuration>
21+
<source>1.5</source>
22+
<target>1.5</target>
23+
</configuration>
24+
</plugin>
25+
</plugins>
26+
</build>
27+
1428
<dependencies>
29+
<dependency>
30+
<groupId>org.apache.tomcat</groupId>
31+
<artifactId>catalina</artifactId>
32+
<version>6.0.39</version>
33+
</dependency>
1534
<dependency>
1635
<groupId>junit</groupId>
1736
<artifactId>junit</artifactId>
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
19+
package org.apache.catalina.startup;
20+
21+
import java.io.File;
22+
import java.io.FileInputStream;
23+
import java.io.InputStream;
24+
import java.net.URL;
25+
import java.util.Enumeration;
26+
import java.util.Properties;
27+
28+
29+
/**
30+
* Utility class to read the bootstrap Catalina configuration.
31+
*
32+
* @author Remy Maucherat
33+
* @version $Id$
34+
*/
35+
36+
public class CatalinaProperties {
37+
38+
39+
// ------------------------------------------------------- Static Variables
40+
41+
private static org.apache.juli.logging.Log log=
42+
org.apache.juli.logging.LogFactory.getLog( CatalinaProperties.class );
43+
44+
private static Properties properties = null;
45+
46+
47+
static {
48+
49+
loadProperties();
50+
51+
}
52+
53+
54+
// --------------------------------------------------------- Public Methods
55+
56+
57+
/**
58+
* Return specified property value.
59+
*/
60+
public static String getProperty(String name) {
61+
62+
return properties.getProperty(name);
63+
64+
}
65+
66+
67+
/**
68+
* Return specified property value.
69+
*/
70+
public static String getProperty(String name, String defaultValue) {
71+
72+
return properties.getProperty(name, defaultValue);
73+
74+
}
75+
76+
77+
// --------------------------------------------------------- Public Methods
78+
79+
80+
/**
81+
* Load properties.
82+
*/
83+
private static void loadProperties() {
84+
85+
InputStream is = null;
86+
Throwable error = null;
87+
88+
try {
89+
String configUrl = getConfigUrl();
90+
if (configUrl != null) {
91+
is = (new URL(configUrl)).openStream();
92+
}
93+
} catch (Throwable t) {
94+
// Ignore
95+
}
96+
97+
if (is == null) {
98+
try {
99+
File home = new File(getCatalinaBase());
100+
File conf = new File(home, "conf");
101+
File properties = new File(conf, "catalina.properties");
102+
is = new FileInputStream(properties);
103+
} catch (Throwable t) {
104+
// Ignore
105+
}
106+
}
107+
108+
if (is == null) {
109+
try {
110+
is = CatalinaProperties.class.getResourceAsStream
111+
("/org/apache/catalina/startup/catalina.properties");
112+
} catch (Throwable t) {
113+
// Ignore
114+
}
115+
}
116+
117+
if (is != null) {
118+
try {
119+
properties = new Properties();
120+
properties.load(is);
121+
is.close();
122+
} catch (Throwable t) {
123+
error = t;
124+
}
125+
}
126+
127+
if ((is == null) || (error != null)) {
128+
// Do something
129+
log.warn("Failed to load catalina.properties", error);
130+
// That's fine - we have reasonable defaults.
131+
properties=new Properties();
132+
}
133+
134+
// Register the properties as system properties
135+
Enumeration enumeration = properties.propertyNames();
136+
while (enumeration.hasMoreElements()) {
137+
String name = (String) enumeration.nextElement();
138+
String value = properties.getProperty(name);
139+
if (value != null) {
140+
System.setProperty(name, value);
141+
}
142+
}
143+
144+
}
145+
146+
147+
/**
148+
* Get the value of the catalina.home environment variable.
149+
*/
150+
private static String getCatalinaHome() {
151+
return System.getProperty("catalina.home",
152+
System.getProperty("user.dir"));
153+
}
154+
155+
156+
/**
157+
* Get the value of the catalina.base environment variable.
158+
*/
159+
private static String getCatalinaBase() {
160+
return System.getProperty("catalina.base", getCatalinaHome());
161+
}
162+
163+
164+
/**
165+
* Get the value of the configuration URL.
166+
*/
167+
private static String getConfigUrl() {
168+
return System.getProperty("catalina.config");
169+
}
170+
171+
172+
}

0 commit comments

Comments
 (0)