/** Return next string in the sequence "a", "b", ... "z", "aa", "ab", ... */
 static String getNextDirName(String old) {
   StringBuilder sb = new StringBuilder(old);
   // go through and increment the first non-'z' char
   // counts back from the last char, so 'aa'->'ab', not 'ba'
   for (int ii = sb.length() - 1; ii >= 0; ii--) {
     char curChar = sb.charAt(ii);
     if (curChar < 'z') {
       sb.setCharAt(ii, (char) (curChar + 1));
       return sb.toString();
     }
     sb.setCharAt(ii, 'a');
   }
   sb.insert(0, 'a');
   return sb.toString();
 }
Ejemplo n.º 2
0
 protected String getSoftwareVersion() {
   String releaseName = BuildInfo.getBuildProperty(BuildInfo.BUILD_RELEASENAME);
   StringBuilder sb = new StringBuilder();
   sb.append("LOCKSS Daemon ");
   if (releaseName != null) {
     sb.append(releaseName);
   }
   return sb.toString();
 }
 /**
  * Adds the 'cache' directory to the HD location.
  *
  * @param cacheDir the root location.
  * @return String the extended location
  */
 static String extendCacheLocation(String cacheDir) {
   StringBuilder buffer = new StringBuilder(cacheDir);
   if (!cacheDir.endsWith(File.separator)) {
     buffer.append(File.separator);
   }
   buffer.append(CACHE_ROOT_NAME);
   buffer.append(File.separator);
   return buffer.toString();
 }
 LockssRepositoryImpl(String rootPath) {
   if (rootPath.endsWith(File.separator)) {
     rootLocation = rootPath;
   } else {
     // shouldn't happen
     StringBuilder sb = new StringBuilder(rootPath.length() + File.separator.length());
     sb.append(rootPath);
     sb.append(File.separator);
     rootLocation = sb.toString();
   }
   // Test code still needs this.
   nodeCache = new UniqueRefLruCache(RepositoryManager.DEFAULT_MAX_PER_AU_CACHE_SIZE);
   rootLocation =
       rootLocation
           .replace("?", "")
           .replace("COM8", "COMEIGHT")
           .replace("%5c", "/"); // //windows folder structure fix
 }
 /**
  * Extracts '#x' encoding and converts back to 'x'.
  *
  * @param orig the original
  * @return the unescaped version.
  */
 static String unescape(String orig) {
   if (orig.indexOf(ESCAPE_CHAR) < 0) {
     // fast treatment of non-escaped strings
     return orig;
   }
   int index = -1;
   StringBuilder buffer = new StringBuilder(orig.length());
   String oldStr = orig;
   while ((index = oldStr.indexOf(ESCAPE_CHAR)) >= 0) {
     buffer.append(oldStr.substring(0, index));
     buffer.append(convertCode(oldStr.substring(index, index + 2)));
     if (oldStr.length() > 2) {
       oldStr = oldStr.substring(index + 2);
     } else {
       oldStr = "";
     }
   }
   buffer.append(oldStr);
   return buffer.toString();
 }
Ejemplo n.º 6
0
 String srvUrlStem(String host) {
   if (host == null) {
     return null;
   }
   StringBuilder sb = new StringBuilder();
   sb.append(reqURL.getProtocol());
   sb.append("://");
   sb.append(host);
   sb.append(':');
   sb.append(reqURL.getPort());
   return sb.toString();
 }
    /**
     * Return the auid -> au-subdir-path mapping. Enumerating the directories if necessary to
     * initialize the map
     */
    Map getAuMap() {
      if (auMap == null) {
        logger.debug3("Loading name map for '" + repoCacheFile + "'.");
        auMap = new HashMap();
        if (!repoCacheFile.exists()) {
          logger.debug3("Creating cache dir:" + repoCacheFile + "'.");
          if (!repoCacheFile.mkdirs()) {
            logger.critical("Couldn't create directory, check owner/permissions: " + repoCacheFile);
            // return empty map
            return auMap;
          }
        } else {
          // read each dir's property file and store mapping auid -> dir
          File[] auDirs = repoCacheFile.listFiles();
          for (int ii = 0; ii < auDirs.length; ii++) {
            String dirName = auDirs[ii].getName();
            //       if (dirName.compareTo(lastPluginDir) == 1) {
            //         // adjust the 'lastPluginDir' upwards if necessary
            //         lastPluginDir = dirName;
            //       }

            String path = auDirs[ii].getAbsolutePath();
            Properties idProps = getAuIdProperties(path);
            if (idProps != null) {
              String auid = idProps.getProperty(AU_ID_PROP);
              StringBuilder sb = new StringBuilder(path.length() + File.separator.length());
              sb.append(path);
              sb.append(File.separator);
              auMap.put(auid, sb.toString());
              logger.debug3("Mapping to: " + auMap.get(auid) + ": " + auid);
            } else {
              logger.debug3("Not mapping " + path + ", no auid file.");
            }
          }
        }
      }
      return auMap;
    }
Ejemplo n.º 8
0
 private void crawlPluginRegistries() {
   StringBuilder sb = new StringBuilder();
   for (ArchivalUnit au : pluginMgr.getAllRegistryAus()) {
     sb.append(au.getName());
     sb.append(": ");
     try {
       startCrawl(au, true, false);
       sb.append("Queued.");
     } catch (CrawlManagerImpl.NotEligibleException e) {
       sb.append("Failed: ");
       sb.append(e.getMessage());
     }
     sb.append("\n");
   }
   statusMsg = sb.toString();
 }
Ejemplo n.º 9
0
 protected String getHttpResponseString(CachedUrl cu) {
   Properties cuProps = cu.getProperties();
   Properties filteredProps = filterResponseProps(cuProps);
   String hdrString = PropUtil.toHeaderString(filteredProps);
   StringBuilder sb = new StringBuilder(hdrString.length() + 30);
   String line1 = inferHttpResponseCode(cu, cuProps);
   sb.append(line1);
   sb.append(Constants.CRLF);
   sb.append(hdrString);
   sb.append(Constants.CRLF);
   return sb.toString();
 }
Ejemplo n.º 10
0
 /**
  * Construct servlet URL, with params as necessary. Avoid generating a hostname different from
  * that used in the original request, or browsers will prompt again for login
  */
 String srvURLFromStem(String stem, ServletDescr d, String params) {
   if (d.isPathIsUrl()) {
     return d.getPath();
   }
   StringBuilder sb = new StringBuilder(80);
   if (stem != null) {
     sb.append(stem);
     if (stem.charAt(stem.length() - 1) != '/') {
       sb.append('/');
     }
   } else {
     // ensure absolute path even if no scheme/host/port
     sb.append('/');
   }
   sb.append(d.getPath());
   if (params != null) {
     sb.append('?');
     sb.append(params);
   }
   return sb.toString();
 }
Ejemplo n.º 11
0
 /**
  * Return a button that invokes the javascript submit routine with the specified action, first
  * storing the value in the specified form prop.
  */
 protected Element submitButton(String label, String action, String prop, String value) {
   StringBuilder sb = new StringBuilder(40);
   sb.append("lockssButton(this, '");
   sb.append(action);
   sb.append("'");
   if (prop != null && value != null) {
     sb.append(", '");
     sb.append(prop);
     sb.append("', '");
     sb.append(value);
     sb.append("'");
   }
   sb.append(")");
   Input btn = jsButton(label, sb.toString());
   btn.attribute("id", "lsb." + (++submitButtonNumber));
   return btn;
 }
 /**
  * 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();
 }