Possible fix for ClassLoader problems in OSGi environments
This commit is contained in:
parent
53b5e3bec3
commit
6029420e5f
5 changed files with 102 additions and 192 deletions
|
@ -43,11 +43,9 @@ import com.sun.syndication.io.impl.FeedParsers;
|
|||
import com.sun.syndication.io.impl.XmlFixerReader;
|
||||
|
||||
/**
|
||||
* Parses an XML document (File, InputStream, Reader, W3C SAX InputSource, W3C
|
||||
* DOM Document or JDom DOcument) into an WireFeed (RSS/Atom).
|
||||
* Parses an XML document (File, InputStream, Reader, W3C SAX InputSource, W3C DOM Document or JDom DOcument) into an WireFeed (RSS/Atom).
|
||||
* <p>
|
||||
* It accepts all flavors of RSS (0.90, 0.91, 0.92, 0.93, 0.94, 1.0 and 2.0) and
|
||||
* Atom 0.3 feeds. Parsers are plugable (they must implement the WireFeedParser
|
||||
* It accepts all flavors of RSS (0.90, 0.91, 0.92, 0.93, 0.94, 1.0 and 2.0) and Atom 0.3 feeds. Parsers are plugable (they must implement the WireFeedParser
|
||||
* interface).
|
||||
* <p>
|
||||
* The WireFeedInput useds liberal parsers.
|
||||
|
@ -62,10 +60,11 @@ public class WireFeedInput {
|
|||
|
||||
private static FeedParsers getFeedParsers() {
|
||||
synchronized (WireFeedInput.class) {
|
||||
FeedParsers parsers = clMap.get(Thread.currentThread().getContextClassLoader());
|
||||
final ClassLoader classLoader = WireFeedInput.class.getClassLoader();
|
||||
FeedParsers parsers = clMap.get(classLoader);
|
||||
if (parsers == null) {
|
||||
parsers = new FeedParsers();
|
||||
clMap.put(Thread.currentThread().getContextClassLoader(), parsers);
|
||||
clMap.put(classLoader, parsers);
|
||||
}
|
||||
return parsers;
|
||||
}
|
||||
|
@ -115,8 +114,7 @@ public class WireFeedInput {
|
|||
* Creates a WireFeedInput instance.
|
||||
* <p>
|
||||
*
|
||||
* @param validate indicates if the input should be validated. NOT
|
||||
* IMPLEMENTED YET (validation does not happen)
|
||||
* @param validate indicates if the input should be validated. NOT IMPLEMENTED YET (validation does not happen)
|
||||
*
|
||||
*/
|
||||
public WireFeedInput(final boolean validate, final Locale locale) {
|
||||
|
@ -128,14 +126,11 @@ public class WireFeedInput {
|
|||
/**
|
||||
* Enables XML healing in the WiredFeedInput instance.
|
||||
* <p>
|
||||
* Healing trims leading chars from the stream (empty spaces and comments)
|
||||
* until the XML prolog.
|
||||
* Healing trims leading chars from the stream (empty spaces and comments) until the XML prolog.
|
||||
* <p>
|
||||
* Healing resolves HTML entities (from literal to code number) in the
|
||||
* reader.
|
||||
* Healing resolves HTML entities (from literal to code number) in the reader.
|
||||
* <p>
|
||||
* The healing is done only with the build(File) and build(Reader)
|
||||
* signatures.
|
||||
* The healing is done only with the build(File) and build(Reader) signatures.
|
||||
* <p>
|
||||
* By default is TRUE.
|
||||
* <p>
|
||||
|
@ -148,17 +143,13 @@ public class WireFeedInput {
|
|||
}
|
||||
|
||||
/**
|
||||
* Indicates if the WiredFeedInput instance will XML heal (if necessary) the
|
||||
* character stream.
|
||||
* Indicates if the WiredFeedInput instance will XML heal (if necessary) the character stream.
|
||||
* <p>
|
||||
* Healing trims leading chars from the stream (empty spaces and comments)
|
||||
* until the XML prolog.
|
||||
* Healing trims leading chars from the stream (empty spaces and comments) until the XML prolog.
|
||||
* <p>
|
||||
* Healing resolves HTML entities (from literal to code number) in the
|
||||
* reader.
|
||||
* Healing resolves HTML entities (from literal to code number) in the reader.
|
||||
* <p>
|
||||
* The healing is done only with the build(File) and build(Reader)
|
||||
* signatures.
|
||||
* The healing is done only with the build(File) and build(Reader) signatures.
|
||||
* <p>
|
||||
* By default is TRUE.
|
||||
* <p>
|
||||
|
@ -173,16 +164,14 @@ public class WireFeedInput {
|
|||
/**
|
||||
* Builds an WireFeed (RSS or Atom) from a file.
|
||||
* <p>
|
||||
* NOTE: This method delages to the 'AsbtractFeed
|
||||
* WireFeedInput#build(org.jdom2.Document)'.
|
||||
* NOTE: This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'.
|
||||
* <p>
|
||||
*
|
||||
* @param file file to read to create the WireFeed.
|
||||
* @return the WireFeed read from the file.
|
||||
* @throws FileNotFoundException thrown if the file could not be found.
|
||||
* @throws IOException thrown if there is problem reading the file.
|
||||
* @throws IllegalArgumentException thrown if feed type could not be
|
||||
* understood by any of the underlying parsers.
|
||||
* @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers.
|
||||
* @throws FeedException if the feed could not be parsed
|
||||
*
|
||||
*/
|
||||
|
@ -200,14 +189,12 @@ public class WireFeedInput {
|
|||
/**
|
||||
* Builds an WireFeed (RSS or Atom) from an Reader.
|
||||
* <p>
|
||||
* NOTE: This method delages to the 'AsbtractFeed
|
||||
* WireFeedInput#build(org.jdom2.Document)'.
|
||||
* NOTE: This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'.
|
||||
* <p>
|
||||
*
|
||||
* @param reader Reader to read to create the WireFeed.
|
||||
* @return the WireFeed read from the Reader.
|
||||
* @throws IllegalArgumentException thrown if feed type could not be
|
||||
* understood by any of the underlying parsers.
|
||||
* @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers.
|
||||
* @throws FeedException if the feed could not be parsed
|
||||
*
|
||||
*/
|
||||
|
@ -231,14 +218,12 @@ public class WireFeedInput {
|
|||
/**
|
||||
* Builds an WireFeed (RSS or Atom) from an W3C SAX InputSource.
|
||||
* <p>
|
||||
* NOTE: This method delages to the 'AsbtractFeed
|
||||
* WireFeedInput#build(org.jdom2.Document)'.
|
||||
* NOTE: This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'.
|
||||
* <p>
|
||||
*
|
||||
* @param is W3C SAX InputSource to read to create the WireFeed.
|
||||
* @return the WireFeed read from the W3C SAX InputSource.
|
||||
* @throws IllegalArgumentException thrown if feed type could not be
|
||||
* understood by any of the underlying parsers.
|
||||
* @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers.
|
||||
* @throws FeedException if the feed could not be parsed
|
||||
*
|
||||
*/
|
||||
|
@ -259,14 +244,12 @@ public class WireFeedInput {
|
|||
/**
|
||||
* Builds an WireFeed (RSS or Atom) from an W3C DOM document.
|
||||
* <p>
|
||||
* NOTE: This method delages to the 'AsbtractFeed
|
||||
* WireFeedInput#build(org.jdom2.Document)'.
|
||||
* NOTE: This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'.
|
||||
* <p>
|
||||
*
|
||||
* @param document W3C DOM document to read to create the WireFeed.
|
||||
* @return the WireFeed read from the W3C DOM document.
|
||||
* @throws IllegalArgumentException thrown if feed type could not be
|
||||
* understood by any of the underlying parsers.
|
||||
* @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers.
|
||||
* @throws FeedException if the feed could not be parsed
|
||||
*
|
||||
*/
|
||||
|
@ -290,8 +273,7 @@ public class WireFeedInput {
|
|||
*
|
||||
* @param document JDOM document to read to create the WireFeed.
|
||||
* @return the WireFeed read from the JDOM document.
|
||||
* @throws IllegalArgumentException thrown if feed type could not be
|
||||
* understood by any of the underlying parsers.
|
||||
* @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers.
|
||||
* @throws FeedException if the feed could not be parsed
|
||||
*
|
||||
*/
|
||||
|
|
|
@ -34,12 +34,10 @@ import com.sun.syndication.feed.WireFeed;
|
|||
import com.sun.syndication.io.impl.FeedGenerators;
|
||||
|
||||
/**
|
||||
* Generates an XML document (String, File, OutputStream, Writer, W3C DOM
|
||||
* document or JDOM document) out of an WireFeed (RSS/Atom).
|
||||
* Generates an XML document (String, File, OutputStream, Writer, W3C DOM document or JDOM document) out of an WireFeed (RSS/Atom).
|
||||
* <p>
|
||||
* It generates all flavors of RSS (0.90, 0.91, 0.92, 0.93, 0.94, 1.0 and 2.0)
|
||||
* and Atom 0.3 feeds. Generators are plugable (they must implement the
|
||||
* ModuleParser interface).
|
||||
* It generates all flavors of RSS (0.90, 0.91, 0.92, 0.93, 0.94, 1.0 and 2.0) and Atom 0.3 feeds. Generators are plugable (they must implement the ModuleParser
|
||||
* interface).
|
||||
* <p>
|
||||
*
|
||||
* @author Alejandro Abdelnur
|
||||
|
@ -50,10 +48,11 @@ public class WireFeedOutput {
|
|||
|
||||
private static FeedGenerators getFeedGenerators() {
|
||||
synchronized (WireFeedOutput.class) {
|
||||
FeedGenerators generators = clMap.get(Thread.currentThread().getContextClassLoader());
|
||||
final ClassLoader classLoader = WireFeedOutput.class.getClassLoader();
|
||||
FeedGenerators generators = clMap.get(classLoader);
|
||||
if (generators == null) {
|
||||
generators = new FeedGenerators();
|
||||
clMap.put(Thread.currentThread().getContextClassLoader(), generators);
|
||||
clMap.put(classLoader, generators);
|
||||
}
|
||||
return generators;
|
||||
}
|
||||
|
@ -83,23 +82,16 @@ public class WireFeedOutput {
|
|||
/**
|
||||
* Creates a String with the XML representation for the given WireFeed.
|
||||
* <p>
|
||||
* If the feed encoding is not NULL, it will be used in the XML prolog
|
||||
* encoding attribute. It is the responsibility of the developer to ensure
|
||||
* that if the String is written to a character stream the stream charset is
|
||||
* the same as the feed encoding property.
|
||||
* If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility of the developer to ensure that if the
|
||||
* String is written to a character stream the stream charset is the same as the feed encoding property.
|
||||
* <p>
|
||||
* NOTE: This method delages to the 'Document
|
||||
* WireFeedOutput#outputJDom(WireFeed)'.
|
||||
* NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
|
||||
* <p>
|
||||
*
|
||||
* @param feed Abstract feed to create XML representation from. The type of
|
||||
* the WireFeed must match the type given to the FeedOuptut
|
||||
* constructor.
|
||||
* @param feed Abstract feed to create XML representation from. The type of the WireFeed must match the type given to the FeedOuptut constructor.
|
||||
* @return a String with the XML representation for the given WireFeed.
|
||||
* @throws IllegalArgumentException thrown if the feed type of the
|
||||
* WireFeedOutput and WireFeed don't match.
|
||||
* @throws FeedException thrown if the XML representation for the feed could
|
||||
* not be created.
|
||||
* @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
|
||||
* @throws FeedException thrown if the XML representation for the feed could not be created.
|
||||
*
|
||||
*/
|
||||
public String outputString(final WireFeed feed) throws IllegalArgumentException, FeedException {
|
||||
|
@ -109,24 +101,17 @@ public class WireFeedOutput {
|
|||
/**
|
||||
* Creates a String with the XML representation for the given WireFeed.
|
||||
* <p>
|
||||
* If the feed encoding is not NULL, it will be used in the XML prolog
|
||||
* encoding attribute. It is the responsibility of the developer to ensure
|
||||
* that if the String is written to a character stream the stream charset is
|
||||
* the same as the feed encoding property.
|
||||
* If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility of the developer to ensure that if the
|
||||
* String is written to a character stream the stream charset is the same as the feed encoding property.
|
||||
* <p>
|
||||
* NOTE: This method delages to the 'Document
|
||||
* WireFeedOutput#outputJDom(WireFeed)'.
|
||||
* NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
|
||||
* <p>
|
||||
*
|
||||
* @param feed Abstract feed to create XML representation from. The type of
|
||||
* the WireFeed must match the type given to the FeedOuptut
|
||||
* constructor.
|
||||
* @param feed Abstract feed to create XML representation from. The type of the WireFeed must match the type given to the FeedOuptut constructor.
|
||||
* @param prettyPrint pretty-print XML (true) oder collapsed
|
||||
* @return a String with the XML representation for the given WireFeed.
|
||||
* @throws IllegalArgumentException thrown if the feed type of the
|
||||
* WireFeedOutput and WireFeed don't match.
|
||||
* @throws FeedException thrown if the XML representation for the feed could
|
||||
* not be created.
|
||||
* @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
|
||||
* @throws FeedException thrown if the XML representation for the feed could not be created.
|
||||
*
|
||||
*/
|
||||
public String outputString(final WireFeed feed, final boolean prettyPrint) throws IllegalArgumentException, FeedException {
|
||||
|
@ -146,28 +131,19 @@ public class WireFeedOutput {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a File containing with the XML representation for the given
|
||||
* WireFeed.
|
||||
* Creates a File containing with the XML representation for the given WireFeed.
|
||||
* <p>
|
||||
* If the feed encoding is not NULL, it will be used in the XML prolog
|
||||
* encoding attribute. The platform default charset encoding is used to
|
||||
* write the feed to the file. It is the responsibility of the developer to
|
||||
* ensure the feed encoding is set to the platform charset encoding.
|
||||
* If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. The platform default charset encoding is used to write the feed
|
||||
* to the file. It is the responsibility of the developer to ensure the feed encoding is set to the platform charset encoding.
|
||||
* <p>
|
||||
* NOTE: This method delages to the 'Document
|
||||
* WireFeedOutput#outputJDom(WireFeed)'.
|
||||
* NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
|
||||
* <p>
|
||||
*
|
||||
* @param feed Abstract feed to create XML representation from. The type of
|
||||
* the WireFeed must match the type given to the FeedOuptut
|
||||
* constructor.
|
||||
* @param file the file where to write the XML representation for the given
|
||||
* WireFeed.
|
||||
* @throws IllegalArgumentException thrown if the feed type of the
|
||||
* WireFeedOutput and WireFeed don't match.
|
||||
* @param feed Abstract feed to create XML representation from. The type of the WireFeed must match the type given to the FeedOuptut constructor.
|
||||
* @param file the file where to write the XML representation for the given WireFeed.
|
||||
* @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
|
||||
* @throws IOException thrown if there was some problem writing to the File.
|
||||
* @throws FeedException thrown if the XML representation for the feed could
|
||||
* not be created.
|
||||
* @throws FeedException thrown if the XML representation for the feed could not be created.
|
||||
*
|
||||
*/
|
||||
public void output(final WireFeed feed, final File file) throws IllegalArgumentException, IOException, FeedException {
|
||||
|
@ -175,29 +151,20 @@ public class WireFeedOutput {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a File containing with the XML representation for the given
|
||||
* WireFeed.
|
||||
* Creates a File containing with the XML representation for the given WireFeed.
|
||||
* <p>
|
||||
* If the feed encoding is not NULL, it will be used in the XML prolog
|
||||
* encoding attribute. The platform default charset encoding is used to
|
||||
* write the feed to the file. It is the responsibility of the developer to
|
||||
* ensure the feed encoding is set to the platform charset encoding.
|
||||
* If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. The platform default charset encoding is used to write the feed
|
||||
* to the file. It is the responsibility of the developer to ensure the feed encoding is set to the platform charset encoding.
|
||||
* <p>
|
||||
* NOTE: This method delages to the 'Document
|
||||
* WireFeedOutput#outputJDom(WireFeed)'.
|
||||
* NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
|
||||
* <p>
|
||||
*
|
||||
* @param feed Abstract feed to create XML representation from. The type of
|
||||
* the WireFeed must match the type given to the FeedOuptut
|
||||
* constructor.
|
||||
* @param file the file where to write the XML representation for the given
|
||||
* WireFeed.
|
||||
* @param feed Abstract feed to create XML representation from. The type of the WireFeed must match the type given to the FeedOuptut constructor.
|
||||
* @param file the file where to write the XML representation for the given WireFeed.
|
||||
* @param prettyPrint pretty-print XML (true) oder collapsed
|
||||
* @throws IllegalArgumentException thrown if the feed type of the
|
||||
* WireFeedOutput and WireFeed don't match.
|
||||
* @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
|
||||
* @throws IOException thrown if there was some problem writing to the File.
|
||||
* @throws FeedException thrown if the XML representation for the feed could
|
||||
* not be created.
|
||||
* @throws FeedException thrown if the XML representation for the feed could not be created.
|
||||
*
|
||||
*/
|
||||
public void output(final WireFeed feed, final File file, final boolean prettyPrint) throws IllegalArgumentException, IOException, FeedException {
|
||||
|
@ -209,25 +176,17 @@ public class WireFeedOutput {
|
|||
/**
|
||||
* Writes to an Writer the XML representation for the given WireFeed.
|
||||
* <p>
|
||||
* If the feed encoding is not NULL, it will be used in the XML prolog
|
||||
* encoding attribute. It is the responsibility of the developer to ensure
|
||||
* the Writer instance is using the same charset encoding.
|
||||
* If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility of the developer to ensure the Writer
|
||||
* instance is using the same charset encoding.
|
||||
* <p>
|
||||
* NOTE: This method delages to the 'Document
|
||||
* WireFeedOutput#outputJDom(WireFeed)'.
|
||||
* NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
|
||||
* <p>
|
||||
*
|
||||
* @param feed Abstract feed to create XML representation from. The type of
|
||||
* the WireFeed must match the type given to the FeedOuptut
|
||||
* constructor.
|
||||
* @param writer Writer to write the XML representation for the given
|
||||
* WireFeed.
|
||||
* @throws IllegalArgumentException thrown if the feed type of the
|
||||
* WireFeedOutput and WireFeed don't match.
|
||||
* @throws IOException thrown if there was some problem writing to the
|
||||
* Writer.
|
||||
* @throws FeedException thrown if the XML representation for the feed could
|
||||
* not be created.
|
||||
* @param feed Abstract feed to create XML representation from. The type of the WireFeed must match the type given to the FeedOuptut constructor.
|
||||
* @param writer Writer to write the XML representation for the given WireFeed.
|
||||
* @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
|
||||
* @throws IOException thrown if there was some problem writing to the Writer.
|
||||
* @throws FeedException thrown if the XML representation for the feed could not be created.
|
||||
*
|
||||
*/
|
||||
public void output(final WireFeed feed, final Writer writer) throws IllegalArgumentException, IOException, FeedException {
|
||||
|
@ -237,26 +196,18 @@ public class WireFeedOutput {
|
|||
/**
|
||||
* Writes to an Writer the XML representation for the given WireFeed.
|
||||
* <p>
|
||||
* If the feed encoding is not NULL, it will be used in the XML prolog
|
||||
* encoding attribute. It is the responsibility of the developer to ensure
|
||||
* the Writer instance is using the same charset encoding.
|
||||
* If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility of the developer to ensure the Writer
|
||||
* instance is using the same charset encoding.
|
||||
* <p>
|
||||
* NOTE: This method delages to the 'Document
|
||||
* WireFeedOutput#outputJDom(WireFeed)'.
|
||||
* NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
|
||||
* <p>
|
||||
*
|
||||
* @param feed Abstract feed to create XML representation from. The type of
|
||||
* the WireFeed must match the type given to the FeedOuptut
|
||||
* constructor.
|
||||
* @param writer Writer to write the XML representation for the given
|
||||
* WireFeed.
|
||||
* @param feed Abstract feed to create XML representation from. The type of the WireFeed must match the type given to the FeedOuptut constructor.
|
||||
* @param writer Writer to write the XML representation for the given WireFeed.
|
||||
* @param prettyPrint pretty-print XML (true) oder collapsed
|
||||
* @throws IllegalArgumentException thrown if the feed type of the
|
||||
* WireFeedOutput and WireFeed don't match.
|
||||
* @throws IOException thrown if there was some problem writing to the
|
||||
* Writer.
|
||||
* @throws FeedException thrown if the XML representation for the feed could
|
||||
* not be created.
|
||||
* @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
|
||||
* @throws IOException thrown if there was some problem writing to the Writer.
|
||||
* @throws FeedException thrown if the XML representation for the feed could not be created.
|
||||
*
|
||||
*/
|
||||
public void output(final WireFeed feed, final Writer writer, final boolean prettyPrint) throws IllegalArgumentException, IOException, FeedException {
|
||||
|
@ -280,18 +231,13 @@ public class WireFeedOutput {
|
|||
* <p>
|
||||
* This method does not use the feed encoding property.
|
||||
* <p>
|
||||
* NOTE: This method delages to the 'Document
|
||||
* WireFeedOutput#outputJDom(WireFeed)'.
|
||||
* NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
|
||||
* <p>
|
||||
*
|
||||
* @param feed Abstract feed to create W3C DOM document from. The type of
|
||||
* the WireFeed must match the type given to the FeedOuptut
|
||||
* constructor.
|
||||
* @param feed Abstract feed to create W3C DOM document from. The type of the WireFeed must match the type given to the FeedOuptut constructor.
|
||||
* @return the W3C DOM document for the given WireFeed.
|
||||
* @throws IllegalArgumentException thrown if the feed type of the
|
||||
* WireFeedOutput and WireFeed don't match.
|
||||
* @throws FeedException thrown if the W3C DOM document for the feed could
|
||||
* not be created.
|
||||
* @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
|
||||
* @throws FeedException thrown if the W3C DOM document for the feed could not be created.
|
||||
*
|
||||
*/
|
||||
public org.w3c.dom.Document outputW3CDom(final WireFeed feed) throws IllegalArgumentException, FeedException {
|
||||
|
@ -312,14 +258,10 @@ public class WireFeedOutput {
|
|||
* NOTE: All other output methods delegate to this method.
|
||||
* <p>
|
||||
*
|
||||
* @param feed Abstract feed to create JDOM document from. The type of the
|
||||
* WireFeed must match the type given to the FeedOuptut
|
||||
* constructor.
|
||||
* @param feed Abstract feed to create JDOM document from. The type of the WireFeed must match the type given to the FeedOuptut constructor.
|
||||
* @return the JDOM document for the given WireFeed.
|
||||
* @throws IllegalArgumentException thrown if the feed type of the
|
||||
* WireFeedOutput and WireFeed don't match.
|
||||
* @throws FeedException thrown if the JDOM document for the feed could not
|
||||
* be created.
|
||||
* @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
|
||||
* @throws FeedException thrown if the JDOM document for the feed could not be created.
|
||||
*
|
||||
*/
|
||||
public Document outputJDom(final WireFeed feed) throws IllegalArgumentException, FeedException {
|
||||
|
|
|
@ -126,23 +126,18 @@ public abstract class PluginManager<T> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Loads and returns the classes defined in the properties files. If the
|
||||
* system property "rome.pluginmanager.useloadclass" is set to true then
|
||||
* classLoader.loadClass will be used to load classes (instead of
|
||||
* Class.forName). This is designed to improve OSGi compatibility. Further
|
||||
* information can be found in
|
||||
* https://rome.dev.java.net/issues/show_bug.cgi?id=118
|
||||
* Loads and returns the classes defined in the properties files. If the system property "rome.pluginmanager.useloadclass" is set to true then
|
||||
* classLoader.loadClass will be used to load classes (instead of Class.forName). This is designed to improve OSGi compatibility. Further information can be
|
||||
* found in https://rome.dev.java.net/issues/show_bug.cgi?id=118
|
||||
* <p>
|
||||
*
|
||||
* @return array containing the classes defined in the properties files.
|
||||
* @throws java.lang.ClassNotFoundException thrown if one of the classes
|
||||
* defined in the properties file cannot be loaded and hard
|
||||
* failure is ON.
|
||||
* @throws java.lang.ClassNotFoundException thrown if one of the classes defined in the properties file cannot be loaded and hard failure is ON.
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private Class<T>[] getClasses() throws ClassNotFoundException {
|
||||
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
final ClassLoader classLoader = PluginManager.class.getClassLoader();
|
||||
final List<Class<T>> classes = new ArrayList<Class<T>>();
|
||||
final boolean useLoadClass = Boolean.valueOf(System.getProperty("rome.pluginmanager.useloadclass", "false")).booleanValue();
|
||||
for (final String propertyValue : propertyValues) {
|
||||
|
|
|
@ -12,15 +12,12 @@ import java.util.StringTokenizer;
|
|||
import java.util.WeakHashMap;
|
||||
|
||||
/**
|
||||
* Properties loader that aggregates a master properties file and several extra
|
||||
* properties files, all from the current classpath.
|
||||
* Properties loader that aggregates a master properties file and several extra properties files, all from the current classpath.
|
||||
* <P>
|
||||
* The master properties file has to be in a distinct location than the extra
|
||||
* properties files. First the master properties file is loaded, then all the
|
||||
* extra properties files in their order of appearance in the classpath.
|
||||
* The master properties file has to be in a distinct location than the extra properties files. First the master properties file is loaded, then all the extra
|
||||
* properties files in their order of appearance in the classpath.
|
||||
* <P>
|
||||
* Current use cases (plugin manager for parsers/converters/generators for feeds
|
||||
* and modules and date formats) assume properties are list of tokens, that why
|
||||
* Current use cases (plugin manager for parsers/converters/generators for feeds and modules and date formats) assume properties are list of tokens, that why
|
||||
* the only method to get property values is the getTokenizedProperty().
|
||||
* <p>
|
||||
*
|
||||
|
@ -35,19 +32,19 @@ public class PropertiesLoader {
|
|||
private static Map<ClassLoader, PropertiesLoader> clMap = new WeakHashMap<ClassLoader, PropertiesLoader>();
|
||||
|
||||
/**
|
||||
* Returns the PropertiesLoader singleton used by ROME to load plugin
|
||||
* components.
|
||||
* Returns the PropertiesLoader singleton used by ROME to load plugin components.
|
||||
*
|
||||
* @return PropertiesLoader singleton.
|
||||
*
|
||||
*/
|
||||
public static PropertiesLoader getPropertiesLoader() {
|
||||
synchronized (PropertiesLoader.class) {
|
||||
PropertiesLoader loader = clMap.get(Thread.currentThread().getContextClassLoader());
|
||||
final ClassLoader classLoader = PropertiesLoader.class.getClassLoader();
|
||||
PropertiesLoader loader = clMap.get(classLoader);
|
||||
if (loader == null) {
|
||||
try {
|
||||
loader = new PropertiesLoader(MASTER_PLUGIN_FILE, EXTRA_PLUGIN_FILE);
|
||||
clMap.put(Thread.currentThread().getContextClassLoader(), loader);
|
||||
clMap.put(classLoader, loader);
|
||||
} catch (final IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
@ -64,13 +61,12 @@ public class PropertiesLoader {
|
|||
*
|
||||
* @param masterFileLocation master file location, there must be only one.
|
||||
* @param extraFileLocation extra file location, there may be many.
|
||||
* @throws IOException thrown if one of the properties file could not be
|
||||
* read.
|
||||
* @throws IOException thrown if one of the properties file could not be read.
|
||||
*
|
||||
*/
|
||||
private PropertiesLoader(final String masterFileLocation, final String extraFileLocation) throws IOException {
|
||||
final List<Properties> propertiesList = new ArrayList<Properties>();
|
||||
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
final ClassLoader classLoader = PropertiesLoader.class.getClassLoader();
|
||||
|
||||
try {
|
||||
final InputStream is = classLoader.getResourceAsStream(masterFileLocation);
|
||||
|
@ -105,16 +101,13 @@ public class PropertiesLoader {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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.
|
||||
* <p>
|
||||
*
|
||||
* @param key property key to retrieve values
|
||||
* @param separator String with all separator characters to tokenize from
|
||||
* the values in all properties files.
|
||||
* @return all the tokens for the given property key from all the properties
|
||||
* files.
|
||||
* @param separator String with all separator characters to tokenize from the values in all properties files.
|
||||
* @return all the tokens for the given property key from all the properties files.
|
||||
*
|
||||
*/
|
||||
public String[] getTokenizedProperty(final String key, final String separator) {
|
||||
|
@ -135,14 +128,12 @@ public class PropertiesLoader {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns an array of values stored under a property key in all properties
|
||||
* files. If the master file has this property it will be the first ones in
|
||||
* the array.
|
||||
* Returns an array of values stored under a property key in all properties files. If the master file has this property it will be the first ones in the
|
||||
* array.
|
||||
* <p>
|
||||
*
|
||||
* @param key property key to retrieve values
|
||||
* @return all the values for the given property key from all the properties
|
||||
* files.
|
||||
* @return all the values for the given property key from all the properties files.
|
||||
*
|
||||
*/
|
||||
public String[] getProperty(final String key) {
|
||||
|
|
|
@ -36,7 +36,7 @@ public abstract class FeedTest extends TestCase {
|
|||
}
|
||||
|
||||
protected Reader getFeedReader() throws Exception {
|
||||
final InputStream resource = Thread.currentThread().getContextClassLoader().getResourceAsStream(getFeedFileName());
|
||||
final InputStream resource = FeedTest.class.getClassLoader().getResourceAsStream(getFeedFileName());
|
||||
assertNotNull("Could not find resource " + getFeedFileName(), resource);
|
||||
return new InputStreamReader(resource);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue