コード例 #1
0
  @Test
  public void testGetDocumentViewFromUrl() {
    DocumentFileCodec codec = new DocumentFileCodec();
    codec.setPrefix("nxfile");
    String url = "nxfile/demo/dbefd5a0-35ee-4ed2-a023-6817714f32cf/file:content/mydoc.odt";
    DocumentView docView = codec.getDocumentViewFromUrl(url);

    DocumentLocation docLoc = docView.getDocumentLocation();
    assertEquals("demo", docLoc.getServerName());
    assertEquals(new IdRef("dbefd5a0-35ee-4ed2-a023-6817714f32cf"), docLoc.getDocRef());
    assertNull(docView.getViewId());
    assertNull(docView.getSubURI());

    Map<String, String> params = docView.getParameters();
    assertEquals("file:content", params.get(DocumentFileCodec.FILE_PROPERTY_PATH_KEY));
    assertEquals("mydoc.odt", params.get(DocumentFileCodec.FILENAME_KEY));
  }
コード例 #2
0
  // same with reserved characters in file name and params
  @Test
  public void testGetDocumentViewFromUrlWithReservedAndParams() {
    DocumentFileCodec codec = new DocumentFileCodec("nxfile");
    String url =
        "nxfile/demo/dbefd5a0-35ee-4ed2-a023-6817714f32cf/file:content/my%20%5Bdoc%5D%3F%20%C3%A9.odt?foo=bar";
    DocumentView docView = codec.getDocumentViewFromUrl(url);

    DocumentLocation docLoc = docView.getDocumentLocation();
    assertEquals("demo", docLoc.getServerName());
    assertEquals(new IdRef("dbefd5a0-35ee-4ed2-a023-6817714f32cf"), docLoc.getDocRef());
    assertNull(docView.getViewId());
    assertNull(docView.getSubURI());

    Map<String, String> params = docView.getParameters();
    assertEquals("file:content", params.get(DocumentFileCodec.FILE_PROPERTY_PATH_KEY));
    assertEquals("my [doc]? \u00e9.odt", params.get(DocumentFileCodec.FILENAME_KEY));
    assertEquals("bar", params.get("foo"));
  }
コード例 #3
0
 @Override
 public String getUrlFromDocumentView(DocumentView docView) {
   DocumentLocation docLoc = docView.getDocumentLocation();
   String filepath = docView.getParameter(FILE_PROPERTY_PATH_KEY);
   String filename = docView.getParameter(FILENAME_KEY);
   if (docLoc != null && filepath != null && filename != null) {
     StringBuilder buf = new StringBuilder();
     buf.append(getPrefix());
     buf.append("/");
     buf.append(docLoc.getServerName());
     buf.append("/");
     buf.append(docLoc.getDocRef().toString());
     buf.append("/");
     buf.append(filepath);
     buf.append("/");
     buf.append(URIUtils.quoteURIPathToken(filename));
     String uri = buf.toString();
     Map<String, String> requestParams = new HashMap<String, String>(docView.getParameters());
     requestParams.remove(FILE_PROPERTY_PATH_KEY);
     requestParams.remove(FILENAME_KEY);
     return URIUtils.addParametersToURIQuery(uri, requestParams);
   }
   return null;
 }