forrest-svn mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgard...@apache.org
Subject svn commit: r477267 - /forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/core/document/DocumentFactory.java
Date Mon, 20 Nov 2006 17:39:26 GMT
Author: rgardler
Date: Mon Nov 20 09:39:25 2006
New Revision: 477267

URL: http://svn.apache.org/viewvc?view=rev&rev=477267
Log:
- Make a stab at guessing HTML documents
- throw an exception if we can't work out the type o fthe source document

Modified:
    forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/core/document/DocumentFactory.java

Modified: forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/core/document/DocumentFactory.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/core/document/DocumentFactory.java?view=diff&rev=477267&r1=477266&r2=477267
==============================================================================
--- forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/core/document/DocumentFactory.java
(original)
+++ forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/core/document/DocumentFactory.java
Mon Nov 20 09:39:25 2006
@@ -21,6 +21,8 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 
+import org.apache.forrest.core.exception.ProcessingException;
+
 /**
  * The document factory creates instances of various types of document.
  * 
@@ -39,9 +41,10 @@
 	 * @throws IOException
 	 *             If there is a problem reading the document content from the
 	 *             InputStream
+	 * @throws ProcessingException 
 	 */
 	public static AbstractSourceDocument getSourceDocumentFor(
-			final InputStream is) throws IOException {
+			final InputStream is) throws IOException, ProcessingException {
 		return readFile(is);
 	}
 
@@ -52,9 +55,10 @@
 	 * the reader used to read the rest of the data.
 	 * 
 	 * @param is
+	 * @throws ProcessingException 
 	 */
 	private static AbstractSourceDocument readFile(final InputStream is)
-			throws java.io.IOException {
+			throws java.io.IOException, ProcessingException {
 		AbstractSourceDocument doc = null;
 		final StringBuffer fileData = new StringBuffer(1024);
 		final BufferedReader reader = new BufferedReader(new InputStreamReader(
@@ -78,9 +82,11 @@
 			if (fileData.toString().contains("<?xml")) {
 				doc = new XMLSourceDocument(fileData.toString(), reader,
 						"application/xml");
-			} else {
+			} if (fileData.toString().toLowerCase().contains("<html>")) {
 				doc = new DefaultSourceDocument(fileData.toString(), reader,
-						null);
+						"html");
+			} else {
+				throw new ProcessingException("Unable to determine the source document type");
 			}
 		}
 		return doc;



Mime
View raw message