struts2中的include的实现

来源:互联网 发布:seo如何做外链 编辑:程序博客网 时间:2024/04/30 04:21
通过读取源代码,发现struts2是通过Xwork中的XmlConfigurationProvider来读取配置的.其中发现在xwork2.1版本中,是支持*号的通配读取.但在xwork2.0中是不支持这样的写法. 
所以在String2.1的版本中是可以使用<include file="resource/struts-config/*.xml"/>这样的配置.在Struts2.0中是不支持这样的配置 
xwork2.1 
Java代码  收藏代码
  1. if ("include".equals(nodeName)) {  
  2.                             String includeFileName = child.getAttribute("file");  
  3.                             if (includeFileName.indexOf('*') != -1) {  
  4.                                 // handleWildCardIncludes(includeFileName, docs, child);  
  5.                                 ClassPathFinder wildcardFinder = new ClassPathFinder();  
  6.                                 wildcardFinder.setPattern(includeFileName);  
  7.                                 Vector<String> wildcardMatches = wildcardFinder.findMatches();  
  8.                                 for (String match : wildcardMatches) {  
  9.                                     finalDocs.addAll(loadConfigurationFiles(match, child));  
  10.                                 }  
  11.                             } else {  
  12.                                 finalDocs.addAll(loadConfigurationFiles(includeFileName, child));  
  13.                             }  
  14.                         }  

xwork2.0 
Java代码  收藏代码
  1. Element rootElement = doc.getDocumentElement();  
  2.                 NodeList children = rootElement.getChildNodes();  
  3.                 int childSize = children.getLength();  
  4.   
  5.                 for (int i = 0; i < childSize; i++) {  
  6.                     Node childNode = children.item(i);  
  7.   
  8.                     if (childNode instanceof Element) {  
  9.                         Element child = (Element) childNode;  
  10.   
  11.                         final String nodeName = child.getNodeName();  
  12.   
  13.                         if (nodeName.equals("include")) {  
  14.                             String includeFileName = child.getAttribute("file");  
  15.                             docs.addAll(loadConfigurationFiles(includeFileName, child));  
  16.                         }  
  17.                     }  
  18.                 }  
  19.                 docs.add(doc);  
  20.                 loadedFileUrls.add(url.toString());  
原创粉丝点击