1 48 49 package org.jpublish.util.uri; 50 51 public class InternalURIParser { 52 53 public static final String REPOSITORY_PROTOCOL = "repository"; 54 public static final String TEMPLATE_PROTOCOL = "template"; 55 56 private static final InternalURIParser INSTANCE = new InternalURIParser(); 57 58 protected InternalURIParser() { 59 60 } 61 62 public static InternalURIParser getInstance() { 63 return INSTANCE; 64 } 65 66 public InternalURI parse(String uriString) throws URIParseException { 67 int protocolTerminatorIndex = uriString.indexOf(":"); 68 if (protocolTerminatorIndex <= 0) { 69 throw new URIParseException("URI string is not a valid URI", 70 uriString); 71 } 72 73 String protocol = uriString.substring(0, protocolTerminatorIndex); 74 75 InternalURI uri = null; 76 if (TEMPLATE_PROTOCOL.equals(protocol)) { 77 uri = new TemplateURI(); 78 } else if (REPOSITORY_PROTOCOL.equals(protocol)) { 79 uri = new RepositoryURI(); 80 } else { 81 throw new URIParseException("Unsupported protocol: " + protocol, 82 uriString); 83 } 84 uri.setURI(uriString); 85 return uri; 86 } 87 88 } 89 | Popular Tags |