1 17 package org.alfresco.service.namespace; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 22 23 34 public class RegexQNamePattern implements QNamePattern 35 { 36 private static final Log logger = LogFactory.getLog(RegexQNamePattern.class); 37 38 39 public static final QNamePattern MATCH_ALL = new QNamePattern() 40 { 41 public boolean isMatch(QName qname) 42 { 43 return true; 44 } 45 }; 46 47 private String namespaceUriPattern; 48 private String localNamePattern; 49 private String combinedPattern; 50 51 55 public RegexQNamePattern(String namespaceUriPattern, String localNamePattern) 56 { 57 this.namespaceUriPattern = namespaceUriPattern; 58 this.localNamePattern = localNamePattern; 59 this.combinedPattern = null; 60 } 61 62 68 public RegexQNamePattern(String combinedPattern) 69 { 70 this.combinedPattern = combinedPattern; 71 this.namespaceUriPattern = null; 72 this.localNamePattern = null; 73 } 74 75 public String toString() 76 { 77 StringBuilder sb = new StringBuilder (56); 78 sb.append("RegexQNamePattern["); 79 if (combinedPattern != null) 80 { 81 sb.append(" pattern=").append(combinedPattern); 82 } 83 else 84 { 85 sb.append(" uri=").append(namespaceUriPattern); 86 sb.append(", localname=").append(namespaceUriPattern); 87 } 88 sb.append(" ]"); 89 return sb.toString(); 90 } 91 92 96 public boolean isMatch(QName qname) 97 { 98 boolean match = false; 99 if (combinedPattern != null) 100 { 101 String qnameStr = qname.toString(); 102 match = qnameStr.matches(combinedPattern); 103 } 104 else 105 { 106 match = (qname.getNamespaceURI().matches(namespaceUriPattern) && 107 qname.getLocalName().matches(localNamePattern)); 108 } 109 if (logger.isDebugEnabled()) 111 { 112 logger.debug("QName matching: \n" + 113 " matcher: " + this + "\n" + 114 " qname: " + qname + "\n" + 115 " result: " + match); 116 } 117 return match; 118 } 119 } 120 | Popular Tags |