upayavira 2003/08/28 12:21:00
Modified: src/java/org/apache/cocoon Main.java
src/java/org/apache/cocoon/bean CocoonBean.java
CocoonWrapper.java
Log:
Moved error detection to correct place
Added basic support for include/exclude
Revision Changes Path
1.13 +26 -2 cocoon-2.1/src/java/org/apache/cocoon/Main.java
Index: Main.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/Main.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Main.java 27 Aug 2003 19:18:18 -0000 1.12
+++ Main.java 28 Aug 2003 19:21:00 -0000 1.13
@@ -163,7 +163,10 @@
private static final String NODE_LOAD_CLASS = "load-class";
private static final String NODE_DEFAULT_FILENAME = "default-filename";
-
+ private static final String NODE_INCLUDE = "include";
+ private static final String NODE_EXCLUDE = "exclude";
+ private static final String ATTR_INCLUDE_EXCLUDE_PATTERN = "pattern";
+
private static final String NODE_URI = "uri";
private static final String ATTR_URI_TYPE = "type";
private static final String ATTR_URI_SOURCEPREFIX = "src-prefix";
@@ -501,6 +504,14 @@
} else if (nodeName.equals(NODE_DEFAULT_FILENAME)) {
cocoon.setDefaultFilename(getNodeValue(node));
+ } else if (nodeName.equals(NODE_INCLUDE)) {
+ String pattern =
Main.parseIncludeExcludeNode(cocoon, node, NODE_INCLUDE);
+ cocoon.addIncludePattern(pattern);
+
+ } else if (nodeName.equals(NODE_EXCLUDE)) {
+ String pattern =
Main.parseIncludeExcludeNode(cocoon, node, NODE_EXCLUDE);
+ cocoon.addExcludePattern(pattern);
+
} else if (nodeName.equals(NODE_URI)) {
Main.parseURINode(cocoon, node, destDir);
@@ -551,6 +562,19 @@
NodeList nodes = node.getChildNodes();
if (nodes.getLength()!=0) {
throw new IllegalArgumentException("Unexpected children of <" +
NODE_BROKEN_LINKS + "> node");
+ }
+ }
+
+ private static String parseIncludeExcludeNode(CocoonBean cocoon, Node
node, final String NODE_TYPE) throws IllegalArgumentException {
+ NodeList nodes = node.getChildNodes();
+ if (nodes.getLength() != 0) {
+ throw new IllegalArgumentException("Unexpected children of <" +
NODE_INCLUDE + "> node");
+ }
+
+ if (Main.hasAttribute(node, ATTR_INCLUDE_EXCLUDE_PATTERN)) {
+ return Main.getAttributeValue(node,
ATTR_INCLUDE_EXCLUDE_PATTERN);
+ } else {
+ throw new IllegalArgumentException("Expected a
"+ATTR_INCLUDE_EXCLUDE_PATTERN+" attribute for <"+NODE_TYPE+"> node");
}
}
1.18 +79 -23
cocoon-2.1/src/java/org/apache/cocoon/bean/CocoonBean.java
Index: CocoonBean.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/bean/CocoonBean.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- CocoonBean.java 27 Aug 2003 19:18:18 -0000 1.17
+++ CocoonBean.java 28 Aug 2003 19:21:00 -0000 1.18
@@ -60,6 +60,7 @@
import org.apache.cocoon.components.notification.Notifier;
import org.apache.cocoon.components.notification.DefaultNotifyingBuilder;
import org.apache.cocoon.components.notification.Notifying;
+import org.apache.cocoon.matching.helpers.WildcardHelper;
import org.apache.excalibur.source.ModifiableSource;
import org.apache.excalibur.source.SourceResolver;
@@ -77,10 +78,13 @@
import java.util.List;
/**
- * The Cocoon Bean simplifies usage of the Cocoon object. Allows to create,
+ * <p>The Cocoon Bean simplifies usage of the Cocoon object. Allows to
create,
* configure Cocoon instance and process requests, one by one or multiple
- * with link traversal.
+ * with link traversal.</p>
*
+ * <p><b>WARNING:</b> This interface is not stable and could be changed in
+ * backward incompatible way without prior notice.</p>
+
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a>
@@ -97,6 +101,8 @@
private List targets = new ArrayList();
private boolean brokenLinkGenerate = false;
private String brokenLinkExtension = "";
+ private List excludePatterns = new ArrayList();
+ private List includePatterns = new ArrayList();
// Internal Objects
private Map allProcessedLinks;
@@ -105,6 +111,7 @@
private List listeners = new ArrayList();
private boolean verbose;
SourceResolver sourceResolver;
+
//
// INITIALISATION METHOD
//
@@ -201,6 +208,16 @@
}
}
+ public void addExcludePattern(String pattern) {
+ int preparedPattern[] = WildcardHelper.compilePattern(pattern);
+ excludePatterns.add(preparedPattern);
+ }
+
+ public void addIncludePattern(String pattern) {
+ int preparedPattern[] = WildcardHelper.compilePattern(pattern);
+ includePatterns.add(preparedPattern);
+ }
+
public void addListener(BeanListener listener) {
this.listeners.add(listener);
}
@@ -413,6 +430,12 @@
String absoluteLink =
NetUtils.normalize(NetUtils.absolutize(path,
relativeLink));
+
+ if (!isIncluded(absoluteLink)) {
+ //@TODO@ Log/report skipped link
+ continue;
+ }
+
{
final TreeMap p = new TreeMap();
absoluteLink =
@@ -482,7 +505,11 @@
NetUtils.deparameterize(absoluteLink, p),
p);
}
- absoluteLinks.add(absoluteLink);
+ if (isIncluded(absoluteLink)) {
+ absoluteLinks.add(absoluteLink);
+ } else {
+ // @TODO@ Log/report skipped link
+ }
}
linkCount = gatheredLinks.size();
}
@@ -621,24 +648,53 @@
return uri;
}
- public ModifiableSource getSource(Target target, String filename)
- throws IOException, ProcessingException {
- final String finalDestinationURI = target.getFinalURI(filename);
- Source src = sourceResolver.resolveURI(finalDestinationURI);
- if (!(src instanceof ModifiableSource)) {
- sourceResolver.release(src);
- throw new ProcessingException(
- "Source is not Modifiable: " +
finalDestinationURI);
- }
- return (ModifiableSource) src;
- }
-
- public long getLastModified(Target target, String filename) throws
IOException, ProcessingException {
- return getSource(target, filename).getLastModified();
- }
+ public ModifiableSource getSource(Target target, String filename)
+ throws IOException, ProcessingException {
+ final String finalDestinationURI = target.getFinalURI(filename);
+ Source src = sourceResolver.resolveURI(finalDestinationURI);
+ if (!(src instanceof ModifiableSource)) {
+ sourceResolver.release(src);
+ throw new ProcessingException(
+ "Source is not Modifiable: " + finalDestinationURI);
+ }
+ return (ModifiableSource) src;
+ }
+
+ public long getLastModified(Target target, String filename) throws
IOException, ProcessingException {
+ return getSource(target, filename).getLastModified();
+ }
- public void releaseSource(ModifiableSource source) {
- sourceResolver.release(source);
- }
-
+ public void releaseSource(ModifiableSource source) {
+ sourceResolver.release(source);
+ }
+ private boolean isIncluded(String uri) {
+ boolean included;
+ Iterator i;
+ HashMap map = new HashMap();
+
+ if (includePatterns.size() == 0) {
+ included = true;
+ } else {
+ included = false;
+ i = includePatterns.iterator();
+ while (i.hasNext()){
+ int pattern[] = (int[])i.next();
+ if (WildcardHelper.match(map, uri, pattern)) {
+ included=true;
+ break;
+ }
+ }
+ }
+ if (excludePatterns.size() != 0) {
+ i = excludePatterns.iterator();
+ while (i.hasNext()) {
+ int pattern[] = (int[])i.next();
+ if (WildcardHelper.match(map, uri, pattern)) {
+ included=false;
+ break;
+ }
+ }
+ }
+ return included;
+ }
}
1.3 +1 -15
cocoon-2.1/src/java/org/apache/cocoon/bean/CocoonWrapper.java
Index: CocoonWrapper.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/bean/CocoonWrapper.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CocoonWrapper.java 27 Aug 2003 19:18:18 -0000 1.2
+++ CocoonWrapper.java 28 Aug 2003 19:21:00 -0000 1.3
@@ -134,20 +134,6 @@
// @todo@ these should log then throw exceptions back to the caller,
not use system.exit()
setLogLevel("ERROR");
- if (contextDir.equals("")) {
- String error =
- "Careful, you must specify a configuration file when using
the -c/--contextDir argument";
- log.fatalError(error);
- throw new ProcessingException(error);
- }
-
- if (workDir.equals("")) {
- String error =
- "Careful, you must specify a destination dir when using the
-w/--workDir argument";
- log.fatalError(error);
- throw new ProcessingException(error);
- }
-
this.context = getDir(this.contextDir, "context");
this.work = getDir(workDir, "working");