1 23 24 package org.apache.slide.search; 25 26 37 public class SlideUri { 38 39 private String context; 40 private String path; 41 42 49 public static SlideUri createWithRequestUri(String slideContextPath, String requestUri) { 50 if (slideContextPath.length() <= 1) { 51 return new SlideUri("/", requestUri); 53 } else { 54 return new SlideUri(slideContextPath, 55 requestUri.substring(slideContextPath.length())); 56 } 57 } 58 59 65 private SlideUri (String slideContextPath, String slideUri) { 66 if (slideContextPath == null || slideUri == null) { 67 throw new NullPointerException (); 68 } 69 if (slideUri.length() == 0) { 70 slideUri = "/"; 71 } 72 if (!slideContextPath.startsWith("/")) { 73 throw new IllegalArgumentException ("slideContextPath must be absolute"); 74 } 75 if (!slideUri.startsWith("/")) { 76 throw new IllegalArgumentException ("slideUri must be absolute"); 77 } 78 this.context = slideContextPath; 79 this.path = slideUri; 80 81 if (this.context.endsWith("/") && this.context.length() > 1) { 83 this.context = this.context.substring(0, this.context.length()-1); 84 } 85 if (this.path.endsWith("/") && this.context.length() > 1) { 86 this.path = this.path.substring(0, this.path.length()-1); 87 } 88 } 89 90 99 public String getSlidePath (String davPath) throws InvalidScopeException { 100 101 if (davPath.startsWith("/")) { 102 if (!(davPath.startsWith(this.context))) { 104 throw new InvalidScopeException ( 105 "Uri \"" + davPath + "\" does not refer to " + context 106 + ". If an absolute scope is used, it must start with \"" 107 + context + "\""); 108 } 109 if (davPath.length() == this.context.length()) { 110 return "/"; 111 } 112 if (this.context.length() > 1 && davPath.charAt(this.context.length()) != '/') { 113 throw new InvalidScopeException ( 114 "Uri \"" + davPath + "\" does not refer to " + context 115 + ". If an absolute scope is used, it must start with \"" 116 + context + "\""); 117 } 118 119 if (this.context.length() > 1) { 120 return davPath.substring(this.context.length()); 121 } else { 122 return davPath; 124 } 125 } else { 126 if (path.length() > 1) { 128 return this.path + "/" + davPath; 129 } else { 130 return this.path + davPath; 132 } 133 } 134 } 135 136 141 public String getContextPath (String slidePath) { 142 if (slidePath.startsWith("/")) { 143 if (context.length() > 1) { 144 return context + slidePath; 145 } else { 146 return slidePath; 148 } 149 } else { 150 if (context.length() > 1) { 151 return context + "/" + slidePath; 152 } else { 153 return "/" + slidePath; 155 } 156 } 157 } 158 } 159 160 | Popular Tags |