Search in sources :

Example 6 with Escaper

use of com.google.common.escape.Escaper in project mylyn.docs by eclipse.

the class DefaultXmlStreamWriter method printEscaped.

private void printEscaped(PrintWriter writer, CharSequence s, boolean attribute) {
    Escaper escaper = attribute ? attributeEscaper : contentEscaper;
    writer.write(escaper.escape(s.toString()));
}
Also used : Escaper(com.google.common.escape.Escaper)

Example 7 with Escaper

use of com.google.common.escape.Escaper in project timbuctoo by HuygensING.

the class HttpRequest method getPathAndQuery.

public String getPathAndQuery() {
    String url = this.path;
    boolean isFirst = true;
    for (Map.Entry<String, String> queryParameter : this.queryParameters.entries()) {
        if (isFirst) {
            url += "?";
            isFirst = false;
        } else {
            url += "&";
        }
        Escaper escaper = UrlEscapers.urlFormParameterEscaper();
        url += escaper.escape(queryParameter.getKey()) + "=" + escaper.escape(queryParameter.getValue());
    }
    return url;
}
Also used : Map(java.util.Map) Escaper(com.google.common.escape.Escaper)

Example 8 with Escaper

use of com.google.common.escape.Escaper in project symja_android_library by axkr.

the class Show3D2ThreeJS method graphics3dToSVG.

/**
 * A 3D Graphics command like
 *
 * <pre>
 *     Graphics3D(Polygon({{0,0,0}, {0,1,1}, {1,0,0}}))
 * </pre>
 *
 * will be converted to:
 *
 * <pre>
 * &lt;graphics3d data="{&quot;viewpoint&quot;: [1.3, -2.4, 2.0], &quot;elements&quot;: [{&quot;coords&quot;:......
 * </pre>
 *
 * <p>
 * It's a bit messy because of all the HTML escaping. What we are interested in is the data field.
 * It's a JSON dict describing the 3D graphics in terms of graphics primitives. This JSON can be
 * used in <a href="http://threejs.org/">threejs.org</a> to construct a 3D div.
 *
 * @param ast
 * @param buf
 * @throws IOException
 * @deprecated
 */
@Deprecated
private static void graphics3dToSVG(IAST ast, StringBuilder buf) {
    EvalEngine engine = EvalEngine.get();
    IAST numericAST = (IAST) engine.evalN(ast);
    double[] viewpoints = new double[] { 1.3, -2.4, 2.0 };
    if (numericAST.size() > 2) {
        final OptionArgs options = new OptionArgs(numericAST.topHead(), numericAST, 2, engine);
        optionViewPoint(options, viewpoints);
    }
    int width = 400;
    int height = 200;
    Dimensions2D dim = new Dimensions2D(width, height);
    buf.append("<graphics3d data=\"{");
    StringBuilder builder = new StringBuilder(1024);
    appendDoubleArray(builder, "viewpoint", viewpoints);
    try {
        for (int i = 1; i < numericAST.size(); i++) {
            // } else
            if (numericAST.get(i).isSameHeadSizeGE(S.Polygon, 2)) {
                elements("polygon", numericAST.getAST(i), builder, dim);
            } else if (numericAST.get(i).isSameHeadSizeGE(S.Point, 2)) {
                elements("point", numericAST.getAST(i), builder, dim);
            }
        }
    } finally {
        builder.append("\"lighting\": [{\"color\": [0.3, 0.2, 0.4], \"type\": \"Ambient\"}, " + "{\"color\": [0.8, 0.0, 0.0], \"position\": [2.0, 0.0, 2.0], \"type\": \"Directional\"}, " + "{\"color\": [0.0, 0.8, 0.0], \"position\": [2.0, 2.0, 2.0], \"type\": \"Directional\"}, " + "{\"color\": [0.0, 0.0, 0.8], \"position\": [0.0, 2.0, 2.0], \"type\": \"Directional\"}], " + "\"axes\": {\"hasaxes\": [false, false, false], " + "\"ticks\": [[[0.0, 0.2, 0.4, 0.6000000000000001, 0.8, 1.0], [0.05, 0.1, 0.15000000000000002, 0.25, 0.30000000000000004, 0.35000000000000003, 0.45, 0.5, 0.55, 0.65, 0.7000000000000001, 0.75, 0.8500000000000001, 0.9, 0.9500000000000001], [\"0.0\", \"0.2\", \"0.4\", \"0.6\", \"0.8\", \"1.0\"]], [[0.0, 0.2, 0.4, 0.6000000000000001, 0.8, 1.0], [0.05, 0.1, 0.15000000000000002, 0.25, 0.30000000000000004, 0.35000000000000003, 0.45, 0.5, 0.55, 0.65, 0.7000000000000001, 0.75, 0.8500000000000001, 0.9, 0.9500000000000001], [\"0.0\", \"0.2\", \"0.4\", \"0.6\", \"0.8\", \"1.0\"]], [[0.0, 0.2, 0.4, 0.6000000000000001, 0.8, 1.0], [0.05, 0.1, 0.15000000000000002, 0.25, 0.30000000000000004, 0.35000000000000003, 0.45, 0.5, 0.55, 0.65, 0.7000000000000001, 0.75, 0.8500000000000001, 0.9, 0.9500000000000001], [\"0.0\", \"0.2\", \"0.4\", \"0.6\", \"0.8\", \"1.0\"]]]}, " + "\"extent\": {\"zmax\": 1.0, \"ymax\": 1.0, \"zmin\": 0.0, \"xmax\": 1.0, \"xmin\": 0.0, \"ymin\": 0.0}");
        Escaper escaper = HtmlEscapers.htmlEscaper();
        buf.append(escaper.escape(builder.toString()));
        buf.append("}\" />");
    }
}
Also used : EvalEngine(org.matheclipse.core.eval.EvalEngine) OptionArgs(org.matheclipse.core.eval.util.OptionArgs) IAST(org.matheclipse.core.interfaces.IAST) Escaper(com.google.common.escape.Escaper)

Example 9 with Escaper

use of com.google.common.escape.Escaper in project eclipse-pmd by acanda.

the class RuleSetConfigurationToXMLTag method apply.

@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);
}
Also used : Escaper(com.google.common.escape.Escaper)

Example 10 with Escaper

use of com.google.common.escape.Escaper in project closure-templates by google.

the class XliffGenerator method generateXliff.

/**
 * 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.
 */
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) {
                // just use the contentType string
                xliffDatatype = contentType;
            }
            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 if (msgPart instanceof SoyMsgPlaceholderPart) {
                SoyMsgPlaceholderPart placeholder = (SoyMsgPlaceholderPart) msgPart;
                ilb.appendParts("<x id=\"", attributeEscaper.escape(placeholder.getPlaceholderName()), "\"" + // convention so we add it in the hope that tools will support it anyway.
                (placeholder.getPlaceholderExample() != null ? " example=\"" + attributeEscaper.escape(placeholder.getPlaceholderExample()) + "\"" : "") + "/>");
            } else {
                throw new RuntimeException("Xliff doesn't support plurals or genders. " + msg.getSourceLocations());
            }
        }
        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;
}
Also used : SoyMsg(com.google.template.soy.msgs.restricted.SoyMsg) SoyMsgPlaceholderPart(com.google.template.soy.msgs.restricted.SoyMsgPlaceholderPart) IndentedLinesBuilder(com.google.template.soy.base.internal.IndentedLinesBuilder) SoyMsgRawTextPart(com.google.template.soy.msgs.restricted.SoyMsgRawTextPart) Escaper(com.google.common.escape.Escaper) SoyMsgPart(com.google.template.soy.msgs.restricted.SoyMsgPart)

Aggregations

Escaper (com.google.common.escape.Escaper)17 Map (java.util.Map)2 TextMatching (annis.model.QueryNode.TextMatching)1 IndentedLinesBuilder (com.google.template.soy.base.internal.IndentedLinesBuilder)1 SoyMsg (com.google.template.soy.msgs.restricted.SoyMsg)1 SoyMsgPart (com.google.template.soy.msgs.restricted.SoyMsgPart)1 SoyMsgPlaceholderPart (com.google.template.soy.msgs.restricted.SoyMsgPlaceholderPart)1 SoyMsgRawTextPart (com.google.template.soy.msgs.restricted.SoyMsgRawTextPart)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 Project (com.intellij.openapi.project.Project)1 CharacterEscapeHandler (com.sun.xml.bind.marshaller.CharacterEscapeHandler)1 IOException (java.io.IOException)1 Writer (java.io.Writer)1 CancellationException (java.util.concurrent.CancellationException)1 CompletionException (java.util.concurrent.CompletionException)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Marshaller (javax.xml.bind.Marshaller)1 Test (org.junit.Test)1