You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@abdera.apache.org by jm...@apache.org on 2007/10/17 23:21:53 UTC
svn commit: r585703 - in
/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera: ./
factory/ filter/ parser/ util/ writer/
Author: jmsnell
Date: Wed Oct 17 14:21:51 2007
New Revision: 585703
URL: http://svn.apache.org/viewvc?rev=585703&view=rev
Log:
Some refactorings and general improvements
Modified:
incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/Abdera.java
incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/factory/ExtensionFactoryMap.java
incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ListParseFilter.java
incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ParseFilter.java
incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/Parser.java
incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/ParserOptions.java
incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractExtensionFactory.java
incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractParser.java
incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/URIHelper.java
incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/WriterOptions.java
Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/Abdera.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/Abdera.java?rev=585703&r1=585702&r2=585703&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/Abdera.java (original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/Abdera.java Wed Oct 17 14:21:51 2007
@@ -38,9 +38,35 @@
* These instances may be retrieved using the appropriate get___ methods.
* Alternatively, new instances may be created using the appropriate
* new___ methods.
+ *
+ * Instances of the Abdera object, and it's direct children (Parser,
+ * Factory, XPath, etc) are Thread safe. Because of the dynamic configuration
+ * model Abdera uses, creating a new instance of the Abdera object can be
+ * time consuming. It is, therefore, a good idea for applications to create
+ * only a single static instance of the Abdera object (see the Abdera.getInstance()
+ * method).
+ *
+ * Abdera's configuration model depends heavily on the context classloader.
+ * Extension Factories, custom writers, custom parsers, etc are all discovered
+ * automatically by searching the classpath. This means that care needs to be
+ * taken when using Abdera in environments that utilize multiple classloaders
+ * (such as Web application servers).
*/
public final class Abdera {
+ /** A static instance of Abdera **/
+ private static Abdera instance;
+
+ /**
+ * Get a static instance of the Abdera object
+ */
+ public static synchronized Abdera getInstance() {
+ if (instance == null) {
+ instance = new Abdera();
+ }
+ return instance;
+ }
+
private final AbderaConfiguration config;
private final Factory factory;
private final Parser parser;
Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/factory/ExtensionFactoryMap.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/factory/ExtensionFactoryMap.java?rev=585703&r1=585702&r2=585703&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/factory/ExtensionFactoryMap.java (original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/factory/ExtensionFactoryMap.java Wed Oct 17 14:21:51 2007
@@ -23,8 +23,6 @@
import java.util.Map;
import java.util.WeakHashMap;
-import javax.xml.namespace.QName;
-
import org.apache.abdera.model.Base;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Element;
@@ -69,7 +67,9 @@
synchronized(factories) {
for (ExtensionFactory factory : factories) {
String[] namespaces = factory.getNamespaces();
- for (String uri : namespaces) ns.add(uri);
+ for (String uri : namespaces) {
+ if (!ns.contains(uri)) ns.add(uri);
+ }
}
}
return ns.toArray(new String[ns.size()]);
@@ -82,13 +82,6 @@
}
}
return false;
- }
-
- public <T extends Element> T newExtensionElement(
- QName qname,
- Base parent,
- Factory factory) {
- return null;
}
public void addFactory(ExtensionFactory factory) {
Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ListParseFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ListParseFilter.java?rev=585703&r1=585702&r2=585703&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ListParseFilter.java (original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ListParseFilter.java Wed Oct 17 14:21:51 2007
@@ -19,26 +19,27 @@
import javax.xml.namespace.QName;
-public interface ListParseFilter extends ParseFilter {
+public interface ListParseFilter
+ extends ParseFilter {
/**
* Add an element QName to the parse filter
*/
- public abstract void add(QName qname);
+ void add(QName qname);
/**
* Returns true if the given qname has been added to the filter
*/
- public abstract boolean contains(QName qname);
+ boolean contains(QName qname);
/**
* Adds an attribute to the parse filter
*/
- public abstract void add(QName parent, QName attribute);
+ void add(QName parent, QName attribute);
/**
* Returns true if the given attribute has been added to the filter
*/
- public abstract boolean contains(QName qname, QName attribute);
+ boolean contains(QName qname, QName attribute);
}
Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ParseFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ParseFilter.java?rev=585703&r1=585702&r2=585703&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ParseFilter.java (original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ParseFilter.java Wed Oct 17 14:21:51 2007
@@ -26,18 +26,18 @@
*/
public interface ParseFilter extends Cloneable {
- public Object clone() throws CloneNotSupportedException;
+ Object clone() throws CloneNotSupportedException;
/**
* Returns true if elements with the given QName are acceptable
*/
- public boolean acceptable(QName qname);
+ boolean acceptable(QName qname);
/**
* Returns true if attributes with the given qname appearing on elements
* with the given qname are acceptable
*/
- public boolean acceptable(QName qname, QName attribute);
+ boolean acceptable(QName qname, QName attribute);
/**
* Return true if the parser should ignore comments
@@ -55,14 +55,17 @@
boolean getIgnoreProcessingInstructions();
/**
- * Return true if the parser should ignore comments
+ * True if the parser should ignore comments
*/
void setIgnoreComments(boolean ignore);
/**
- * Return true if the parser should ignore insignificant whitespace
+ * True if the parser should ignore insignificant whitespace
*/
void setIgnoreWhitespace(boolean ignore);
+ /**
+ * True if the parser should ignore processing instructions
+ */
void setIgnoreProcessingInstructions(boolean ignore);
}
Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/Parser.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/Parser.java?rev=585703&r1=585702&r2=585703&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/Parser.java (original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/Parser.java Wed Oct 17 14:21:51 2007
@@ -20,6 +20,7 @@
import java.io.InputStream;
import java.io.Reader;
+import org.apache.abdera.i18n.iri.IRISyntaxException;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Element;
@@ -49,6 +50,21 @@
InputStream in,
String base)
throws ParseException;
+
+ /**
+ * Parse the input stream using the default character set encoding (UTF-8).
+ * The specified Base URI is used to resolve relative references contained
+ * in the document
+ * @param in The input stream to parse
+ * @param options The Parse options
+ * @return The parsed Abdera Document
+ * @throws ParseException if the parse failed
+ * @throws IRISyntaxException if the Base URI is malformed
+ */
+ <T extends Element>Document<T> parse(
+ InputStream in,
+ ParserOptions options)
+ throws ParseException;
/**
* Parse the input stream using using the specified Parse options. The
@@ -91,6 +107,19 @@
<T extends Element>Document<T> parse(
Reader in,
String base)
+ throws ParseException;
+
+ /**
+ * Parse the reader using the specified Base URI
+ * @param in The Reader to parse
+ * @param options The Parse Options
+ * @return The parsed Abdera Document
+ * @throws ParseException if the parse failed
+ * @throws IRISyntaxException if the Base URI is malformed
+ */
+ <T extends Element>Document<T> parse(
+ Reader in,
+ ParserOptions options)
throws ParseException;
/**
Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/ParserOptions.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/ParserOptions.java?rev=585703&r1=585702&r2=585703&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/ParserOptions.java (original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/ParserOptions.java Wed Oct 17 14:21:51 2007
@@ -127,11 +127,27 @@
*/
void setCompressionCodecs(CompressionCodec... codecs);
+ /**
+ * Register a named entity. This provides an escape clause for when
+ * feeds use entities that are not supported in XML without a DTD decl.
+ * By default, all of the (X)HTML entities are preregistered
+ */
void registerEntity(String name, String value);
-
+
+ /**
+ * Resolves a value for a named entity. This provides an escape clause for when
+ * feeds use entities that are not supported in XML without a DTD decl.
+ * By default, all of the (X)HTML entities are preregistered
+ */
String resolveEntity(String name);
+ /**
+ * True if undeclared named entities should be resolved.
+ */
void setResolveEntities(boolean resolve);
-
+
+ /**
+ * True if undeclared named entities should be resolved.
+ */
boolean getResolveEntities();
}
Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractExtensionFactory.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractExtensionFactory.java?rev=585703&r1=585702&r2=585703&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractExtensionFactory.java (original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractExtensionFactory.java Wed Oct 17 14:21:51 2007
@@ -30,6 +30,28 @@
import org.apache.abdera.model.Element;
import org.apache.abdera.model.ElementWrapper;
+/**
+ * <p>Provides a base implementation for ExtensionFactory instances. By extending
+ * this, specific extension factories need only to associate a QName with an
+ * implementation class, e.g.,</p>
+ *
+ * <pre>
+ * public class MyExtensionFactory
+ * extends AbstractExtensionFactory {
+ *
+ * private String NS = "http://example.org/foo/ns";
+ * private QName FOO = new QName(NS, "foo");
+ *
+ * public MyExtensionFactory() {
+ * super(NS);
+ * addImpl(FOO, Foo.class);
+ * }
+ * }
+ *
+ * public class Foo extends ElementWrapper { ... }
+ *
+ * </pre>
+ */
public abstract class AbstractExtensionFactory
implements ExtensionFactory {
@@ -57,10 +79,16 @@
return t != null ? t : (T)internal;
}
+ /**
+ * Associate a MIME media type for the specific QName
+ */
protected void addMimeType(QName qname, String mimetype) {
mimetypes.put(qname, mimetype);
}
+ /**
+ * Associate a QName with an implementation class
+ */
protected void addImpl(QName qname, Class<? extends ElementWrapper> impl) {
impls.put(qname, impl);
}
Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractParser.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractParser.java?rev=585703&r1=585702&r2=585703&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractParser.java (original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractParser.java Wed Oct 17 14:21:51 2007
@@ -65,6 +65,13 @@
throws ParseException {
return parse(in, base, getDefaultParserOptions());
}
+
+ public <T extends Element>Document<T> parse(
+ InputStream in,
+ ParserOptions options)
+ throws ParseException {
+ return parse(in, null, options);
+ }
public <T extends Element>Document<T> parse(
InputStream in,
@@ -87,6 +94,13 @@
return parse(in, base, getDefaultParserOptions());
}
+ public <T extends Element>Document<T> parse(
+ Reader in,
+ ParserOptions options)
+ throws ParseException {
+ return parse(in, null, options);
+ }
+
public synchronized ParserOptions getDefaultParserOptions() {
if (options == null) options = initDefaultParserOptions();
Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/URIHelper.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/URIHelper.java?rev=585703&r1=585702&r2=585703&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/URIHelper.java (original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/URIHelper.java Wed Oct 17 14:21:51 2007
@@ -28,10 +28,12 @@
private static final Pattern javascript =
Pattern.compile(
- "\\s*j\\s*a\\s*v\\s*a\\s*s\\s*c\\s*r\\s*i\\s*p\\s*t\\s*:.*");
+ "\\s*j\\s*a\\s*v\\s*a\\s*s\\s*c\\s*r\\s*i\\s*p\\s*t\\s*:.*",
+ Pattern.CASE_INSENSITIVE);
private static final Pattern mailto =
Pattern.compile(
- "\\s*m\\s*a\\s*i\\s*l\\s*t\\s*o\\s*:.*");
+ "\\s*m\\s*a\\s*i\\s*l\\s*t\\s*o\\s*:.*",
+ Pattern.CASE_INSENSITIVE);
public static boolean isJavascriptUri(IRI uri) {
if (uri == null) return false;
Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/WriterOptions.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/WriterOptions.java?rev=585703&r1=585702&r2=585703&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/WriterOptions.java (original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/WriterOptions.java Wed Oct 17 14:21:51 2007
@@ -32,12 +32,24 @@
void setCompressionCodecs(CompressionCodec... codecs);
Object clone() throws CloneNotSupportedException;
-
+
+ /**
+ * The character encoding to use for the output
+ */
String getCharset();
+ /**
+ * The character encoding to use for the output
+ */
void setCharset(String charset);
-
+
+ /**
+ * True if the writer should close the output stream or writer when finished
+ */
boolean getAutoClose();
-
+
+ /**
+ * True if the writer should close the output stream or writer when finished
+ */
void setAutoClose(boolean autoclose);
}