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.tolven.deploy.glassfish3.GlassFish3Deploy.java

private String escape(String string) {
    return string.replaceAll("=", Matcher.quoteReplacement("\\=")).replaceAll(":",
            Matcher.quoteReplacement("\\:"));
}

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

@Test
public void test_Controller_Java_Widget() throws IOException {
    String commonPath = "src/main/java/com/myportal/apsadmin/portal".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(4, actualFiles.size());
    this.compareFiles(actualFiles);
}

From source file:org.robovm.templater.Templater.java

private void substitutePlaceholdersInFile(File file) throws IOException {
    String extension = FilenameUtils.getExtension(file.getName());

    if (ROBOVM_PROPERTIES_FILE.equals(file.getName())) {
        String content = FileUtils.readFileToString(file, "UTF-8");
        content = content.replace("\r", ""); // windows is special...
        // special case for app id
        content = content.replaceAll(Pattern.quote("app.id=${package}"), "app.id=" + appId);
        content = content.replaceAll(ROBOVM_PROPERTIES_APP_NAME_PLACEHOLDER, appName);
        content = content.replaceAll(ROBOVM_PROPERTIES_MAIN_CLASS_PLACEHOLDER, mainClassName);
        String propsPackageName = packageName == null || packageName.length() == 0 ? "" : packageName;
        content = content.replaceAll(ROBOVM_PROPERTIES_PACKAGE_PLACEHOLDER, propsPackageName);
        // need to fix up app.mainclass in case package name was empty
        content = content.replaceAll(Pattern.quote("mainclass=."), "mainclass=");
        FileUtils.writeStringToFile(file, content, "UTF-8");
    } else if (ANDROID_MANIFEST_FILE.equals(file.getName())) {
        String content = FileUtils.readFileToString(file, "UTF-8");
        content = content.replace("\r", ""); // windows is special...
        String propsPackageName = packageName == null || packageName.length() == 0 ? "" : packageName;
        content = content.replaceAll(ANDROID_MANIFEST_PACKAGE_PLACEHOLDER, propsPackageName);
        content = content.replaceAll(ANDROID_MANIFEST_MAIN_CLASS_PLACEHOLDER, mainClassName);
        FileUtils.writeStringToFile(file, content, "UTF-8");
    } else if (ANDROID_STRINGS_FILE.equals(file.getName())) {
        String content = FileUtils.readFileToString(file, "UTF-8");
        content = content.replace("\r", ""); // windows is special...
        content = content.replaceAll(ANDROID_STRINGS_APP_NAME_PLACEHOLDER, appName);
        FileUtils.writeStringToFile(file, content, "UTF-8");
    } else if (ANDROID_BUILD_FILE.equals(file.getName())) {
        String content = FileUtils.readFileToString(file, "UTF-8");
        content = content.replace("\r", ""); // windows is special...
        content = content.replaceAll(ANDROID_SDK_VERSION, androidSdkVersion);
        content = content.replaceAll(ANDROID_BUILD_TOOLS_VERSION, "\"" + androidBuildToolsVersion + "\"");
        String propsPackageName = packageName == null || packageName.length() == 0 ? "" : packageName;
        content = content.replaceAll(ROBOVM_PROPERTIES_PACKAGE_PLACEHOLDER, propsPackageName);
        FileUtils.writeStringToFile(file, content, "UTF-8");
    } else if (SUBSTITUTED_PLACEHOLDER_FILES_EXTENSIONS.contains(extension)) {
        String content = FileUtils.readFileToString(file, "UTF-8");
        content = content.replace("\r", ""); // windows is special...
        content = content.replaceAll(MAVEN_ARCHETYPE_SET_PLACEHOLDER, "");
        content = content.replaceAll(DOLLAR_SYMBOL_PLACEHOLDER, Matcher.quoteReplacement("$"));
        content = content.replaceAll(PACKAGE_PLACEHOLDER, getPackageNameReplacement(extension, packageName));
        content = content.replaceAll(MAIN_CLASS_PLACEHOLDER, mainClassName);
        FileUtils.writeStringToFile(file, content, "UTF-8");
    }/*from  w  ww .j  a  va  2  s  .  c  om*/
}

From source file:org.xwiki.contrib.dokuwiki.text.internal.input.DokuWikiInputFilterStream.java

private void readDocument(File directory, String dokuwikiDataDirectory, DokuWikiFilter proxyFilter)
        throws FilterException, IOException {
    File[] directoryFiles = directory.listFiles();
    //Maintain order across file systems
    if (directoryFiles != null) {
        Arrays.sort(directoryFiles);
        for (File file : directoryFiles) {
            if (file.isDirectory()) {
                proxyFilter.beginWikiSpace(file.getName(), FilterEventParameters.EMPTY);
                readDocument(file, dokuwikiDataDirectory, proxyFilter);
                proxyFilter.endWikiSpace(file.getName(), FilterEventParameters.EMPTY);
            } else if (file.getName().endsWith(KEY_TEXT_FILE_FORMAT)
                    && !file.getName().startsWith(KEY_FULL_STOP)) {
                String[] pathArray = file.getName()
                        .split(Matcher.quoteReplacement(System.getProperty(KEY_FILE_SEPERATOR)));
                String documentName = pathArray[pathArray.length - 1].replace(KEY_TEXT_FILE_FORMAT, "");
                String fileMetadataPath = file.getAbsolutePath()
                        .replace(/*  w  ww.  j av  a  2  s  .c  o  m*/
                                dokuwikiDataDirectory + System.getProperty(KEY_FILE_SEPERATOR)
                                        + KEY_PAGES_DIRECTORY,
                                dokuwikiDataDirectory + System.getProperty(KEY_FILE_SEPERATOR) + "meta")
                        .replace(KEY_TEXT_FILE_FORMAT, ".meta");
                //                    FilterEventParameters documentParameters = new FilterEventParameters();
                //                    documentParameters.put(WikiDocumentFilter.PARAMETER_LOCALE, Locale.ROOT);

                //wiki document
                proxyFilter.beginWikiDocument(documentName, FilterEventParameters.EMPTY);

                FilterEventParameters documentLocaleParameters = new FilterEventParameters();

                File f = new File(fileMetadataPath);
                if (f.exists() && !f.isDirectory()) {
                    String metadataFileContents = FileUtils.readFileToString(new File(fileMetadataPath),
                            "UTF-8");
                    MixedArray documentMetadata = Pherialize.unserialize(metadataFileContents).toArray();
                    readDocumentParametersFromMetadata(documentMetadata, documentLocaleParameters);

                    //Wiki document revision

                    if ((documentMetadata.getArray(KEY_CURRENT).getArray(KEY_DATE).containsKey(KEY_CREATED)
                            && documentMetadata.getArray(KEY_CURRENT).getArray(KEY_DATE)
                                    .containsKey(KEY_MODIFIED))
                            && documentMetadata.getArray(KEY_CURRENT).getArray(KEY_DATE)
                                    .getLong(KEY_CREATED) < documentMetadata.getArray(KEY_CURRENT)
                                            .getArray(KEY_DATE).getLong(KEY_MODIFIED)) {
                        //Wiki Document Locale
                        proxyFilter.beginWikiDocumentLocale(Locale.ROOT, documentLocaleParameters);
                        //read revisions
                        readPageRevision(file, dokuwikiDataDirectory, proxyFilter);
                    } else {
                        documentLocaleParameters = readDocument(file, documentLocaleParameters,
                                dokuwikiDataDirectory, proxyFilter);
                    }
                } else {
                    this.logger.warn("File [{}] not found (Some datafile's properties (eg. filesize, "
                            + "last modified date) are not imported. Details can be found on "
                            + "https://www.dokuwiki.org/devel:metadata)", f);
                    documentLocaleParameters = readDocument(file, documentLocaleParameters,
                            dokuwikiDataDirectory, proxyFilter);
                }

                proxyFilter.endWikiDocumentLocale(Locale.ROOT, documentLocaleParameters);
                proxyFilter.endWikiDocument(documentName, FilterEventParameters.EMPTY);
            }
        }
    }
}

From source file:dk.deck.resolver.ArtifactResolverRemote.java

private String getSnapshotItemPath(Artifact artifact, MavenVersion version, String timestamp,
        String buildNumber) {//from   w w w . j a v  a 2s  .  co  m
    String artifactPath = artifact.getGroupId().replaceAll(Pattern.quote("."), Matcher.quoteReplacement("/"))
            + "/" + artifact.getArtifactId();
    String artifactVersionPath = artifactPath + "/" + artifact.getVersion();

    String snapshotVersion = version.toSnapshotString(timestamp, buildNumber);
    String artifactFilename = artifact.getArtifactId() + "-" + snapshotVersion + "." + artifact.getPackaging();
    if (!artifact.getClassifier().isEmpty()) {
        artifactFilename = artifact.getArtifactId() + "-" + snapshotVersion + "-" + artifact.getClassifier()
                + "." + artifact.getPackaging();
    }

    String artifactItemPath = artifactVersionPath + "/" + artifactFilename;
    return artifactItemPath;
}

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

@Test
public void test_Controller_Java_Widget() throws IOException {
    String commonPath = "src/main/java/org/entando/entando/plugins/jppet/apsadmin/portal".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(4, actualFiles.size());
    this.compareFiles(actualFiles);
}

From source file:org.springframework.integration.ftp.outbound.FtpServerOutboundTests.java

@Test
@SuppressWarnings("unchecked")
public void testInt3172LocalDirectoryExpressionMGETRecursiveFiltered() {
    String dir = "ftpSource/";
    this.inboundMGetRecursiveFiltered.send(new GenericMessage<Object>(dir + "*"));
    Message<?> result = this.output.receive(1000);
    assertNotNull(result);/*from w w w  .  j ava2s  . co  m*/
    List<File> localFiles = (List<File>) result.getPayload();
    // should have filtered ftpSource2.txt
    assertEquals(2, localFiles.size());

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

}

From source file:org.infoglue.deliver.invokers.ComponentBasedHTMLPageInvoker.java

protected String appendPagePartTemplates(String componentXML, Integer siteNodeId) throws Exception {
    String resultComponentXML = componentXML;

    List entries = new ArrayList();
    int isPagePartReferenceIndex = componentXML.indexOf("isPagePartReference");
    while (isPagePartReferenceIndex > -1) {
        int tagStartIndex = componentXML.lastIndexOf("<component ", isPagePartReferenceIndex);
        int tagEndIndex = componentXML.indexOf(">", isPagePartReferenceIndex);
        String componentString = componentXML.substring(tagStartIndex, tagEndIndex);

        int contentIdIndex = componentString.indexOf(" contentId=");
        String contentId = componentString.substring(contentIdIndex + 12,
                componentString.indexOf("\"", contentIdIndex + 12));

        int idIndex = componentString.indexOf(" id=");
        String id = componentString.substring(idIndex + 5, componentString.indexOf("\"", idIndex + 5));

        int nameIndex = componentString.indexOf(" name=");
        String name = componentString.substring(nameIndex + 7, componentString.indexOf("\"", nameIndex + 7));

        Map entry = new HashMap();
        entry.put("contentId", contentId);
        entry.put("id", id);
        entry.put("name", name);
        entries.add(entry);//from   ww w .ja  v  a2 s  .  co  m

        isPagePartReferenceIndex = componentXML.indexOf("isPagePartReference", isPagePartReferenceIndex + 20);
    }

    Iterator entriesIterator = entries.iterator();
    while (entriesIterator.hasNext()) {
        Map entry = (Map) entriesIterator.next();

        String contentIdString = (String) entry.get("contentId");
        Integer contentId = new Integer(contentIdString);
        String id = (String) entry.get("id");
        String name = (String) entry.get("name");
        try {
            ContentTypeDefinitionVO contentTypeDefinitionVO = ContentDeliveryController
                    .getContentDeliveryController().getContentTypeDefinitionVO(getDatabase(), contentId);
            if (contentTypeDefinitionVO != null
                    && contentTypeDefinitionVO.getName().equals("PagePartTemplate")) {
                //logger.info("This was a pagePart reference..");
                this.getTemplateController().getDeliveryContext()
                        .addUsedContent("selectiveCacheUpdateNonApplicable");

                String pagePartString = this.getTemplateController().getContentAttribute(contentId,
                        "ComponentStructure", true);
                logger.info("pagePartString: " + pagePartString);
                if (pagePartString == null || pagePartString.equals("")) {
                    ContentVO contentVO = ContentDeliveryController.getContentDeliveryController().getContentVO(
                            getTemplateController().getDatabase(), contentId,
                            getTemplateController().getDeliveryContext());
                    LanguageVO masterLanguageVO = LanguageController.getController().getMasterLanguage(
                            contentVO.getRepositoryId(), getTemplateController().getDatabase());
                    pagePartString = this.getTemplateController().getContentAttribute(contentId,
                            masterLanguageVO.getId(), "ComponentStructure", true);
                    logger.info("pagePartString: " + pagePartString);
                }

                pagePartString = pagePartString.replaceFirst(" id=\".*?\"", " id=\"" + id + "\"");
                pagePartString = pagePartString.replaceFirst(" name=\".*?\"", " name=\"" + name + "\"");
                pagePartString = pagePartString.replaceFirst(" pagePartTemplateContentId=\".*?\"",
                        " pagePartTemplateContentId=\"" + contentId + "\"");
                logger.info("Bytte id och namn: " + pagePartString);

                pagePartString = pagePartString.substring(pagePartString.indexOf("<component "));
                pagePartString = pagePartString.substring(0, pagePartString.lastIndexOf("</components>"));

                //logger.info("componentXML: " + componentXML);
                logger.info("contentId" + contentId);
                logger.info("pagePartString" + pagePartString);
                pagePartString = Matcher.quoteReplacement(pagePartString);
                String newComponentXML = componentXML.replaceAll(
                        "<component contentId=\"" + contentId + ".*?</component>", "" + pagePartString);
                //logger.info("newComponentXML: " + newComponentXML);
                resultComponentXML = newComponentXML;
            }
        } catch (Exception e) {
            logger.warn("Could not append page part as the content was removed - fix on page with id: ["
                    + siteNodeId + "]:" + e.getMessage());
        }
    }

    return resultComponentXML;
}

From source file:org.ops4j.pax.url.maven.commons.MavenSettingsImpl.java

/**
 * Gets the list of repositories from settings.xml.
 * If there is no settings.xml file or there are no repositories in settings.xml the list returned will be null.
 * /*from   w w w.  ja  va  2  s .co m*/
 * If there are repositories in settings.xml and those repositories have user and password the user and password
 * will be included in the repository url as for example http://user:password@repository.ops4j.org/maven2.
 *
 * Repositories are organized in profiles.
 * Active profiles are selected by looking at activeProfiles tag (just under <settings>)
 *
 * @return a comma separated list of repositories from settings.xml
 */
public String getRepositories() {
    if (m_repositories == null) {
        readSettings();
        if (m_document != null) {
            Set<String> activeProfiles = getActiveProfiles();
            Map<String, String> repositories = null;
            List<String> order = null;
            List<Element> profiles = XmlUtils.getElements(m_document, PROFILE_TAG);
            // first look for profiles
            if (profiles != null) {
                for (Element profile : profiles) {
                    Element profileIdElement = XmlUtils.getElement(profile, "id");
                    if (profileIdElement != null) {
                        String profileId = XmlUtils.getTextContent(profileIdElement);
                        if (profileId != null) {
                            if (activeProfiles.contains(profileId)) {
                                List<Element> repos = XmlUtils.getElements(profile, REPOSITORY_TAG);
                                if (repos != null) {
                                    for (Element repo : repos) {
                                        Element element = XmlUtils.getElement(repo, "id");
                                        if (element != null) {
                                            String id = XmlUtils.getTextContent(element);
                                            element = XmlUtils.getElement(repo, "layout");
                                            String layout = null;
                                            if (element != null) {
                                                layout = XmlUtils.getTextContent(element);
                                            }
                                            // take only repositories with a default layout (skip legacy ones)
                                            if (layout == null || "default".equals(layout)) {
                                                String snapshots = XmlUtils.getTextContentOfElement(repo,
                                                        "snapshots/enabled");
                                                String releases = XmlUtils.getTextContentOfElement(repo,
                                                        "releases/enabled");
                                                element = XmlUtils.getElement(repo, "url");
                                                if (element != null) {
                                                    String url = XmlUtils.getTextContent(element);
                                                    if (url != null) {
                                                        if (repositories == null) {
                                                            repositories = new HashMap<String, String>();
                                                            order = new ArrayList<String>();
                                                        }
                                                        if (snapshots != null && Boolean.valueOf(snapshots)) {
                                                            url += MavenConstants.SEPARATOR_OPTIONS
                                                                    + MavenConstants.OPTION_ALLOW_SNAPSHOTS;
                                                        }
                                                        if (releases != null && !Boolean.valueOf(releases)) {
                                                            url += MavenConstants.SEPARATOR_OPTIONS
                                                                    + MavenConstants.OPTION_DISALLOW_RELEASES;
                                                        }
                                                        repositories.put(id, url);
                                                        order.add(id);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            } else {
                                LOGGER.debug("Profile " + "[" + profileId + "] is inactive (ignored).");
                            }
                        }
                    }
                }

                // then look for user / passwords but only if we have repositories
                if (repositories != null) {
                    List<Element> servers = XmlUtils.getElements(m_document, SERVER_TAG);
                    if (servers != null) {
                        for (Element server : servers) {
                            Element element = XmlUtils.getElement(server, "id");
                            if (element != null) {
                                String id = XmlUtils.getTextContent(element);
                                // if we do not find a corresponding repository don't go furter
                                String repository = repositories.get(id);
                                if (repository != null && repository.contains("://")) {
                                    element = XmlUtils.getElement(server, "username");
                                    if (element != null) {
                                        String username = XmlUtils.getTextContent(element);
                                        // if there is no username stop the search
                                        if (username != null) {
                                            element = XmlUtils.getElement(server, "password");
                                            if (element != null) {
                                                String password = XmlUtils.getTextContent(element);
                                                if (password != null) {
                                                    username = username + ":" + password;
                                                }
                                            }
                                            // PAXURL-86: treat string as
                                            // literal
                                            String repo = "://" + username + "@";
                                            repo = Matcher.quoteReplacement(repo);
                                            repositories.put(id, repository.replaceFirst("://", repo));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                // build the list of repositories
                final StringBuilder builder = new StringBuilder();
                if (order != null) {
                    for (String repositoryId : order) {
                        if (builder.length() > 0) {
                            builder.append(",");
                        }
                        builder.append(repositories.get(repositoryId));
                    }
                }
                m_repositories = builder.toString();
            }
        }

        // PAXURL-92 Have the ability to only use a local repository, by
        // not requiring the use of a DEFAULT_REPOSITORY.  Helps with
        // users who have proxies and want to lockdown their repos.
        if (m_useFallbackRepositories) {
            if (m_repositories == null || m_repositories.length() == 0) {
                m_repositories = FALLBACK_REPOSITORIES;
            } else {
                m_repositories = m_repositories + "," + FALLBACK_REPOSITORIES;
            }
        }
    }
    return m_repositories;
}

From source file:fi.helsinki.cs.iot.hub.jsengine.DuktapeJavascriptEngineWrapper.java

private String jsonConfigToString(JSONObject json) {
    return json.toString().replaceAll("\"", Matcher.quoteReplacement("\\\""));
}