当前位置: 首页>>代码示例>>Java>>正文


Java StrUtils.partialURLEncodeVal方法代码示例

本文整理汇总了Java中org.apache.solr.common.util.StrUtils.partialURLEncodeVal方法的典型用法代码示例。如果您正苦于以下问题:Java StrUtils.partialURLEncodeVal方法的具体用法?Java StrUtils.partialURLEncodeVal怎么用?Java StrUtils.partialURLEncodeVal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.solr.common.util.StrUtils的用法示例。


在下文中一共展示了StrUtils.partialURLEncodeVal方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toString

import org.apache.solr.common.util.StrUtils; //导入方法依赖的package包/类
/** Like {@link #toQueryString()}, but only replacing enough chars so that
 * the URL may be unambiguously pasted back into a browser.
 * This method can be used to properly log query parameters without
 * making them unreadable.
 * <p>
 * Characters with a numeric value less than 32 are encoded.
 * &amp;,=,%,+,space are encoded.
 */
@Override
public String toString() {
    final StringBuilder sb = new StringBuilder(128);
    try {
        boolean first=true;
        for (final Iterator<String> it = getParameterNamesIterator(); it.hasNext();) {
            final String name = it.next();
            for (String val : getParams(name)) {
                if (!first) sb.append('&');
                first=false;
                StrUtils.partialURLEncodeVal(sb, name);
                sb.append('=');
                StrUtils.partialURLEncodeVal(sb, val);
            }
        }
        return sb.toString();
    } catch (IOException e) {
        // impossible!
        throw new AssertionError(e);
    }
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:30,代码来源:SolrParams.java

示例2: toString

import org.apache.solr.common.util.StrUtils; //导入方法依赖的package包/类
@Override
public String toString() {
  StringBuilder sb = new StringBuilder(128);
  try {
    boolean first=true;

    for (Map.Entry<String,String[]> entry : map.entrySet()) {
      String key = entry.getKey();
      String[] valarr = entry.getValue();

      for (String val : valarr) {
        if (!first) sb.append('&');
        first=false;
        sb.append(key);
        sb.append('=');
        StrUtils.partialURLEncodeVal(sb, val==null ? "" : val);
      }
    }
  }
  catch (IOException e) {throw new RuntimeException(e);}  // can't happen

  return sb.toString();
}
 
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:MultiMapSolrParams.java

示例3: toString

import org.apache.solr.common.util.StrUtils; //导入方法依赖的package包/类
@Override
public String toString() {
  StringBuilder sb = new StringBuilder(128);
  try {
    boolean first=true;

    for (Map.Entry<String,String> entry : map.entrySet()) {
      String key = entry.getKey();
      String val = entry.getValue();

      if (!first) sb.append('&');
      first=false;
      sb.append(key);
      sb.append('=');
      StrUtils.partialURLEncodeVal(sb, val==null ? "" : val);
    }
  }
  catch (IOException e) {throw new RuntimeException(e);}  // can't happen

  return sb.toString();
}
 
开发者ID:europeana,项目名称:search,代码行数:22,代码来源:MapSolrParams.java

示例4: setParam

import org.apache.solr.common.util.StrUtils; //导入方法依赖的package包/类
/**
 * Insures that the given param is included in the query with the given value.
 *
 * <ol>
 *   <li>If the param is already included with the given value, the request is returned unchanged.</li>
 *   <li>If the param is not already included, it is added with the given value.</li>
 *   <li>If the param is already included, but with a different value, the value is replaced with the given value.</li>
 *   <li>If the param is already included multiple times, they are replaced with a single param with given value.</li>
 * </ol>
 *
 * The passed-in valueToSet should NOT be URL encoded, as it will be URL encoded by this method.
 *
 * @param query The query portion of a request URL, e.g. "wt=json&indent=on&fl=id,_version_"
 * @param paramToSet The parameter name to insure the presence of in the returned request 
 * @param valueToSet The parameter value to insure in the returned request
 * @return The query with the given param set to the given value 
 */
private static String setParam(String query, String paramToSet, String valueToSet) {
  if (null == valueToSet) {
    valueToSet = "";
  }
  try {
    StringBuilder builder = new StringBuilder();
    if (null == query || query.trim().isEmpty()) {
      // empty query -> return "paramToSet=valueToSet"
      builder.append(paramToSet);
      builder.append('=');
      StrUtils.partialURLEncodeVal(builder, valueToSet);
      return builder.toString();
    }
    MultiMapSolrParams requestParams = SolrRequestParsers.parseQueryString(query);
    String[] values = requestParams.getParams(paramToSet);
    if (null == values) {
      // paramToSet isn't present in the request -> append "&paramToSet=valueToSet"
      builder.append(query);
      builder.append('&');
      builder.append(paramToSet);
      builder.append('=');
      StrUtils.partialURLEncodeVal(builder, valueToSet);
      return builder.toString();
    }
    if (1 == values.length && valueToSet.equals(values[0])) {
      // paramToSet=valueToSet is already in the query - just return the query as-is.
      return query;
    }
    // More than one value for paramToSet on the request, or paramToSet's value is not valueToSet
    // -> rebuild the query
    boolean isFirst = true;
    for (Map.Entry<String,String[]> entry : requestParams.getMap().entrySet()) {
      String key = entry.getKey();
      String[] valarr = entry.getValue();

      if ( ! key.equals(paramToSet)) {
        for (String val : valarr) {
          builder.append(isFirst ? "" : '&');
          isFirst = false;
          builder.append(key);
          builder.append('=');
          StrUtils.partialURLEncodeVal(builder, null == val ? "" : val);
        }
      }
    }
    builder.append(isFirst ? "" : '&');
    builder.append(paramToSet);
    builder.append('=');
    StrUtils.partialURLEncodeVal(builder, valueToSet);
    return builder.toString();
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:72,代码来源:RestTestBase.java


注:本文中的org.apache.solr.common.util.StrUtils.partialURLEncodeVal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。