1 11 package org.jboss.portal.core.impl.invocation; 12 13 20 public class SimpleMapper implements Mapper 21 { 22 public MappingResult map(MappingContext ctx, String path) 23 { 24 Object root = ctx.getRoot(); 25 Object target = null; 26 String targetPath = null; 27 String targetPathInfo = null; 28 29 if (path == null || path.length() == 0) 30 { 31 targetPath = null; 32 targetPathInfo = null; 33 } 34 else if ("/".equals(path)) 35 { 36 targetPath = null; 37 targetPathInfo = "/"; 38 } 39 else 40 { 41 int firstSlashPos = path.indexOf('/', 1); 42 if (firstSlashPos == -1) 43 { 44 String firstChunk = path.substring(1); 45 target = ctx.getChild(root, firstChunk); 46 if (target != null) 47 { 48 targetPath = path; 49 targetPathInfo = null; 50 } 51 else 52 { 53 targetPath = null; 54 targetPathInfo = path; 55 } 56 } 57 else if (firstSlashPos == 1) 58 { 59 targetPath = null; 60 targetPathInfo = "/"; 61 } 62 else 63 { 64 String firstChunk = path.substring(1, firstSlashPos); 65 target = ctx.getChild(root, firstChunk); 66 if (target != null) 67 { 68 int secondSlashPos = path.indexOf('/', firstSlashPos + 1); 69 if (secondSlashPos == -1) 70 { 71 String secondChunck = path.substring(firstSlashPos + 1); 72 if (secondChunck.length() == 0) 73 { 74 targetPath = "/" + firstChunk; 75 targetPathInfo = "/"; 76 } 77 else 78 { 79 Object child = ctx.getChild(target, secondChunck); 80 if (child != null) 81 { 82 target = child; 83 targetPath = path; 84 targetPathInfo = null; 85 } 86 else 87 { 88 targetPath = "/" + firstChunk; 89 targetPathInfo = "/" + secondChunck; 90 } 91 } 92 } 93 else 94 { 95 targetPath = "/" + firstChunk; 96 targetPathInfo = path.substring(firstSlashPos); 97 } 98 } 99 else 100 { 101 targetPath = null; 102 targetPathInfo = path; 103 } 104 } 105 } 106 return new MappingResult(target, targetPath, targetPathInfo); 107 } 108 } 109 | Popular Tags |