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.infoscoop.request.filter.GadgetFilter.java

private static String replaceContentStr(Document doc, I18NConverter i18n, Map<String, String> urlParameters)
        throws Exception {
    NodeList contentNodeList = doc.getElementsByTagName("Content");
    if (contentNodeList.getLength() == 0)
        return "";

    Node content = contentNodeList.item(0);
    String contentStr = XmlUtil.getChildText(content);
    contentStr = i18n.replace(contentStr);

    for (Map.Entry<String, String> param : urlParameters.entrySet()) {
        String key = param.getKey();
        if (!PARAM_MODULE_ID.equals(key) && !(key.startsWith("__UP_") && key.endsWith("__")))
            continue;

        contentStr = contentStr.replaceAll(key, Matcher.quoteReplacement(param.getValue()));
    }//www . j  a  va 2  s.c om

    return contentStr;
}

From source file:com.mediaworx.xmlutils.XmlHelper.java

/**
 * Parses the XML content of the file at the given path using the default encoding (UTF-8). Empty text nodes or
 * text nodes containing whitespace only are removed. If a replacement map is provided, each key in the map is
 * replaced by the corresponding value in the file's content.
 *
 * @param file the file containing the XML
 * @param replacements Map containing replacement strings, key: string to be replaced, value: replacement string (if the map is null, no replacements are made)
 * @param encoding  the encoding to be used to parse the file (must be a valid encoding like "UTF-8")
 * @return  the parsed XML document/*from www.j a v  a2s  . c o  m*/
 * @throws IOException  if there's a problem accessing the file
 * @throws SAXException if the file content can't be parsed
 */
public Document parseFile(File file, Map<String, String> replacements, String encoding)
        throws IOException, SAXException {
    String fileContent = readFile(file, encoding);

    if (replacements != null) {
        for (String search : replacements.keySet()) {
            String replace = replacements.get(search);
            fileContent = fileContent.replaceAll(Pattern.quote(search), Matcher.quoteReplacement(replace));
        }
    }
    StringReader reader = new StringReader(fileContent);
    Document document = builder.parse(new InputSource(reader));
    cleanEmptyTextNodes(document);
    return document;
}

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

public String getResourceFilePath(String testCaseFolderName, String resourceFileName) {
    String relativeFilePath = FrameworkPathUtil.getSystemResourceLocation()
            + CEPIntegrationTestConstants.RELATIVE_PATH_TO_TEST_ARTIFACTS + testCaseFolderName + File.separator
            + resourceFileName;/*from   ww  w  .ja  v a  2s. com*/
    return relativeFilePath.replaceAll("[\\\\/]", Matcher.quoteReplacement(File.separator));
}

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

public String getResourceFilePath(String testCaseFolderName, String resourceFileName) {
    String relativeFilePath = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator
            + "ESB" + File.separator + testCaseFolderName + File.separator + resourceFileName;
    return relativeFilePath.replaceAll("[\\\\/]", Matcher.quoteReplacement(File.separator));
}

From source file:fr.paris.lutece.plugins.extend.service.content.ExtendableContentPostProcessor.java

/**
 * {@inheritDoc}//  w w  w . ja va  2  s .  co m
 */
@Override
public String process(HttpServletRequest request, String strContent) {
    String strHtmlContent = strContent;

    // Check if the process is carried out in client or server side
    boolean bClientSide = Boolean.valueOf(AppPropertiesService.getProperty(PROPERTY_CLIENT_SIDE, "false"));

    if (bClientSide) {
        // CLIENT SIDE
        int nPos = strHtmlContent.indexOf(END_BODY);

        if (nPos < 0) {
            AppLogService.error("ExtendableContentPostProcessor Service : no BODY end tag found");

            return strHtmlContent;
        }

        Map<String, Object> model = new HashMap<String, Object>();
        model.put(MARK_BASE_URL, AppPathService.getBaseUrl(request));
        model.put(MARK_REGEX_PATTERN, _strRegexPattern);

        HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_CONTENT_POST_PROCESSOR,
                request.getLocale(), model);

        StringBuilder sb = new StringBuilder();
        sb.append(strHtmlContent.substring(0, nPos));
        sb.append(template.getHtml());
        sb.append(strHtmlContent.substring(nPos));
        strHtmlContent = sb.toString();
    } else {
        // SERVER SIDE

        /**
         * Replace all makers @Extender[<idResource>,<resourceType>,<extenderType>,<params>]@ to
         * the correct HTML content of the extender.
         * 1) First parse the content of the markers
         * 2) Get all information (idResource, resourceType, extenderType, params)
         * 3) Get the html content from the given information
         * 4) Replace the markers by the html content
         */

        // 1) First parse the content of the markers
        Matcher match = _regexPattern.matcher(strHtmlContent);
        Matcher parameterMatch = null;
        StringBuffer strResultHTML = new StringBuffer(strHtmlContent.length());
        while (match.find()) {
            String strMarker = match.group();

            // 2) Get all information (idResource, resourceType, extenderType, params)
            ResourceExtenderDTO resourceExtender = _mapper.map(match.group(1));
            boolean bParameteredId = StringUtils.equalsIgnoreCase(resourceExtender.getIdExtendableResource(),
                    EXTEND_PARAMETERED_ID);

            if (bParameteredId) {
                if (parameterMatch == null) {
                    parameterMatch = _extendedParameterRegexPattern.matcher(strHtmlContent);
                } else {
                    parameterMatch.reset();
                }

                while (parameterMatch.find()) {
                    ResourceExtenderDTO realResourceExtender = _mapper.map(parameterMatch.group(1));

                    if (StringUtils.equals(realResourceExtender.getExtendableResourceType(),
                            resourceExtender.getExtendableResourceType())
                            && StringUtils.equals(realResourceExtender.getExtenderType(),
                                    resourceExtender.getExtenderType())) {
                        resourceExtender
                                .setIdExtendableResource(realResourceExtender.getIdExtendableResource());

                        break;
                    }
                }
            }

            String strHtml = StringUtils.EMPTY;

            if (!bParameteredId || !StringUtils.equalsIgnoreCase(resourceExtender.getIdExtendableResource(),
                    EXTEND_PARAMETERED_ID)) {
                // 3) Get the html content from the given information
                if (!StringUtils.equals(resourceExtender.getExtendableResourceType(), Page.RESOURCE_TYPE)
                        || (StringUtils.isBlank(request.getParameter(PARAM_PAGE))
                                && StringUtils.isBlank(request.getParameter(PARAM_PORTLET_ID)))) {
                    strHtml = _extenderService.getContent(resourceExtender.getIdExtendableResource(),
                            resourceExtender.getExtendableResourceType(), resourceExtender.getExtenderType(),
                            resourceExtender.getParameters(), request);
                }
            }

            // 4) Replace the markers by the html content
            match.appendReplacement(strResultHTML, Matcher.quoteReplacement(strHtml));
        }
        match.appendTail(strResultHTML);
        strHtmlContent = strResultHTML.toString();
    }

    if (StringUtils.isNotBlank(_strExtenderParameterRegexPattern)) {
        strHtmlContent = _extendedParameterRegexPattern.matcher(strHtmlContent).replaceAll("");
    }

    return strHtmlContent;
}

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

@Test
public void test_Controller_Shortcuts() throws IOException {
    String commonPath = "src/main/resources/shortcuts/sandbox/apsadmin".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.wso2.identity.integration.test.analytics.commons.ThriftServer.java

public String getResourceFilePath(String testCaseFolderName, String resourceFileName) {
    String relativeFilePath = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator
            + "IS" + File.separator + "analytics" + File.separator + testCaseFolderName + File.separator
            + resourceFileName;/*from   w  w w.  j a va 2s .  c  o m*/
    return relativeFilePath.replaceAll("[\\\\/]", Matcher.quoteReplacement(File.separator));
}

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditN3GeneratorVTwo.java

protected String subInNonBracketedURIS(String var, String value, String target) {
    /* var followed by dot some whitespace OR var followed by whitespace OR at end of line*/
    String varRegex = "\\?" + var + "(?=\\p{Punct}|\\p{Space}|$)";
    String out = null;/*  w w w  .  j a va  2  s . c om*/
    if ("".equals(value))
        return target.replaceAll(varRegex, ">::" + var + " was BLANK::< ");
    else {
        String replaceWith = Matcher.quoteReplacement(value);
        return target.replaceAll(varRegex, replaceWith);
    }
}

From source file:com.cubusmail.mail.text.MessageTextUtil.java

/**
 * Convert a plaint text to html.//w  ww  .j ava2 s  . c o m
 * 
 * @param plainText
 * @return
 */
public static String convertPlainText2Html(String plainText, MessageTextMode mode) {

    try {
        plainText = HtmlUtils.htmlEscape(plainText).replaceAll(REPL_LINEBREAK, HTML_BR);

        final Matcher m = PATTERN_HREF.matcher(plainText);
        final StringBuffer sb = new StringBuffer(plainText.length());
        final StringBuilder tmp = new StringBuilder(256);
        while (m.find()) {
            final String nonHtmlLink = m.group(1);
            if ((nonHtmlLink == null) || (hasSrcAttribute(plainText, m.start(1)))) {
                m.appendReplacement(sb, Matcher.quoteReplacement(checkTarget(m.group())));
            } else {
                tmp.setLength(0);
                m.appendReplacement(sb, tmp.append("<a href=\"").append(
                        (nonHtmlLink.startsWith("www") || nonHtmlLink.startsWith("news") ? "http://" : ""))
                        .append("$1\" target=\"_blank\">$1</a>").toString());
            }
        }
        m.appendTail(sb);

        if (mode == MessageTextMode.DISPLAY) {
            sb.insert(0, "<p style=\"font-family: monospace; font-size: 10pt;\">");
            sb.append("</p>");
        }

        return sb.toString();
    } catch (final Exception e) {
        log.error(e.getMessage(), e);
    } catch (final StackOverflowError error) {
        log.error(StackOverflowError.class.getName(), error);
    }

    return plainText;
}

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

@Test
public void test_Controller_Shortcuts() throws IOException {
    String commonPath = "src/main/resources/shortcuts/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);
}