forrest-svn mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgard...@apache.org
Subject svn commit: r482010 - in /forrest/trunk/whiteboard/forrest2/core/src: core/org/apache/forrest/core/Controller.java core/org/apache/forrest/core/IController.java test/org/apache/forrest/test/core/TestController.java
Date Mon, 04 Dec 2006 01:46:25 GMT
Author: rgardler
Date: Sun Dec  3 17:46:24 2006
New Revision: 482010

URL: http://svn.apache.org/viewvc?view=rev&rev=482010
Log:
Add a .forrestPipeline URL extension that returns a representation
of the pipeline used to process a request. Note that this is a
horrible hack, but it gives an idea of what should be done. I'll
create an issue to refactor this implementation.

Modified:
    forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/Controller.java
    forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/IController.java
    forrest/trunk/whiteboard/forrest2/core/src/test/org/apache/forrest/test/core/TestController.java

Modified: forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/Controller.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/Controller.java?view=diff&rev=482010&r1=482009&r2=482010
==============================================================================
--- forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/Controller.java
(original)
+++ forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/Controller.java
Sun Dec  3 17:46:24 2006
@@ -79,6 +79,12 @@
 
 	private AbstractXmlApplicationContext context;
 
+	private String outputPluginClass;
+
+	private String inputPluginClass;
+
+	private String readerClass;
+
 	/**
 	 * Create a controller that uses the locationmap definition file at the
 	 * provided location.
@@ -152,8 +158,8 @@
 		final List<AbstractSourceDocument> sourceDocs = this
 				.loadAllSourceDocuments(requestURI, sourceLocs);
 
-		final InternalDocument internalDoc = this
-				.processInputPlugins(requestURI, sourceDocs);
+		final InternalDocument internalDoc = this.processInputPlugins(
+				requestURI, sourceDocs);
 		this.internalDocsCache.put(requestURI, internalDoc);
 
 		final AbstractOutputDocument output = this
@@ -165,18 +171,20 @@
 	/**
 	 * Process each of the documents supplied with the appropriate input plugins
 	 * to get a document in our internal format.
-	 * @param requestURI 
+	 * 
+	 * @param requestURI
 	 * 
 	 * @param sourceDocuments
 	 * @throws IOException
 	 * @throws ProcessingException
 	 */
-	private InternalDocument processInputPlugins(
-			URI requestURI, final List<AbstractSourceDocument> sourceDocuments)
+	private InternalDocument processInputPlugins(URI requestURI,
+			final List<AbstractSourceDocument> sourceDocuments)
 			throws IOException, ProcessingException {
 		InternalDocument result = null;
 		if (sourceDocuments.size() == 0) {
-			result = new InternalErrorDocument(requestURI, "Unable to load source document");
+			result = new InternalErrorDocument(requestURI,
+					"Unable to load source document");
 		} else {
 			for (int i = 0; i < sourceDocuments.size(); i++) {
 				final AbstractSourceDocument doc = sourceDocuments.get(i);
@@ -203,6 +211,7 @@
 		} catch (final NoSuchBeanDefinitionException e) {
 			plugin = new PassThroughInputPlugin();
 		}
+		inputPluginClass = plugin.getClass().toString();
 		return plugin;
 	}
 
@@ -242,6 +251,7 @@
 		if (plugin == null) {
 			plugin = new BaseOutputPlugin();
 		}
+		outputPluginClass = plugin.getClass().toString();
 		return plugin;
 	}
 
@@ -315,6 +325,7 @@
 			throw new ProcessingException(
 					"Unable to get a reader for : " + uri, e);
 		}
+		readerClass = reader.getClass().toString();
 		return reader;
 	}
 
@@ -457,6 +468,8 @@
 			return getSourceDocumentAsOutput(requestURI);
 		} else if (requestURI.getPath().endsWith(this.internalURLExtension)) {
 			return getInternalDocumentAsOutput(requestURI);
+		} else if (requestURI.getPath().endsWith(this.pipelineURLExtension)) {
+			return getPipelineAsOutput(requestURI);
 		}
 
 		AbstractOutputDocument output = this.outputDocCache.get(requestURI);
@@ -471,7 +484,57 @@
 		return output;
 	}
 
-	private DefaultOutputDocument getInternalDocumentAsOutput(final URI requestURI) throws ProcessingException
{
+	/**
+	 * Return an XML document that represents the processing pipeline for the
+	 * given request URI.
+	 * 
+	 * @param requestURI
+	 * @return
+	 * @throws ProcessingException 
+	 */
+	private AbstractOutputDocument getPipelineAsOutput(URI requestURI) throws ProcessingException
{
+		try {
+			this.processRequest(requestURI);
+		} catch (final Exception e) {
+			throw new ProcessingException(
+					"Unable to create the output documents for "
+							+ requestURI + " because " + e.getMessage(), e);
+		}
+		StringBuffer sb = new StringBuffer();
+		sb.append("<forrestPipeline request=\"");
+		sb.append(requestURI);
+		sb.append("\">");
+		sb.append("<source url=\"");
+		sb.append("URL calculation not implemented yet\">");
+		sb.append("</source>");
+		sb.append("<!-- FIXME: if there are a chain of readers we should show them all here
-->");
+		sb.append("<reader class=\"");
+		sb.append(readerClass);
+		sb.append("\">");
+		sb.append("</reader>");
+		sb.append("<!-- FIXME: if there are a chain of input plugins we should show them all
here -->");
+		sb.append("<inputPlugin class=\"");
+		sb.append(inputPluginClass);
+		sb.append("\">");
+		sb.append("</inputPlugin>");
+		sb.append("<outputPlugin class=\"");
+		sb.append(outputPluginClass);
+		sb.append("\">");
+		sb.append("</outputPlugin>");
+		sb.append("<forrestPipeline>");
+		return new DefaultOutputDocument(requestURI, sb.toString());
+	}
+
+	/**
+	 * Get an output document that contains the internal document gneerated by
+	 * the given request URI.
+	 * 
+	 * @param requestURI
+	 * @return
+	 * @throws ProcessingException
+	 */
+	private DefaultOutputDocument getInternalDocumentAsOutput(
+			final URI requestURI) throws ProcessingException {
 		final InternalDocument doc = this.getInternalDocument(requestURI);
 		final StringBuffer content = new StringBuffer();
 		try {
@@ -481,14 +544,21 @@
 			content.append(requestURI);
 			content.append("</error>");
 		}
-		final DefaultOutputDocument output = new DefaultOutputDocument(
-				requestURI, content.toString());
-		return output;
+		return new DefaultOutputDocument(requestURI, content.toString());
 	}
 
-	private DefaultOutputDocument getSourceDocumentAsOutput(final URI requestURI) throws MalformedURLException,
ProcessingException {
-		final AbstractSourceDocument doc = this
-				.getSourceDocuments(requestURI);
+	/**
+	 * Get an output document that contains the original source document for the
+	 * given request URI.
+	 * 
+	 * @param requestURI
+	 * @return
+	 * @throws MalformedURLException
+	 * @throws ProcessingException
+	 */
+	private DefaultOutputDocument getSourceDocumentAsOutput(final URI requestURI)
+			throws MalformedURLException, ProcessingException {
+		final AbstractSourceDocument doc = this.getSourceDocuments(requestURI);
 		final StringBuffer content = new StringBuffer();
 		try {
 			content.append(doc.getContentAsString());
@@ -498,8 +568,6 @@
 			content.append("</error>");
 		}
 
-		final DefaultOutputDocument output = new DefaultOutputDocument(
-				requestURI, content.toString());
-		return output;
+		return new DefaultOutputDocument(requestURI, content.toString());
 	}
 }

Modified: forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/IController.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/IController.java?view=diff&rev=482010&r1=482009&r2=482010
==============================================================================
--- forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/IController.java
(original)
+++ forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/IController.java
Sun Dec  3 17:46:24 2006
@@ -19,6 +19,8 @@
 	final String sourceURLExtension = ".forrestSource";
 
 	final String internalURLExtension = ".forrestInternal";
+
+	final String pipelineURLExtension = ".forrestPipeline";
 	
 	public abstract AbstractInputPlugin getInputPlugin(
 			final AbstractSourceDocument doc);

Modified: forrest/trunk/whiteboard/forrest2/core/src/test/org/apache/forrest/test/core/TestController.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest2/core/src/test/org/apache/forrest/test/core/TestController.java?view=diff&rev=482010&r1=482009&r2=482010
==============================================================================
--- forrest/trunk/whiteboard/forrest2/core/src/test/org/apache/forrest/test/core/TestController.java
(original)
+++ forrest/trunk/whiteboard/forrest2/core/src/test/org/apache/forrest/test/core/TestController.java
Sun Dec  3 17:46:24 2006
@@ -51,6 +51,9 @@
 	public static final String INTERNAL_REQUEST_URI = BASE_REQUEST_URI
 			+ "testPage.forrestInternal";
 
+	public static final String PIPELINE_REQUEST_URI = BASE_REQUEST_URI
+			+ "testPage.forrestPipeline";
+
 	public static final String VARIABLE_SUBSTITUTION_REQUEST_URI = BASE_REQUEST_URI
 			+ "variable/sample_simple.forrestSource";
 
@@ -140,6 +143,23 @@
 		assertNotNull(output);
 		assertTrue("Content is not as expected", output.getContentAsString()
 				.contains("http://www.w3.org/2002/06/xhtml2"));
+	}
+
+	public void testForrestPipelineRequest() throws ProcessingException,
+			URISyntaxException, IOException {
+		final AbstractOutputDocument output = this.controller
+				.getOutputDocument(new URI(PIPELINE_REQUEST_URI));
+		assertNotNull(output);
+		assertTrue("Content does not appear to be a pipeline description", output.getContentAsString()
+				.contains("forrestPipeline"));
+		assertTrue("Pipeline does not define source location", output.getContentAsString()
+				.contains("<source"));
+		assertTrue("Pipeline does not define a reader", output.getContentAsString()
+				.contains("<reader"));
+		assertTrue("Pipeline does not define an input plugin", output.getContentAsString()
+				.contains("<inputPlugin"));
+		assertTrue("Pipeline does not define an output plugin", output.getContentAsString()
+				.contains("<outputPlugin"));
 	}
 
 	public void testVariableSubstitution() throws ProcessingException,



Mime
View raw message