Created
October 8, 2013 22:10
-
-
Save imk/6892654 to your computer and use it in GitHub Desktop.
Attachments from https://rometools.jira.com/browse/ROME-129 by buckett (now https://github.com/rometools/rome/issues/130)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: src/java/com/sun/syndication/io/impl/PropertiesLoader.java | |
=================================================================== | |
RCS file: /cvs/rome/src/java/com/sun/syndication/io/impl/PropertiesLoader.java,v | |
retrieving revision 1.2 | |
diff -u -r1.2 PropertiesLoader.java | |
--- src/java/com/sun/syndication/io/impl/PropertiesLoader.java 31 Jul 2007 16:58:07 -0000 1.2 | |
+++ src/java/com/sun/syndication/io/impl/PropertiesLoader.java 20 Apr 2009 13:16:24 -0000 | |
@@ -5,6 +5,8 @@ | |
import java.net.URL; | |
import java.util.*; | |
+import com.sun.syndication.util.ClassloaderUtils; | |
+ | |
/** | |
* Properties loader that aggregates a master properties file and several extra properties files, | |
* all from the current classpath. | |
@@ -40,11 +42,11 @@ | |
public static PropertiesLoader getPropertiesLoader() { | |
synchronized(PropertiesLoader.class) { | |
PropertiesLoader loader = (PropertiesLoader) | |
- clMap.get(Thread.currentThread().getContextClassLoader()); | |
+ clMap.get(ClassloaderUtils.getClassLoader()); | |
if (loader == null) { | |
try { | |
loader = new PropertiesLoader(MASTER_PLUGIN_FILE, EXTRA_PLUGIN_FILE); | |
- clMap.put(Thread.currentThread().getContextClassLoader(), loader); | |
+ clMap.put(ClassloaderUtils.getClassLoader(), loader); | |
} | |
catch (IOException ex) { | |
throw new RuntimeException(ex); | |
@@ -66,7 +68,7 @@ | |
*/ | |
private PropertiesLoader(String masterFileLocation,String extraFileLocation) throws IOException { | |
List propertiesList = new ArrayList(); | |
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); | |
+ ClassLoader classLoader = ClassloaderUtils.getClassLoader(); | |
try { | |
InputStream is = classLoader.getResourceAsStream(masterFileLocation); | |
@@ -104,6 +106,7 @@ | |
propertiesList.toArray(_properties); | |
} | |
+ | |
/** | |
* Returns an array of tokenized values stored under a property key in all properties files. | |
* If the master file has this property its tokens will be the first ones in the array. | |
@@ -151,5 +154,5 @@ | |
entriesList.toArray(entries); | |
return entries; | |
} | |
- | |
+ | |
} | |
Index: src/java/com/sun/syndication/io/impl/PluginManager.java | |
=================================================================== | |
RCS file: /cvs/rome/src/java/com/sun/syndication/io/impl/PluginManager.java,v | |
retrieving revision 1.12 | |
diff -u -r1.12 PluginManager.java | |
--- src/java/com/sun/syndication/io/impl/PluginManager.java 1 Mar 2009 23:13:19 -0000 1.12 | |
+++ src/java/com/sun/syndication/io/impl/PluginManager.java 20 Apr 2009 13:16:24 -0000 | |
@@ -20,6 +20,7 @@ | |
import com.sun.syndication.io.DelegatingModuleParser; | |
import com.sun.syndication.io.WireFeedGenerator; | |
import com.sun.syndication.io.WireFeedParser; | |
+import com.sun.syndication.util.ClassloaderUtils; | |
import java.util.*; | |
@@ -129,7 +130,7 @@ | |
* | |
*/ | |
private Class[] getClasses() throws ClassNotFoundException { | |
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); | |
+ ClassLoader classLoader = ClassloaderUtils.getClassLoader(); | |
List classes = new ArrayList(); | |
boolean useLoadClass = Boolean.valueOf(System.getProperty("rome.pluginmanager.useloadclass", "false")).booleanValue(); | |
for (int i = 0; i <_propertyValues.length; i++) { | |
Index: src/java/com/sun/syndication/io/WireFeedOutput.java | |
=================================================================== | |
RCS file: /cvs/rome/src/java/com/sun/syndication/io/WireFeedOutput.java,v | |
retrieving revision 1.5 | |
diff -u -r1.5 WireFeedOutput.java | |
--- src/java/com/sun/syndication/io/WireFeedOutput.java 5 Jan 2009 22:11:45 -0000 1.5 | |
+++ src/java/com/sun/syndication/io/WireFeedOutput.java 20 Apr 2009 13:16:24 -0000 | |
@@ -18,6 +18,8 @@ | |
import com.sun.syndication.feed.WireFeed; | |
import com.sun.syndication.io.impl.FeedGenerators; | |
+import com.sun.syndication.util.ClassloaderUtils; | |
+ | |
import org.jdom.Document; | |
import org.jdom.JDOMException; | |
import org.jdom.output.DOMOutputter; | |
@@ -48,10 +50,10 @@ | |
private static FeedGenerators getFeedGenerators() { | |
synchronized(WireFeedOutput.class) { | |
FeedGenerators generators = (FeedGenerators) | |
- clMap.get(Thread.currentThread().getContextClassLoader()); | |
+ clMap.get(ClassloaderUtils.getClassLoader()); | |
if (generators == null) { | |
generators = new FeedGenerators(); | |
- clMap.put(Thread.currentThread().getContextClassLoader(), generators); | |
+ clMap.put(ClassloaderUtils.getClassLoader(), generators); | |
} | |
return generators; | |
} | |
Index: src/java/com/sun/syndication/io/WireFeedInput.java | |
=================================================================== | |
RCS file: /cvs/rome/src/java/com/sun/syndication/io/WireFeedInput.java,v | |
retrieving revision 1.16 | |
diff -u -r1.16 WireFeedInput.java | |
--- src/java/com/sun/syndication/io/WireFeedInput.java 1 Apr 2008 11:35:33 -0000 1.16 | |
+++ src/java/com/sun/syndication/io/WireFeedInput.java 20 Apr 2009 13:16:24 -0000 | |
@@ -39,6 +39,7 @@ | |
import com.sun.syndication.feed.WireFeed; | |
import com.sun.syndication.io.impl.FeedParsers; | |
import com.sun.syndication.io.impl.XmlFixerReader; | |
+import com.sun.syndication.util.ClassloaderUtils; | |
/** | |
* Parses an XML document (File, InputStream, Reader, W3C SAX InputSource, W3C DOM Document or JDom DOcument) | |
@@ -59,10 +60,10 @@ | |
private static FeedParsers getFeedParsers() { | |
synchronized(WireFeedInput.class) { | |
FeedParsers parsers = (FeedParsers) | |
- clMap.get(Thread.currentThread().getContextClassLoader()); | |
+ clMap.get(ClassloaderUtils.getClassLoader()); | |
if (parsers == null) { | |
parsers = new FeedParsers(); | |
- clMap.put(Thread.currentThread().getContextClassLoader(), parsers); | |
+ clMap.put(ClassloaderUtils.getClassLoader(), parsers); | |
} | |
return parsers; | |
} | |
Index: src/java/com/sun/syndication/util/ClassloaderUtils.java | |
=================================================================== | |
RCS file: src/java/com/sun/syndication/util/ClassloaderUtils.java | |
diff -N src/java/com/sun/syndication/util/ClassloaderUtils.java | |
--- /dev/null 1 Jan 1970 00:00:00 -0000 | |
+++ src/java/com/sun/syndication/util/ClassloaderUtils.java 1 Jan 1970 00:00:00 -0000 | |
@@ -0,0 +1,36 @@ | |
+/* | |
+ * Copyright 2004 Sun Microsystems, Inc. | |
+ * | |
+ * 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 com.sun.syndication.util; | |
+ | |
+import com.sun.syndication.io.impl.PropertiesLoader; | |
+ | |
+public class ClassloaderUtils | |
+{ | |
+ | |
+ /** | |
+ * Return the classloader to use for loading the files. | |
+ * This allows rome to work when the calling code is in a different classloader | |
+ * to the configuration files. | |
+ * @return the classloader to load supporting files from. | |
+ */ | |
+ public static ClassLoader getClassLoader() | |
+ { | |
+ boolean useLoadClass = Boolean.valueOf(System.getProperty("rome.use.thread.classloader", "false")).booleanValue(); | |
+ return (useLoadClass)?Thread.currentThread().getContextClassLoader():PropertiesLoader.class.getClassLoader(); | |
+ } | |
+ | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment