예제 #1
0
파일: Utils.java 프로젝트: raduf/core
  public static final Map<String, String[]> parseQueryString(String queryString) {
    Map<String, String[]> parameterMap = new HashMap<String, String[]>();
    if (queryString != null) {
      for (String queryParameter : Strings.split(queryString, '&')) {

        String parts[] = Strings.split(queryParameter, '=');
        if (parts.length > 0) {
          for (int i = 0; (i < 2) && (i < parts.length); i++) {
            parts[i] = UrlDecoder.QUERY_INSTANCE.decode(parts[i], DEFAULT_CHARSET_NAME);
          }

          String[] values = parameterMap.get(parts[0]);
          if (values == null) {
            parameterMap.put(parts[0], new String[] {(parts.length > 1 ? parts[1] : null)});
          } else {
            String[] moreValues = new String[values.length + 1];
            System.arraycopy(values, 0, moreValues, 0, values.length);
            moreValues[values.length - 1] = (parts.length > 1 ? parts[1] : null);
            parameterMap.put(parts[0], moreValues);
          }
        }
      }
    }
    return parameterMap;
  }
    @Override
    public void onComponentTag(final Component component, final ComponentTag tag) {
      String expr = tag.getAttributes().getString(wicketMessageAttrName);
      if (!Strings.isEmpty(expr)) {
        expr = expr.trim();

        String[] attrsAndKeys = Strings.split(expr, ',');

        for (String attrAndKey : attrsAndKeys) {
          int colon = attrAndKey.lastIndexOf(":");
          // make sure the attribute-key pair is valid
          if (attrAndKey.length() < 3 || colon < 1 || colon > attrAndKey.length() - 2) {
            throw new WicketRuntimeException(
                "wicket:message attribute contains an invalid value [["
                    + expr
                    + "]], must be of form (attr:key)+");
          }

          String attr = attrAndKey.substring(0, colon);
          String key = attrAndKey.substring(colon + 1);

          // we need to call the proper getString() method based on
          // whether or not we have a default value
          final String value;
          if (tag.getAttributes().containsKey(attr)) {
            value = component.getString(key, null, tag.getAttributes().getString(attr));
          } else {
            value = component.getString(key);
          }
          tag.put(attr, value);
        }
      }
    }
 public ExtensionResourceNameIterator(final String extension, final char separatorChar) {
   super();
   String[] extensions = Strings.split(extension, separatorChar);
   if (extensions.length == 0) {
     extensions = new String[] {""};
   }
   this.extensions = extensions;
   this.index = 0;
 }
예제 #4
0
 public static SupportedMedia resolveFromPath(String media) {
   if (Strings.isEmpty(media)) return null;
   String[] splits = Strings.split(media, '|');
   if (splits.length == 1) {
     String[] fileNameSplits = Strings.split(splits[0], '.');
     String ext = fileNameSplits.length == 2 ? fileNameSplits[1] : null;
     if (ext != null) {
       for (SupportedMedia supportedMedia : SupportedMedia.values()) {
         if (supportedMedia.getExtensions() != null) {
           for (String e : supportedMedia.getExtensions()) {
             if (StringUtils.equalsIgnoreCase(e, ext)) return supportedMedia;
           }
         }
       }
     }
     return null;
   }
   return resolveFromMimeType(splits[1]);
 }
예제 #5
0
 /**
  * initializes the ignore paths parameter
  *
  * @param filterConfig
  */
 private void initIgnorePaths(final FilterConfig filterConfig) {
   String paths = filterConfig.getInitParameter(IGNORE_PATHS_PARAM);
   if (Strings.isEmpty(paths) == false) {
     String[] parts = Strings.split(paths, ',');
     for (String path : parts) {
       path = path.trim();
       if (path.startsWith("/")) {
         path = path.substring(1);
       }
       ignorePaths.add(path);
     }
   }
 }
예제 #6
0
 private static String extractWorkspaceFromReferer(String refererURL) {
   int i = refererURL.indexOf('?');
   if (i != -1 && i != refererURL.length() - 1) {
     String param = refererURL.substring(i + 1);
     String params[] = Strings.split(param, '&');
     for (String s : params) {
       try {
         s = URLDecoder.decode(s, "utf-8");
       } catch (UnsupportedEncodingException e) {
         // rrright
         throw new RuntimeException(e);
       }
       if (s.startsWith(WORKSPACE_PARAM + "=")) {
         String value = s.substring(WORKSPACE_PARAM.length() + 1);
         if (value.length() > 0) {
           return value;
         }
       }
     }
   }
   return null;
 }
 @Override
 public String[] convertToObject(String value, Locale locale) {
   return Strings.split(value, ',');
 }