1 16 package org.apache.cocoon.forms.formmodel.tree.builder; 17 18 import org.apache.avalon.framework.logger.AbstractLogEnabled; 19 import org.apache.avalon.framework.service.ServiceException; 20 import org.apache.avalon.framework.service.ServiceManager; 21 import org.apache.avalon.framework.service.Serviceable; 22 import org.apache.cocoon.forms.FormsConstants; 23 import org.apache.cocoon.forms.formmodel.tree.SourceTreeModelDefinition; 24 import org.apache.cocoon.forms.formmodel.tree.TreeModelDefinition; 25 import org.apache.cocoon.forms.util.DomHelper; 26 import org.apache.cocoon.matching.helpers.WildcardHelper; 27 import org.apache.excalibur.source.SourceResolver; 28 import org.w3c.dom.Element ; 29 30 35 public class SourceTreeModelDefinitionBuilder extends AbstractLogEnabled 36 implements Serviceable, TreeModelDefinitionBuilder { 37 38 private ServiceManager manager; 39 40 public void service(ServiceManager manager) throws ServiceException { 41 this.manager = manager; 42 } 43 44 public TreeModelDefinition build(Element modelElt) throws Exception { 45 46 SourceTreeModelDefinition definition = new SourceTreeModelDefinition(); 47 48 definition.setURL(DomHelper.getAttribute(modelElt, "src")); 49 50 Element fileSet = DomHelper.getChildElement(modelElt, FormsConstants.DEFINITION_NS, "fileset"); 51 if (fileSet != null) { 52 definition.setFilePatterns(getPatterns(fileSet, "include"), 53 getPatterns(fileSet, "exclude")); 54 } 55 56 Element dirSet = DomHelper.getChildElement(modelElt, FormsConstants.DEFINITION_NS, "dirset"); 57 if (dirSet != null) { 58 definition.setDirectoryPatterns(getPatterns(dirSet, "include"), 59 getPatterns(dirSet, "exclude")); 60 } 61 62 definition.setSourceResolver((SourceResolver)this.manager.lookup(SourceResolver.ROLE)); 63 64 return definition; 65 } 66 67 int[][] getPatterns(Element parent, String name) throws Exception { 68 Element [] children = DomHelper.getChildElements(parent, FormsConstants.DEFINITION_NS, name); 69 70 if (children.length == 0) { 71 return null; 72 } 73 74 int[][] result = new int[children.length][]; 75 for (int i = 0; i < children.length; i++) { 76 String pattern = DomHelper.getAttribute(children[i], "pattern"); 77 result[i] = WildcardHelper.compilePattern(pattern); 78 } 79 return result; 80 } 81 82 } 83 | Popular Tags |