Author: rgardler
Date: Fri Nov 17 17:59:26 2006
New Revision: 476411

URL: http://svn.apache.org/viewvc?view=rev&rev=476411
Log:
 * A chained reader implements a psuedo protocol.
 * It is commonly used when you need to retrieve a
 * document that whose type cannot be identified
 * from the raw source alone.
 * 
 * It is defined in forrestContext.xml as follows:
 * 
 * <bean id="fooProtocol"
 *   class="org.apache.forrest.reader.ChainedReader" >
 *   <property name="docType"
 *             value="org.foo.Bar" />
 * </bean>
 * 
 * We can then define a chain of readers like this:
 *
 * <location pattern="classpath/foo.*">
 *   <source href="fooProtocol:classpath:/xdocs/exampleFeed.xml"/>
 * </location>
 *
 * <location pattern="file/foo.*">
 *    <source href="fooProtocol:file:/xdocs/exampleFeed.xml"/>
 * </location>
 * 
 * <location pattern="http/foo.*">
 *   <source href="fooProtocol:http:/xdocs/exampleFeed.xml"/>
 * </location>
 * 
 * etc.

[FOR-943]

Added:
    
forrest/trunk/whiteboard/forrest2/core/org/apache/forrest/reader/ChainedReader.java
   (with props)

Added: 
forrest/trunk/whiteboard/forrest2/core/org/apache/forrest/reader/ChainedReader.java
URL: 
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest2/core/org/apache/forrest/reader/ChainedReader.java?view=auto&rev=476411
==============================================================================
--- 
forrest/trunk/whiteboard/forrest2/core/org/apache/forrest/reader/ChainedReader.java
 (added)
+++ 
forrest/trunk/whiteboard/forrest2/core/org/apache/forrest/reader/ChainedReader.java
 Fri Nov 17 17:59:26 2006
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.forrest.reader;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.forrest.core.document.AbstractSourceDocument;
+import org.apache.forrest.core.document.DefaultSourceDocument;
+import org.apache.forrest.core.locationMap.Location;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+/**
+ * A chained reader implements a psuedo protocol.
+ * It is commonly used when you need to retrieve a
+ * document that whose type cannot be identified
+ * from the raw source alone.
+ * 
+ * It is defined in forrestContext.xml as follows:
+ * 
+ * <bean id="fooProtocol"
+ *   class="org.apache.forrest.reader.ChainedReader" >
+ *   <property name="docType"
+ *             value="org.foo.Bar" />
+ * </bean>
+ * 
+ * We can then define a chain of readers like this:
+ *
+ * <location pattern="classpath/foo.*">
+ *   <source href="fooProtocol:classpath:/xdocs/exampleFeed.xml"/>
+ * </location>
+ *
+ * <location pattern="file/foo.*">
+ *    <source href="fooProtocol:file:/xdocs/exampleFeed.xml"/>
+ * </location>
+ * 
+ * <location pattern="http/foo.*">
+ *   <source href="fooProtocol:http:/xdocs/exampleFeed.xml"/>
+ * </location>
+ * 
+ * etc.
+ * 
+ */
+public class ChainedReader extends AbstractReader {
+
+       private String docType;
+       
+       public AbstractSourceDocument read(AbstractXmlApplicationContext 
context,
+                       final Location location) {
+               DefaultSourceDocument doc = null;
+               final URI psudeoURI = location.getSourceURI();
+               final String ssp = psudeoURI.getSchemeSpecificPart();
+               URI uri;
+               try {
+                       uri = new URI(ssp);
+                       location.setSourceURI(uri);
+                       IReader reader;
+                       reader = (IReader) context.getBean(uri.getScheme());
+                       doc = (DefaultSourceDocument) reader.read(context, 
location);
+                       if (doc != null) {
+                               doc
+                                               .setType(getDocType());
+                       }
+               } catch (final URISyntaxException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               } catch (MalformedURLException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+               return doc;
+       }
+
+       public String getDocType() {
+               return docType;
+       }
+
+       public void setDocType(String docType) {
+               this.docType = docType;
+       }
+       
+       
+}

Propchange: 
forrest/trunk/whiteboard/forrest2/core/org/apache/forrest/reader/ChainedReader.java
------------------------------------------------------------------------------
    svn:eol-style = native