1 16 17 package org.apache.taglibs.standard.extra.spath; 18 19 import java.util.List ; 20 21 26 public class Step { 27 28 private boolean depthUnlimited; 29 private String name; 30 private List predicates; 31 32 private String uri, localPart; 34 35 43 public Step(boolean depthUnlimited, String name, List predicates) { 44 if (name == null) 45 throw new IllegalArgumentException ("non-null name required"); 46 this.depthUnlimited = depthUnlimited; 47 this.name = name; 48 this.predicates = predicates; 49 } 50 51 56 public boolean isMatchingName(String uri, String localPart) { 57 if (localPart == null) 59 throw new IllegalArgumentException ("need non-null localPart"); 60 if (uri != null && uri.equals("")) 61 uri = null; 62 63 if (this.localPart == null && this.uri == null) 65 parseStepName(); 66 67 if (this.uri == null && this.localPart.equals("*")) 69 return true; 70 71 if (uri == null && this.uri == null 73 && localPart.equals(this.localPart)) 74 return true; 75 76 if (uri != null && this.uri != null && uri.equals(this.uri)) { 77 if (localPart.equals(this.localPart)) 79 return true; 80 81 if (this.localPart.equals("*")) 83 return true; 84 } 85 86 return false; 88 } 89 90 91 public boolean isDepthUnlimited() { 92 return depthUnlimited; 93 } 94 95 96 public String getName() { 97 return name; 98 } 99 100 101 public List getPredicates() { 102 return predicates; 103 } 104 105 106 private void parseStepName() { 107 String prefix; 108 int colonIndex = name.indexOf(":"); 109 110 if (colonIndex == -1) { 111 prefix = null; 113 localPart = name; 114 } else { 115 prefix = name.substring(0, colonIndex); 116 localPart = name.substring(colonIndex + 1); 117 } 118 119 uri = mapPrefix(prefix); 120 } 121 122 123 private String mapPrefix(String prefix) { 124 if (prefix == null) 126 return null; 127 else 128 throw new IllegalArgumentException ( 129 "unknown prefix '" + prefix + "'"); 130 } 131 } 132 | Popular Tags |