Refactoring code
This commit is contained in:
parent
b50771724f
commit
3d42211970
2 changed files with 19 additions and 15 deletions
|
@ -38,22 +38,25 @@ public abstract class AbstractFeedFetcher implements FeedFetcher {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(AbstractFeedFetcher.class);
|
private static final Logger LOG = LoggerFactory.getLogger(AbstractFeedFetcher.class);
|
||||||
|
|
||||||
private final Set<FetcherListener> fetcherEventListeners;
|
private final Set<FetcherListener> listeners;
|
||||||
private String userAgent;
|
private String userAgent;
|
||||||
private boolean usingDeltaEncoding;
|
private boolean usingDeltaEncoding;
|
||||||
private boolean preserveWireFeed;
|
private boolean preserveWireFeed;
|
||||||
|
|
||||||
public AbstractFeedFetcher() {
|
public AbstractFeedFetcher() {
|
||||||
fetcherEventListeners = Collections.synchronizedSet(new HashSet<FetcherListener>());
|
|
||||||
|
listeners = Collections.synchronizedSet(new HashSet<FetcherListener>());
|
||||||
|
|
||||||
final Properties props = new Properties(System.getProperties());
|
final Properties props = new Properties(System.getProperties());
|
||||||
final String resourceName = "fetcher.properties";
|
final String resourceName = "fetcher.properties";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(resourceName);
|
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(resourceName);
|
||||||
if (inputStream == null) {
|
if (inputStream == null) {
|
||||||
inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName);
|
inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inputStream != null) {
|
if (inputStream != null) {
|
||||||
props.load(inputStream);
|
props.load(inputStream);
|
||||||
System.getProperties().putAll(props);
|
System.getProperties().putAll(props);
|
||||||
|
@ -61,6 +64,7 @@ public abstract class AbstractFeedFetcher implements FeedFetcher {
|
||||||
} else {
|
} else {
|
||||||
LOG.warn("Could not find {} on classpath", resourceName);
|
LOG.warn("Could not find {} on classpath", resourceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
// do nothing - we don't want to fail just because we could not find the version
|
// do nothing - we don't want to fail just because we could not find the version
|
||||||
LOG.error("Error reading {} from classpath: {}", resourceName, e.getMessage());
|
LOG.error("Error reading {} from classpath: {}", resourceName, e.getMessage());
|
||||||
|
@ -117,8 +121,8 @@ public abstract class AbstractFeedFetcher implements FeedFetcher {
|
||||||
*/
|
*/
|
||||||
protected void fireEvent(final String eventType, final String urlStr, final SyndFeed feed) {
|
protected void fireEvent(final String eventType, final String urlStr, final SyndFeed feed) {
|
||||||
final FetcherEvent fetcherEvent = new FetcherEvent(this, urlStr, eventType, feed);
|
final FetcherEvent fetcherEvent = new FetcherEvent(this, urlStr, eventType, feed);
|
||||||
synchronized (fetcherEventListeners) {
|
synchronized (listeners) {
|
||||||
for (final FetcherListener fetcherEventListener : fetcherEventListeners) {
|
for (final FetcherListener fetcherEventListener : listeners) {
|
||||||
fetcherEventListener.fetcherEvent(fetcherEvent);
|
fetcherEventListener.fetcherEvent(fetcherEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,14 +131,14 @@ public abstract class AbstractFeedFetcher implements FeedFetcher {
|
||||||
@Override
|
@Override
|
||||||
public void addFetcherEventListener(final FetcherListener listener) {
|
public void addFetcherEventListener(final FetcherListener listener) {
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
fetcherEventListeners.add(listener);
|
listeners.add(listener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeFetcherEventListener(final FetcherListener listener) {
|
public void removeFetcherEventListener(final FetcherListener listener) {
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
fetcherEventListeners.remove(listener);
|
listeners.remove(listener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,9 +202,8 @@ public abstract class AbstractFeedFetcher implements FeedFetcher {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static SyndFeed combineFeeds(final SyndFeed originalFeed, final SyndFeed newFeed) {
|
public static SyndFeed combineFeeds(final SyndFeed originalFeed, final SyndFeed newFeed) {
|
||||||
SyndFeed result;
|
|
||||||
try {
|
try {
|
||||||
result = (SyndFeed) newFeed.clone();
|
final SyndFeed result = (SyndFeed) newFeed.clone();
|
||||||
result.getEntries().addAll(result.getEntries().size(), originalFeed.getEntries());
|
result.getEntries().addAll(result.getEntries().size(), originalFeed.getEntries());
|
||||||
return result;
|
return result;
|
||||||
} catch (final CloneNotSupportedException e) {
|
} catch (final CloneNotSupportedException e) {
|
||||||
|
|
|
@ -11,22 +11,23 @@ public class AbstractFeedFetcherBeanInfo extends SimpleBeanInfo {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EventSetDescriptor[] getEventSetDescriptors() {
|
public EventSetDescriptor[] getEventSetDescriptors() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final Class<AbstractFeedFetcher> clz = AbstractFeedFetcher.class; // get the class
|
|
||||||
// object which we'll
|
// get the class object which we'll describe
|
||||||
// describe
|
final Class<AbstractFeedFetcher> clz = AbstractFeedFetcher.class;
|
||||||
final Method addMethod = clz.getMethod("addFetcherEventListener", new Class[] { FetcherListener.class });
|
final Method addMethod = clz.getMethod("addFetcherEventListener", new Class[] { FetcherListener.class });
|
||||||
final Method removeMethod = clz.getMethod("removeFetcherEventListener", new Class[] { FetcherListener.class });
|
final Method removeMethod = clz.getMethod("removeFetcherEventListener", new Class[] { FetcherListener.class });
|
||||||
final Method listenerMethod = FetcherListener.class.getMethod("fetcherEvent", new Class[] { FetcherEvent.class });
|
final Method listenerMethod = FetcherListener.class.getMethod("fetcherEvent", new Class[] { FetcherEvent.class });
|
||||||
final EventSetDescriptor est = new EventSetDescriptor("fetcherEvent", clz, new Method[] { listenerMethod }, addMethod, removeMethod);
|
final EventSetDescriptor est = new EventSetDescriptor("fetcherEvent", clz, new Method[] { listenerMethod }, addMethod, removeMethod);
|
||||||
final EventSetDescriptor[] results = new EventSetDescriptor[] { est };
|
return new EventSetDescriptor[] { est };
|
||||||
return results;
|
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
// IntrospectionException, SecurityException and/or NoSuchMethodException can be thrown
|
// IntrospectionException, SecurityException and/or NoSuchMethodException can be thrown
|
||||||
// here
|
// here. The best we can do is to convert them to runtime exceptions
|
||||||
// the best we can do is to convert them to runtime exceptions
|
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue