Author: rgardler
Date: Thu Nov 30 15:57:58 2006
New Revision: 481112
URL: http://svn.apache.org/viewvc?view=rev&rev=481112
Log:
Add processing of optional documents
Added:
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/document/InternalErrorDocument.java
(with props)
Modified:
forrest/trunk/whiteboard/forrest2/core/.classpath
forrest/trunk/whiteboard/forrest2/core/.settings/org.jayasoft.ivyde.eclipse.prefs
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/Controller.java
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/plugin/BaseOutputPlugin.java
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/plugin/IPlugin.java
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/plugin/PassThroughInputPlugin.java
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/plugin/XSLTInputPlugin.java
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/plugin/XSLTOutputPlugin.java
forrest/trunk/whiteboard/forrest2/core/src/examples/helloWorld/ (props
changed)
forrest/trunk/whiteboard/forrest2/core/src/test/org/apache/forrest/test/core/plugins/input/HelloWorldInputPlugin.java
Modified: forrest/trunk/whiteboard/forrest2/core/.classpath
URL:
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest2/core/.classpath?view=diff&rev=481112&r1=481111&r2=481112
==============================================================================
--- forrest/trunk/whiteboard/forrest2/core/.classpath (original)
+++ forrest/trunk/whiteboard/forrest2/core/.classpath Thu Nov 30 15:57:58 2006
@@ -8,6 +8,5 @@
<classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con"
path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="con"
path="org.jayasoft.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER/ivy.xml/*"/>
- <classpathentry combineaccessrules="false" kind="src"
path="/org.saafe.catalogue"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>
Modified:
forrest/trunk/whiteboard/forrest2/core/.settings/org.jayasoft.ivyde.eclipse.prefs
URL:
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest2/core/.settings/org.jayasoft.ivyde.eclipse.prefs?view=diff&rev=481112&r1=481111&r2=481112
==============================================================================
---
forrest/trunk/whiteboard/forrest2/core/.settings/org.jayasoft.ivyde.eclipse.prefs
(original)
+++
forrest/trunk/whiteboard/forrest2/core/.settings/org.jayasoft.ivyde.eclipse.prefs
Thu Nov 30 15:57:58 2006
@@ -1,5 +1,5 @@
-#Sat Nov 18 00:17:17 GMT 2006
+#Fri Nov 24 22:25:36 GMT 2006
acceptedTypes=[inherited]
eclipse.preferences.version=1
-ivy_conf_path=file\:/D\:/openSource/forrest/whiteboard/forrest2/ivyconf.xml
+ivy_conf_path=file\:/D\:/openSource/forrest/whiteboard/forrest2/core/ivyconf.xml
retreive.pattern=none
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=481112&r1=481111&r2=481112
==============================================================================
---
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
Thu Nov 30 15:57:58 2006
@@ -32,6 +32,7 @@
import org.apache.forrest.core.document.AggregatedSourceDocument;
import org.apache.forrest.core.document.DefaultOutputDocument;
import org.apache.forrest.core.document.InternalDocument;
+import org.apache.forrest.core.document.InternalErrorDocument;
import org.apache.forrest.core.exception.LocationmapException;
import org.apache.forrest.core.exception.ProcessingException;
import org.apache.forrest.core.locationMap.Location;
@@ -156,7 +157,7 @@
.loadAllSourceDocuments(requestURI, sourceLocs);
final InternalDocument internalDoc = this
- .processInputPlugins(sourceDocs);
+ .processInputPlugins(requestURI, sourceDocs);
this.internalDocsCache.put(requestURI, internalDoc);
final AbstractOutputDocument output = this
@@ -168,23 +169,28 @@
/**
* Process each of the documents supplied with the appropriate input
plugins
* to get a document in our internal format.
+ * @param requestURI
*
* @param sourceDocuments
* @throws IOException
* @throws ProcessingException
*/
private InternalDocument processInputPlugins(
- final List<AbstractSourceDocument> sourceDocuments)
+ URI requestURI, final List<AbstractSourceDocument>
sourceDocuments)
throws IOException, ProcessingException {
InternalDocument result = null;
- for (int i = 0; i < sourceDocuments.size(); i++) {
- final AbstractSourceDocument doc =
sourceDocuments.get(i);
- if (doc == null) {
- throw new ProcessingException(
- "No source document is
available.");
+ if (sourceDocuments.size() == 0) {
+ result = new InternalErrorDocument(requestURI, "Unable
to load source document");
+ } else {
+ for (int i = 0; i < sourceDocuments.size(); i++) {
+ final AbstractSourceDocument doc =
sourceDocuments.get(i);
+ if (doc == null) {
+ throw new ProcessingException(
+ "No source document is
available.");
+ }
+ AbstractInputPlugin plugin =
getInputPlugin(doc);
+ result = (InternalDocument)
plugin.process(this, doc);
}
- AbstractInputPlugin plugin = getInputPlugin(doc);
- result = (InternalDocument) plugin.process(doc);
}
return result;
}
@@ -217,7 +223,7 @@
throws ProcessingException, IOException {
final InternalDocument intDoc =
this.getInternalDocument(requestURI);
BaseOutputPlugin plugin = getOutputPlugin(requestURI);
- return (AbstractOutputDocument) plugin.process(intDoc);
+ return (AbstractOutputDocument) plugin.process(this, intDoc);
}
/*
@@ -277,8 +283,8 @@
IReader reader = getReader(uri);
doc = reader.read(this, requestURI, location,
uri);
if (doc != null) {
- addToSourceDocCache(requestURI, doc);
- break;
+ addToSourceDocCache(requestURI, doc);
+ break;
}
}
}
@@ -350,7 +356,7 @@
loc = sourceLocs.next();
if (sourceExists(requestURI, loc)) {
result.add(loc);
- log.debug("Found valid location: " +
loc.toString());
+ log.debug("Found valid location");
} else {
if (loc.isRequired()) {
isValid = false;
@@ -463,8 +469,8 @@
content.append("</error>");
}
- final DefaultOutputDocument output = new
DefaultOutputDocument(requestURI,
- content.toString());
+ final DefaultOutputDocument output = new
DefaultOutputDocument(
+ requestURI, content.toString());
return output;
} else if
(requestURI.getPath().endsWith(this.internalURLExtension)) {
final InternalDocument doc =
this.getInternalDocument(requestURI);
@@ -476,8 +482,8 @@
content.append(requestURI);
content.append("</error>");
}
- final DefaultOutputDocument output = new
DefaultOutputDocument(requestURI,
- content.toString());
+ final DefaultOutputDocument output = new
DefaultOutputDocument(
+ requestURI, content.toString());
return output;
}
Added:
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/document/InternalErrorDocument.java
URL:
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/document/InternalErrorDocument.java?view=auto&rev=481112
==============================================================================
---
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/document/InternalErrorDocument.java
(added)
+++
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/document/InternalErrorDocument.java
Thu Nov 30 15:57:58 2006
@@ -0,0 +1,29 @@
+package org.apache.forrest.core.document;
+
+import java.io.IOException;
+import java.net.URI;
+
+public class InternalErrorDocument extends InternalDocument {
+
+ public InternalErrorDocument(URI requestURI, String message) {
+ super (requestURI, message);
+ }
+
+ @Override
+ public String getContentAsString() throws IOException {
+ StringBuffer sb = new StringBuffer("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>");
+ sb.append("<html xmlns=\"http://www.w3.org/2002/06/xhtml2\"
xml:lang=\"en\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xsi:schemaLocation=\"http://www.w3.org/2002/06/xhtml2/
http://www.w3.org/MarkUp/SCHEMA/xhtml2.xsd\">");
+ sb.append("<head><title>Internal Forrest Error</title></head>");
+ sb.append("<body>");
+ sb.append("<h>");
+ sb.append("Error processing request for " + getRequestURI());
+ sb.append("</h>");
+ sb.append("<p>");
+ sb.append(super.getContentAsString());
+ sb.append("</p>");
+ sb.append("</body>");
+ sb.append("</html>");
+ return sb.toString();
+ }
+
+}
Propchange:
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/document/InternalErrorDocument.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/plugin/BaseOutputPlugin.java
URL:
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/plugin/BaseOutputPlugin.java?view=diff&rev=481112&r1=481111&r2=481112
==============================================================================
---
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/plugin/BaseOutputPlugin.java
(original)
+++
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/plugin/BaseOutputPlugin.java
Thu Nov 30 15:57:58 2006
@@ -21,8 +21,10 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.forrest.core.Controller;
import org.apache.forrest.core.document.DefaultOutputDocument;
import org.apache.forrest.core.document.IDocument;
+import org.apache.forrest.core.exception.ProcessingException;
/**
* A base output plugin from which all other output plugins should be etended.
@@ -67,7 +69,7 @@
return matcher.find();
}
- public IDocument process(final IDocument doc) throws IOException {
+ public IDocument process(final Controller controller, final IDocument
doc) throws IOException, ProcessingException {
return new DefaultOutputDocument(doc.getRequestURI(),
doc.getContentAsString());
}
Modified:
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/plugin/IPlugin.java
URL:
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/plugin/IPlugin.java?view=diff&rev=481112&r1=481111&r2=481112
==============================================================================
---
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/plugin/IPlugin.java
(original)
+++
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/plugin/IPlugin.java
Thu Nov 30 15:57:58 2006
@@ -18,7 +18,9 @@
import java.io.IOException;
+import org.apache.forrest.core.Controller;
import org.apache.forrest.core.document.IDocument;
+import org.apache.forrest.core.exception.ProcessingException;
public interface IPlugin {
@@ -29,6 +31,7 @@
* @param doc
* @return
* @throws IOException
+ * @throws ProcessingException
*/
- public IDocument process(IDocument doc) throws IOException;
+ public IDocument process(Controller controller, IDocument doc) throws
IOException, ProcessingException;
}
Modified:
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/plugin/PassThroughInputPlugin.java
URL:
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/plugin/PassThroughInputPlugin.java?view=diff&rev=481112&r1=481111&r2=481112
==============================================================================
---
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/plugin/PassThroughInputPlugin.java
(original)
+++
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/plugin/PassThroughInputPlugin.java
Thu Nov 30 15:57:58 2006
@@ -18,6 +18,7 @@
import java.io.IOException;
+import org.apache.forrest.core.Controller;
import org.apache.forrest.core.document.IDocument;
import org.apache.forrest.core.document.InternalDocument;
@@ -29,7 +30,7 @@
*/
public class PassThroughInputPlugin extends AbstractInputPlugin {
- public IDocument process(final IDocument doc) throws IOException {
+ public IDocument process(final Controller controller, final IDocument
doc) throws IOException {
return new InternalDocument(doc.getRequestURI(),
doc.getContentAsString());
}
Modified:
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/plugin/XSLTInputPlugin.java
URL:
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/plugin/XSLTInputPlugin.java?view=diff&rev=481112&r1=481111&r2=481112
==============================================================================
---
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/plugin/XSLTInputPlugin.java
(original)
+++
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/plugin/XSLTInputPlugin.java
Thu Nov 30 15:57:58 2006
@@ -32,6 +32,7 @@
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
+import org.apache.forrest.core.Controller;
import org.apache.forrest.core.document.IDocument;
import org.apache.forrest.core.document.InternalDocument;
@@ -67,7 +68,7 @@
}
}
- public IDocument process(final IDocument doc) throws IOException {
+ public IDocument process(final Controller controller, final IDocument
doc) throws IOException {
final TransformerFactory tFactory =
TransformerFactory.newInstance();
try {
Modified:
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/plugin/XSLTOutputPlugin.java
URL:
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/plugin/XSLTOutputPlugin.java?view=diff&rev=481112&r1=481111&r2=481112
==============================================================================
---
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/plugin/XSLTOutputPlugin.java
(original)
+++
forrest/trunk/whiteboard/forrest2/core/src/core/org/apache/forrest/core/plugin/XSLTOutputPlugin.java
Thu Nov 30 15:57:58 2006
@@ -30,6 +30,7 @@
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
+import org.apache.forrest.core.Controller;
import org.apache.forrest.core.document.DefaultOutputDocument;
import org.apache.forrest.core.document.IDocument;
import org.apache.log4j.Logger;
@@ -54,7 +55,7 @@
}
@Override
- public IDocument process(final IDocument doc) throws IOException {
+ public IDocument process(final Controller controller, final IDocument
doc) throws IOException {
final TransformerFactory tFactory =
TransformerFactory.newInstance();
log.debug("Processing document with output stylesheet from " +
this.getXsltPath());
try {
Propchange: forrest/trunk/whiteboard/forrest2/core/src/examples/helloWorld/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Nov 30 15:57:58 2006
@@ -0,0 +1,2 @@
+
+build
Modified:
forrest/trunk/whiteboard/forrest2/core/src/test/org/apache/forrest/test/core/plugins/input/HelloWorldInputPlugin.java
URL:
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest2/core/src/test/org/apache/forrest/test/core/plugins/input/HelloWorldInputPlugin.java?view=diff&rev=481112&r1=481111&r2=481112
==============================================================================
---
forrest/trunk/whiteboard/forrest2/core/src/test/org/apache/forrest/test/core/plugins/input/HelloWorldInputPlugin.java
(original)
+++
forrest/trunk/whiteboard/forrest2/core/src/test/org/apache/forrest/test/core/plugins/input/HelloWorldInputPlugin.java
Thu Nov 30 15:57:58 2006
@@ -16,6 +16,7 @@
*/
package org.apache.forrest.test.core.plugins.input;
+import org.apache.forrest.core.Controller;
import org.apache.forrest.core.document.IDocument;
import org.apache.forrest.core.document.InternalDocument;
import org.apache.forrest.core.plugin.AbstractInputPlugin;
@@ -29,7 +30,7 @@
public static final String CONTENT = "<html
xmlns=\"http://www.w3.org/2002/06/xhtml2\" xml:lang=\"en\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xsi:schemaLocation=\"http://www.w3.org/2002/06/xhtml2/
http://www.w3.org/MarkUp/SCHEMA/xhtml2.xsd\"> <head> <title>XHTML 2 Simple
Sample Page</title> </head> <body> <h>Hello World</h> </body></html>";
- public IDocument process(final IDocument doc) {
+ public IDocument process(final Controller controller, final IDocument
doc) {
return new InternalDocument(doc.getRequestURI(), CONTENT);
}
}