Example #1
1
 /**
  * Return a copy of the string with all reserved regexp chars escaped by backslash.
  *
  * @param str the string to add escapes to
  * @return String return a string with escapes or "" if str is null
  */
 private String escapeReservedChars(String str) {
   if (str == null) return "";
   StringBuilder sb = new StringBuilder();
   for (int ci = 0; ci < str.length(); ci++) {
     char ch = str.charAt(ci);
     if (RESERVED_STRING.indexOf(ch) >= 0) {
       sb.append('\\');
     }
     sb.append(ch);
   }
   return escapePrintfChars(sb.toString());
 }
Example #2
1
 private String escapePrintfChars(String str) {
   if (str == null) return "";
   StringBuilder sb = new StringBuilder();
   for (int ci = 0; ci < str.length(); ci++) {
     char ch = str.charAt(ci);
     if (ch == '%') {
       sb.append('%');
     }
     sb.append(ch);
   }
   return sb.toString();
 }
 /** 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();
 }
Example #4
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();
 }
 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;
    }
Example #10
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();
 }
Example #11
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();
 }
Example #12
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();
 }
  private String constructRDF(Collection<String> urlList, boolean withIdentifiers) {
    StringBuilder sb = new StringBuilder("<?xml version=\"1.0\"?>\n");
    sb.append("<!DOCTYPE rdf:RDF SYSTEM \"http://purl.org/dc/schemas/dcmes-xml-20000714.dtd\">\n");
    sb.append(
        "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"
            + "         xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n");

    for (String url : urlList) {
      sb.append(constructResource(url, withIdentifiers));
    }

    sb.append("</rdf:RDF>");
    return sb.toString();
  }
Example #14
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;
 }
 private String constructResource(String url, boolean includeIdentifier) {
   StringBuilder sb = new StringBuilder("  <rdf:Description about=\"" + url + "\">\n");
   sb.append("    <dc:title>Title</dc:title>\n");
   sb.append("    <dc:creator>Creator</dc:creator>\n");
   sb.append("    <dc:description>Description</dc:description>\n");
   sb.append("    <dc:publisher>Publisher</dc:publisher>\n");
   sb.append("    <dc:contributor>Contributor</dc:contributor>\n");
   sb.append("    <dc:date>2006-05-18</dc:date>\n");
   sb.append("    <dc:type>Image</dc:type>\n");
   sb.append("    <dc:format>jpeg</dc:format>\n");
   if (includeIdentifier) {
     sb.append("    <dc:identifier>" + url + "</dc:identifier>\n");
   }
   sb.append("    <dc:source>Source</dc:source>\n");
   sb.append("    <dc:language>eng</dc:language>\n");
   sb.append("    <dc:relation>Relation</dc:relation>\n");
   sb.append("    <dc:coverage>Coverage</dc:coverage>\n");
   sb.append("    <dc:rights>In the public domain.</dc:rights>\n");
   sb.append("  </rdf:Description>");
   return sb.toString();
 }
 private String createGoodRisContent() {
   StringBuilder sb = new StringBuilder();
   sb.append("TY  - JOUR");
   for (String auth : goodAuthors) {
     sb.append("\nA1  - ");
     sb.append(auth);
   }
   sb.append("\nDA  - ");
   sb.append(goodDate);
   sb.append("\nJF  - ");
   sb.append(goodJournal);
   sb.append("\nSP  - ");
   sb.append(goodStartPage);
   sb.append("\nEP  - ");
   sb.append(goodEndPage);
   sb.append("\nVL  - ");
   sb.append(goodVolume);
   sb.append("\nIS  - ");
   sb.append(goodIssue);
   sb.append("\nSN  - ");
   sb.append(goodIssn);
   sb.append("\nT1  - ");
   sb.append(goodTitle);
   sb.append("\nPB  - ");
   sb.append(goodPublisher);
   sb.append("\nDO  - ");
   sb.append(goodDOI);
   sb.append("\nUR  - ");
   sb.append(doiURL);
   sb.append("\nER  -");
   return sb.toString();
 }
 /**
  * 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();
 }
 /* the extractor checks if data is missing it uses possible alternate RIS tags */
 private String createAlternateRisContent() {
   StringBuilder sb = new StringBuilder();
   sb.append("TY  - JOUR");
   for (String auth : goodAuthors) {
     sb.append("\nAU  - ");
     sb.append(auth);
   }
   sb.append("\nY1  - ");
   sb.append(goodDate);
   sb.append("\nT2  - ");
   sb.append(goodJournal);
   sb.append("\nT1  - ");
   sb.append(goodTitle);
   sb.append("\nPB  - ");
   sb.append(goodPublisher);
   sb.append("\nER  -");
   return sb.toString();
 }
Example #19
0
  void insertButton_actionPerformed(ActionEvent e) {
    Object selected = paramComboBox.getSelectedItem();
    ConfigParamDescr descr;
    String key;
    int type = 0;
    String format = "";
    if (selected instanceof ConfigParamDescr) {
      descr = (ConfigParamDescr) selected;
      key = descr.getKey();
      type = descr.getType();
      switch (type) {
        case ConfigParamDescr.TYPE_STRING:
        case ConfigParamDescr.TYPE_URL:
        case ConfigParamDescr.TYPE_BOOLEAN:
          format = "%s";
          break;
        case ConfigParamDescr.TYPE_INT:
        case ConfigParamDescr.TYPE_LONG:
        case ConfigParamDescr.TYPE_POS_INT:
          NumericPaddingDialog dialog = new NumericPaddingDialog();
          Point pos = this.getLocationOnScreen();
          dialog.setLocation(pos.x, pos.y);
          dialog.pack();
          dialog.setVisible(true);
          StringBuilder fbuf = new StringBuilder("%");
          int width = dialog.getPaddingSize();
          boolean is_zero = dialog.useZero();
          if (width > 0) {
            fbuf.append(".");
            if (is_zero) {
              fbuf.append(0);
            }
            fbuf.append(width);
          }
          if (type == ConfigParamDescr.TYPE_LONG) {
            fbuf.append("ld");
          } else {
            fbuf.append("d");
          }
          format = fbuf.toString();
          break;
        case ConfigParamDescr.TYPE_YEAR:
          if (key.startsWith(DefinableArchivalUnit.PREFIX_AU_SHORT_YEAR)) {
            format = "%02d";
          } else {
            format = "%d";
          }
          break;
        case ConfigParamDescr.TYPE_RANGE:
        case ConfigParamDescr.TYPE_NUM_RANGE:
        case ConfigParamDescr.TYPE_SET:
          format = "%s";
          break;
      }
      if (selectedPane == 0) {
        insertParameter(descr, format, editorPane.getSelectionStart());
      } else if (selectedPane == 1) {
        // add the combobox data value to the edit box
        int pos = formatTextArea.getCaretPosition();
        formatTextArea.insert(format, pos);

        pos = parameterTextArea.getCaretPosition();
        parameterTextArea.insert(", " + key, pos);
      }
    } else {
      key = selected.toString();
      format =
          escapePrintfChars(
              (String)
                  JOptionPane.showInputDialog(
                      this,
                      "Enter the string you wish to input",
                      "String Literal Input",
                      JOptionPane.OK_CANCEL_OPTION));
      if (StringUtil.isNullString(format)) {
        return;
      }
      if (selectedPane == 0) {
        insertText(format, PLAIN_ATTR, editorPane.getSelectionStart());
      } else if (selectedPane == 1) {
        // add the combobox data value to the edit box
        formatTextArea.insert(format, formatTextArea.getCaretPosition());
      }
    }
  }