1 13 package info.magnolia.cms.beans.config; 14 15 import org.apache.commons.lang.StringUtils; 16 17 18 23 public class URI2RepositoryMapping { 24 25 28 private String uriPrefix; 29 30 33 private String repository; 34 35 38 private String handlePrefix; 39 40 45 public URI2RepositoryMapping(String uriPrefix, String repository, String handlePrefix) { 46 super(); 47 this.uriPrefix = uriPrefix; 48 this.repository = repository; 49 this.handlePrefix = handlePrefix; 50 } 51 52 public URI2RepositoryMapping() { 53 } 54 55 60 public boolean matches(String uri) { 61 return uri.startsWith(uriPrefix); 62 } 63 64 69 public String getHandle(String uri) { 70 String handle; 71 handle = StringUtils.removeStart(uri, this.uriPrefix); 72 if (StringUtils.isNotEmpty(this.handlePrefix)) { 73 StringUtils.removeStart(handle, "/"); 74 handle = this.handlePrefix + "/" + handle; 75 } 76 return cleanHandle(handle); 77 } 78 79 84 private String cleanHandle(String handle) { 85 if (!handle.startsWith("/")) { 86 handle = "/" + handle; 87 } 88 handle = StringUtils.replace(handle, "//", "/"); 89 return handle; 90 } 91 92 97 public String getURI(String handle) { 98 if (StringUtils.isNotEmpty(this.handlePrefix)) { 99 handle = StringUtils.removeStart(handle, this.handlePrefix); 100 } 101 if (StringUtils.isNotEmpty(this.uriPrefix)) { 102 handle = this.uriPrefix + "/" + handle; 103 } 104 return cleanHandle(handle); 105 } 106 107 public String getHandlePrefix() { 108 return handlePrefix; 109 } 110 111 public void setHandlePrefix(String handlePrefix) { 112 this.handlePrefix = handlePrefix; 113 } 114 115 public String getRepository() { 116 return repository; 117 } 118 119 public void setRepository(String repository) { 120 this.repository = repository; 121 } 122 123 public String getUriPrefix() { 124 return uriPrefix; 125 } 126 127 public void setUriPrefix(String uriPrefix) { 128 this.uriPrefix = uriPrefix; 129 } 130 131 public String toString() { 132 return this.uriPrefix + " --> " + repository + ":" + this.handlePrefix; 133 } 134 } 135 | Popular Tags |