Package jodd.util

Examples of jodd.util.StringBand


  /**
   * Creates unique key for method signatures map.
   */
  public static String createMethodSignaturesKey(int access, String methodName, String description, String className) {
    return new StringBand(7)
      .append(access)
      .append(COLON)
      .append(description)
      .append(StringPool.UNDERSCORE)
      .append(className)
View Full Code Here


   * Returns full URL path.
   * Simply concatenates {@link #protocol(String) protocol}, {@link #host(String) host},
   * {@link #port(int) port}, {@link #path(String) path} and {@link #queryString(String) query string}.
   */
  public String url() {
    StringBand url = new StringBand(8);

    if (protocol != null) {
      url.append(protocol);
      url.append("://");
    }

    if (host != null) {
      url.append(host);
    }

    if (port != DEFAULT_PORT) {
      url.append(':');
      url.append(port);
    }

    if (path != null) {
      url.append(path);
    }

    String queryString = queryString();

    if (StringUtil.isNotBlank(queryString)) {
      url.append('?');
      url.append(queryString);
    }

    return url.toString();
  }
View Full Code Here

    if (queryMapSize == 0) {
      return StringPool.EMPTY;
    }

    StringBand query = new StringBand(queryMapSize * 4);

    int count = 0;
    for (Map.Entry<String, Object[]> entry : queryMap.entrySet()) {
      String key = entry.getKey();
      Object[] values = entry.getValue();

      key = URLCoder.encodeQueryParam(key, encoding);

      if (values == null) {
        if (count != 0) {
          query.append('&');
        }

        query.append(key);
        count++;
      } else {
        for (Object value : values) {
          if (count != 0) {
            query.append('&');
          }

          query.append(key);
          count++;
          query.append('=');

          String valueString = URLCoder.encodeQueryParam(value.toString(), encoding);
          query.append(valueString);
        }
      }
    }

    return query.toString();
  }
View Full Code Here

    }
    if (sortResources) {
      Arrays.sort(sourcesArray);
    }

    StringBand sb = new StringBand(sourcesArray.length);
    for (String src : sourcesArray) {
      sb.append(src);
    }
    String sourcesString = sb.toString();

    String bundleId = createDigest(sourcesString);
    bundleId += '.' + bundleContentType;

    // bundle appears for the first time, create the bundle
View Full Code Here

    File bundleFile = createBundleFile(bundleId);
    if (bundleFile.exists()) {
      return;
    }

    StringBand sb = new StringBand(sources.size() * 2);
    for (String src : sources) {
      if (sb.length() != 0) {
        sb.append(StringPool.NEWLINE);
      }
      String content;
      if (isExternalResource(src)) {
        try {
          content = NetUtil.downloadString(src, localFilesEncoding);
        } catch (IOException ioex) {
          if (notFoundExceptionEnabled) {
            throw ioex;
          }
          if (log.isWarnEnabled()) {
            log.warn("Download failed: " + src + "; " + ioex.getMessage());
          }
          content = null;
        }
      } else {
        if (downloadLocal == false) {
          // load local resource from file system
          String localFile = webRoot;

          if (src.startsWith(contextPath + '/')) {
            src = src.substring(contextPath.length());
          }

          if (src.startsWith(StringPool.SLASH)) {
            // absolute path
            localFile += src;
          } else {
            // relative path
            localFile += '/' + FileNameUtil.getPathNoEndSeparator(actionPath) + '/' + src;
          }

          // trim link parameters, if any
          int qmndx = localFile.indexOf('?');
          if (qmndx != -1) {
            localFile = localFile.substring(0, qmndx);
          }

          try {
            content = FileUtil.readString(localFile);
          } catch (IOException ioex) {
            if (notFoundExceptionEnabled) {
              throw ioex;
            }
            if (log.isWarnEnabled()) {
              log.warn(ioex.getMessage());
            }
            content = null;
          }
        } else {
          // download local resource
          String localUrl = localAddressAndPort;

          if (src.startsWith(StringPool.SLASH)) {
            localUrl += contextPath + src;
          } else {
            localUrl += contextPath + FileNameUtil.getPath(actionPath) + '/' + src;
          }

          try {
            content = NetUtil.downloadString(localUrl, localFilesEncoding);
          } catch (IOException ioex) {
            if (notFoundExceptionEnabled) {
              throw ioex;
            }
            if (log.isWarnEnabled()) {
              log.warn("Download failed: " + localUrl + "; " + ioex.getMessage());
            }
            content = null;
          }
        }

        if (content != null) {
          if (isCssResource(src)) {
            content = fixCssRelativeUrls(content, src);
          }
        }
      }

      if (content != null) {
        content = onResourceContent(content);
        sb.append(content);
      }
    }

    FileUtil.writeString(bundleFile, sb.toString());

    if (log.isInfoEnabled()) {
      log.info("Bundle created: " + bundleId);
    }
  }
View Full Code Here

  /**
   * Creates unique key for method signatures map.
   */
  public static String createMethodSignaturesKey(int access, String methodName, String description, String className) {
    return new StringBand(7)
      .append(access)
      .append(COLON)
      .append(description)
      .append(StringPool.UNDERSCORE)
      .append(className)
View Full Code Here

   * Returns full URL path.
   * Simply concatenates {@link #protocol(String) protocol}, {@link #host(String) host},
   * {@link #port(int) port}, {@link #path(String) path} and {@link #queryString(String) query string}.
   */
  public String url() {
    StringBand url = new StringBand(8);

    if (protocol != null) {
      url.append(protocol);
      url.append("://");
    }

    if (host != null) {
      url.append(host);
    }

    if (port != DEFAULT_PORT) {
      url.append(':');
      url.append(port);
    }

    if (path != null) {
      url.append(path);
    }

    String queryString = queryString();

    if (StringUtil.isNotBlank(queryString)) {
      url.append('?');
      url.append(queryString);
    }

    return url.toString();
  }
View Full Code Here

    if (queryMapSize == 0) {
      return StringPool.EMPTY;
    }

    StringBand query = new StringBand(queryMapSize * 4);

    int count = 0;
    for (Map.Entry<String, Object[]> entry : queryMap.entrySet()) {
      String key = entry.getKey();
      Object[] values = entry.getValue();

      key = URLCoder.encodeQueryParam(key, encoding);

      if (values == null) {
        if (count != 0) {
          query.append('&');
        }

        query.append(key);
        count++;
      } else {
        for (Object value : values) {
          if (count != 0) {
            query.append('&');
          }

          query.append(key);
          count++;
          query.append('=');

          String valueString = URLCoder.encodeQueryParam(value.toString(), encoding);
          query.append(valueString);
        }
      }
    }

    return query.toString();
  }
View Full Code Here

TOP

Related Classes of jodd.util.StringBand

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.