Example usage for java.util.regex Matcher quoteReplacement

List of usage examples for java.util.regex Matcher quoteReplacement

Introduction

In this page you can find the example usage for java.util.regex Matcher quoteReplacement.

Prototype

public static String quoteReplacement(String s) 

Source Link

Document

Returns a literal replacement String for the specified String .

Usage

From source file:common.ckplugins.handlers.command.FileUploadCommand.java

/**
 * execute file upload command.//w ww . j ava 2  s. c  o m
 *
 * @param out output stream from response.
 * @throws ConnectorException when error occurs.
 */
@Override
public void execute(final OutputStream out) throws ConnectorException {
    if (configuration.isDebugMode() && this.exception != null) {
        throw new ConnectorException(this.errorCode, this.exception);
    }
    try {
        String errorMsg = this.errorCode == Constants.Errors.CKFINDER_CONNECTOR_ERROR_NONE ? ""
                : (this.errorCode == Constants.Errors.CKFINDER_CONNECTOR_ERROR_CUSTOM_ERROR
                        ? this.customErrorMsg
                        : ErrorUtils.getInstance().getErrorMsgByLangAndCode(this.langCode, this.errorCode,
                                this.configuration));
        errorMsg = errorMsg.replaceAll("%1", Matcher.quoteReplacement(this.newFileName));
        String path = "";

        if (!uploaded) {
            this.newFileName = "";
            this.currentFolder = "";
        } else {
            path = configuration.getTypes().get(type).getUrl() + this.currentFolder;
        }

        if (this.responseType != null && this.responseType.equals("txt")) {
            out.write((this.newFileName + "|" + errorMsg).getBytes("UTF-8"));
        } else {
            out.write("<script type=\"text/javascript\">".getBytes("UTF-8"));
            if (checkFuncNum()) {
                handleOnUploadCompleteCallFuncResponse(out, errorMsg, path);
            } else {
                handleOnUploadCompleteResponse(out, errorMsg);
            }
            out.write("</script>".getBytes("UTF-8"));
        }

    } catch (IOException e) {
        throw new ConnectorException(Constants.Errors.CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED, e);
    }

}

From source file:com.networknt.utility.Util.java

public static String substituteVariables(String template, Map<String, String> variables) {
    Pattern pattern = Pattern.compile("\\$\\{(.+?)\\}");
    Matcher matcher = pattern.matcher(template);
    // StringBuilder cannot be used here because Matcher expects StringBuffer
    StringBuffer buffer = new StringBuffer();
    while (matcher.find()) {
        if (variables.containsKey(matcher.group(1))) {
            String replacement = variables.get(matcher.group(1));
            // quote to work properly with $ and {,} signs
            matcher.appendReplacement(buffer,
                    replacement != null ? Matcher.quoteReplacement(replacement) : "null");
        }/*  w  w  w .j a  v  a2  s  .co m*/
    }
    matcher.appendTail(buffer);
    return buffer.toString();
}

From source file:com.afis.jx.ckfinder.connector.handlers.command.FileUploadCommand.java

/**
 * Executes file upload command./* w w w . j  av a  2s .  c om*/
 *
 * @param out the response output stream
 * @throws ConnectorException when error occurs.
 */
@Override
public void execute(final OutputStream out) throws ConnectorException {
    if (configuration.isDebugMode() && this.exception != null) {
        throw new ConnectorException(this.errorCode, this.exception);
    }
    try {
        String errorMsg = this.errorCode == Constants.Errors.CKFINDER_CONNECTOR_ERROR_NONE ? ""
                : (this.errorCode == Constants.Errors.CKFINDER_CONNECTOR_ERROR_CUSTOM_ERROR
                        ? this.customErrorMsg
                        : ErrorUtils.getInstance().getErrorMsgByLangAndCode(this.langCode, this.errorCode,
                                this.configuration));
        errorMsg = errorMsg.replaceAll("%1", Matcher.quoteReplacement(this.newFileName));
        String path = "";

        if (!uploaded) {
            this.newFileName = "";
            this.currentFolder = "";
        } else {
            path = configuration.getTypes().get(this.type).getUrl() + this.currentFolder;
        }

        if (this.responseType != null && this.responseType.equals("txt")) {
            out.write((this.newFileName + "|" + errorMsg).getBytes("UTF-8"));
        } else {
            if (checkFuncNum()) {
                handleOnUploadCompleteCallFuncResponse(out, errorMsg, path);
            } else {
                handleOnUploadCompleteResponse(out, errorMsg);
            }
        }

    } catch (IOException e) {
        throw new ConnectorException(Constants.Errors.CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED, e);
    }

}

From source file:com.jwebmp.core.utilities.EscapeChars.java

/**
 * Escape <tt>'$'</tt> and <tt>'\'</tt> characters in replacement strings.
 *
 * @param input//from www .  j ava2 s.c o  m
 *
 * @return
 */
public static String forReplacementString(String input) {
    return Matcher.quoteReplacement(input);
}

From source file:org.entando.edo.builder.TestBuilderNoPlugin.java

@Test
public void test_Service_Java() throws IOException {
    String commonPath = "src/main/java/com/myportal/aps/system/services/cat".replaceAll("/",
            Matcher.quoteReplacement(File.separator));

    String actualPath = ACTUAL_BASE_FOLDER + commonPath;

    File actualDir = new File(actualPath);
    Assert.assertTrue(actualDir.exists());

    FileFilter excludeAPIFolder = new FileFilter() {
        @Override/*from ww w.  ja  v  a  2s . c  om*/
        public boolean accept(File pathname) {
            if (pathname.isDirectory() && pathname.getName().equals("api"))
                return false;
            return true;
        }
    };

    List<File> actualFiles = this.searchFiles(actualDir, excludeAPIFolder);
    Assert.assertEquals(7, actualFiles.size());
    this.compareFiles(actualFiles);
}

From source file:org.entando.edo.builder.TestBuilder.java

@Test
public void test_Service_Java() throws IOException {
    String commonPath = "src/main/java/org/entando/entando/plugins/jppet/aps/system/services/cat"
            .replaceAll("/", Matcher.quoteReplacement(File.separator));

    String actualPath = ACTUAL_BASE_FOLDER + commonPath;

    File actualDir = new File(actualPath);
    Assert.assertTrue(actualDir.exists());

    FileFilter excludeAPIFolder = new FileFilter() {
        @Override/*ww  w . j ava  2  s.c  om*/
        public boolean accept(File pathname) {
            if (pathname.isDirectory() && pathname.getName().equals("api"))
                return false;
            return true;
        }
    };

    List<File> actualFiles = this.searchFiles(actualDir, excludeAPIFolder);
    Assert.assertEquals(7, actualFiles.size());
    this.compareFiles(actualFiles);
}

From source file:org.sigmah.server.servlet.base.AbstractServlet.java

/**
 * {@inheritDoc}//from   ww  w.jav a  2  s  .c  o  m
 */
@Override
public final void init(final ServletConfig config) throws ServletException {

    if (LOG.isDebugEnabled()) {
        LOG.debug("Reading HTML error page template.");
    }

    try (final InputStream is = getClass().getResourceAsStream(ERROR_PAGE_NAME)) {

        template = Servlets.readAll(is);

        // Replaces tags.
        template = template.replaceAll(Pattern.quote("<!-- ${AppName} -->"),
                Matcher.quoteReplacement(properties.getProperty(PropertyKey.APP_NAME)));

    } catch (final IOException e) {
        throw new ServletException("Cannot read the HTML page template.", e);
    }
}

From source file:com.igormaznitsa.mindmap.model.ModelUtils.java

@Nonnull
public static String unescapeMarkdownStr(@Nonnull final String text) {
    String unescaped = UNESCAPE_BR.matcher(text).replaceAll("\n"); //NOI18N
    final StringBuffer result = new StringBuffer(text.length());
    final Matcher escaped = MD_ESCAPED_PATTERN.matcher(unescaped);
    while (escaped.find()) {
        final String group = escaped.group(1);
        escaped.appendReplacement(result, Matcher.quoteReplacement(group.substring(1)));
    }// w  ww  .j  a va  2 s.c  o m
    escaped.appendTail(result);
    return result.toString();
}

From source file:pt.webdetails.cdf.dd.model.inst.writer.cdfrunjs.dashboard.legacy.CdfRunJsDashboardWriter.java

public void write(CdfRunJsDashboardWriteResult.Builder builder, CdfRunJsDashboardWriteContext ctx,
        Dashboard dash) throws ThingWriteException {
    assert dash == ctx.getDashboard();

    DashboardWcdfDescriptor wcdf = dash.getWcdf();

    String template;//www .j  av a 2  s .  co m
    try {
        template = Utils.readTemplate(wcdf);
    } catch (IOException ex) {
        throw new ThingWriteException("Could not read style template file.", ex);
    }

    template = ctx.replaceTokens(template);

    String footer;
    try {
        footer = Util.toString(
                CdeEnvironment.getPluginSystemReader().getFileInputStream(CdeConstants.RESOURCE_FOOTER));
    } catch (IOException ex) {
        throw new ThingWriteException("Could not read footer file.", ex);
    }

    String layout = ctx.replaceTokensAndAlias(this.writeLayout(ctx, dash));
    String components = ctx.replaceTokensAndAlias(this.writeComponents(ctx, dash));
    String content = writeContent(layout, components);
    String header = ctx.replaceTokens(writeHeaders(content, ctx));

    // Leave the DASHBOARD_HEADER_TAG to replace additional stuff on render.
    template = template
            .replaceAll(CdeConstants.DASHBOARD_HEADER_TAG,
                    Matcher.quoteReplacement(header) + CdeConstants.DASHBOARD_HEADER_TAG)
            .replaceAll(CdeConstants.DASHBOARD_FOOTER_TAG, Matcher.quoteReplacement(footer))
            .replaceAll(CdeConstants.DASHBOARD_CONTENT_TAG, Matcher.quoteReplacement(content));

    // Export
    builder.setTemplate(template).setHeader(header).setLayout(layout).setComponents(components)
            .setContent(content).setFooter(footer).setLoadedDate(ctx.getDashboard().getSourceDate());
}

From source file:com.thoughtworks.go.util.command.CommandLineTest.java

@Test
void testToStringMisMatchedQuote() {
    final CommandLine cl2 = CommandLine.createCommandLine(EXEC_WITH_SPACES).withEncoding("utf-8");
    final String argWithMismatchedDblQuote = "argMisMatch='singlequoted\"WithMismatchedDblQuote'";
    cl2.withArg(argWithMismatchedDblQuote);
    assertEquals("Should escape double quotes inside the string",
            DBL_QUOTE + EXEC_WITH_SPACES + DBL_QUOTE + " " + DBL_QUOTE
                    + argWithMismatchedDblQuote.replaceAll("\"", Matcher.quoteReplacement("\\\"")) + DBL_QUOTE,
            cl2.toString());//from   www.  j a  va2 s.  co  m
}