コード例 #1
0
 /**
  * Escapes instances of File.separator from the query. These are safe from filename overlap, but
  * can't convert into extended paths and directories.
  *
  * @param query the query
  * @return the escaped query
  */
 static String escapeQuery(String query) {
   if (query.indexOf(File.separator) >= 0) {
     return StringUtil.replaceString(query, File.separator, ESCAPE_STR + ENCODED_SEPARATOR_CHAR);
   } else {
     return query;
   }
 }
コード例 #2
0
 /**
  * Escapes instances of the ESCAPE_CHAR from the path. This avoids name conflicts with the
  * repository files, such as '#nodestate.xml'.
  *
  * @param path the path
  * @return the escaped path
  */
 static String escapePath(String path) {
   // XXX escaping disabled because of URL encoding
   if (false && path.indexOf(ESCAPE_CHAR) >= 0) {
     return StringUtil.replaceString(path, ESCAPE_STR, ESCAPE_STR + ESCAPE_STR);
   } else {
     return path;
   }
 }
コード例 #3
0
 /**
  * mapUrlToFileLocation() is the method used to resolve urls into file names. This maps a given
  * url to a file location, using the au top directory as the base. It creates directories which
  * mirror the html string, so 'http://www.journal.org/issue1/index.html' would be cached in the
  * file: <rootLocation>/www.journal.org/http/issue1/index.html
  *
  * @param rootLocation the top directory for ArchivalUnit this URL is in
  * @param urlStr the url to translate
  * @return the url file location
  * @throws java.net.MalformedURLException
  */
 public static String mapUrlToFileLocation(String rootLocation, String urlStr)
     throws MalformedURLException {
   int totalLength = rootLocation.length() + urlStr.length();
   URL url = new URL(urlStr);
   StringBuilder buffer = new StringBuilder(totalLength);
   buffer.append(rootLocation);
   if (!rootLocation.endsWith(File.separator)) {
     buffer.append(File.separator);
   }
   buffer.append(url.getHost().toLowerCase());
   int port = url.getPort();
   if (port != -1) {
     buffer.append(PORT_SEPARATOR);
     buffer.append(port);
   }
   buffer.append(File.separator);
   buffer.append(url.getProtocol());
   if (RepositoryManager.isEnableLongComponents()) {
     String escapedPath =
         escapePath(
             StringUtil.replaceString(url.getPath(), UrlUtil.URL_PATH_SEPARATOR, File.separator));
     String query = url.getQuery();
     if (query != null) {
       escapedPath = escapedPath + "?" + escapeQuery(query);
     }
     String encodedPath = RepositoryNodeImpl.encodeUrl(escapedPath);
     // encodeUrl strips leading / from path
     buffer.append(File.separator);
     buffer.append(encodedPath);
   } else {
     buffer.append(
         escapePath(
             StringUtil.replaceString(url.getPath(), UrlUtil.URL_PATH_SEPARATOR, File.separator)));
     String query = url.getQuery();
     if (query != null) {
       buffer.append("?");
       buffer.append(escapeQuery(query));
     }
   }
   return buffer.toString();
 }