@Test public void testGetUrlFromDocumentView() { DocumentPathCodec codec = new DocumentPathCodec(); String docid = "dbefd5a0-35ee-4ed2-a023-6817714f32cf"; DocumentView docView = getDocumentView(docid, "/path/to/my/doc", "view_documents"); String url = "nxpath/demo/path/to/my/doc@view_documents?tabId=TAB_CONTENT"; assertEquals(url, codec.getUrlFromDocumentView(docView)); docView = getDocumentView(docid, "path/to/my/doc", "view_documents"); url = "nxpath/demo/path/to/my/doc@view_documents?tabId=TAB_CONTENT"; assertEquals(url, codec.getUrlFromDocumentView(docView)); docView = getDocumentView(docid, "/default-domain", "view_documents"); url = "nxpath/demo/default-domain@view_documents?tabId=TAB_CONTENT"; assertEquals(url, codec.getUrlFromDocumentView(docView)); docView = getDocumentView(docid, "/", "view_domains"); url = "nxpath/demo@view_domains?tabId=TAB_CONTENT"; assertEquals(url, codec.getUrlFromDocumentView(docView)); docView = getDocumentView(docid, "path/to/my/doc", "view.documents"); url = "nxpath/demo/path/to/my/doc@view.documents?tabId=TAB_CONTENT"; assertEquals(url, codec.getUrlFromDocumentView(docView)); docView = getDocumentView(docid, "path/to/my/doc.withdot", "view_documents"); url = "nxpath/demo/path/to/my/doc.withdot@view_documents?tabId=TAB_CONTENT"; assertEquals(url, codec.getUrlFromDocumentView(docView)); StringBuilder veryLongUrl = new StringBuilder(); veryLongUrl.append("nxpath/demo/path/to/my/doc"); while (veryLongUrl.length() <= DocumentPathCodec.URL_MAX_LENGTH) { veryLongUrl.append("/doc"); } DocumentView docViewMaxLength = getDocumentView(docid, veryLongUrl.toString(), "view_documents"); url = "nxdoc/demo/dbefd5a0-35ee-4ed2-a023-6817714f32cf/view_documents?tabId=TAB_CONTENT"; assertEquals(url, codec.getUrlFromDocumentView(docViewMaxLength)); docView = getDocumentView(docid, "/path/ca f\u00e9/doc", "view_documents"); url = "nxpath/demo/path/ca%20f%C3%A9/doc@view_documents?tabId=TAB_CONTENT"; assertEquals(url, codec.getUrlFromDocumentView(docView)); docView = getDocumentView(docid, "/path/foo@bar/doc", "view_documents"); url = "nxpath/demo/path/foo%40bar/doc@view_documents?tabId=TAB_CONTENT"; assertEquals(url, codec.getUrlFromDocumentView(docView)); }
@Override public String getUrlFromDocumentView(DocumentView docView) { if ("true".equals(docView.getParameter("version"))) { if (docView.getDocumentLocation().getIdRef() != null) { DocumentIdCodec idCodec = new DocumentIdCodec(); return idCodec.getUrlFromDocumentView(docView); } } DocumentLocation docLoc = docView.getDocumentLocation(); if (docLoc != null) { List<String> items = new ArrayList<>(); items.add(getPrefix()); items.add(docLoc.getServerName()); PathRef docRef = docLoc.getPathRef(); if (docRef != null) { String path = docRef.toString(); if (path.startsWith("/")) { path = path.substring(1); } if (path.length() > 0) { items.add(URIUtils.quoteURIPathComponent(path, false)); } } String uri = String.join("/", items); String viewId = docView.getViewId(); if (viewId != null) { uri += "@" + viewId; } String uriWithParam = URIUtils.addParametersToURIQuery(uri, docView.getParameters()); if (uriWithParam.length() > URL_MAX_LENGTH) { if (null == docView.getDocumentLocation().getIdRef()) { log.error("The DocumentLocation did not contains the RefId."); return uriWithParam; } DocumentIdCodec idCodec = new DocumentIdCodec(); return idCodec.getUrlFromDocumentView(docView); } else { return uriWithParam; } } return null; }
DocumentPathCodec extends AbstractDocumentViewCodec { @Override public String getUrlFromDocumentView(DocumentView docView) { if ("true".equals(docView.getParameter("version"))) { if (docView.getDocumentLocation().getIdRef() != null) { DocumentIdCodec idCodec = new DocumentIdCodec(); return idCodec.getUrlFromDocumentView(docView); } } DocumentLocation docLoc = docView.getDocumentLocation(); if (docLoc != null) { List<String> items = new ArrayList<>(); items.add(getPrefix()); items.add(docLoc.getServerName()); PathRef docRef = docLoc.getPathRef(); if (docRef != null) { String path = docRef.toString(); if (path.startsWith("/")) { path = path.substring(1); } if (path.length() > 0) { items.add(URIUtils.quoteURIPathComponent(path, false)); } } String uri = String.join("/", items); String viewId = docView.getViewId(); if (viewId != null) { uri += "@" + viewId; } String uriWithParam = URIUtils.addParametersToURIQuery(uri, docView.getParameters()); if (uriWithParam.length() > URL_MAX_LENGTH) { if (null == docView.getDocumentLocation().getIdRef()) { log.error("The DocumentLocation did not contains the RefId."); return uriWithParam; } DocumentIdCodec idCodec = new DocumentIdCodec(); return idCodec.getUrlFromDocumentView(docView); } else { return uriWithParam; } } return null; } }
DocumentPathCodec extends AbstractDocumentViewCodec { @Override public String getUrlFromDocumentView(DocumentView docView) { if ("true".equals(docView.getParameter("version"))) { if (docView.getDocumentLocation().getIdRef() != null) { DocumentIdCodec idCodec = new DocumentIdCodec(); return idCodec.getUrlFromDocumentView(docView); } } DocumentLocation docLoc = docView.getDocumentLocation(); if (docLoc != null) { List<String> items = new ArrayList<>(); items.add(getPrefix()); items.add(docLoc.getServerName()); PathRef docRef = docLoc.getPathRef(); if (docRef != null) { String path = docRef.toString(); if (path.startsWith("/")) { path = path.substring(1); } if (path.length() > 0) { items.add(URIUtils.quoteURIPathComponent(path, false)); } } String uri = String.join("/", items); String viewId = docView.getViewId(); if (viewId != null) { uri += "@" + viewId; } String uriWithParam = URIUtils.addParametersToURIQuery(uri, docView.getParameters()); if (uriWithParam.length() > URL_MAX_LENGTH) { if (null == docView.getDocumentLocation().getIdRef()) { log.error("The DocumentLocation did not contains the RefId."); return uriWithParam; } DocumentIdCodec idCodec = new DocumentIdCodec(); return idCodec.getUrlFromDocumentView(docView); } else { return uriWithParam; } } return null; } DocumentPathCodec();  DocumentPathCodec(String prefix); }
DocumentPathCodec extends AbstractDocumentViewCodec { @Override public String getUrlFromDocumentView(DocumentView docView) { if ("true".equals(docView.getParameter("version"))) { if (docView.getDocumentLocation().getIdRef() != null) { DocumentIdCodec idCodec = new DocumentIdCodec(); return idCodec.getUrlFromDocumentView(docView); } } DocumentLocation docLoc = docView.getDocumentLocation(); if (docLoc != null) { List<String> items = new ArrayList<>(); items.add(getPrefix()); items.add(docLoc.getServerName()); PathRef docRef = docLoc.getPathRef(); if (docRef != null) { String path = docRef.toString(); if (path.startsWith("/")) { path = path.substring(1); } if (path.length() > 0) { items.add(URIUtils.quoteURIPathComponent(path, false)); } } String uri = String.join("/", items); String viewId = docView.getViewId(); if (viewId != null) { uri += "@" + viewId; } String uriWithParam = URIUtils.addParametersToURIQuery(uri, docView.getParameters()); if (uriWithParam.length() > URL_MAX_LENGTH) { if (null == docView.getDocumentLocation().getIdRef()) { log.error("The DocumentLocation did not contains the RefId."); return uriWithParam; } DocumentIdCodec idCodec = new DocumentIdCodec(); return idCodec.getUrlFromDocumentView(docView); } else { return uriWithParam; } } return null; } DocumentPathCodec();  DocumentPathCodec(String prefix); @Override String getPrefix(); @Override String getUrlFromDocumentView(DocumentView docView); @Override DocumentView getDocumentViewFromUrl(String url); }
DocumentPathCodec extends AbstractDocumentViewCodec { @Override public String getUrlFromDocumentView(DocumentView docView) { if ("true".equals(docView.getParameter("version"))) { if (docView.getDocumentLocation().getIdRef() != null) { DocumentIdCodec idCodec = new DocumentIdCodec(); return idCodec.getUrlFromDocumentView(docView); } } DocumentLocation docLoc = docView.getDocumentLocation(); if (docLoc != null) { List<String> items = new ArrayList<>(); items.add(getPrefix()); items.add(docLoc.getServerName()); PathRef docRef = docLoc.getPathRef(); if (docRef != null) { String path = docRef.toString(); if (path.startsWith("/")) { path = path.substring(1); } if (path.length() > 0) { items.add(URIUtils.quoteURIPathComponent(path, false)); } } String uri = String.join("/", items); String viewId = docView.getViewId(); if (viewId != null) { uri += "@" + viewId; } String uriWithParam = URIUtils.addParametersToURIQuery(uri, docView.getParameters()); if (uriWithParam.length() > URL_MAX_LENGTH) { if (null == docView.getDocumentLocation().getIdRef()) { log.error("The DocumentLocation did not contains the RefId."); return uriWithParam; } DocumentIdCodec idCodec = new DocumentIdCodec(); return idCodec.getUrlFromDocumentView(docView); } else { return uriWithParam; } } 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; }