You are viewing a plain text version of this content. The canonical link for it is here.
Posted to svn@forrest.apache.org by rg...@apache.org on 2007/01/03 23:47:37 UTC

svn commit: r492327 - /forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/document/DocumentFactory.java

Author: rgardler
Date: Wed Jan  3 14:47:36 2007
New Revision: 492327

URL: http://svn.apache.org/viewvc?view=rev&rev=492327
Log:
If we don't know the doc type then take a guess based on the source URL

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

Modified: forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/document/DocumentFactory.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/document/DocumentFactory.java?view=diff&rev=492327&r1=492326&r2=492327
==============================================================================
--- forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/document/DocumentFactory.java (original)
+++ forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/document/DocumentFactory.java Wed Jan  3 14:47:36 2007
@@ -21,7 +21,11 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.URI;
+import java.net.URL;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.forrest.core.IController;
 import org.apache.forrest.core.exception.ProcessingException;
 
 /**
@@ -29,6 +33,8 @@
  * 
  */
 public class DocumentFactory {
+	
+	static Log log = LogFactory.getLog(DocumentFactory.class);
 
 	/**
 	 * Reads as much of the supplied input stream as needed in order to identify
@@ -44,9 +50,9 @@
 	 *             InputStream
 	 * @throws ProcessingException 
 	 */
-	public static AbstractSourceDocument getSourceDocumentFor(final URI requestURI, 
+	public static AbstractSourceDocument getSourceDocumentFor(final URL sourceURL, final URI requestURI, 
 			final InputStream is) throws IOException, ProcessingException {
-		return readFile(requestURI, is);
+		return readFile(sourceURL, requestURI, is);
 	}
 
 	/**
@@ -58,7 +64,7 @@
 	 * @param is
 	 * @throws ProcessingException 
 	 */
-	private static AbstractSourceDocument readFile(final URI requestURI, final InputStream is)
+	private static AbstractSourceDocument readFile(final URL sourceURL, final URI requestURI, final InputStream is)
 			throws java.io.IOException, ProcessingException {
 		AbstractSourceDocument doc = null;
 		final StringBuffer fileData = new StringBuffer(1024);
@@ -87,7 +93,11 @@
 				doc = new DefaultSourceDocument(requestURI, fileData.toString(), reader,
 						"html");
 			} else {
-				throw new ProcessingException("Unable to determine the source document type");
+				String file = sourceURL.getFile();
+				String ext = file.substring(file.lastIndexOf(".") + 1);
+				log.warn("We don't know the document type, so using source file extension: " + ext);
+				doc = new DefaultSourceDocument(requestURI, fileData.toString(), reader,
+				ext);
 			}
 		}
 		return doc;