Refactored some code

This commit is contained in:
Patrick Gotthard 2014-04-13 20:08:21 +02:00
parent d4b34a05cd
commit 3a31c851b6
8 changed files with 147 additions and 145 deletions

View file

@ -24,7 +24,6 @@ import java.lang.reflect.Modifier;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -39,9 +38,9 @@ import org.slf4j.LoggerFactory;
* It works on all read/write properties, recursively. It support all primitive types, Strings, * It works on all read/write properties, recursively. It support all primitive types, Strings,
* Collections, Cloneable objects and multi-dimensional arrays of any of them. * Collections, Cloneable objects and multi-dimensional arrays of any of them.
* <p> * <p>
* *
* @author Alejandro Abdelnur * @author Alejandro Abdelnur
* *
*/ */
public class CloneableBean implements Serializable, Cloneable { public class CloneableBean implements Serializable, Cloneable {
@ -72,7 +71,7 @@ public class CloneableBean implements Serializable, Cloneable {
* <p> * <p>
* To be used by classes extending CloneableBean only. * To be used by classes extending CloneableBean only.
* <p> * <p>
* *
*/ */
protected CloneableBean() { protected CloneableBean() {
obj = this; obj = this;
@ -86,21 +85,21 @@ public class CloneableBean implements Serializable, Cloneable {
* <code> * <code>
* public class Foo implements Cloneable { * public class Foo implements Cloneable {
* private CloneableBean cloneableBean; * private CloneableBean cloneableBean;
* *
* public Foo() { * public Foo() {
* cloneableBean = new CloneableBean(this); * cloneableBean = new CloneableBean(this);
* } * }
* *
* public Object clone() throws CloneNotSupportedException { * public Object clone() throws CloneNotSupportedException {
* return cloneableBean.beanClone(); * return cloneableBean.beanClone();
* } * }
* *
* } * }
* </code> * </code>
* <p> * <p>
* *
* @param obj object bean to clone. * @param obj object bean to clone.
* *
*/ */
public CloneableBean(final Object obj) { public CloneableBean(final Object obj) {
this(obj, null); this(obj, null);
@ -115,10 +114,10 @@ public class CloneableBean implements Serializable, Cloneable {
* and SyndEntry beans have convenience properties, publishedDate, author, copyright and * and SyndEntry beans have convenience properties, publishedDate, author, copyright and
* categories all of them mapped to properties in the DC Module. * categories all of them mapped to properties in the DC Module.
* <p> * <p>
* *
* @param obj object bean to clone. * @param obj object bean to clone.
* @param ignoreProperties properties to ignore when cloning. * @param ignoreProperties properties to ignore when cloning.
* *
*/ */
public CloneableBean(final Object obj, final Set<String> ignoreProperties) { public CloneableBean(final Object obj, final Set<String> ignoreProperties) {
this.obj = obj; this.obj = obj;
@ -134,12 +133,12 @@ public class CloneableBean implements Serializable, Cloneable {
* <p> * <p>
* To be used by classes extending CloneableBean. Although it works also for classes using * To be used by classes extending CloneableBean. Although it works also for classes using
* CloneableBean in a delegation pattern, for correctness those classes should use the * CloneableBean in a delegation pattern, for correctness those classes should use the
* *
* @see #beanClone() beanClone method. * @see #beanClone() beanClone method.
* <p> * <p>
* @return a clone of the object bean. * @return a clone of the object bean.
* @throws CloneNotSupportedException thrown if the object bean could not be cloned. * @throws CloneNotSupportedException thrown if the object bean could not be cloned.
* *
*/ */
@Override @Override
public Object clone() throws CloneNotSupportedException { public Object clone() throws CloneNotSupportedException {
@ -150,12 +149,12 @@ public class CloneableBean implements Serializable, Cloneable {
* Makes a deep bean clone of the object passed in the constructor. * Makes a deep bean clone of the object passed in the constructor.
* <p> * <p>
* To be used by classes using CloneableBean in a delegation pattern, * To be used by classes using CloneableBean in a delegation pattern,
* *
* @see #CloneableBean(Object) constructor. * @see #CloneableBean(Object) constructor.
* *
* @return a clone of the object bean. * @return a clone of the object bean.
* @throws CloneNotSupportedException thrown if the object bean could not be cloned. * @throws CloneNotSupportedException thrown if the object bean could not be cloned.
* *
*/ */
public Object beanClone() throws CloneNotSupportedException { public Object beanClone() throws CloneNotSupportedException {
@ -238,23 +237,20 @@ public class CloneableBean implements Serializable, Cloneable {
private <T> Collection<T> cloneCollection(final Collection<T> collection) throws Exception { private <T> Collection<T> cloneCollection(final Collection<T> collection) throws Exception {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
final Class<Collection<T>> mClass = (Class<Collection<T>>) collection.getClass(); final Collection<T> newCollection = collection.getClass().newInstance();
final Collection<T> newColl = mClass.newInstance(); for (final T item : collection) {
final Iterator<T> i = collection.iterator(); newCollection.add(doClone(item));
while (i.hasNext()) {
newColl.add(doClone(i.next()));
} }
return newColl; return newCollection;
} }
private <S, T> Map<S, T> cloneMap(final Map<S, T> map) throws Exception { private <K, V> Map<K, V> cloneMap(final Map<K, V> map) throws Exception {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
final Class<Map<S, T>> mClass = (Class<Map<S, T>>) map.getClass(); final Map<K, V> newMap = map.getClass().newInstance();
final Map<S, T> newMap = mClass.newInstance(); for (final Entry<K, V> entry : map.entrySet()) {
final Iterator<Entry<S, T>> entries = map.entrySet().iterator(); final K clonedKey = doClone(entry.getKey());
while (entries.hasNext()) { final V clonedValue = doClone(entry.getValue());
final Map.Entry<S, T> entry = entries.next(); newMap.put(clonedKey, clonedValue);
newMap.put(doClone(entry.getKey()), doClone(entry.getValue()));
} }
return newMap; return newMap;
} }

View file

@ -24,7 +24,6 @@ import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -130,7 +129,7 @@ public class CopyFromHelper {
} else { // it goes CopyFrom } else { // it goes CopyFrom
if (value instanceof CopyFrom) { if (value instanceof CopyFrom) {
final CopyFrom source = (CopyFrom) value; final CopyFrom source = (CopyFrom) value;
CopyFrom target = (CopyFrom) createInstance(source.getInterface()); CopyFrom target = createInstance(source.getInterface());
if (target == null) { if (target == null) {
target = (CopyFrom) value.getClass().newInstance(); target = (CopyFrom) value.getClass().newInstance();
} }
@ -157,32 +156,40 @@ public class CopyFromHelper {
} }
private <T> Collection<T> doCopyCollection(final Collection<T> collection, final Class<?> baseInterface) throws Exception { private <T> Collection<T> doCopyCollection(final Collection<T> collection, final Class<?> baseInterface) throws Exception {
// expecting SETs or LISTs only, going default implementation of them
final Collection<T> newColl; // expecting a set or a list
final Collection<T> newCollection;
if (collection instanceof Set) { if (collection instanceof Set) {
newColl = new LinkedHashSet<T>(); newCollection = new LinkedHashSet<T>();
} else { } else {
newColl = new ArrayList<T>(); newCollection = new ArrayList<T>();
} }
final Iterator<T> i = collection.iterator();
while (i.hasNext()) { for (final T item : collection) {
newColl.add(this.<T> doCopy(i.next(), baseInterface)); final T copied = doCopy(item, baseInterface);
newCollection.add(copied);
} }
return newColl;
return newCollection;
} }
private <S, T> Map<S, T> doCopyMap(final Map<S, T> map, final Class<?> baseInterface) throws Exception { private <S, T> Map<S, T> doCopyMap(final Map<S, T> map, final Class<?> baseInterface) throws Exception {
final Map<S, T> newMap = new HashMap<S, T>(); final Map<S, T> newMap = new HashMap<S, T>();
final Iterator<Entry<S, T>> entries = map.entrySet().iterator();
while (entries.hasNext()) { for (final Entry<S, T> entry : map.entrySet()) {
final Map.Entry<S, T> entry = entries.next(); // TODO mustn't the key be copied too?
newMap.put(entry.getKey(), doCopy(entry.getValue(), baseInterface)); final T copiedValue = doCopy(entry.getValue(), baseInterface);
newMap.put(entry.getKey(), copiedValue);
} }
return newMap; return newMap;
} }
private boolean isBasicType(final Class<?> vClass) { private boolean isBasicType(final Class<?> type) {
return BASIC_TYPES.contains(vClass); return BASIC_TYPES.contains(type);
} }
} }

View file

@ -17,7 +17,6 @@
package com.sun.syndication.io.impl; package com.sun.syndication.io.impl;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -257,18 +256,17 @@ public class Atom03Parser extends BaseWireFeedParser {
value = Base64.decode(e.getText()); value = Base64.decode(e.getText());
} else if (mode.equals(Content.XML)) { } else if (mode.equals(Content.XML)) {
final XMLOutputter outputter = new XMLOutputter(); final XMLOutputter outputter = new XMLOutputter();
final List<org.jdom2.Content> eContent = e.getContent(); final List<org.jdom2.Content> contents = e.getContent();
final Iterator<org.jdom2.Content> i = eContent.iterator(); for (final org.jdom2.Content content : contents) {
while (i.hasNext()) { if (content instanceof Element) {
final org.jdom2.Content c = i.next(); final Element element = (Element) content;
if (c instanceof Element) { if (element.getNamespace().equals(getAtomNamespace())) {
final Element eC = (Element) c; element.setNamespace(Namespace.NO_NAMESPACE);
if (eC.getNamespace().equals(getAtomNamespace())) {
((Element) c).setNamespace(Namespace.NO_NAMESPACE);
} }
} }
} }
value = outputter.outputString(eContent); value = outputter.outputString(contents);
} }
final Content content = new Content(); final Content content = new Content();

View file

@ -20,7 +20,6 @@ import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -49,7 +48,7 @@ import com.sun.syndication.io.WireFeedOutput;
/** /**
* Parser for Atom 1.0 * Parser for Atom 1.0
* *
* @author Dave Johnson * @author Dave Johnson
*/ */
public class Atom10Parser extends BaseWireFeedParser { public class Atom10Parser extends BaseWireFeedParser {
@ -336,18 +335,16 @@ public class Atom10Parser extends BaseWireFeedParser {
if (type.equals(Content.XHTML) || type.indexOf("/xml") != -1 || type.indexOf("+xml") != -1) { if (type.equals(Content.XHTML) || type.indexOf("/xml") != -1 || type.indexOf("+xml") != -1) {
// XHTML content needs special handling // XHTML content needs special handling
final XMLOutputter outputter = new XMLOutputter(); final XMLOutputter outputter = new XMLOutputter();
final List<org.jdom2.Content> eContent = e.getContent(); final List<org.jdom2.Content> contents = e.getContent();
final Iterator<org.jdom2.Content> i = eContent.iterator(); for (final org.jdom2.Content content : contents) {
while (i.hasNext()) { if (content instanceof Element) {
final org.jdom2.Content c = i.next(); final Element element = (Element) content;
if (c instanceof Element) { if (element.getNamespace().equals(getAtomNamespace())) {
final Element eC = (Element) c; element.setNamespace(Namespace.NO_NAMESPACE);
if (eC.getNamespace().equals(getAtomNamespace())) {
((Element) c).setNamespace(Namespace.NO_NAMESPACE);
} }
} }
} }
value = outputter.outputString(eContent); value = outputter.outputString(contents);
} else { } else {
// Everything else comes in verbatim // Everything else comes in verbatim
value = e.getText(); value = e.getText();
@ -503,7 +500,7 @@ public class Atom10Parser extends BaseWireFeedParser {
/** /**
* Resolve URI via base URL and parent element. Resolve URI based considering xml:base and * Resolve URI via base URL and parent element. Resolve URI based considering xml:base and
* baseURI. * baseURI.
* *
* @param baseURI Base URI used to fetch the XML document * @param baseURI Base URI used to fetch the XML document
* @param parent Parent element from which to consider xml:base * @param parent Parent element from which to consider xml:base
* @param url URL to be resolved * @param url URL to be resolved
@ -568,7 +565,7 @@ public class Atom10Parser extends BaseWireFeedParser {
/** /**
* Find base URI of feed considering relative URIs. * Find base URI of feed considering relative URIs.
* *
* @param root Root element of feed. * @param root Root element of feed.
*/ */
private String findBaseURI(final Element root) throws MalformedURLException { private String findBaseURI(final Element root) throws MalformedURLException {
@ -589,7 +586,7 @@ public class Atom10Parser extends BaseWireFeedParser {
/** /**
* Return URL string of Atom link element under parent element. Link with no rel attribute is * Return URL string of Atom link element under parent element. Link with no rel attribute is
* considered to be rel="alternate" * considered to be rel="alternate"
* *
* @param parent Consider only children of this parent element * @param parent Consider only children of this parent element
* @param rel Consider only links with this relationship * @param rel Consider only links with this relationship
*/ */
@ -613,7 +610,7 @@ public class Atom10Parser extends BaseWireFeedParser {
/** /**
* Form URI by combining base with append portion and giving special consideration to append * Form URI by combining base with append portion and giving special consideration to append
* portions that begin with ".." * portions that begin with ".."
* *
* @param base Base of URI, may end with trailing slash * @param base Base of URI, may end with trailing slash
* @param append String to append, may begin with slash or ".." * @param append String to append, may begin with slash or ".."
*/ */

View file

@ -2,7 +2,6 @@ package com.sun.syndication.io.impl;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -40,25 +39,31 @@ public abstract class BaseWireFeedGenerator implements WireFeedGenerator {
private final Namespace[] allModuleNamespaces; private final Namespace[] allModuleNamespaces;
protected BaseWireFeedGenerator(final String type) { protected BaseWireFeedGenerator(final String type) {
this.type = type; this.type = type;
feedModuleGenerators = new ModuleGenerators(type + FEED_MODULE_GENERATORS_POSFIX_KEY, this); feedModuleGenerators = new ModuleGenerators(type + FEED_MODULE_GENERATORS_POSFIX_KEY, this);
itemModuleGenerators = new ModuleGenerators(type + ITEM_MODULE_GENERATORS_POSFIX_KEY, this); itemModuleGenerators = new ModuleGenerators(type + ITEM_MODULE_GENERATORS_POSFIX_KEY, this);
personModuleGenerators = new ModuleGenerators(type + PERSON_MODULE_GENERATORS_POSFIX_KEY, this); personModuleGenerators = new ModuleGenerators(type + PERSON_MODULE_GENERATORS_POSFIX_KEY, this);
final Set<Namespace> allModuleNamespaces = new HashSet<Namespace>(); final Set<Namespace> allModuleNamespaces = new HashSet<Namespace>();
Iterator<Namespace> i = feedModuleGenerators.getAllNamespaces().iterator();
while (i.hasNext()) { for (final Namespace namespace : feedModuleGenerators.getAllNamespaces()) {
allModuleNamespaces.add(i.next()); allModuleNamespaces.add(namespace);
} }
i = itemModuleGenerators.getAllNamespaces().iterator();
while (i.hasNext()) { for (final Namespace namespace : itemModuleGenerators.getAllNamespaces()) {
allModuleNamespaces.add(i.next()); allModuleNamespaces.add(namespace);
} }
i = personModuleGenerators.getAllNamespaces().iterator();
while (i.hasNext()) { for (final Namespace namespace : personModuleGenerators.getAllNamespaces()) {
allModuleNamespaces.add(i.next()); allModuleNamespaces.add(namespace);
} }
this.allModuleNamespaces = new Namespace[allModuleNamespaces.size()]; this.allModuleNamespaces = new Namespace[allModuleNamespaces.size()];
allModuleNamespaces.toArray(this.allModuleNamespaces); allModuleNamespaces.toArray(this.allModuleNamespaces);
} }
@Override @Override
@ -84,16 +89,14 @@ public abstract class BaseWireFeedGenerator implements WireFeedGenerator {
personModuleGenerators.generateModules(modules, person); personModuleGenerators.generateModules(modules, person);
} }
protected void generateForeignMarkup(final Element e, final List<Element> foreignMarkup) { protected void generateForeignMarkup(final Element element, final List<Element> foreignElements) {
if (foreignMarkup != null) { if (foreignElements != null) {
final Iterator<Element> elems = foreignMarkup.iterator(); for (final Element foreignElement : foreignElements) {
while (elems.hasNext()) { final Parent parent = foreignElement.getParent();
final Element elem = elems.next();
final Parent parent = elem.getParent();
if (parent != null) { if (parent != null) {
parent.removeContent(elem); parent.removeContent(foreignElement);
} }
e.addContent(elem); element.addContent(foreignElement);
} }
} }
} }
@ -109,14 +112,15 @@ public abstract class BaseWireFeedGenerator implements WireFeedGenerator {
* at generate() time, to make sure their namespace declarations are present. * at generate() time, to make sure their namespace declarations are present.
*/ */
protected static void purgeUnusedNamespaceDeclarations(final Element root) { protected static void purgeUnusedNamespaceDeclarations(final Element root) {
final Set<String> usedPrefixes = new HashSet<String>(); final Set<String> usedPrefixes = new HashSet<String>();
collectUsedPrefixes(root, usedPrefixes); collectUsedPrefixes(root, usedPrefixes);
final List<Namespace> list = root.getAdditionalNamespaces(); final List<Namespace> list = root.getAdditionalNamespaces();
final List<Namespace> additionalNamespaces = new ArrayList<Namespace>(); final List<Namespace> additionalNamespaces = new ArrayList<Namespace>();
additionalNamespaces.addAll(list); // the duplication will prevent a additionalNamespaces.addAll(list); // the duplication will prevent a
// ConcurrentModificationException // ConcurrentModificationException
// below // below
for (int i = 0; i < additionalNamespaces.size(); i++) { for (int i = 0; i < additionalNamespaces.size(); i++) {
final Namespace ns = additionalNamespaces.get(i); final Namespace ns = additionalNamespaces.get(i);
@ -135,7 +139,7 @@ public abstract class BaseWireFeedGenerator implements WireFeedGenerator {
final List<Element> kids = el.getChildren(); final List<Element> kids = el.getChildren();
for (int i = 0; i < kids.size(); i++) { for (int i = 0; i < kids.size(); i++) {
collectUsedPrefixes(kids.get(i), collector); // recursion collectUsedPrefixes(kids.get(i), collector); // recursion
// - worth it // - worth it
} }
} }

View file

@ -1,7 +1,6 @@
package com.sun.syndication.io.impl; package com.sun.syndication.io.impl;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -24,19 +23,19 @@ import com.sun.syndication.io.WireFeedParser;
public abstract class BaseWireFeedParser implements WireFeedParser { public abstract class BaseWireFeedParser implements WireFeedParser {
/** /**
* [TYPE].feed.ModuleParser.classes= [className] ... * [TYPE].feed.ModuleParser.classes= [className] ...
* *
*/ */
private static final String FEED_MODULE_PARSERS_POSFIX_KEY = ".feed.ModuleParser.classes"; private static final String FEED_MODULE_PARSERS_POSFIX_KEY = ".feed.ModuleParser.classes";
/** /**
* [TYPE].item.ModuleParser.classes= [className] ... * [TYPE].item.ModuleParser.classes= [className] ...
* *
*/ */
private static final String ITEM_MODULE_PARSERS_POSFIX_KEY = ".item.ModuleParser.classes"; private static final String ITEM_MODULE_PARSERS_POSFIX_KEY = ".item.ModuleParser.classes";
/** /**
* [TYPE].person.ModuleParser.classes= [className] ... * [TYPE].person.ModuleParser.classes= [className] ...
* *
*/ */
private static final String PERSON_MODULE_PARSERS_POSFIX_KEY = ".person.ModuleParser.classes"; private static final String PERSON_MODULE_PARSERS_POSFIX_KEY = ".person.ModuleParser.classes";
@ -57,11 +56,11 @@ public abstract class BaseWireFeedParser implements WireFeedParser {
/** /**
* Returns the type of feed the parser handles. * Returns the type of feed the parser handles.
* <p> * <p>
* *
* @see WireFeed for details on the format of this string. * @see WireFeed for details on the format of this string.
* <p> * <p>
* @return the type of feed the parser handles. * @return the type of feed the parser handles.
* *
*/ */
@Override @Override
public String getType() { public String getType() {
@ -80,29 +79,25 @@ public abstract class BaseWireFeedParser implements WireFeedParser {
return personModuleParsers.parseModules(itemElement, locale); return personModuleParsers.parseModules(itemElement, locale);
} }
protected List<Element> extractForeignMarkup(final Element e, final Extendable ext, final Namespace basens) { protected List<Element> extractForeignMarkup(final Element e, final Extendable ext, final Namespace namespace) {
final ArrayList<Element> foreignMarkup = new ArrayList<Element>();
final Iterator<Element> children = e.getChildren().iterator();
while (children.hasNext()) {
final Element elem = children.next();
if (
// if elemet not in the RSS namespace
!basens.equals(elem.getNamespace())
// and elem was not handled by a module
&& null == ext.getModule(elem.getNamespaceURI())) {
// save it as foreign markup, final ArrayList<Element> foreignElements = new ArrayList<Element>();
// but we can't detach it while we're iterating
foreignMarkup.add(elem.clone()); for (final Element element : e.getChildren()) {
if (!namespace.equals(element.getNamespace()) && ext.getModule(element.getNamespaceURI()) == null) {
// if element not in the RSS namespace and elem was not handled by a module save it
// as foreign markup but we can't detach it while we're iterating
foreignElements.add(element.clone());
} }
} }
// Now we can detach the foreign markup elements
final Iterator<Element> fm = foreignMarkup.iterator(); // now we can detach the foreign markup elements
while (fm.hasNext()) { for (final Element foreignElement : foreignElements) {
final Element elem = fm.next(); foreignElement.detach();
elem.detach();
} }
return foreignMarkup;
return foreignElements;
} }
protected Attribute getAttribute(final Element e, final String attributeName) { protected Attribute getAttribute(final Element e, final String attributeName) {

View file

@ -17,6 +17,7 @@
package com.sun.syndication.io.impl; package com.sun.syndication.io.impl;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -31,9 +32,9 @@ import com.sun.syndication.io.WireFeedParser;
/** /**
* <p> * <p>
* *
* @author Alejandro Abdelnur * @author Alejandro Abdelnur
* *
*/ */
public abstract class PluginManager<T> { public abstract class PluginManager<T> {
private final String[] propertyValues; private final String[] propertyValues;
@ -46,9 +47,9 @@ public abstract class PluginManager<T> {
/** /**
* Creates a PluginManager * Creates a PluginManager
* <p> * <p>
* *
* @param propertyKey property key defining the plugins classes * @param propertyKey property key defining the plugins classes
* *
*/ */
protected PluginManager(final String propertyKey) { protected PluginManager(final String propertyKey) {
this(propertyKey, null, null); this(propertyKey, null, null);
@ -102,28 +103,30 @@ public abstract class PluginManager<T> {
} }
pluginsMap.put(getKey(plugin), plugin); pluginsMap.put(getKey(plugin), plugin);
pluginsList.add(plugin); // to preserve the order of // to preserve the order of definition in the rome.properties files
// definition pluginsList.add(plugin);
// in the rome.properties files
}
Iterator<T> i = pluginsMap.values().iterator();
while (i.hasNext()) {
finalPluginsList.add(i.next()); // to remove overridden plugin
// impls
} }
i = pluginsList.iterator(); final Collection<T> plugins = pluginsMap.values();
while (i.hasNext()) { for (final T plugin : plugins) {
final Object plugin = i.next(); // to remove overridden plugin impls
finalPluginsList.add(plugin);
}
final Iterator<T> iterator = pluginsList.iterator();
while (iterator.hasNext()) {
final T plugin = iterator.next();
if (!finalPluginsList.contains(plugin)) { if (!finalPluginsList.contains(plugin)) {
i.remove(); iterator.remove();
} }
} }
} catch (final Exception ex) { } catch (final Exception ex) {
throw new RuntimeException("could not instantiate plugin " + className, ex); throw new RuntimeException("could not instantiate plugin " + className, ex);
} catch (final ExceptionInInitializerError er) { } catch (final ExceptionInInitializerError er) {
throw new RuntimeException("could not instantiate plugin " + className, er); throw new RuntimeException("could not instantiate plugin " + className, er);
} }
} }
/** /**
@ -132,11 +135,11 @@ public abstract class PluginManager<T> {
* load classes (instead of Class.forName). This is designed to improve OSGi compatibility. * 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 * Further information can be found in https://rome.dev.java.net/issues/show_bug.cgi?id=118
* <p> * <p>
* *
* @return array containing the classes defined in the properties files. * @return array containing the classes defined in the properties files.
* @throws java.lang.ClassNotFoundException thrown if one of the classes defined in the * @throws java.lang.ClassNotFoundException thrown if one of the classes defined in the
* properties file cannot be loaded and hard failure is ON. * properties file cannot be loaded and hard failure is ON.
* *
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private Class<T>[] getClasses() throws ClassNotFoundException { private Class<T>[] getClasses() throws ClassNotFoundException {

View file

@ -102,7 +102,7 @@ public class RSS090Parser extends BaseWireFeedParser {
* <P> * <P>
* This implementation returns the EMTPY namespace. * This implementation returns the EMTPY namespace.
* <p> * <p>
* *
* @return returns the EMPTY namespace. * @return returns the EMPTY namespace.
*/ */
protected Namespace getRSSNamespace() { protected Namespace getRSSNamespace() {
@ -115,7 +115,7 @@ public class RSS090Parser extends BaseWireFeedParser {
* <P> * <P>
* This implementation returns the EMTPY namespace. * This implementation returns the EMTPY namespace.
* <p> * <p>
* *
* @return returns the EMPTY namespace. * @return returns the EMPTY namespace.
*/ */
protected Namespace getRDFNamespace() { protected Namespace getRDFNamespace() {
@ -127,7 +127,7 @@ public class RSS090Parser extends BaseWireFeedParser {
* <P> * <P>
* This implementation returns the EMTPY namespace. * This implementation returns the EMTPY namespace.
* <p> * <p>
* *
* @return returns the EMPTY namespace. * @return returns the EMPTY namespace.
*/ */
protected Namespace getContentNamespace() { protected Namespace getContentNamespace() {
@ -142,7 +142,7 @@ public class RSS090Parser extends BaseWireFeedParser {
* different RSS version may have this information in different parts of the XML tree (no * different RSS version may have this information in different parts of the XML tree (no
* assumptions made thanks to the specs variaty) * assumptions made thanks to the specs variaty)
* <p/> * <p/>
* *
* @param rssRoot the root element of the RSS document to parse. * @param rssRoot the root element of the RSS document to parse.
* @return the parsed Channel bean. * @return the parsed Channel bean.
*/ */
@ -227,7 +227,7 @@ public class RSS090Parser extends BaseWireFeedParser {
* <p/> * <p/>
* It reads title and url out of the 'image' element. * It reads title and url out of the 'image' element.
* <p/> * <p/>
* *
* @param rssRoot the root element of the RSS document to parse for image information. * @param rssRoot the root element of the RSS document to parse for image information.
* @return the parsed image bean. * @return the parsed image bean.
*/ */
@ -260,7 +260,7 @@ public class RSS090Parser extends BaseWireFeedParser {
* parseItem() for each item element. The resulting RSSItem of each item element is stored in a * parseItem() for each item element. The resulting RSSItem of each item element is stored in a
* list. * list.
* <p/> * <p/>
* *
* @param rssRoot the root element of the RSS document to parse for all items information. * @param rssRoot the root element of the RSS document to parse for all items information.
* @return a list with all the parsed RSSItem beans. * @return a list with all the parsed RSSItem beans.
*/ */
@ -280,7 +280,7 @@ public class RSS090Parser extends BaseWireFeedParser {
* <p/> * <p/>
* It reads title and link out of the 'item' element. * It reads title and link out of the 'item' element.
* <p/> * <p/>
* *
* @param rssRoot the root element of the RSS document in case it's needed for context. * @param rssRoot the root element of the RSS document in case it's needed for context.
* @param eItem the item element to parse. * @param eItem the item element to parse.
* @return the parsed RSSItem bean. * @return the parsed RSSItem bean.
@ -307,14 +307,16 @@ public class RSS090Parser extends BaseWireFeedParser {
// used // used
final Iterator<Element> iterator = foreignMarkup.iterator(); final Iterator<Element> iterator = foreignMarkup.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
final Element ie = iterator.next(); final Element element = iterator.next();
if (getContentNamespace().equals(ie.getNamespace()) && ie.getName().equals("encoded")) { if (getContentNamespace().equals(element.getNamespace()) && element.getName().equals("encoded")) {
iterator.remove(); iterator.remove();
} }
} }
if (foreignMarkup.size() > 0) {
if (!foreignMarkup.isEmpty()) {
item.setForeignMarkup(foreignMarkup); item.setForeignMarkup(foreignMarkup);
} }
return item; return item;
} }
@ -323,7 +325,7 @@ public class RSS090Parser extends BaseWireFeedParser {
* <p/> * <p/>
* It reads title, description, name and link out of the 'textinput' or 'textInput' element. * It reads title, description, name and link out of the 'textinput' or 'textInput' element.
* <p/> * <p/>
* *
* @param rssRoot the root element of the RSS document to parse for text-input information. * @param rssRoot the root element of the RSS document to parse for text-input information.
* @return the parsed RSSTextInput bean. * @return the parsed RSSTextInput bean.
*/ */