[rules-users] how to create a list obj for a rule using 'memberOf'
eyal edri
eyal.edri at gmail.com
Sun May 9 08:46:01 EDT 2010
Hi,
sorry for the newbi question, i'm just starting to find my way in Drools.
i want to write a rule that filters URLs with a certain suffix (e.g. jpg,
gif, css, etc...).
i read about global vars and other variables and i'm not sure what to do.
i need to create a List with all the suffixes i want to filter, should i
create it inside FileType?
can you help?
Eyal.
-------------------------------------------
here's why i had so far:
the .drl file:
*package com.test.drools*
* *
*import com.test.drools.Facts.FileType;*
*
*
* *
*rule "Filter File Types"*
* *
* **when*
* $fileTypes : ??? *
* **FileType( type memberOf $fileTypes )*
* **then*
* **System.out.println("ALLOW");*
*end*
here's FileType:
package com.commtouch.drools;
import java.net.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Facts {
// return a file type of a url
public static class FileType {
private String type = "html";
public FileType (URL url) {
// get the path from the url
//TODO: use parser to do it?
String path = url.getPath();
if (path != null) {
// define regex to extract file from path
Pattern fileRegex = Pattern.compile("([^/]+)$");
Matcher fileMatcher = fileRegex.matcher(path);
// get regex capure $1 (filename)
String file = null;
while (fileMatcher.find())
file = fileMatcher.group(1);
String suffix = null;
if (file != null)
{
//try to extract suffix from file
Pattern suffixRegex = Pattern.compile("\\.([^\\.]+)$");
Matcher suffixMatcher = suffixRegex.matcher(file);
while (suffixMatcher.find())
suffix = suffixMatcher.group(1);
//verify that the suffix is a valid suffix
if (suffix != null && (suffix.length()> 1 && suffix.length() < 6))
setType(suffix);
}
}
}
public void setType(String type) {
this.type = type;
}
public String getType() {
return type;
}
}
}
--
Eyal Edri
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100509/166522c8/attachment.html
More information about the rules-users
mailing list