protected Set<Resource> doFindPathMatchingFileResources(
     Resource rootDirResource, String pattern) {
   File rootDir;
   try {
     rootDir = rootDirResource.getFile().getAbsoluteFile();
   } catch (IOException ex) {
     LOGGER.logMessage(
         LogLevel.WARN,
         "Cannot search for matching files underneath "
             + rootDirResource
             + " because it does not correspond to a directory in the file system",
         ex);
     return Collections.emptySet();
   }
   if (!rootDir.exists()) {
     // Silently skip non-existing directories.
     LOGGER.logMessage(
         LogLevel.DEBUG, "Skipping [" + rootDir.getAbsolutePath() + "] because it does not exist");
     return Collections.emptySet();
   }
   if (!rootDir.isDirectory()) {
     // Complain louder if it exists but is no directory.
     LOGGER.logMessage(
         LogLevel.WARN,
         "Skipping [" + rootDir.getAbsolutePath() + "] because it does not denote a directory");
     return Collections.emptySet();
   }
   if (!rootDir.canRead()) {
     LOGGER.logMessage(
         LogLevel.WARN,
         "Cannot search for matching files underneath directory ["
             + rootDir.getAbsolutePath()
             + "] because the application is not allowed to read the directory");
     return Collections.emptySet();
   }
   String fullPattern = StringUtils.replace(rootDir.getAbsolutePath(), File.separator, "/");
   if (!pattern.startsWith("/")) {
     fullPattern += "/";
   }
   String subPattern = StringUtils.replace(pattern, File.separator, "/");
   fullPattern = fullPattern + subPattern;
   Set<Resource> result = new LinkedHashSet<Resource>(8);
   try {
     doRetrieveMatchingFiles(fullPattern, subPattern, rootDir, result);
   } catch (IOException e) {
     LOGGER.errorMessage(e.getMessage(), e);
   }
   return result;
 }
  private Set<GrantedAuthority> parseAuthoritiesString(String authorizationsString) {
    final Set<GrantedAuthority> requiredAuthorities = new HashSet<GrantedAuthority>();
    final String[] authorities = StringUtils.commaDelimitedListToStringArray(authorizationsString);

    for (String authority : authorities) {
      // Remove the role's whitespace characters without depending on JDK 1.4+
      // Includes space, tab, new line, carriage return and form feed.
      String role = StringUtils.replace(authority, " ", "");
      role = StringUtils.replace(role, "\t", "");
      role = StringUtils.replace(role, "\r", "");
      role = StringUtils.replace(role, "\n", "");
      role = StringUtils.replace(role, "\f", "");

      requiredAuthorities.add(new GrantedAuthorityImpl(role));
    }

    return requiredAuthorities;
  }
 public String getPageTitle() {
   if (StringUtils.isEmpty(this.pathToPage)) return "";
   this.pageTitle = StringUtils.getFilename(this.pathToPage);
   this.pageTitle = StringUtils.stripFilenameExtension(this.pageTitle);
   this.pageTitle = StringUtils.replace(this.pageTitle, "_", " ");
   this.pageTitle = StringUtils.capitalize(this.pageTitle);
   this.pageTitle = StringUtils.trimWhitespace(this.pageTitle);
   return this.pageTitle;
 }
  /**
   * Replace patterns in the input to produce a valid SQL query. This implementation lazily
   * initializes a simple map-based cache, only replacing the table prefix on the first access to a
   * named query. Further accesses will be resolved from the cache.
   *
   * @param base the SQL query to be transformed
   * @return a transformed query with replacements
   */
  protected String getQuery(Query base) {
    String query = queryCache.get(base);

    if (query == null) {
      query = StringUtils.replace(base.getSql(), "%PREFIX%", tablePrefix);
      queryCache.put(base, query);
    }

    return query;
  }
示例#5
0
 @Override
 public void actionPerformed(ActionEvent e) {
   try {
     if (alternativeSpaces.isSelected())
       encodedUrl.setText(
           StringUtils.replace(URLEncoder.encode(decodedUrl.getText(), "UTF-8"), "+", "%20"));
     else encodedUrl.setText(URLEncoder.encode(decodedUrl.getText(), "UTF-8"));
   } catch (UnsupportedEncodingException e1) {
     JOptionPane.showMessageDialog(null, e1.getCause());
   }
 }
  public String getSiren(final String uai) {
    String result = this.defaultSiren;

    String searchString = StringUtils.replace(this.estSearchString, "%UAI", uai);
    String searchFilter = StringUtils.replace(this.estSearchFilter, "%UAI", uai);

    LdapEstablishment.LOG.debug(
        "Searching for siren for establishment ["
            + uai
            + "] with searchString "
            + searchString
            + " and searchfilter "
            + searchFilter);

    AttributesMapper domainMapper =
        new AttributesMapper() {
          @Override
          public Object mapFromAttributes(final Attributes attrs) throws NamingException {
            Attribute attr = attrs.get(LdapEstablishment.this.getSirenAttribute());
            Object result = null;
            if (attr != null) {
              result = attr.get();
            }
            return result;
          }
        };

    List<String> l =
        LdapUtils.ldapSearch(this.ldapTemplate, searchFilter, searchString, domainMapper);
    if ((l == null) || (l.size() != 1)) {
      LdapEstablishment.LOG.debug("LDAP Establishement siren search " + "did not return anything");
    } else {
      result = l.iterator().next();
      LdapEstablishment.LOG.debug("LDAP Establishement siren search returned " + result);
    }

    return result;
  }
示例#7
0
 @Override
 public String convertToEntityAttribute(String dbData) {
   if (!StringUtils.hasText(dbData)) {
     return null;
   }
   dbData = StringUtils.replace(dbData, "\\D+", "");
   NumberFormat numberFormat = NumberFormat.getCurrencyInstance();
   numberFormat.setCurrency(Currency.getInstance(LocaleContextHolder.getLocale()));
   try {
     dbData = numberFormat.format(Integer.parseInt(dbData));
   } catch (IllegalArgumentException e) {
     log.warn("IllegalArgumentException... dbData: {}, message:{} ", dbData, e.getMessage());
   }
   return dbData;
 }
  private void doRetrieveMatchingFiles(
      String fullPattern, String subPattern, File dir, Set<Resource> result) throws IOException {
    LOGGER.logMessage(
        LogLevel.DEBUG,
        "Searching directory ["
            + dir.getAbsolutePath()
            + "] for files matching pattern ["
            + fullPattern
            + "]");
    File[] dirContents = dir.listFiles();
    if (dirContents == null) {
      LOGGER.logMessage(
          LogLevel.WARN,
          "Could not retrieve contents of directory [" + dir.getAbsolutePath() + "]");
      return;
    }
    for (File content : dirContents) {
      String currPath = StringUtils.replace(content.getAbsolutePath(), File.separator, "/");
      if (content.isDirectory() && getPathMatcher().matchStart(fullPattern, currPath + "/")) {
        if (!content.canRead()) {
          LOGGER.logMessage(
              LogLevel.DEBUG,
              "Skipping subdirectory ["
                  + dir.getAbsolutePath()
                  + "] because the application is not allowed to read the directory");
        } else {
          doRetrieveMatchingFiles(fullPattern, subPattern, content, result);
        }
      }

      // can accurately judge by : new JarFile(content);
      if (content.isFile() && content.getName().endsWith(".jar")) {
        // JarFile jarFile= new JarFile(content);
        URL jarFileUrl = new URL("jar:" + content.toURI() + "!/");
        LOGGER.logMessage(LogLevel.INFO, "find match jar resource [{0}]", jarFileUrl.toString());
        Resource dirRes = new UrlResource(jarFileUrl);
        Set<Resource> resources = doFindPathMatchingJarResources(dirRes, subPattern);
        if (!CollectionUtil.isEmpty(resources)) {
          result.addAll(resources);
        }
      }

      if (getPathMatcher().match(fullPattern, currPath)) {
        result.add(new FileSystemResource(content));
      }
    }
  }
  private void parseLocaleCookieIfNecessary(HttpServletRequest request) {
    if (request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME) == null) {
      // Retrieve and parse cookie value.
      Cookie cookie = WebUtils.getCookie(request, getCookieName());
      Locale locale = null;
      TimeZone timeZone = null;
      if (cookie != null) {
        String value = cookie.getValue();

        // Remove the double quote
        value = StringUtils.replace(value, "%22", "");

        String localePart = value;
        String timeZonePart = null;
        int spaceIndex = localePart.indexOf(' ');
        if (spaceIndex != -1) {
          localePart = value.substring(0, spaceIndex);
          timeZonePart = value.substring(spaceIndex + 1);
        }
        locale =
            (!"-".equals(localePart)
                ? StringUtils.parseLocaleString(localePart.replace('-', '_'))
                : null);
        if (timeZonePart != null) {
          timeZone = StringUtils.parseTimeZoneString(timeZonePart);
        }
        if (logger.isTraceEnabled()) {
          logger.trace(
              "Parsed cookie value ["
                  + cookie.getValue()
                  + "] into locale '"
                  + locale
                  + "'"
                  + (timeZone != null ? " and time zone '" + timeZone.getID() + "'" : ""));
        }
      }
      request.setAttribute(
          LOCALE_REQUEST_ATTRIBUTE_NAME,
          (locale != null ? locale : determineDefaultLocale(request)));

      request.setAttribute(
          TIME_ZONE_REQUEST_ATTRIBUTE_NAME,
          (timeZone != null ? timeZone : determineDefaultTimeZone(request)));
    }
  }
示例#10
0
  /**
   * Filters the given {@link Resource} by replacing values within.
   *
   * @param source must not be {@literal null}.
   * @param replacements
   * @return {@link Resource} with replaced values.
   * @throws IOException
   */
  public static Resource filterResource(Resource source, Map<String, ?> replacements)
      throws IOException {

    Assert.notNull(source, "Cannot filter 'null' resource");
    if (CollectionUtils.isEmpty(replacements)) {
      return source;
    }

    String temp = StreamUtils.copyToString(source.getInputStream(), UTF8);

    for (Map.Entry<String, ?> entry : replacements.entrySet()) {
      temp =
          StringUtils.replace(
              temp, entry.getKey(), entry.getValue() != null ? entry.getValue().toString() : "");
    }

    return new ByteArrayResource(temp.getBytes(UTF8));
  }
 /**
  * If a pointcut expression has been specified in XML, the user cannot write {@code and} as "&&"
  * (though &amp;&amp; will work). We also allow {@code and} between two pointcut sub-expressions.
  *
  * <p>This method converts back to {@code &&} for the AspectJ pointcut parser.
  */
 private String replaceBooleanOperators(String pcExpr) {
   String result = StringUtils.replace(pcExpr, " and ", " && ");
   result = StringUtils.replace(result, " or ", " || ");
   result = StringUtils.replace(result, " not ", " ! ");
   return result;
 }
示例#12
0
 /**
  * Turn GC names like 'PS Scavenge' or 'PS MarkSweep' into something that is more metrics
  * friendly.
  */
 private String beautifyGcName(String name) {
   return StringUtils.replace(name, " ", "_").toLowerCase();
 }
 private String generateUUID() {
   String uuid = UUID.randomUUID().toString();
   return org.springframework.util.StringUtils.replace(uuid, "-", "");
 }