@Test public void testGetUrlWithoutPathRef() { DocumentPathCodec codec = new DocumentPathCodec(); DocumentLocation docLoc = new DocumentLocationImpl("demo", null); Map<String, String> params = new HashMap<>(); params.put("tabId", "TAB_CONTENT"); DocumentView docView = new DocumentViewImpl(docLoc, "view_documents", params); String url = "nxpath/demo@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; }