本文整理汇总了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.
* &,=,%,+,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);
}
}
示例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();
}
示例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();
}
示例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 "¶mToSet=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);
}
}