1 package com.opensymphony.webwork.webFlow.entities; 2 3 import com.opensymphony.util.FileUtils; 4 import com.opensymphony.webwork.config.Configuration; 5 import com.opensymphony.webwork.webFlow.model.Link; 6 7 import java.io.File ; 8 import java.util.HashSet ; 9 import java.util.Set ; 10 import java.util.TreeSet ; 11 import java.util.regex.Matcher ; 12 import java.util.regex.Pattern ; 13 14 19 public abstract class FileBasedView implements View { 20 private String name; 21 private String contents; 22 23 public FileBasedView(File file) { 24 this.name = file.getName(); 25 this.contents = FileUtils.readFile(file).replaceAll("[\r\n ]+", " "); 27 } 28 29 public String getName() { 30 return name; 31 } 32 33 public Set getTargets() { 34 TreeSet targets = new TreeSet (); 35 36 matchPatterns(getLinkPattern(), targets, Link.TYPE_HREF); 38 39 matchPatterns(getActionPattern(), targets, Link.TYPE_ACTION); 41 42 matchPatterns(getFormPattern(), targets, Link.TYPE_FORM); 44 45 return targets; 46 } 47 48 protected Pattern getLinkPattern() { 49 Object ext = Configuration.get("webwork.action.extension"); 50 String actionRegex = "([A-Za-z0-9\\._\\-\\!]+\\." + ext + ")"; 51 return Pattern.compile(actionRegex); 52 } 53 54 private void matchPatterns(Pattern pattern, Set targets, int type) { 55 Matcher matcher = pattern.matcher(contents); 56 while (matcher.find()) { 57 String target = matcher.group(1); 58 targets.add(new Target(target, type)); 59 } 60 } 61 62 protected abstract Pattern getActionPattern(); 63 64 protected abstract Pattern getFormPattern(); 65 } 66 | Popular Tags |