1 package org.sapia.soto.state.util; 2 3 4 13 public class StateIdParser { 14 private static final char SEP = '/'; 15 private static final char DOT = '.'; 16 17 public static Created parseStateFrom(String pathInfo, String extension) { 18 if (pathInfo.length() == 0) { 19 return null; 20 } 21 22 if (pathInfo.charAt(0) == SEP) { 23 if (pathInfo.length() == 1) { 24 return null; 25 } 26 27 pathInfo = pathInfo.substring(1); 28 29 if (pathInfo.length() == 0) { 30 return null; 31 } 32 } 33 34 int i; 35 String path = null; 36 37 if ((i = pathInfo.lastIndexOf(SEP)) > 0) { 38 path = pathInfo.substring(0, i); 39 pathInfo = pathInfo.substring(i + 1); 40 } 41 42 if (extension != null) { 43 i = pathInfo.lastIndexOf(DOT); 44 45 if ((i > 0) && extension.equals(pathInfo.substring(i + 1))) { 46 pathInfo = pathInfo.substring(0, i); 47 } 48 } 49 50 i = pathInfo.lastIndexOf(DOT); 51 52 if (i > 0) { 53 String module = pathInfo.substring(0, i); 54 55 if (path != null) { 56 pathInfo = new StringBuffer (path).append(SEP) 57 .append(pathInfo.substring(i + 1)) 58 .toString(); 59 } else { 60 pathInfo = pathInfo.substring(i + 1); 61 } 62 63 return new Created(pathInfo, module); 64 } else { 65 if (path != null) { 66 pathInfo = new StringBuffer (path).append(SEP) 67 .append(pathInfo.substring(i + 1)) 68 .toString(); 69 } else { 70 pathInfo = pathInfo.substring(i + 1); 71 } 72 73 return new Created(pathInfo, null); 74 } 75 } 76 77 public static class Created { 78 public final String state; 79 public final String module; 80 81 Created(String state, String module) { 82 this.state = state; 83 this.module = module; 84 } 85 } 86 } 87 | Popular Tags |