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:org.entando.edo.builder.TestBuilder.java

@Test
public void test_Service_Api_Xml() throws IOException {
    String commonPath = "src/main/resources/api/plugins/jppet".replaceAll("/",
            Matcher.quoteReplacement(File.separator));

    String actualPath = ACTUAL_BASE_FOLDER + commonPath;

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

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

From source file:io.klerch.alexa.tellask.model.wrapper.AlexaSpeechletResponse.java

private String resolveSlotsInUtterance(final String utterance) {
    final StringBuffer buffer = new StringBuffer();
    // extract all the placeholders found in the utterance
    final Matcher slotsInUtterance = Pattern.compile("\\{(.*?)\\}").matcher(utterance);
    // for any of the placeholders ...
    while (slotsInUtterance.find()) {
        // ... placeholder-name is the slotName to look after in two places of the output
        final String slotName = slotsInUtterance.group(1);
        final AlexaOutputSlot outputSlot = output
                // prefer directly set output slots
                .getSlots().stream()//from www .j a va  2s . c om
                // which do have the same name as what is found in the utterance
                .filter(slot -> slot.getName().equals(slotName)).findFirst()
                // if not directly applied look in provided models for AlexaSlotSave fields
                .orElse(getSavedSlot(slotName));

        Validate.notNull(outputSlot, "Could not replace placeholder with name {" + slotName
                + "} because no corresponding slot was set in the output.");
        // RJH - FEB 2017 - Matcher.quoteReplacement on slot input to fix bug
        // ~ https://github.com/KayLerch/alexa-skills-kit-tellask-java/issues/1
        slotsInUtterance.appendReplacement(buffer, Matcher.quoteReplacement(outputSlot.getSsml()));
    }
    slotsInUtterance.appendTail(buffer);
    return "<speak>" + buffer.toString() + "</speak>";
}

From source file:sernet.verinice.service.ReportDepositService.java

@Deprecated
private String removeWrongPathSeparators(String path) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("File.separatorChar:\t" + File.separatorChar);
    }/*from   w  ww.ja  v a2  s .co m*/
    if (path.contains("/") && !(String.valueOf(File.separatorChar).equals("/"))) {
        String oldPath = path;
        path = path.replaceAll("/", Matcher.quoteReplacement(String.valueOf(File.separatorChar)));
        if (LOG.isDebugEnabled()) {
            LOG.debug(oldPath + "\t replaced with \t" + path);
        }
    }
    if (path.contains("\\") && !(String.valueOf(File.separatorChar).equals("\\"))) {
        String oldPath = path;
        path = path.replaceAll(Pattern.quote("\\"),
                Matcher.quoteReplacement(String.valueOf(File.separatorChar)));
        if (LOG.isDebugEnabled()) {
            LOG.debug(oldPath + "\t replaced with \t" + path);
        }
    }
    return path;

}

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

/**
 * Writes the dashboard to a provided builder object.
 *
 * @param builder the builder object to where the processed dashboard will be stored
 * @param ctx the dashboard context.//from ww  w .  j av a2s  .c o m
 * @param dash the dashboard to write.
 * @throws ThingWriteException
 */
public void write(CdfRunJsDashboardWriteResult.Builder builder, CdfRunJsDashboardWriteContext ctx,
        Dashboard dash) throws ThingWriteException {
    assert dash == ctx.getDashboard();

    DashboardWcdfDescriptor wcdf = dash.getWcdf();

    // header
    final String header = ctx.replaceTokens(writeHeaders(dash));

    // content resources
    ResourceMap resources;
    try {
        resources = getResourceRenderer(dash.getLayout("TODO").getLayoutXPContext(), ctx)
                .renderResources(ctx.getOptions().getAliasPrefix());
    } catch (Exception ex) {
        throw new ThingWriteException("Error rendering resources.", ex);
    }

    // content layout
    final String layout;
    try {
        layout = ctx.replaceTokensAndAlias(this.writeCssCodeResources(resources) + this.writeLayout(ctx, dash));
    } catch (Exception ex) {
        throw new ThingWriteException("Error rendering layout", ex);
    }

    StringBuilder out = new StringBuilder();
    // content dashboard wcdf settings, write WCDF settings
    final String wcdfSettings = writeWcdfSettings(dash);
    // content dashboard components, write component AMD modules and add them to the componentModules map
    final Map<String, String> componentModules = writeComponents(ctx, dash, out);
    final String components = ctx.replaceTokensAndAlias(out.toString());
    // content
    final String content = writeContent(resources, layout, componentModules, wcdfSettings + components, ctx);

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

    // template
    String template;
    try {
        template = ctx.replaceTokens(Utils.readTemplate(wcdf));
    } catch (IOException ex) {
        throw new ThingWriteException("Could not read style template file.", ex);
    }
    // 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_CONTENT_TAG, Matcher.quoteReplacement(content))
            .replaceAll(CdeConstants.DASHBOARD_FOOTER_TAG, Matcher.quoteReplacement(footer));

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

From source file:com.confighub.core.utils.FileUtils.java

private static String previewFile(final Context context, String fileContent, Map<String, Property> resolved,
        MultivaluedMap<String, String> passwords, Set<Long> breadcrumbs) {
    Collection<String> keyStrings = FileUtils.getKeys(fileContent);

    String patternString = "(?i)\\$\\{\\s*\\b(" + StringUtils.join(keyStrings, "|") + ")\\b\\s*}";
    Pattern pattern = Pattern.compile(patternString);
    Matcher matcher = pattern.matcher(fileContent);

    StringBuffer sb = new StringBuffer();

    while (matcher.find()) {
        String key = matcher.group(1);
        Property property = resolved.get(key);

        // replace each key specification with the property value
        String value = "";

        if (null != property) {
            if (null != property.getAbsoluteFilePath() && PropertyKey.ValueDataType.FileEmbed
                    .equals(property.getPropertyKey().getValueDataType())) {
                if (breadcrumbs.contains(property.getAbsoluteFilePath().getId())) {
                    JsonObject json = property.toJson();
                    json.addProperty("key", key);
                    throw new ConfigException(Error.Code.FILE_CIRCULAR_REFERENCE, json);
                }// w  ww  . j  a  v a2 s  . c  o m

                breadcrumbs.add(property.getAbsoluteFilePath().getId());

                RepoFile injectFile = context.resolveFullContextFilePath(property.getAbsoluteFilePath());
                if (null == injectFile)
                    value = "[ ERROR: No file resolved ]";
                else
                    value = previewFile(context, injectFile.getContent(), resolved, passwords, breadcrumbs);
            } else {
                if (property.isEncrypted()) {
                    String spName = property.getPropertyKey().getSecurityProfile().getName();
                    if (null != passwords && passwords.containsKey(spName)) {
                        String password = passwords.get(spName).get(0);
                        if (!Utils.isBlank(password))
                            property.decryptValue(password);
                    }
                }
                value = setValue(property);
            }
        }

        matcher.appendReplacement(sb, Matcher.quoteReplacement(value));
    }

    matcher.appendTail(sb);
    fileContent = sb.toString();

    // Remove all escapes \${...}
    fileContent = fileContent.replaceAll("\\\\\\$\\{", "\\$\\{");
    return fileContent;
}

From source file:org.wso2.carbon.integration.test.client.Wso2EventServer.java

public List<StreamDefinition> loadStreamDefinitions() {
    String relativeFilePath = FrameworkPathUtil.getSystemResourceLocation()
            + CEPIntegrationTestConstants.RELATIVE_PATH_TO_TEST_ARTIFACTS + testCaseResourceFolderName;
    String directoryPath = relativeFilePath.replaceAll("[\\\\/]", Matcher.quoteReplacement(File.separator));
    GenericExtFilter filter = new GenericExtFilter(FILE_STREAM_DEFINITION_EXT);
    File directory = new File(directoryPath);
    List<StreamDefinition> streamDefinitions = new ArrayList<StreamDefinition>();
    if (!directory.exists()) {
        log.error(//w  w w  .ja  v a 2 s  .  c  o  m
                "Cannot load stream definitions from " + directory.getAbsolutePath() + " directory not exist");
        return streamDefinitions;
    }
    if (!directory.isDirectory()) {
        log.error("Cannot load stream definitions from " + directory.getAbsolutePath() + " not a directory");
        return streamDefinitions;
    }

    // List out all the file names and filter by the extension.
    String[] listStreamDefinitionFiles = directory.list(filter);
    if (listStreamDefinitionFiles != null) {
        for (final String fileEntry : listStreamDefinitionFiles) {
            BufferedReader bufferedReader = null;
            StringBuilder stringBuilder = new StringBuilder();
            String fullPathToStreamDefinitionFile = directoryPath + File.separator + fileEntry;
            try {
                bufferedReader = new BufferedReader(new FileReader(fullPathToStreamDefinitionFile));
                String line;
                while ((line = bufferedReader.readLine()) != null) {
                    stringBuilder.append(line).append("\n");
                }
                StreamDefinition streamDefinition = EventDefinitionConverterUtils
                        .convertFromJson(stringBuilder.toString().trim());
                streamDefinitions.add(streamDefinition);
            } catch (IOException e) {
                log.error("Error in reading file : " + fullPathToStreamDefinitionFile, e);
            } catch (MalformedStreamDefinitionException e) {
                log.error("Error in converting Stream definition : " + e.getMessage(), e);
            } finally {
                try {
                    if (bufferedReader != null) {
                        bufferedReader.close();
                    }
                } catch (IOException e) {
                    log.error("Error occurred when reading the file : " + e.getMessage(), e);
                }
            }
        }
    }
    return streamDefinitions;
}

From source file:org.springframework.integration.sftp.outbound.SftpServerOutboundTests.java

@Test
@SuppressWarnings("unchecked")
public void testInt2866LocalDirectoryExpressionMGET() {
    String dir = "sftpSource/";
    long modified = setModifiedOnSource1();
    this.inboundMGet.send(new GenericMessage<Object>(dir + "*.txt"));
    Message<?> result = this.output.receive(1000);
    assertNotNull(result);//from w  ww .  j a va 2s.  co  m
    List<File> localFiles = (List<File>) result.getPayload();

    assertThat(localFiles.size(), Matchers.greaterThan(0));

    boolean assertedModified = false;
    for (File file : localFiles) {
        assertThat(file.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"),
                containsString(dir));
        if (file.getPath().contains("localTarget1")) {
            assertedModified = assertPreserved(modified, file);
        }
    }
    assertTrue(assertedModified);

    dir = "sftpSource/subSftpSource/";
    this.inboundMGet.send(new GenericMessage<Object>(dir + "*.txt"));
    result = this.output.receive(1000);
    assertNotNull(result);
    localFiles = (List<File>) result.getPayload();

    assertThat(localFiles.size(), Matchers.greaterThan(0));

    for (File file : localFiles) {
        assertThat(file.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"),
                containsString(dir));
    }
}

From source file:org.wso2.esb.integration.common.utils.servers.ThriftServer.java

public List<StreamDefinition> loadStreamDefinitions() {
    String relativeFilePath = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator
            + "ESB" + File.separator + testCaseResourceFolderName;
    String directoryPath = relativeFilePath.replaceAll("[\\\\/]", Matcher.quoteReplacement(File.separator));
    GenericExtFilter filter = new GenericExtFilter(FILE_STREAM_DEFINITION_EXT);
    File directory = new File(directoryPath);
    List<StreamDefinition> streamDefinitions = new ArrayList<StreamDefinition>();
    if (!directory.exists()) {
        log.error(//  ww w. j a  va 2 s .  co m
                "Cannot load stream definitions from " + directory.getAbsolutePath() + " directory not exist");
        return streamDefinitions;
    }
    if (!directory.isDirectory()) {
        log.error("Cannot load stream definitions from " + directory.getAbsolutePath() + " not a directory");
        return streamDefinitions;
    }

    // List out all the file names and filter by the extension.
    String[] listStreamDefinitionFiles = directory.list(filter);
    if (listStreamDefinitionFiles != null) {
        for (final String fileEntry : listStreamDefinitionFiles) {
            BufferedReader bufferedReader = null;
            StringBuilder stringBuilder = new StringBuilder();
            String fullPathToStreamDefinitionFile = directoryPath + File.separator + fileEntry;
            try {
                bufferedReader = new BufferedReader(new FileReader(fullPathToStreamDefinitionFile));
                String line;
                while ((line = bufferedReader.readLine()) != null) {
                    stringBuilder.append(line).append("\n");
                }
                StreamDefinition streamDefinition = EventDefinitionConverterUtils
                        .convertFromJson(stringBuilder.toString().trim());
                streamDefinitions.add(streamDefinition);
            } catch (IOException e) {
                log.error("Error in reading file : " + fullPathToStreamDefinitionFile, e);
            } catch (MalformedStreamDefinitionException e) {
                log.error("Error in converting Stream definition : " + e.getMessage(), e);
            } finally {
                try {
                    if (bufferedReader != null) {
                        bufferedReader.close();
                    }
                } catch (IOException e) {
                    log.error("Error occurred when reading the file : " + e.getMessage(), e);
                }
            }
        }
    }
    return streamDefinitions;
}

From source file:org.wso2.identity.integration.test.analytics.commons.ThriftServer.java

public List<StreamDefinition> loadStreamDefinitions() {

    String relativeFilePath = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator
            + "ESB" + File.separator + testCaseResourceFolderName;
    String directoryPath = relativeFilePath.replaceAll("[\\\\/]", Matcher.quoteReplacement(File.separator));
    directoryPath = getResourceFilePath(testCaseResourceFolderName, "");
    GenericExtFilter filter = new GenericExtFilter(FILE_STREAM_DEFINITION_EXT);
    File directory = new File(directoryPath);
    List<StreamDefinition> streamDefinitions = new ArrayList<StreamDefinition>();
    if (!directory.exists()) {
        log.error(//  w  w w . j  av a  2s . c  om
                "Cannot load stream definitions from " + directory.getAbsolutePath() + " directory not exist");
        return streamDefinitions;
    }
    if (!directory.isDirectory()) {
        log.error("Cannot load stream definitions from " + directory.getAbsolutePath() + " not a directory");
        return streamDefinitions;
    }

    // List out all the file names and filter by the extension.
    String[] listStreamDefinitionFiles = directory.list(filter);
    if (listStreamDefinitionFiles != null) {
        for (final String fileEntry : listStreamDefinitionFiles) {
            BufferedReader bufferedReader = null;
            StringBuilder stringBuilder = new StringBuilder();
            String fullPathToStreamDefinitionFile = directoryPath + File.separator + fileEntry;
            try {
                bufferedReader = new BufferedReader(new FileReader(fullPathToStreamDefinitionFile));
                String line;
                while ((line = bufferedReader.readLine()) != null) {
                    stringBuilder.append(line).append("\n");
                }
                StreamDefinition streamDefinition = EventDefinitionConverterUtils
                        .convertFromJson(stringBuilder.toString().trim());
                streamDefinitions.add(streamDefinition);
            } catch (IOException e) {
                log.error("Error in reading file : " + fullPathToStreamDefinitionFile, e);
            } catch (MalformedStreamDefinitionException e) {
                log.error("Error in converting Stream definition : " + e.getMessage(), e);
            } finally {
                try {
                    if (bufferedReader != null) {
                        bufferedReader.close();
                    }
                } catch (IOException e) {
                    log.error("Error occurred when reading the file : " + e.getMessage(), e);
                }
            }
        }
    }
    return streamDefinitions;
}

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

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

    String actualPath = ACTUAL_BASE_FOLDER + commonPath;

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

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