List of usage examples for com.google.common.net UrlEscapers urlFormParameterEscaper
public static Escaper urlFormParameterEscaper()
From source file:com.google.gapid.views.ErrorDialog.java
public static void showErrorDialog(Shell shell, String text, String detailString) { new IconAndMessageDialog(shell) { private Group details; @Override//from w ww .jav a 2s. c om protected void configureShell(Shell newShell) { super.configureShell(newShell); newShell.setText("Error"); } @Override protected boolean isResizable() { return true; } @Override protected Control createDialogArea(Composite parent) { Composite container = (Composite) super.createDialogArea(parent); ((GridLayout) container.getLayout()).numColumns = 2; createMessageArea(container); String msg = String.format(Messages.ERROR_MESSAGE, text); withLayoutData(createTextbox(container, SWT.WRAP | SWT.READ_ONLY, msg), withSizeHints(new GridData(SWT.FILL, SWT.CENTER, true, false), getWidthHint(), SWT.DEFAULT)) .setBackground(container.getBackground()); if (detailString != null) { ExpandBar bar = withLayoutData(new ExpandBar(container, SWT.NONE), withSpans(new GridData(SWT.FILL, SWT.TOP, true, false), 2, 1)); new ExpandItem(bar, SWT.NONE, 0).setText("Details..."); bar.addListener(SWT.Expand, e -> { createDetails(container); Point curr = getShell().getSize(); Point want = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT); if (want.y > curr.y) { getShell().setSize( new Point(curr.x, curr.y + Math.min(MAX_DETAILS_SIZE, want.y - curr.y))); } else { details.requestLayout(); } }); bar.addListener(SWT.Collapse, e -> { Point curr = getShell().getSize(); if (details != null) { details.dispose(); details = null; } Point want = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT); if (want.y < curr.y) { getShell().setSize(new Point(curr.x, want.y)); } }); } return container; } private int getWidthHint() { return convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); } private void createDetails(Composite container) { details = createGroup(container, ""); GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(details); Composite inner = createComposite(details, new GridLayout(1, false)); withLayoutData(createTextbox(inner, DETAILS_STYLE, detailString), new GridData(SWT.FILL, SWT.FILL, true, true)); withLayoutData(createLink(inner, "<a>File a bug</a> on GitHub", e -> { Program.launch(getFileBugUrl()); }), new GridData(SWT.RIGHT, SWT.BOTTOM, false, false)); withLayoutData(createLink(inner, "<a>Show logs</a> directory", e -> { AboutDialog.showLogDir(); }), new GridData(SWT.RIGHT, SWT.BOTTOM, false, false)); } private String getFileBugUrl() { Escaper esc = UrlEscapers.urlFormParameterEscaper(); return String.format(FILE_BUG_URL, esc.escape(text), esc.escape(Messages.BUG_BODY)); } @Override protected void createButtonsForButtonBar(Composite parent) { createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true).setFocus(); } @Override protected Image getImage() { return getErrorImage(); } }.open(); }
From source file:com.tinspx.util.net.FormEncodedBody.java
/** * Returns the {@code Escaper} being used to escape parameter names and * values. Unless explicitly set through {@link #escaper(Escaper)} (which * typically should not be necessary), the returned {@code Escaper} will be * {@link UrlEscapers#urlFormParameterEscaper()}. *//*from w w w . ja v a2 s. c o m*/ public Escaper escaper() { return MoreObjects.firstNonNull(escaper, UrlEscapers.urlFormParameterEscaper()); }
From source file:com.android.tools.idea.fd.actions.SubmitFeedback.java
@Override public void actionPerformed(AnActionEvent e) { Project project = e.getProject();// ww w. j av a 2 s . c o m if (project == null) { Logger.getInstance(SubmitFeedback.class).info("Unable to identify current project"); return; } if (!InstantRunSettings.isInstantRunEnabled() || !InstantRunSettings.isRecorderEnabled()) { int result = Messages.showYesNoDialog(project, AndroidBundle.message("instant.run.flr.would.you.like.to.enable"), AndroidBundle.message("instant.run.flr.dialog.title"), "Yes, I'd like to help", "Cancel", Messages.getQuestionIcon()); if (result == Messages.NO) { return; } InstantRunSettings.setInstantRunEnabled(true); InstantRunSettings.setRecorderEnabled(true); Messages.showInfoMessage(project, AndroidBundle.message("instant.run.flr.howto"), AndroidBundle.message("instant.run.flr.dialog.title")); return; } InstantRunFeedbackDialog dialog = new InstantRunFeedbackDialog(project); boolean ok = dialog.showAndGet(); if (ok) { new Task.Backgroundable(project, "Submitting Instant Run Issue") { public CompletableFuture<String> myReport; @Override public void run(@NotNull ProgressIndicator indicator) { myReport = GoogleCrash.getInstance().submit(FlightRecorder.get(project), dialog.getIssueText(), dialog.getLogs()); while (!myReport.isDone()) { try { myReport.get(200, TimeUnit.MILLISECONDS); } catch (Exception ignored) { } if (indicator.isCanceled()) { return; } } } @Override public void onSuccess() { if (myReport.isDone()) { String reportId; try { reportId = myReport.getNow("00"); } catch (CancellationException e) { Logger.getInstance(SubmitFeedback.class) .info("Submission of flight recorder logs cancelled"); return; } catch (CompletionException e) { FLR_NOTIFICATION_GROUP.createNotification( "Unexpected error while submitting instant run logs: " + e.getMessage(), NotificationType.ERROR); Logger.getInstance(SubmitFeedback.class).info(e); return; } String message = String.format("<html>Thank you for submitting the bug report.<br>" + "If you would like to follow up on this report, please file a bug at <a href=\"bug\">b.android.com</a> and specify the report id '%1$s'<html>", reportId); FLR_NOTIFICATION_GROUP.createNotification("", message, NotificationType.INFORMATION, (notification, event) -> { Escaper escaper = UrlEscapers.urlFormParameterEscaper(); String comment = String.format("Build: %1$s\nInstant Run Report: %2$s", ApplicationInfo.getInstance().getFullVersion(), reportId); String url = String.format( "https://code.google.com/p/android/issues/entry?template=%1$s&comment=%2$s&status=New", escaper.escape("Android Studio Instant Run Bug"), escaper.escape(comment)); BrowserUtil.browse(url); }).notify(project); } } }.queue(); } }
From source file:ratpack.http.internal.DefaultHttpUrlBuilder.java
private void appendQueryString(StringBuilder stringBuilder) { if (!params.isEmpty()) { stringBuilder.append("?"); Iterator<Map.Entry<String, Object>> parts = params.entries().iterator(); if (parts.hasNext()) { Map.Entry<String, Object> entry = parts.next(); stringBuilder.append(UrlEscapers.urlFormParameterEscaper().escape(entry.getKey())); String value = entry.getValue().toString(); if (value != null && value.length() > 0) { stringBuilder.append("="); stringBuilder.append(UrlEscapers.urlFormParameterEscaper().escape(value)); }/*from w ww .j a v a2 s. c o m*/ while (parts.hasNext()) { stringBuilder.append("&"); Map.Entry<String, Object> e = parts.next(); stringBuilder.append(UrlEscapers.urlFormParameterEscaper().escape(e.getKey())); String v = e.getValue().toString(); if (v != null && v.length() > 0) { stringBuilder.append("="); stringBuilder.append(UrlEscapers.urlFormParameterEscaper().escape(v)); } } } } }
From source file:ratpack.http.internal.HttpUrlSpecBacking.java
private void appendQueryString(StringBuilder stringBuilder) { if (!params.isEmpty()) { stringBuilder.append("?"); Iterator<Map.Entry<String, String>> parts = params.entries().iterator(); if (parts.hasNext()) { Map.Entry<String, String> entry = parts.next(); stringBuilder.append(UrlEscapers.urlFormParameterEscaper().escape(entry.getKey())); String value = entry.getValue(); if (value != null && value.length() > 0) { stringBuilder.append("="); stringBuilder.append(UrlEscapers.urlFormParameterEscaper().escape(value)); }// w ww .j a v a 2 s . c o m while (parts.hasNext()) { stringBuilder.append("&"); Map.Entry<String, String> e = parts.next(); stringBuilder.append(UrlEscapers.urlFormParameterEscaper().escape(e.getKey())); String v = e.getValue(); if (v != null && v.length() > 0) { stringBuilder.append("="); stringBuilder.append(UrlEscapers.urlFormParameterEscaper().escape(v)); } } } } }
From source file:org.dllearner.algorithms.qtl.experiments.PathDetectionTask.java
private Model loadDataFromCacheOrCompute(OWLClass cls, int maxDepth, boolean singleQuery) { String filename = UrlEscapers.urlFormParameterEscaper().escape(cls.toStringID()) + "-" + maxDepth + ".ttl"; File file = new File(dataDir, filename); Model model;// w ww. ja v a2s. c o m if (file.exists()) { model = ModelFactory.createDefaultModel(); try { model.read(new FileInputStream(file), null, "TURTLE"); } catch (FileNotFoundException e) { e.printStackTrace(); } } else { if (singleQuery) { model = loadDataFromEndpointBatch(cls, maxDepth); } else { model = loadDataFromEndpointBatch(cls, maxDepth); } try { model.write(new FileOutputStream(file), "TURTLE"); } catch (FileNotFoundException e) { e.printStackTrace(); } } model.add(schema); return model; }
From source file:org.datacleaner.panels.WelcomePanel.java
private JComponent createContentPanel() { JComponent result = null;/*from w ww. j a va 2s . c om*/ final String welcomePanelClassName = SystemProperties.getString(SystemProperties.UI_DESKTOP_WELCOME_PANEL, null); if (!Strings.isNullOrEmpty(welcomePanelClassName)) { final Injector injector = _dcModule.createInjectorBuilder().with(WelcomePanel.class, this) .createInjector(); try { @SuppressWarnings("unchecked") final Class<? extends JComponent> componentClass = (Class<? extends JComponent>) Class .forName(welcomePanelClassName); result = injector.getInstance(componentClass); } catch (Exception e) { logger.error("Failed to instantiate welcome panel class: {}", welcomePanelClassName, e); } } if (result == null) { result = new DCPanel(); if (Version.isCommunityEdition()) { final JXEditorPane editorPane = new JXEditorPane("text/html", "You're now using the <b>Community Edition</b> of DataCleaner.<br/><br/>" + "We hope that you enjoy this free product. We encourage you to also check out the " + "commercial DataCleaner editions which feature added functionality, " + "helpful getting started wizards and commercial support. " + "You can find more information about them online."); editorPane.setEditable(false); editorPane.setOpaque(false); editorPane.setFont(WidgetUtils.FONT_HEADER2); editorPane.setPreferredSize(new Dimension(DCSplashPanel.WIDTH_CONTENT, 120)); final JButton tryProfessionalButton = WidgetFactory.createDefaultButton("Try professional edition", IconUtils.APPLICATION_ICON); tryProfessionalButton .addActionListener(new OpenBrowserAction("http://datacleaner.org/get_datacleaner")); final JButton readMoreButton = WidgetFactory.createDefaultButton("Compare the editions", IconUtils.WEBSITE); readMoreButton.addActionListener(new OpenBrowserAction("http://datacleaner.org/editions")); final JButton discussionForumButton = WidgetFactory .createDefaultButton("Visit the discussion forum", "images/menu/forum.png"); discussionForumButton.setToolTipText( "Visit the online discussion forum for questions and answers in the community"); final OpenBrowserAction forumActionListener = new OpenBrowserAction("http://datacleaner.org/forum"); discussionForumButton.addActionListener(forumActionListener); final JButton twitterButton = WidgetFactory.createDefaultButton(null, "images/menu/twitter.png"); twitterButton.setToolTipText("Spread the message about #DataCleaner on Twitter"); twitterButton.addActionListener(new OpenBrowserAction("https://twitter.com/intent/tweet?text=" + UrlEscapers.urlFormParameterEscaper().escape("I'm using @DataCleaner (v. " + Version.getVersion() + ") for some really fancy #dataquality stuff!"))); final JButton linkedInButton = WidgetFactory.createDefaultButton(null, "images/menu/linkedin.png"); linkedInButton.setToolTipText("Join our LinkedIn group of users and professionals"); linkedInButton .addActionListener(new OpenBrowserAction("http://www.linkedin.com/groups?gid=3352784")); final JLabel loveFeedbackAnimation = new JLabel( ImageManager.get().getImageIcon("images/window/we_love_community_and_feedback.gif"), JLabel.LEFT); loveFeedbackAnimation.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); loveFeedbackAnimation.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { forumActionListener.actionPerformed(null); } }); final DCPanel innerPanel = new DCPanel(); innerPanel.setLayout(new VerticalLayout()); innerPanel.setBorder( new CompoundBorder(WidgetUtils.BORDER_LIST_ITEM_LEFT_ONLY, new EmptyBorder(0, 20, 0, 0))); innerPanel.add(editorPane); innerPanel.add(DCPanel.flow(tryProfessionalButton, readMoreButton)); innerPanel.add(Box.createVerticalStrut(80)); innerPanel.add(loveFeedbackAnimation); innerPanel.add(Box.createVerticalStrut(20)); innerPanel.add(DCPanel.flow(discussionForumButton, twitterButton, linkedInButton)); innerPanel.add(Box.createVerticalStrut(5)); result.setLayout(new VerticalLayout()); result.add(Box.createVerticalStrut(100)); result.add(innerPanel); } } return wrapContent(result); }
From source file:org.dllearner.algorithms.qtl.experiments.PathDetectionTask.java
private Model loadDataFromEndpointBatch(OWLClass cls, int maxDepth) { String filename = UrlEscapers.urlFormParameterEscaper().escape(cls.toStringID()) + ".ttl"; File file = new File(dataDir, filename); Model model;// w w w . j a va 2s .c o m if (file.exists()) { model = ModelFactory.createDefaultModel(); try { model.read(new FileInputStream(file), null, "TURTLE"); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { String query = "construct{" + "?s ?p0 ?o0 . "; for (int i = 1; i < maxDepth; i++) { query += String.format("?o%d ?p%d ?o%d .", i - 1, i, i); } query += "} where {" + "?s a <" + cls.toStringID() + ">. " + "?s ?p0 ?o0 . "; for (int i = 1; i < maxDepth; i++) { query += String.format("optional{?o%d ?p%d ?o%d .", i - 1, i, i); } for (int i = 1; i < maxDepth; i++) { query += "}"; } query += "}"; QueryExecutionFactory qef = new QueryExecutionFactoryPaginated(ks.getQueryExecutionFactory(), 500000); model = qef.createQueryExecution(query).execConstruct(); } return model; }
From source file:com.addthis.hydra.task.source.DataSourceQuery.java
private static void writePostBody(HttpURLConnection conn, Map<String, String> parameters) throws IOException { try (OutputStream os = conn.getOutputStream()) { Escaper escaper = UrlEscapers.urlFormParameterEscaper(); // Select non-null (key, value) pairs and join them List<String> kvpairs = parameters.entrySet().stream().filter((e) -> (e.getValue() != null)) .map((e) -> (escaper.escape(e.getKey()) + "=" + escaper.escape(e.getValue()))) .collect(Collectors.toList()); String content = AMPERSAND_JOINER.join(kvpairs); log.info("First {} characters of POST body are {}", LOG_TRUNCATE_CHARS, LessStrings.trunc(content, LOG_TRUNCATE_CHARS)); os.write(content.getBytes());/*from ww w.jav a 2 s . c o m*/ os.flush(); } }
From source file:com.uber.sdk.rides.auth.OAuth2Credentials.java
/** * Gets the authorization URL to retrieve the authorization code. *//*from ww w.j a va2 s . c o m*/ @Nullable public String getAuthorizationUrl() { String authorizationCodeRequestUrl = authorizationCodeFlow.newAuthorizationUrl().setScopes(scopes).build(); if (redirectUri != null) { authorizationCodeRequestUrl += "&redirect_uri=" + UrlEscapers.urlFormParameterEscaper().escape(redirectUri); } return authorizationCodeRequestUrl; }