List of usage examples for com.google.common.escape Escaper escape
public abstract String escape(String string);
From source file:com.google.template.soy.xliffmsgplugin.XliffGenerator.java
/** * Generates the output XLIFF file content for a given SoyMsgBundle. * * @param msgBundle The SoyMsgBundle to process. * @param sourceLocaleString The source language/locale string of the messages. * @param targetLocaleString The target language/locale string of the messages (optional). If * specified, the resulting XLIFF file will specify this target language and will contain * empty 'target' tags. If not specified, the resulting XLIFF file will not contain target * language and will not contain 'target' tags. * @return The generated XLIFF file content. *//* w w w. ja va 2 s . c o m*/ static CharSequence generateXliff(SoyMsgBundle msgBundle, String sourceLocaleString, @Nullable String targetLocaleString) { Escaper attributeEscaper = XmlEscapers.xmlAttributeEscaper(); Escaper contentEscaper = XmlEscapers.xmlContentEscaper(); boolean hasTarget = targetLocaleString != null && targetLocaleString.length() > 0; IndentedLinesBuilder ilb = new IndentedLinesBuilder(2); ilb.appendLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); ilb.appendLine("<xliff version=\"1.2\" xmlns=\"urn:oasis:names:tc:xliff:document:1.2\">"); ilb.increaseIndent(); ilb.appendLineStart("<file original=\"SoyMsgBundle\" datatype=\"x-soy-msg-bundle\"", " xml:space=\"preserve\"", " source-language=\"", attributeEscaper.escape(sourceLocaleString), "\""); if (hasTarget) { ilb.appendParts(" target-language=\"", attributeEscaper.escape(targetLocaleString), "\""); } ilb.appendLineEnd(">"); ilb.increaseIndent(); ilb.appendLine("<body>"); ilb.increaseIndent(); for (SoyMsg msg : msgBundle) { // Begin 'trans-unit'. ilb.appendLineStart("<trans-unit id=\"", Long.toString(msg.getId()), "\""); String contentType = msg.getContentType(); if (contentType != null && contentType.length() > 0) { String xliffDatatype = CONTENT_TYPE_TO_XLIFF_DATATYPE_MAP.get(contentType); if (xliffDatatype == null) { xliffDatatype = contentType; // just use the contentType string } ilb.appendParts(" datatype=\"", attributeEscaper.escape(xliffDatatype), "\""); } ilb.appendLineEnd(">"); ilb.increaseIndent(); // Source. ilb.appendLineStart("<source>"); for (SoyMsgPart msgPart : msg.getParts()) { if (msgPart instanceof SoyMsgRawTextPart) { String rawText = ((SoyMsgRawTextPart) msgPart).getRawText(); ilb.append(contentEscaper.escape(rawText)); } else { String placeholderName = ((SoyMsgPlaceholderPart) msgPart).getPlaceholderName(); ilb.appendParts("<x id=\"", attributeEscaper.escape(placeholderName), "\"/>"); } } ilb.appendLineEnd("</source>"); // Target. if (hasTarget) { ilb.appendLine("<target/>"); } // Description and meaning. String desc = msg.getDesc(); if (desc != null && desc.length() > 0) { ilb.appendLine("<note priority=\"1\" from=\"description\">", contentEscaper.escape(desc), "</note>"); } String meaning = msg.getMeaning(); if (meaning != null && meaning.length() > 0) { ilb.appendLine("<note priority=\"1\" from=\"meaning\">", contentEscaper.escape(meaning), "</note>"); } // End 'trans-unit'. ilb.decreaseIndent(); ilb.appendLine("</trans-unit>"); } ilb.decreaseIndent(); ilb.appendLine("</body>"); ilb.decreaseIndent(); ilb.appendLine("</file>"); ilb.decreaseIndent(); ilb.appendLine("</xliff>"); return ilb; }
From source file:eu.trentorise.opendata.jackan.test.ckan.CkanTestReporter.java
public static String renderRunSuite(Map<String, String> catalogs, List<String> testNames, RunSuite runSuite) { String outputFileContent;//from w ww. ja va 2 s.c o m BuildInfo buildInfo = TodConfig.of(JackanTestConfig.class).getBuildInfo(); try { HtmlCanvas html = new HtmlCanvas(); html.html().head().title().content("Jackan Test Results") // .meta(name("description").add("content","Jackan test // analyzer",false)) // .macros().stylesheet("htdocs/style-01.css")) // .render(JQueryLibrary.core("1.4.3")) // .render(JQueryLibrary.ui("1.8.6")) // .render(JQueryLibrary.baseTheme("1.8")) .style().write("." + ERROR_CLASS + " {color:red}").write("." + PASSED_CLASS + " {color:black}") .write("." + JACKAN_TABLE_CLASS + " { border-collapse:collapse; table-layout: fixed; width: 100%; }") .write("." + JACKAN_TABLE_CLASS + " td, th { border: 1px solid black; vertical-align: top; padding:10px; width:100px;}") .write("." + JACKAN_TABLE_CLASS + " th { position:absolute; left:0; width:230px;}") .write(".outer {position:relative}").write(".inner {\n" + " overflow-x:scroll;\n" + " overflow-y:visible;\n" + " margin-left:250px;\n" + "}") ._style()._head(); html.body().h1().a(href("https://github.com/opendatatrentino/jackan").target("_blank")).write("Jackan") ._a().write(" Report - " + formatDateUpToDay(runSuite.getStartTime()))._h1().b().write("NOTE: ") ._b().span() .write("Some tests might fail due to missing items in the target catalog (i.e. catalog has no tags or no organizations). " + "Also, some catalogs might only be ckan-compatible and support a subset of ckan functionality (i.e. DKAN). ") ._span().br(); labelValue(html, "Jackan Version: ").write(buildInfo.getVersion() + " ") .a(href("https://github.com/opendatatrentino/jackan/commit/" + buildInfo.getGitSha()) .target("_blank")) .write("Git commit")._a()._span(); labelValue(html, "Started: ", formatDateUpToSecond(runSuite.getStartTime())); labelValue(html, "Finished: ", formatDateUpToSecond(runSuite.getEndTime())); labelValue(html, "Catalogs scanned: ", Integer.toString(catalogs.keySet().size())); labelValue(html, "Tests per catalog executed: ", Integer.toString(testNames.size())); html.br().br(); Escaper escaper = HtmlEscapers.htmlEscaper(); html.div(class_("outer")).div(class_("inner")); html.table(class_(JACKAN_TABLE_CLASS)).tr().th(style("height:100%")).write("test")._th(); html.td().write("Passed")._td(); for (String catalogUrl : catalogs.keySet()) { html.td().a(href(catalogUrl).target("_blank")).write(escaper.escape(catalogs.get(catalogUrl)))._a() ._td(); } html._tr(); html.tr(); html.th().write("Passed")._th().td()._td(); for (String catalogUrl : catalogs.keySet()) { int passedByCat = runSuite.getPassedTestsByCatalogUrl(catalogUrl).size(); html.td(errClass(passedByCat, testNames.size())).write(passedByCat + "/" + testNames.size())._td(); } html._tr(); Iterator<TestResult> resultIterator = runSuite.getResults().iterator(); for (String testName : testNames) { html.tr(); html.th().b().write(testName)._b()._th(); int passedByName = runSuite.getPassedTestsByName(testName).size(); html.td().b().write(passedByName + "/" + catalogs.size())._b()._td(); for (String catalogURL : catalogs.keySet()) { TestResult result = resultIterator.next(); if (result.passed()) { html.td() // .a(href(TEST_RESULT_PREFIX + result.getId() + // ".html").target("_blank")) .write("PASSED")._td(); } else { html.td().a(href(TEST_RESULT_PREFIX + result.getId() + ".html").target("_blank") .class_(ERROR_CLASS)).write("ERROR")._a()._td(); } } html._tr(); } html._table()._div()._div()._body()._html(); outputFileContent = html.toHtml(); } catch (IOException ex) { outputFileContent = "HTML generation problem!" + ex; } return outputFileContent; }
From source file:com.google.devtools.common.options.OptionsUsage.java
/** * Append the usage message for a single option-field message to 'usage'. */// w w w . j ava 2 s. co m static void getUsageHtml(Field optionField, StringBuilder usage, Escaper escaper) { String plainFlagName = optionField.getAnnotation(Option.class).name(); String flagName = getFlagName(optionField); String valueDescription = optionField.getAnnotation(Option.class).valueHelp(); String typeDescription = getTypeDescription(optionField); Option annotation = optionField.getAnnotation(Option.class); usage.append("<dt><code><a name=\"flag--").append(plainFlagName).append("\"></a>--"); usage.append(flagName); if (OptionsParserImpl.isBooleanField(optionField) || OptionsParserImpl.isVoidField(optionField)) { // Nothing for boolean, tristate, boolean_or_enum, or void options. } else if (!valueDescription.isEmpty()) { usage.append("=").append(escaper.escape(valueDescription)); } else if (!typeDescription.isEmpty()) { // Generic fallback, which isn't very good. usage.append("=<").append(escaper.escape(typeDescription)).append(">"); } usage.append("</code>"); if (annotation.abbrev() != '\0') { usage.append(" [<code>-").append(annotation.abbrev()).append("</code>]"); } if (annotation.allowMultiple()) { // Allow-multiple options can't have a default value. usage.append(" multiple uses are accumulated"); } else { // Don't call the annotation directly (we must allow overrides to certain defaults). String defaultValueString = OptionsParserImpl.getDefaultOptionString(optionField); if (OptionsParserImpl.isVoidField(optionField)) { // Void options don't have a default. } else if (OptionsParserImpl.isSpecialNullDefault(defaultValueString, optionField)) { usage.append(" default: see description"); } else { usage.append(" default: \"").append(escaper.escape(defaultValueString)).append("\""); } } usage.append("</dt>\n"); usage.append("<dd>\n"); if (!annotation.help().isEmpty()) { usage.append(paragraphFill(escaper.escape(annotation.help()), 0, 80)); // (indent, width) usage.append('\n'); } if (annotation.expansion().length > 0) { usage.append("<br/>\n"); StringBuilder expandsMsg = new StringBuilder("Expands to:<br/>\n"); for (String exp : annotation.expansion()) { // TODO(ulfjack): Can we link to the expanded flags here? expandsMsg.append(" <code>").append(escaper.escape(exp)).append("</code><br/>\n"); } usage.append(expandsMsg.toString()); // (indent, width) usage.append('\n'); } usage.append("</dd>\n"); }
From source file:ch.acanda.eclipse.pmd.repository.RuleSetConfigurationToXMLTag.java
@Override public String apply(final RuleSetModel config) { final Escaper escaper = XmlEscapers.xmlAttributeEscaper(); final String name = escaper.escape(nullToEmpty(config.getName())); final String ref = escaper.escape(nullToEmpty(config.getLocation().getPath())); final String refcontext = getContext(config); return String.format(Locale.ENGLISH, "<%s %s=\"%s\" %s=\"%s\" %s=\"%s\" />", TAG_NAME_RULESET, ATTRIBUTE_NAME_NAME, name, ATTRIBUTE_NAME_REF, ref, ATTRIBUTE_NAME_REFCONTEXT, refcontext); }
From source file:org.eclipse.packagedrone.repo.trigger.common.foobar.FooBarProcessorFactory.java
@Override public Processor create(final String configuration) throws IllegalArgumentException { final FooBarConfiguration cfg = FooBarConfiguration.fromJson(configuration); return new Processor() { @Override/* w w w .j av a 2s . c o m*/ public void process(final Object context) { System.out.format("Foo bar: %s - %s%n", cfg.getString1(), context); } @Override public void streamHtmlState(final PrintWriter writer) { final Escaper esc = HtmlEscapers.htmlEscaper(); writer.format("<p>This action is doing foo bar: <code>%s</code></p>", esc.escape(cfg.getString1())); } }; }
From source file:org.spf4j.stackmonitor.Method.java
public void toHtmlWriter(final Writer w) throws IOException { Escaper htmlEscaper = HtmlEscapers.htmlEscaper(); w.append(htmlEscaper.escape(methodName)).append(htmlEscaper.escape("@")) .append(htmlEscaper.escape(declaringClass)); }
From source file:org.sfs.integration.java.func.ContainerExport.java
@Override public Observable<HttpClientResponseAndBuffer> call(Void aVoid) { return auth.toHttpAuthorization().flatMap(s -> { final Escaper escaper = urlFormParameterEscaper(); Iterable<String> keyValues = from(queryParams.entries()) .transform(input -> escaper.escape(input.getKey()) + '=' + escaper.escape(input.getValue())); String query = on('&').join(keyValues); ObservableFuture<HttpClientResponse> handler = RxHelper.observableFuture(); HttpClientRequest httpClientRequest = httpClient .post("/export_container/" + accountName + "/" + containerName + (query.length() > 0 ? "?" + query : ""), handler::complete) .exceptionHandler(handler::fail).setTimeout(20000).putHeader(AUTHORIZATION, s); for (String entry : headerParams.keySet()) { httpClientRequest = httpClientRequest.putHeader(entry, headerParams.get(entry)); }// w ww . j a va 2 s . c o m httpClientRequest = httpClientRequest.putHeader(X_SFS_DEST_DIRECTORY, destDirectory.toString()); httpClientRequest.end(); return handler.flatMap(httpClientResponse -> just(httpClientResponse) .flatMap(new HttpClientKeepAliveResponseBodyBuffer()) .map(buffer -> new HttpClientResponseAndBuffer(httpClientResponse, buffer))).single(); }); }
From source file:org.sfs.integration.java.func.ContainerImport.java
@Override public Observable<HttpClientResponseAndBuffer> call(Void aVoid) { return auth.toHttpAuthorization().flatMap(s -> { final Escaper escaper = urlFormParameterEscaper(); Iterable<String> keyValues = from(queryParams.entries()) .transform(input -> escaper.escape(input.getKey()) + '=' + escaper.escape(input.getValue())); String query = on('&').join(keyValues); ObservableFuture<HttpClientResponse> handler = RxHelper.observableFuture(); HttpClientRequest httpClientRequest = httpClient .post("/import_container/" + accountName + "/" + containerName + (query.length() > 0 ? "?" + query : ""), handler::complete) .exceptionHandler(handler::fail).setTimeout(20000).putHeader(AUTHORIZATION, s); for (String entry : headerParams.keySet()) { httpClientRequest = httpClientRequest.putHeader(entry, headerParams.get(entry)); }/* ww w .j a v a 2 s . c o m*/ httpClientRequest = httpClientRequest.putHeader(X_SFS_SRC_DIRECTORY, srcDirectory.toString()); httpClientRequest.end(); return handler.flatMap(httpClientResponse -> just(httpClientResponse) .flatMap(new HttpClientKeepAliveResponseBodyBuffer()) .map(buffer -> new HttpClientResponseAndBuffer(httpClientResponse, buffer))).single(); }); }
From source file:org.sfs.integration.java.func.VerifyRepairAllContainersExecute.java
@Override public Observable<HttpClientResponseAndBuffer> call(Void aVoid) { return auth.toHttpAuthorization().flatMap(s -> { final Escaper escaper = urlFormParameterEscaper(); Iterable<String> keyValues = FluentIterable.from(queryParams.entries()) .transform(input -> escaper.escape(input.getKey()) + '=' + escaper.escape(input.getValue())); String query = Joiner.on('&').join(keyValues); ObservableFuture<HttpClientResponse> handler = RxHelper.observableFuture(); HttpClientRequest httpClientRequest = httpClient .post("/verify_repair_containers" + (query.length() > 0 ? "?" + query : ""), handler::complete) .exceptionHandler(handler::fail).setTimeout(20000) .putHeader(Jobs.Parameters.TIMEOUT, String.valueOf(TimeUnit.MINUTES.toMillis(1))) .putHeader(HttpHeaders.AUTHORIZATION, s); for (String entry : headerParams.keySet()) { httpClientRequest = httpClientRequest.putHeader(entry, headerParams.get(entry)); }/* w ww. j a v a2 s . co m*/ httpClientRequest.end(); return handler.flatMap(httpClientResponse -> Defer.just(httpClientResponse) .flatMap(new HttpClientKeepAliveResponseBodyBuffer()) .map(buffer -> new HttpClientResponseAndBuffer(httpClientResponse, buffer))).single(); }); }
From source file:org.sfs.integration.java.func.GetContainer.java
@Override public Observable<HttpClientResponse> call(Void aVoid) { return auth.toHttpAuthorization().flatMap(new Func1<String, Observable<HttpClientResponse>>() { @Override/*from ww w.j a v a 2 s . c o m*/ public Observable<HttpClientResponse> call(String s) { final Escaper escaper = urlFormParameterEscaper(); Iterable<String> keyValues = from(queryParams.entries()).transform( input -> escaper.escape(input.getKey()) + '=' + escaper.escape(input.getValue())); String query = on('&').join(keyValues); ObservableFuture<HttpClientResponse> handler = RxHelper.observableFuture(); HttpClientRequest httpClientRequest = httpClient .get("/openstackswift001/" + accountName + "/" + containerName + (query.length() > 0 ? "?" + query : ""), handler::complete) .exceptionHandler(handler::fail).setTimeout(20000).putHeader(AUTHORIZATION, s); for (String entry : headerParams.keySet()) { httpClientRequest = httpClientRequest.putHeader(entry, headerParams.get(entry)); } httpClientRequest.end(); return handler.single(); } }); }