예제 #1
0
 protected String getCurrentMainTabFromRequest() {
   URLPolicyService service = Framework.getService(URLPolicyService.class);
   ServletRequest request =
       (ServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
   if (request instanceof HttpServletRequest) {
     DocumentView docView = service.getDocumentViewFromRequest((HttpServletRequest) request);
     if (docView == null) {
       return null;
     }
     String tabIds = docView.getParameter(WebActions.TAB_IDS_PARAMETER);
     String mainTabId = docView.getParameter(WebActions.MAIN_TAB_ID_PARAMETER);
     if (mainTabId != null && !mainTabId.isEmpty()) {
       tabIds = mainTabId;
     }
     if (tabIds != null && tabIds.contains(WebActions.MAIN_TABS_CATEGORY)) {
       String[] encodedActions = tabIds.split(",");
       for (String encodedAction : encodedActions) {
         if (encodedAction.startsWith(WebActions.MAIN_TABS_CATEGORY)) {
           String[] actionInfo = encodedAction.split(":");
           if (actionInfo != null && actionInfo.length > 1) {
             return actionInfo[1];
           }
         }
       }
     }
   }
   return null;
 }
예제 #2
0
 public static String getFilename(DocumentModel doc, DocumentView docView) {
   String filename = docView.getParameter(FILENAME_KEY);
   if (filename == null) {
     // try to get it from document
     String propertyPath = docView.getParameter(FILENAME_PROPERTY_PATH_KEY);
     String propertyName = DocumentModelUtils.decodePropertyName(propertyPath);
     if (propertyName != null) {
       filename = (String) DocumentModelUtils.getPropertyValue(doc, propertyName);
     }
   }
   return filename;
 }
예제 #3
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));
  }
예제 #4
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"));
  }
예제 #5
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;
 }