本文整理汇总了Java中com.google.common.net.UrlEscapers类的典型用法代码示例。如果您正苦于以下问题:Java UrlEscapers类的具体用法?Java UrlEscapers怎么用?Java UrlEscapers使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UrlEscapers类属于com.google.common.net包,在下文中一共展示了UrlEscapers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAsQuery
import com.google.common.net.UrlEscapers; //导入依赖的package包/类
public String getAsQuery() {
StringBuffer sb = new StringBuffer();
Escaper esc = UrlEscapers.urlFormParameterEscaper();
if (!Strings.isNullOrEmpty(asset)) {
sb.append("&asset=").append(esc.escape(asset));
}
if (startTime != null) {
sb.append("&startTime=").append(startTime.getTime());
}
if (endTime != null) {
sb.append("&endTime=").append(endTime.getTime());
}
String s = sb.toString();
return s.length() > 1 ? s.substring(1) : s; // skipping the first &
}
示例2: encode
import com.google.common.net.UrlEscapers; //导入依赖的package包/类
@Override
public ObjectNode encode(Intent intent, CodecContext context) {
checkNotNull(intent, "Intent cannot be null");
final ObjectNode result = context.mapper().createObjectNode()
.put(TYPE, intent.getClass().getSimpleName())
.put(ID, intent.id().toString())
.put(APP_ID, UrlEscapers.urlPathSegmentEscaper()
.escape(intent.appId().name()));
final ArrayNode jsonResources = result.putArray(RESOURCES);
for (final NetworkResource resource : intent.resources()) {
jsonResources.add(resource.toString());
}
IntentService service = context.getService(IntentService.class);
IntentState state = service.getIntentState(intent.key());
if (state != null) {
result.put(STATE, state.toString());
}
return result;
}
示例3: encodePath
import com.google.common.net.UrlEscapers; //导入依赖的package包/类
public static String encodePath(String path) {
if (path.isEmpty() || path.equals("/")) {
return path;
}
StringBuilder sb = new StringBuilder();
Escaper escaper = UrlEscapers.urlPathSegmentEscaper();
Iterable<String> iterable = pathSplitter.split(path);
Iterator<String> iterator = iterable.iterator();
while (iterator.hasNext()) {
String part = iterator.next();
if (part.isEmpty()) {
sb.append("/");
continue;
}
part = escaper.escape(part);
sb.append(part);
if (iterator.hasNext()) {
sb.append("/");
}
}
return sb.toString();
}
示例4: getParametersString
import com.google.common.net.UrlEscapers; //导入依赖的package包/类
@VisibleForTesting
static String getParametersString(Map<String, String> parametersMap) {
StringBuilder resultBuilder = new StringBuilder();
boolean ampersandNeeded = false;
for (Map.Entry<String, String> entry : parametersMap.entrySet()) {
if (ampersandNeeded) {
resultBuilder.append('&');
} else {
ampersandNeeded = true;
}
resultBuilder.append(entry.getKey());
resultBuilder.append('=');
resultBuilder.append(UrlEscapers.urlFormParameterEscaper().escape(entry.getValue()));
}
return resultBuilder.toString();
}
示例5: add
import com.google.common.net.UrlEscapers; //导入依赖的package包/类
public Builder add ( final String label, final String targetPattern, final String... pathSegments )
{
Objects.requireNonNull ( targetPattern );
Objects.requireNonNull ( pathSegments );
final Escaper esc = UrlEscapers.urlPathSegmentEscaper ();
final Object[] encoded = new String[pathSegments.length];
for ( int i = 0; i < pathSegments.length; i++ )
{
encoded[i] = esc.escape ( pathSegments[i] );
}
this.entries.add ( new Entry ( label, MessageFormat.format ( targetPattern, encoded ) ) );
return this;
}
示例6: editPost
import com.google.common.net.UrlEscapers; //导入依赖的package包/类
@RequestMapping ( value = "/{channelId}/edit", method = RequestMethod.POST )
public ModelAndView editPost ( @PathVariable ( "channelId" ) final String channelId, @Valid @FormData ( "command" ) final P2MetaDataInformation data, final BindingResult result) throws Exception
{
return Channels.withChannel ( this.service, channelId, ModifiableChannel.class, channel -> {
final Map<String, Object> model = new HashMap<> ();
if ( result.hasErrors () )
{
model.put ( "channel", channel.getInformation () );
model.put ( "command", data );
fillBreadcrumbs ( model, channelId, "Edit" );
return new ModelAndView ( "p2edit", model );
}
final Map<MetaKey, String> providedMetaData = MetaKeys.unbind ( data );
channel.applyMetaData ( providedMetaData );
return new ModelAndView ( "redirect:/p2.metadata/" + UrlEscapers.urlPathSegmentEscaper ().escape ( channelId ) + "/info", model );
} );
}
示例7: editPost
import com.google.common.net.UrlEscapers; //导入依赖的package包/类
@RequestMapping ( value = "/{channelId}/edit", method = RequestMethod.POST )
public ModelAndView editPost ( @PathVariable ( "channelId" ) final String channelId, @Valid @FormData ( "command" ) final P2ChannelInformation data, final BindingResult result) throws Exception
{
return Channels.withChannel ( this.service, channelId, ModifiableChannel.class, channel -> {
final Map<String, Object> model = new HashMap<> ();
if ( result.hasErrors () )
{
model.put ( "channel", channel.getInformation () );
model.put ( "command", data );
fillBreadcrumbs ( model, channelId, "Edit" );
return new ModelAndView ( "p2edit", model );
}
final Map<MetaKey, String> providedMetaData = MetaKeys.unbind ( data );
channel.applyMetaData ( providedMetaData );
return new ModelAndView ( "redirect:/p2.repo/" + UrlEscapers.urlPathSegmentEscaper ().escape ( channelId ) + "/info", model );
} );
}
示例8: uiReportEntityMentionsAggregate
import com.google.common.net.UrlEscapers; //导入依赖的package包/类
private void uiReportEntityMentionsAggregate(final Map<String, Object> model,
final URI entityID) throws Throwable {
// Do nothing in case the entity ID is missing
if (entityID == null) {
return;
}
// Render the table
final Stream<Record> mentions = getEntityMentions(entityID, Integer.MAX_VALUE, null);
final Predicate<URI> filter = Predicates.not(Predicates.in(ImmutableSet.<URI>of(
NIF.BEGIN_INDEX, NIF.END_INDEX, KS.MENTION_OF)));
final String linkTemplate = "ui?action=entity-mentions&entity="
+ UrlEscapers.urlFormParameterEscaper().escape(entityID.stringValue())
+ "&property=${property}&value=${value}";
model.put("propertyValuesTable", RenderUtils.renderRecordsAggregateTable(
new StringBuilder(), mentions, filter, linkTemplate, null));
}
示例9: uiReportMentionValueOccurrences
import com.google.common.net.UrlEscapers; //导入依赖的package包/类
private void uiReportMentionValueOccurrences(final Map<String, Object> model,
final URI entityID, @Nullable final URI property) throws Throwable {
// Do nothing in case the entity ID is missing
if (entityID == null || property == null) {
return;
}
// Compute the # of occurrences of all the values of the given property in entity mentions
final Multiset<Value> propertyValues = HashMultiset.create();
for (final Record mention : getEntityMentions(entityID, Integer.MAX_VALUE, null)) {
propertyValues.addAll(mention.get(property, Value.class));
}
// Render the table
final Escaper esc = UrlEscapers.urlFormParameterEscaper();
final String linkTemplate = "ui?action=entity-mentions&entity="
+ esc.escape(entityID.stringValue()) + "&property="
+ esc.escape(Data.toString(property, Data.getNamespaceMap()))
+ "&value=${element}";
model.put("valueOccurrencesTable", RenderUtils.renderMultisetTable(new StringBuilder(),
propertyValues, "Property value", "# Mentions", linkTemplate));
}
示例10: uiReportMentionPropertyOccurrences
import com.google.common.net.UrlEscapers; //导入依赖的package包/类
private void uiReportMentionPropertyOccurrences(final Map<String, Object> model,
final URI entityID) throws Throwable {
// Do nothing in case the entity ID is missing
if (entityID == null) {
return;
}
// Compute the # of occurrences of each property URI in entity mentions
final Multiset<URI> propertyURIs = HashMultiset.create();
for (final Record mention : getEntityMentions(entityID, Integer.MAX_VALUE, null)) {
propertyURIs.addAll(mention.getProperties());
}
// Render the table
final Escaper esc = UrlEscapers.urlFormParameterEscaper();
final String linkTemplate = "ui?action=entity-mentions&entity="
+ esc.escape(entityID.stringValue()) + "&property=${element}";
model.put("propertyOccurrencesTable", RenderUtils.renderMultisetTable(new StringBuilder(),
propertyURIs, "Property", "# Mentions", linkTemplate));
}
示例11: projectExists
import com.google.common.net.UrlEscapers; //导入依赖的package包/类
public boolean projectExists(String projectId) throws IOException
{
ListenableFuture<String> jsonChangeInfoHolder = HttpHelper.getAsyncFromHttp(new URL(gerritURL + "projects/" + UrlEscapers.urlPathSegmentEscaper().escape(projectId)));
try
{
String json = jsonChangeInfoHolder.get(20000, TimeUnit.MILLISECONDS);
if ("NOT FOUND".equalsIgnoreCase(json.trim()))
{
return false;
}
json = json.substring(4);
JsonParser parser = new JsonParser();
JsonObject jsonObj = parser.parse(json).getAsJsonObject();
JsonElement stateElement = jsonObj.get("state");
String state = stateElement != null ? stateElement.getAsString() : null;
return "ACTIVE".equals(state);
}
catch (Exception e)
{
e.printStackTrace();
}
return false;
}
示例12: userExists
import com.google.common.net.UrlEscapers; //导入依赖的package包/类
public boolean userExists(String userId) throws IOException
{
ListenableFuture<String> jsonChangeInfoHolder = HttpHelper.getAsyncFromHttp(new URL(gerritURL + "accounts/" + UrlEscapers.urlPathSegmentEscaper().escape(userId)));
try
{
String json = jsonChangeInfoHolder.get(20000, TimeUnit.MILLISECONDS);
if ("NOT FOUND".equalsIgnoreCase(json.trim()))
{
return false;
}
return true;
}
catch (Exception e)
{
e.printStackTrace();
}
return false;
}
示例13: buildRawPathString
import com.google.common.net.UrlEscapers; //导入依赖的package包/类
public StringBuilder buildRawPathString(boolean absolute, boolean slashAtEnd, String[] segments) {
StringBuilder result = new StringBuilder();
if (absolute) {
result.append('/');
}
boolean addedOne = false;
for (String s : segments) {
result.append(UrlEscapers.urlPathSegmentEscaper()
.escape(s));
result.append('/');
addedOne = true;
}
if (addedOne && !slashAtEnd) {
result.deleteCharAt(result.length() - 1);
}
return result;
}
示例14: buildQueryParametersString
import com.google.common.net.UrlEscapers; //导入依赖的package包/类
public static CharSequence buildQueryParametersString(Multimap<String, String> currentQueryParameters) {
StringBuilder paramsString = new StringBuilder();
boolean first = true;
for (Map.Entry<String, String> entry : currentQueryParameters.entries()) {
if (!first) {
paramsString.append('&');
}
String keyEnc = UrlEscapers.urlFormParameterEscaper()
.escape(entry.getKey());
if (entry.getValue() != null) {
String valueEnc = UrlEscapers.urlFormParameterEscaper()
.escape(entry.getValue());
paramsString.append(keyEnc)
.append('=')
.append(valueEnc);
} else {
paramsString.append(keyEnc);
}
first = false;
}
return paramsString;
}
示例15: transform
import com.google.common.net.UrlEscapers; //导入依赖的package包/类
@Override
public String[] transform(final InputRow inputRow) {
final String value = inputRow.getValue(column);
if (value == null) {
return new String[1];
}
final Escaper escaper;
switch (targetFormat) {
case FORM_PARAMETER:
escaper = UrlEscapers.urlFormParameterEscaper();
break;
case FRAGMENT:
escaper = UrlEscapers.urlFragmentEscaper();
break;
case PATH_SEGMENT:
escaper = UrlEscapers.urlPathSegmentEscaper();
break;
default:
throw new UnsupportedOperationException();
}
final String escaped = escaper.escape(value);
return new String[] { escaped };
}