Author: rgardler
Date: Mon Nov 20 08:34:12 2006
New Revision: 477244
URL: http://svn.apache.org/viewvc?view=rev&rev=477244
Log:
@refactor Enabling variable substitution in Locations
Modified:
forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/core/Controller.java
forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/core/exception/ProcessingException.java
forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/reader/ChainedReader.java
forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/reader/FileReader.java
forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/reader/HTTPReader.java
forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/reader/IReader.java
Modified:
forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/core/Controller.java
URL:
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/core/Controller.java?view=diff&rev=477244&r1=477243&r2=477244
==============================================================================
---
forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/core/Controller.java
(original)
+++
forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/core/Controller.java
Mon Nov 20 08:34:12 2006
@@ -148,7 +148,7 @@
this.sourceLocationsCache.put(requestURI, sourceLocs);
final List<AbstractSourceDocument> sourceDocs = this
- .loadSourceDocuments(sourceLocs);
+ .loadSourceDocuments(requestURI, sourceLocs);
this.sourceDocsCache.put(requestURI, sourceDocs);
final List<InternalDocument> internalDocs = this
@@ -255,7 +255,7 @@
* @fixme resource handlers should be provided from a factory class
*/
private List<AbstractSourceDocument> loadSourceDocuments(
- final List<Location> sourceLocations) throws
MalformedURLException,
+ URI requestURI, final List<Location> sourceLocations)
throws MalformedURLException,
ProcessingException {
final List<AbstractSourceDocument> results = new
ArrayList<AbstractSourceDocument>(
sourceLocations.size());
@@ -263,7 +263,7 @@
for (int i = 0; i < sourceLocations.size(); i++) {
final Location location = sourceLocations.get(i);
IReader reader = getReader(location);
- results.add(reader.read(this, location));
+ results.add(reader.read(this, requestURI, location));
}
return results;
}
@@ -279,12 +279,8 @@
try {
reader = (IReader)
this.context.getBean(location.getScheme());
} catch (Exception e) {
- try {
- throw new ProcessingException("Unable to get a
reader for : "
- +
location.getResolvedSourceURL().toExternalForm(), e);
- } catch (MalformedURLException e1) {
- throw new ProcessingException("Unable to get a
reader", e1);
- }
+ throw new ProcessingException("Unable to get a reader
for : "
+ + location.getRequestPattern(), e);
}
return reader;
}
Modified:
forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/core/exception/ProcessingException.java
URL:
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/core/exception/ProcessingException.java?view=diff&rev=477244&r1=477243&r2=477244
==============================================================================
---
forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/core/exception/ProcessingException.java
(original)
+++
forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/core/exception/ProcessingException.java
Mon Nov 20 08:34:12 2006
@@ -27,4 +27,8 @@
super(message, e);
}
+ public ProcessingException(String message) {
+ super(message);
+ }
+
}
Modified:
forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/reader/ChainedReader.java
URL:
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/reader/ChainedReader.java?view=diff&rev=477244&r1=477243&r2=477244
==============================================================================
---
forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/reader/ChainedReader.java
(original)
+++
forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/reader/ChainedReader.java
Mon Nov 20 08:34:12 2006
@@ -62,7 +62,7 @@
private String docType;
public AbstractSourceDocument read(IController controller,
- final Location location) throws ProcessingException {
+ URI requestURI, final Location location) throws
ProcessingException {
DefaultSourceDocument doc = null;
final URI psudeoURI = location.getSourceURI();
final String ssp = psudeoURI.getSchemeSpecificPart();
@@ -72,7 +72,7 @@
location.setSourceURI(uri);
IReader reader;
reader = (IReader) controller.getReader(location);
- doc = (DefaultSourceDocument) reader.read(controller,
location);
+ doc = (DefaultSourceDocument) reader.read(controller,
requestURI, location);
if (doc != null) {
doc
.setType(getDocType());
Modified:
forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/reader/FileReader.java
URL:
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/reader/FileReader.java?view=diff&rev=477244&r1=477243&r2=477244
==============================================================================
---
forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/reader/FileReader.java
(original)
+++
forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/reader/FileReader.java
Mon Nov 20 08:34:12 2006
@@ -19,6 +19,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
+import java.net.URI;
import org.apache.forrest.core.IController;
import org.apache.forrest.core.document.AbstractSourceDocument;
@@ -38,11 +39,11 @@
*
* @see
org.apache.forrest.reader.IReader#read(org.apache.forrest.test.core.locationMap.Location)
*/
- public AbstractSourceDocument read(IController controller, final
Location location) {
+ public AbstractSourceDocument read(IController controller, URI
requestURI, final Location location) {
AbstractSourceDocument result = null;
try {
final InputStream is = new FileInputStream(new
File(location
- .getResolvedSourceURL().toURI()));
+
.getResolvedSourceURL(requestURI).toURI()));
result = DocumentFactory.getSourceDocumentFor(is);
} catch (final Exception e) {
if (location.isRequired())
Modified:
forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/reader/HTTPReader.java
URL:
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/reader/HTTPReader.java?view=diff&rev=477244&r1=477243&r2=477244
==============================================================================
---
forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/reader/HTTPReader.java
(original)
+++
forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/reader/HTTPReader.java
Mon Nov 20 08:34:12 2006
@@ -19,6 +19,7 @@
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.MalformedURLException;
+import java.net.URI;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
@@ -26,6 +27,7 @@
import org.apache.forrest.core.IController;
import org.apache.forrest.core.document.AbstractSourceDocument;
import org.apache.forrest.core.document.DefaultSourceDocument;
+import org.apache.forrest.core.exception.ProcessingException;
import org.apache.forrest.core.exception.SourceException;
import org.apache.forrest.core.locationMap.Location;
import org.w3c.tidy.Tidy;
@@ -53,12 +55,12 @@
*
* @see
org.apache.forrest.reader.IReader#read(org.apache.forrest.test.core.locationMap.Location)
*/
- public AbstractSourceDocument read(IController controller, final
Location location)
- throws MalformedURLException {
+ public AbstractSourceDocument read(IController controller, final URI
requestURI, final Location location)
+ throws MalformedURLException, ProcessingException {
InputStream is;
DefaultSourceDocument result = null;
final ByteArrayOutputStream out = new ByteArrayOutputStream();
- final GetMethod get = new
GetMethod(location.getResolvedSourceURL()
+ final GetMethod get = new
GetMethod(location.getResolvedSourceURL(requestURI)
.toExternalForm());
get.setFollowRedirects(true);
try {
Modified:
forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/reader/IReader.java
URL:
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/reader/IReader.java?view=diff&rev=477244&r1=477243&r2=477244
==============================================================================
---
forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/reader/IReader.java
(original)
+++
forrest/trunk/whiteboard/forrest2/src/core/org/apache/forrest/reader/IReader.java
Mon Nov 20 08:34:12 2006
@@ -17,6 +17,7 @@
package org.apache.forrest.reader;
import java.net.MalformedURLException;
+import java.net.URI;
import org.apache.forrest.core.IController;
import org.apache.forrest.core.document.AbstractSourceDocument;
@@ -38,12 +39,15 @@
* it is a required location throw SourceException.
* @param context
*
- * @param location
+ * @param controller - the forrest controller in use
+ * @param requestURI - the URI being requested
+ * @param location - the location we are to read the document from
+ *
* @return
* @throws MalformedURLException
* @throws ProcessingException
*/
- public abstract AbstractSourceDocument read(IController controller,
Location location)
+ public abstract AbstractSourceDocument read(IController controller, URI
requestURI, Location location)
throws MalformedURLException, ProcessingException;
}