cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jer...@apache.org
Subject svn commit: r160680 - in cocoon/branches/BRANCH_2_1_X/src/blocks/querybean/samples: flow/indexer.js sitemap.xmap
Date Sat, 09 Apr 2005 13:19:07 GMT
Author: jeremy
Date: Sat Apr  9 06:19:04 2005
New Revision: 160680

URL: http://svn.apache.org/viewcvs?view=rev&rev=160680
Log:
updated to add a uri for re-indexing a single asset, changed indexer from using java.util.File
to using Excalibur Source, so now any TraversableSource can be indexed.

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/querybean/samples/flow/indexer.js
    cocoon/branches/BRANCH_2_1_X/src/blocks/querybean/samples/sitemap.xmap

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/querybean/samples/flow/indexer.js
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/querybean/samples/flow/indexer.js?view=diff&r1=160679&r2=160680
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/querybean/samples/flow/indexer.js (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/querybean/samples/flow/indexer.js Sat Apr  9 06:19:04
2005
@@ -15,8 +15,7 @@
 */
 
 importClass(Packages.org.apache.excalibur.source.SourceResolver);
-importClass(Packages.java.net.URL);
-importClass(Packages.java.io.File);
+importClass(Packages.org.apache.excalibur.source.TraversableSource);
 importClass(Packages.java.util.ArrayList);
 
 
@@ -24,21 +23,24 @@
 // flowscripts for indexing content for the Query Bean
 // $Id: query.js,v 1.3 2004/10/22 12:14:23 jeremy Exp $
 
-function createIndex () {
+function indexItem() {
 	var cdir = cocoon.parameters["content-directory"]
+	var target = cocoon.parameters["indexer-target"]
 	var rdir = cocoon.parameters["result-directory"];
-	var include = cocoon.parameters["include-pattern"];
-	var exclude = cocoon.parameters["exclude-pattern"];
 	var rsuffix = cocoon.parameters["result-suffix"];
 	var files = new ArrayList();
+	var resolver = cocoon.getComponent(SourceResolver.ROLE);
+	var base;
+	var source;
 	try {
-		var inRegExp = "undefined".equals(include) ? new RegExp(".*") : new RegExp(include);
-		var exRegExp = "undefined".equals(exclude) ? null : new RegExp(exclude);
-		var base = new File(new URL(resolve(cdir).getURI()).getFile());
-		if (base.isDirectory()) {
-			getFiles(base, files, inRegExp, exRegExp);
+		base = resolver.resolveURI(cdir);
+		if (!base.isCollection()) throw ("error.invalid.content");
+		source = resolver.resolveURI(base.getURI() + target);
+		if (source.isCollection()) {
+			throw ("error.invalid.content");
 		} else {
-			throw("error.invalid.content");
+			files.add(source.getURI());
+			cocoon.log.error("reindexing: " + source.getURI());
 		}
 		cocoon.sendPage(cocoon.parameters["screen"], 
 			{
@@ -47,47 +49,72 @@
 				merge: cocoon.parameters["lucene-merge-factor"],
 				create: cocoon.parameters["lucene-create-index"],
 				files: files,
-				converter: new Converter(base, rdir, rsuffix),
+				converter: new Converter(base.getURI(), rdir, rsuffix),
 				content: cocoon.parameters["lucene-content"]
 			}
 		);
 	} catch (error) {
 		cocoon.log.error(error);
 		cocoon.sendPage("screen/error", {message: error});	
+	} finally {
+		resolver.release(base);
+		resolver.release(source);
+		cocoon.releaseComponent(resolver);
 	}
+
 }
 
-/**
- * Utility function - resolve a URI to a Source
- *
- */
-function resolve(uri) {
-   try {
-      var resolver = cocoon.getComponent(SourceResolver.ROLE);
-      return resolver.resolveURI(uri);
-    } catch (error) {
-      cocoon.log.error("Unable to resolve source", error);
-      throw (error);
-    } finally {
-      cocoon.releaseComponent(resolver);
-   } 
+function indexCollection () {
+	var cdir = cocoon.parameters["content-directory"]
+	var rdir = cocoon.parameters["result-directory"];
+	var include = cocoon.parameters["include-pattern"];
+	var exclude = cocoon.parameters["exclude-pattern"];
+	var rsuffix = cocoon.parameters["result-suffix"];
+	var files = new ArrayList();
+	var resolver = cocoon.getComponent(SourceResolver.ROLE);
+	var source;
+	try {
+		var inRegExp = "undefined".equals(include) || "".equals(include) ? new RegExp(".*") : new
RegExp(include);
+		var exRegExp = "undefined".equals(exclude) || "".equals(exclude) ? null : new RegExp(exclude);
+		source = resolver.resolveURI(cdir);
+		if (source instanceof TraversableSource && source.isCollection()) {
+			getFiles(source, files, inRegExp, exRegExp);
+		} else {
+			throw ("error.invalid.content");
+		}
+		cocoon.sendPage(cocoon.parameters["screen"], 
+			{
+				directory: cocoon.parameters["lucene-directory"],
+				analyzer: cocoon.parameters["lucene-analyzer"],
+				merge: cocoon.parameters["lucene-merge-factor"],
+				create: cocoon.parameters["lucene-create-index"],
+				files: files,
+				converter: new Converter(source.getURI(), rdir, rsuffix),
+				content: cocoon.parameters["lucene-content"]
+			}
+		);
+	} catch (error) {
+		cocoon.log.error(error);
+		cocoon.sendPage("screen/error", {message: error});	
+	} finally {
+		resolver.release(source);
+		cocoon.releaseComponent(resolver);
+	}
 }
 
 function getFiles(dir, files, inRegExp, exRegExp) {
 	try {
-		var theFiles = dir.listFiles();
-		for (var i = 0; i < theFiles.length; i++ ) {
-			var f = theFiles[i];
-			if (f.isDirectory()) {
+		var theFiles = dir.getChildren();
+		for (var i = 0; i < theFiles.size(); i++ ) {
+			var f = theFiles.get(i);
+			if (f.isCollection()) {
 				getFiles(f, files, inRegExp, exRegExp);
-			} else if (f.isFile()) {
-				if (f.canRead()) {
-					var apath = f.getAbsolutePath();
-					if (inRegExp.test(apath)) {
-						if (exRegExp == null || !exRegExp.test(apath)) {
-							files.add(apath);
-						}						
-					}
+			} else {
+				var apath = f.getURI();
+				if (inRegExp.test(apath)) {
+					if (exRegExp == null || !exRegExp.test(apath)) {
+						files.add(apath);
+					}						
 				}
 			}
 		}
@@ -97,7 +124,7 @@
 }
 
 function Converter (base, rdir, rsuffix) {
-	this._base = base.getAbsolutePath();
+	this._base = base;
 	this._rdir = rdir;
 	this._rsuffix = rsuffix;
 	if ("undefined".equals(this._rdir)) this._rdir = "";
@@ -107,7 +134,7 @@
 Converter.prototype.convert = function(file) {
 	var path = file.toString();
 	// remove the absolute base path
-	path = path.substring(this._base.length() +1);
+	path = path.substring(this._base.length());
 	// replace the suffix, if a replacement was provided
 	if (!"".equals(this._rsuffix)) path = path.substring(0, path.lastIndexOf(".")) + this._rsuffix;
 	// prefix with the results path

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/querybean/samples/sitemap.xmap
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/querybean/samples/sitemap.xmap?view=diff&r1=160679&r2=160680
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/querybean/samples/sitemap.xmap (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/querybean/samples/sitemap.xmap Sat Apr  9 06:19:04
2005
@@ -158,10 +158,9 @@
     		<map:read src="resources/images/{1}"/>
       </map:match>
 
-
-			<!-- create the index -->
+			<!-- create the index from the contents of a collection -->
 			<map:match pattern="create.html">
-				<map:call function="createIndex">
+				<map:call function="indexCollection">
 					<map:parameter name="screen" value="screen/indexer"/>
 					<map:parameter name="lucene-directory" value="{global:lucene-directory}"/>
 					<map:parameter name="lucene-analyzer" value="{global:lucene-analyzer}"/>
@@ -171,6 +170,22 @@
 					<map:parameter name="content-directory" value="context://docs/xdocs"/>
 					<map:parameter name="include-pattern" value="\.xml$"/>
 					<map:parameter name="exclude-pattern" value="/book\.xml$"/>
+					<map:parameter name="result-directory" value="/docs/"/>
+					<map:parameter name="result-suffix" value=".html"/>
+				</map:call>
+			</map:match>
+
+			<!-- update the index with a single resource -->
+			<map:match pattern="update/**">
+				<map:call function="indexItem">
+					<map:parameter name="screen" value="screen/indexer"/>
+					<map:parameter name="lucene-directory" value="{global:lucene-directory}"/>
+					<map:parameter name="lucene-analyzer" value="{global:lucene-analyzer}"/>
+					<map:parameter name="lucene-merge-factor" value="10"/>
+					<map:parameter name="lucene-create-index" value="false"/>
+					<map:parameter name="lucene-content" value="cocoon:/prepare4indexing/"/>
+					<map:parameter name="content-directory" value="{global:root}"/>
+					<map:parameter name="indexer-target" value="{1}"/><!-- the resource to be indexed
-->
 					<map:parameter name="result-directory" value="/docs/"/>
 					<map:parameter name="result-suffix" value=".html"/>
 				</map:call>



Mime
View raw message