コード例 #1
0
  /** Extracts document location from a Zope-like URL ie : server/path_or_docId/view_id/tab_id . */
  @Override
  public DocumentView getDocumentViewFromUrl(String url) {
    final Pattern pattern = Pattern.compile(getPrefix() + URLPattern);
    Matcher m = pattern.matcher(url);
    if (m.matches()) {
      if (m.groupCount() >= 4) {

        // for debug
        // for (int i = 1; i < m.groupCount() + 1; i++) {
        // System.err.println(i + ": " + m.group(i));
        // }

        final String server = m.group(1);
        String uuid = m.group(2);
        final DocumentRef docRef = new IdRef(uuid);

        // get other parameters

        Map<String, String> params = new HashMap<String, String>();
        if (m.groupCount() >= 4) {
          String filePropertyPath = m.group(4);
          params.put(FILE_PROPERTY_PATH_KEY, filePropertyPath);
        }

        if (m.groupCount() >= 6) {
          String filename = m.group(6);
          try {
            filename = URLDecoder.decode(filename, "UTF-8");
          } catch (UnsupportedEncodingException e) {
            filename = StringUtils.toAscii(filename);
          }
          int jsessionidIndex = filename.indexOf(";jsessionid");
          if (jsessionidIndex != -1) {
            filename = filename.substring(0, jsessionidIndex);
          }
          params.put(FILENAME_KEY, filename);
        }

        if (m.groupCount() >= 8) {
          String query = m.group(8);
          Map<String, String> requestParams = URIUtils.getRequestParameters(query);
          if (requestParams != null) {
            params.putAll(requestParams);
          }
        }

        final DocumentLocation docLoc = new DocumentLocationImpl(server, docRef);

        return new DocumentViewImpl(docLoc, null, params);
      }
    }

    return null;
  }