@Test public void testGetDocumentViewFromUrl() { DocumentPathCodec codec = new DocumentPathCodec(); String url = "nxpath/demo/path/to/my/doc@view_documents?tabId=TAB_CONTENT"; DocumentView docView = codec.getDocumentViewFromUrl(url); DocumentLocation docLoc = docView.getDocumentLocation(); assertEquals("demo", docLoc.getServerName()); assertEquals(new PathRef("/path/to/my/doc"), docLoc.getDocRef()); assertEquals("view_documents", docView.getViewId()); assertNull(docView.getSubURI()); Map<String, String> params = docView.getParameters(); assertEquals("TAB_CONTENT", params.get("tabId")); url = "nxpath/demo/default-domain@view_documents"; docView = codec.getDocumentViewFromUrl(url); docLoc = docView.getDocumentLocation(); assertEquals("demo", docLoc.getServerName()); assertEquals(new PathRef("/default-domain"), docLoc.getDocRef()); assertEquals("view_documents", docView.getViewId()); assertNull(docView.getSubURI()); url = "nxpath/demo/@view_domains"; docView = codec.getDocumentViewFromUrl(url); docLoc = docView.getDocumentLocation(); assertEquals("demo", docLoc.getServerName()); assertEquals(new PathRef("/"), docLoc.getDocRef()); assertEquals("view_domains", docView.getViewId()); assertNull(docView.getSubURI()); url = "nxpath/demo@view_domains"; docView = codec.getDocumentViewFromUrl(url); docLoc = docView.getDocumentLocation(); assertEquals("demo", docLoc.getServerName()); assertEquals(null, docLoc.getDocRef()); assertEquals("view_domains", docView.getViewId()); assertNull(docView.getSubURI()); url = "nxpath/demo@view.domains"; docView = codec.getDocumentViewFromUrl(url); docLoc = docView.getDocumentLocation(); assertEquals("demo", docLoc.getServerName()); assertEquals(null, docLoc.getDocRef()); assertEquals("view.domains", docView.getViewId()); assertNull(docView.getSubURI()); url = "nxpath/demo.withdot@view_domains"; docView = codec.getDocumentViewFromUrl(url); docLoc = docView.getDocumentLocation(); assertEquals("demo.withdot", docLoc.getServerName()); assertEquals(null, docLoc.getDocRef()); assertEquals("view_domains", docView.getViewId()); assertNull(docView.getSubURI()); url = "nxpath/demo/doc.withdot@view_domains"; docView = codec.getDocumentViewFromUrl(url); docLoc = docView.getDocumentLocation(); assertEquals("demo", docLoc.getServerName()); assertEquals(new PathRef("/doc.withdot"), docLoc.getDocRef()); assertEquals("view_domains", docView.getViewId()); assertNull(docView.getSubURI()); url = "nxpath/demo/ca%20f%C3%A9doc@view_domains"; docView = codec.getDocumentViewFromUrl(url); assertNotNull(docView); docLoc = docView.getDocumentLocation(); assertEquals("demo", docLoc.getServerName()); assertEquals(new PathRef("/ca f\u00e9doc"), docLoc.getDocRef()); assertEquals("view_domains", docView.getViewId()); assertNull(docView.getSubURI()); url = "nxpath/demo/path/foo%40bar/doc@view_documents?tabId=TAB_CONTENT"; docView = codec.getDocumentViewFromUrl(url); assertNotNull(docView); docLoc = docView.getDocumentLocation(); assertEquals("demo", docLoc.getServerName()); assertEquals(new PathRef("/path/foo@bar/doc"), docLoc.getDocRef()); assertEquals("view_documents", docView.getViewId()); assertNull(docView.getSubURI()); url = "nxpath/demo/path/foo@bar/doc@view_documents?tabId=TAB_CONTENT"; docView = codec.getDocumentViewFromUrl(url); assertNotNull(docView); docLoc = docView.getDocumentLocation(); assertEquals("demo", docLoc.getServerName()); assertEquals(new PathRef("/path/foo@bar/doc"), docLoc.getDocRef()); assertEquals("view_documents", docView.getViewId()); assertNull(docView.getSubURI()); }
@Override public DocumentView getDocumentViewFromUrl(String url) { final Pattern pattern = Pattern.compile(getPrefix() + URL_PATTERN); Matcher m = pattern.matcher(url); if (m.matches()) { final String server = m.group(1); String path = m.group(2); if (path != null) { path = "/" + URIUtils.unquoteURIPathComponent(path); } final DocumentRef docRef = path != null ? new PathRef(path) : null; String viewId = m.group(3); int jsessionidIndex = viewId.indexOf(";jsessionid"); if (jsessionidIndex != -1) { viewId = viewId.substring(0, jsessionidIndex); } String query = m.group(4); Map<String, String> params = URIUtils.getRequestParameters(query); final DocumentLocation docLoc = new DocumentLocationImpl(server, docRef); return new DocumentViewImpl(docLoc, viewId, params); } return null; }
DocumentPathCodec extends AbstractDocumentViewCodec { @Override public DocumentView getDocumentViewFromUrl(String url) { final Pattern pattern = Pattern.compile(getPrefix() + URL_PATTERN); Matcher m = pattern.matcher(url); if (m.matches()) { final String server = m.group(1); String path = m.group(2); if (path != null) { path = "/" + URIUtils.unquoteURIPathComponent(path); } final DocumentRef docRef = path != null ? new PathRef(path) : null; String viewId = m.group(3); int jsessionidIndex = viewId.indexOf(";jsessionid"); if (jsessionidIndex != -1) { viewId = viewId.substring(0, jsessionidIndex); } String query = m.group(4); Map<String, String> params = URIUtils.getRequestParameters(query); final DocumentLocation docLoc = new DocumentLocationImpl(server, docRef); return new DocumentViewImpl(docLoc, viewId, params); } return null; } }
DocumentPathCodec extends AbstractDocumentViewCodec { @Override public DocumentView getDocumentViewFromUrl(String url) { final Pattern pattern = Pattern.compile(getPrefix() + URL_PATTERN); Matcher m = pattern.matcher(url); if (m.matches()) { final String server = m.group(1); String path = m.group(2); if (path != null) { path = "/" + URIUtils.unquoteURIPathComponent(path); } final DocumentRef docRef = path != null ? new PathRef(path) : null; String viewId = m.group(3); int jsessionidIndex = viewId.indexOf(";jsessionid"); if (jsessionidIndex != -1) { viewId = viewId.substring(0, jsessionidIndex); } String query = m.group(4); Map<String, String> params = URIUtils.getRequestParameters(query); final DocumentLocation docLoc = new DocumentLocationImpl(server, docRef); return new DocumentViewImpl(docLoc, viewId, params); } return null; } DocumentPathCodec();  DocumentPathCodec(String prefix); }
DocumentPathCodec extends AbstractDocumentViewCodec { @Override public DocumentView getDocumentViewFromUrl(String url) { final Pattern pattern = Pattern.compile(getPrefix() + URL_PATTERN); Matcher m = pattern.matcher(url); if (m.matches()) { final String server = m.group(1); String path = m.group(2); if (path != null) { path = "/" + URIUtils.unquoteURIPathComponent(path); } final DocumentRef docRef = path != null ? new PathRef(path) : null; String viewId = m.group(3); int jsessionidIndex = viewId.indexOf(";jsessionid"); if (jsessionidIndex != -1) { viewId = viewId.substring(0, jsessionidIndex); } String query = m.group(4); Map<String, String> params = URIUtils.getRequestParameters(query); final DocumentLocation docLoc = new DocumentLocationImpl(server, docRef); return new DocumentViewImpl(docLoc, viewId, params); } return null; } DocumentPathCodec();  DocumentPathCodec(String prefix); @Override String getPrefix(); @Override String getUrlFromDocumentView(DocumentView docView); @Override DocumentView getDocumentViewFromUrl(String url); }
DocumentPathCodec extends AbstractDocumentViewCodec { @Override public DocumentView getDocumentViewFromUrl(String url) { final Pattern pattern = Pattern.compile(getPrefix() + URL_PATTERN); Matcher m = pattern.matcher(url); if (m.matches()) { final String server = m.group(1); String path = m.group(2); if (path != null) { path = "/" + URIUtils.unquoteURIPathComponent(path); } final DocumentRef docRef = path != null ? new PathRef(path) : null; String viewId = m.group(3); int jsessionidIndex = viewId.indexOf(";jsessionid"); if (jsessionidIndex != -1) { viewId = viewId.substring(0, jsessionidIndex); } String query = m.group(4); Map<String, String> params = URIUtils.getRequestParameters(query); final DocumentLocation docLoc = new DocumentLocationImpl(server, docRef); return new DocumentViewImpl(docLoc, viewId, params); } return null; } DocumentPathCodec();  DocumentPathCodec(String prefix); @Override String getPrefix(); @Override String getUrlFromDocumentView(DocumentView docView); @Override DocumentView getDocumentViewFromUrl(String url); static final int URL_MAX_LENGTH; static final String PREFIX; static final String URL_PATTERN; }