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:de.uzk.hki.da.convert.PublishCLIConversionStrategy.java

@Override
public List<Event> convertFile(WorkArea wa, ConversionInstruction ci

) throws FileNotFoundException {
    if (pkg == null)
        throw new IllegalStateException("Package not set");

    List<Event> results = new ArrayList<Event>();

    for (String audience : audiences) {

        String audience_lc = audience.toLowerCase();
        String repName = WorkArea.TMP_PIPS + "/" + audience_lc;

        Path.make(wa.dataPath(), repName, ci.getTarget_folder()).toFile().mkdirs();

        String[] commandAsArray = assemble(wa, ci, repName);
        if (!cliConnector.execute(commandAsArray))
            throw new RuntimeException("convert did not succeed");

        String targetSuffix = ci.getConversion_routine().getTarget_suffix();
        if (targetSuffix.equals("*"))
            targetSuffix = FilenameUtils.getExtension(wa.toFile(ci.getSource_file()).getAbsolutePath());
        DAFile result = new DAFile(repName,
                ci.getTarget_folder() + "/"
                        + FilenameUtils.removeExtension(Matcher.quoteReplacement(
                                FilenameUtils.getName(wa.toFile(ci.getSource_file()).getAbsolutePath())))
                        + "." + targetSuffix);

        Event e = new Event();
        e.setType("CONVERT");
        e.setDetail(StringUtilities.createString(commandAsArray));
        e.setSource_file(ci.getSource_file());
        e.setTarget_file(result);/*from  w  ww. j  a  v  a2  s .c o  m*/
        e.setDate(new Date());

        results.add(e);

    }

    return results;

}

From source file:de.Keyle.MyPet.api.Util.java

public static String formatText(String text, Object... values) {
    for (int i = 0; i < values.length; i++) {
        if (values[i] != null) {
            text = text.replaceAll("\\{" + i + "}", Matcher.quoteReplacement(values[i].toString()));
        }/* w  ww  . j  a  v  a  2 s.  c  om*/
    }
    return text;
}

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

public static String getTestDataFileLocation(String testCaseFolderName, String dataFileName) {

    String relativeFilePath = FrameworkPathUtil.getSystemResourceLocation()
            + CEPIntegrationTestConstants.RELATIVE_PATH_TO_TEST_ARTIFACTS + testCaseFolderName + "/"
            + dataFileName;/*from w w  w . ja v a2 s .  c  o m*/
    relativeFilePath = relativeFilePath.replaceAll("[\\\\/]", Matcher.quoteReplacement(File.separator));
    return relativeFilePath;
}

From source file:org.pentaho.platform.plugin.services.metadata.SessionAwareRowLevelSecurityHelper.java

@Override
protected String expandFunctions(String formula, String user, List<String> roles) {
    formula = super.expandFunctions(formula, user, roles);

    // "expand" any SESSION('var')

    IPentahoSession session = PentahoSessionHolder.getSession();

    Pattern p = Pattern.compile("SESSION\\(\"(.*?)\"\\)"); //$NON-NLS-1$
    Matcher m = p.matcher(formula);
    StringBuffer sb = new StringBuffer(formula.length());
    while (m.find()) {
        String text = m.group(1);
        String value = null;//from ww w.j  a v a2 s . c om
        if (session.getAttribute(text) != null) {
            value = session.getAttribute(text).toString();
        } else {
            logger.warn(Messages.getInstance()
                    .getString("SessionAwareRowLevelSecurityHelper.WARN_0001_NULL_ATTRIBUTE", text, user)); //$NON-NLS-1$
            return "FALSE()"; //$NON-NLS-1$
        }
        // escape string if necessary (double quote quotes)
        m.appendReplacement(sb, Matcher.quoteReplacement(value.replaceAll("\"", "\"\""))); //$NON-NLS-1$ //$NON-NLS-2$
    }
    m.appendTail(sb);
    return sb.toString();
}

From source file:org.nuxeo.ecm.web.resources.wro.processor.FlavorResourceProcessor.java

@Override
protected void process(final Resource resource, final Reader reader, final Writer writer, String flavorName)
        throws IOException {
    final InputStream is = new ProxyInputStream(new ReaderInputStream(reader, getEncoding())) {
    };/*from  w  w  w  .ja  v a2 s .  c om*/
    final OutputStream os = new ProxyOutputStream(new WriterOutputStream(writer, getEncoding()));
    try {
        Map<String, String> presets = null;
        if (flavorName != null) {
            ThemeStylingService s = Framework.getService(ThemeStylingService.class);
            presets = s.getPresetVariables(flavorName);
        }
        if (presets == null || presets.isEmpty()) {
            IOUtils.copy(is, os);
        } else {
            String content = IOUtils.toString(reader);
            for (Map.Entry<String, String> preset : presets.entrySet()) {
                content = Pattern.compile("\"" + preset.getKey() + "\"", Pattern.LITERAL).matcher(content)
                        .replaceAll(Matcher.quoteReplacement(preset.getValue()));
            }
            writer.write(content);
            writer.flush();
        }
        is.close();
    } catch (final Exception e) {
        log.error("Error while serving resource " + resource.getUri(), e);
        throw WroRuntimeException.wrap(e);
    } finally {
        IOUtils.closeQuietly(is);
        IOUtils.closeQuietly(os);
    }
}

From source file:edworld.pdfreader4humans.PDFReader.java

public String toXML() {
    String output = template("pdfreader4humans.xml", 0);
    String content = "";
    for (int pageIndex = 0; pageIndex < firstLevel.size(); pageIndex++)
        content += pageToXML(pageIndex + 1, firstLevel.get(pageIndex), 1);
    return removeEmptyLines(output.replaceAll("\\$\\{content\\}", Matcher.quoteReplacement(content)));
}

From source file:pt.webdetails.cdf.dd.extapi.FileHandler.java

@Override
public boolean saveDashboardAs(String path, String title, String description, String cdfdeJsText,
        boolean isPreview) throws Exception {

    // 1. Read empty wcdf file or get original wcdf file if previewing dashboard
    InputStream wcdfFile;/*w  w  w.  j  ava  2  s  .co m*/
    if (isPreview) {
        String wcdfPath = path.replace("_tmp", "");
        wcdfFile = Utils.getSystemOrUserRWAccess(wcdfPath).getFileInputStream(wcdfPath);
    } else {
        wcdfFile = CdeEnvironment.getPluginSystemReader()
                .getFileInputStream(DashboardStructure.SYSTEM_PLUGIN_EMPTY_WCDF_FILE_PATH);

        // [CDE-130] CDE Dash saves file with name @DASHBOARD_TITLE@
        if (CdeConstants.DASHBOARD_TITLE_TAG.equals(title)) {
            title = FilenameUtils.getBaseName(path);
        }
        if (CdeConstants.DASHBOARD_DESCRIPTION_TAG.equals(description)) {
            description = FilenameUtils.getBaseName(path);
        }
    }

    String wcdfContentAsString = IOUtils.toString(wcdfFile, CharsetHelper.getEncoding());

    // 2. Fill-in wcdf file title and description
    wcdfContentAsString = wcdfContentAsString.replaceFirst(CdeConstants.DASHBOARD_TITLE_TAG,
            Matcher.quoteReplacement(title));
    wcdfContentAsString = wcdfContentAsString.replaceFirst(CdeConstants.DASHBOARD_DESCRIPTION_TAG,
            Matcher.quoteReplacement(description));

    // 3. Publish new wcdf file
    ByteArrayInputStream bais = new ByteArrayInputStream(
            wcdfContentAsString.getBytes(CharsetHelper.getEncoding()));

    if (isPreview) {
        return Utils.getSystemOrUserRWAccess(path).saveFile(path, bais);

    } else {
        FileContent file = new FileContent();
        file.setPath(path);
        file.setContents(bais);
        file.setTitle(title);
        file.setDescription(description);

        return PentahoCdeEnvironment.getInstance().getContentAccessFactory().getUserContentAccess(null)
                .saveFile(file);

    }
}

From source file:org.hawkular.apm.api.services.ConfigurationLoader.java

/**
 * This method loads the configuration from the supplied URI.
 *
 * @param uri The URI/*from w w w. jav  a  2s. c om*/
 * @param type The type, or null if default (jvm)
 * @return The configuration
 */
protected static CollectorConfiguration loadConfig(String uri, String type) {
    final CollectorConfiguration config = new CollectorConfiguration();

    if (type == null) {
        type = DEFAULT_TYPE;
    }

    uri += java.io.File.separator + type;

    File f = new File(uri);

    if (!f.isAbsolute()) {
        if (f.exists()) {
            uri = f.getAbsolutePath();
        } else if (System.getProperties().containsKey("jboss.server.config.dir")) {
            uri = System.getProperty("jboss.server.config.dir") + java.io.File.separatorChar + uri;
        } else {
            try {
                URL url = Thread.currentThread().getContextClassLoader().getResource(uri);
                if (url != null) {
                    uri = url.getPath();
                } else {
                    log.severe("Failed to get absolute path for uri '" + uri + "'");
                }
            } catch (Exception e) {
                log.log(Level.SEVERE, "Failed to get absolute path for uri '" + uri + "'", e);
                uri = null;
            }
        }
    }

    if (uri != null) {
        String[] uriParts = uri.split(Matcher.quoteReplacement(File.separator));
        int startIndex = 0;

        // Remove any file prefix
        if (uriParts[0].equals("file:")) {
            startIndex++;
        }

        try {
            Path path = getPath(startIndex, uriParts);

            Files.walkFileTree(path, new FileVisitor<Path>() {

                @Override
                public FileVisitResult postVisitDirectory(Path path, IOException exc) throws IOException {
                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes attrs)
                        throws IOException {
                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
                    if (path.toString().endsWith(".json")) {
                        String json = new String(Files.readAllBytes(path));
                        CollectorConfiguration childConfig = mapper.readValue(json,
                                CollectorConfiguration.class);
                        if (childConfig != null) {
                            config.merge(childConfig, false);
                        }
                    }
                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult visitFileFailed(Path path, IOException exc) throws IOException {
                    return FileVisitResult.CONTINUE;
                }

            });
        } catch (Throwable e) {
            log.log(Level.SEVERE, "Failed to load configuration", e);
        }
    }

    return config;
}

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

@Test
public void test_Service_Init_Java() throws IOException {
    String commonPath = "src/main/java/com/myportal/aps/system/init".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:org.entando.edo.builder.TestBuilder.java

@Test
public void test_Service_Init_Java() throws IOException {
    String commonPath = "src/main/java/org/entando/entando/plugins/jppet/aps/system/init".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);
}