public static SharedEntity requestPathToSharedEntity(String inRp) {
		try {
			if (!inRp.startsWith("/shares")) {
				return null;
			}

			String rp = inRp.substring(("/shares".length() + 1));
			
			//System.out.println (inRp + " -> " + rp);

			int slashIndex = rp.indexOf('/');

			if (slashIndex == -1) {
				rp = rp + '/';
				slashIndex = rp.indexOf('/');
			}

			String shareName = URL.decode(rp.substring(0, slashIndex));
			Share share = ShareManager.instance().getShare(shareName);

			// share not found!
			if (share == null) {
				return null;
			}

			String requestedFileName = rp.substring(slashIndex);
			String shareDirectory = share.getFileLocation();
			File shareDirectoryFile = (new File(shareDirectory))
					.getCanonicalFile();

			File f = SharedEntity.getFileFromRequest(shareDirectory, requestedFileName);
			// does the file exist?
			if (f == null) {
				return null;
			}

			f = f.getCanonicalFile();

			if (!f.toString().startsWith(shareDirectoryFile.toString())) {
				return null;
			}
			
			SharedEntity sharedEntity = new SharedEntity (share, f, inRp);
			
			return sharedEntity;

		} catch (Exception e) {
			return null;
		}
	}