Example usage for java.util.regex Pattern MULTILINE

List of usage examples for java.util.regex Pattern MULTILINE

Introduction

In this page you can find the example usage for java.util.regex Pattern MULTILINE.

Prototype

int MULTILINE

To view the source code for java.util.regex Pattern MULTILINE.

Click Source Link

Document

Enables multiline mode.

Usage

From source file:com.groupon.jenkins.buildtype.util.shell.ShellCommands.java

public Pattern regexp(String re) {
    final int n = re.length() - 1;
    final int flags = Pattern.UNIX_LINES | Pattern.MULTILINE;
    if (re.charAt(0) != '^') {
        re = ".*" + re;
    }/*w  w  w .j  a v a2 s  .c  o  m*/
    if (re.charAt(n) != '$') {
        re = re + ".*";
    }
    return Pattern.compile(re, flags);
}

From source file:com.edgenius.wiki.render.filter.ImageFilter.java

public void init() {
    regexProvider.compile(getRegex(), Pattern.MULTILINE);
}

From source file:com.edgenius.wiki.render.filter.MacroFilter.java

public void init() {

    pairedMacroProvider.compile(FilterRegxConstants.PAIRED_MACRO, Pattern.DOTALL);
    singleMacroProvider.compile(FilterRegxConstants.SINGLE_MACRO, Pattern.MULTILINE);
    Collection<Macro> list = macroMgr.getImmutableContentMacros();
    for (Macro macro : list) {
        String identifier = macro.getHTMLIdentifier();
        immutableHTMLIds.addAll(RenderUtil.parseHtmlIdentifier(identifier));
    }/*from  www .  j  a  v a2s.  c  om*/

}

From source file:org.apache.zookeeper.server.persistence.TxnLogToolkitTest.java

@Test
public void testDumpWithCrcError() throws Exception {
    // Arrange//from w w  w  . j  a  v  a  2  s  . c  om
    File logfile = new File(new File(mySnapDir, "version-2"), "log.42");
    TxnLogToolkit lt = new TxnLogToolkit(false, false, logfile.toString(), true);

    // Act
    lt.dump(null);

    // Assert
    String output = outContent.toString();
    Pattern p = Pattern.compile(
            "^CRC ERROR.*session 0x8061fac5ddeb0000 cxid 0x0 zxid 0x8800000002 createSession 30000$",
            Pattern.MULTILINE);
    Matcher m = p.matcher(output);
    assertTrue("Output doesn't indicate CRC error for the broken session id: " + output, m.find());
}

From source file:com.qualinsight.plugins.sonarqube.smell.plugin.extension.SmellMeasurer.java

private Map<SmellType, Integer> parseAnnotations(final String fileContent) {
    final Pattern pattern = Pattern.compile(SMELL_ANNOTATION_TYPE_DETECTION_REGULAR_EXPRESSION,
            Pattern.MULTILINE);
    final Matcher matcher = pattern.matcher(fileContent);
    final Map<SmellType, Integer> fileMeasures = new EnumMap<>(SmellType.class);
    while (matcher.find()) {
        final SmellType type = SmellType.valueOf(matcher.group(3));
        if (fileMeasures.containsKey(type)) {
            fileMeasures.put(type, fileMeasures.get(type) + 1);
        } else {/* www. j  a va2  s .  c  o  m*/
            fileMeasures.put(type, 1);
        }
    }
    return fileMeasures;
}

From source file:Normalization.TextNormalization.java

public String removeSymbolsFromString(String content) {

    String utf8tweet = "";
    try {/*  w w  w.  j a v  a2 s.  c  o  m*/
        byte[] utf8Bytes = content.getBytes("UTF-8");

        utf8tweet = new String(utf8Bytes, "UTF-8");
    } catch (UnsupportedEncodingException e) {
    }

    final String regex = "[\\./\\()\"':,.;<>~!$%^&*\\|+={}?\\-`1234567890_]";
    final Pattern unicodeOutliers = Pattern.compile(regex,
            Pattern.MULTILINE | Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);

    Matcher unicodeOutlierMatcher = unicodeOutliers.matcher(utf8tweet);
    utf8tweet = unicodeOutlierMatcher.replaceAll(" ");
    return utf8tweet;
}

From source file:net.palette_software.pet.restart.HelperHttpClient.java

static List<BalancerManagerManagedWorker> getWorkersFromHtml(String body, String clusterName,
        String jmxObjectName) throws Exception {

    String regex;/*  ww  w. j av  a  2 s .co  m*/
    Pattern p;
    String nonce = "";
    String[] bodySlpit;
    Matcher m;
    int jmxPort;

    //search for the cluster's nonce string
    regex = "<h3>.*&nonce=([^\"]+)\">balancer://" + clusterName + "</a>.*";
    p = Pattern.compile(regex, Pattern.MULTILINE | Pattern.DOTALL);
    bodySlpit = body.split("\n");
    for (String s : bodySlpit) {
        m = p.matcher(s);
        if (m.matches()) {
            nonce = m.group(1);
            break;
        }
    }

    if (nonce.equals("")) {
        throw new Exception("Cannot found the worker load balancer in balancer-manager");
    }

    List<BalancerManagerManagedWorker> workers = new ArrayList<>();

    //Search for the Workers' name
    for (String s : bodySlpit) {
        regex = "<td><a href=\"/balancer-manager\\?b=" + clusterName + "&w=([^&]+)&nonce=" + nonce
                + "[^<]*</a></td><td>([^<]+)?.*";
        p = Pattern.compile(regex, Pattern.MULTILINE | Pattern.DOTALL);
        m = p.matcher(s);
        if (m.matches()) {
            String memberName = m.group(1);
            String route = m.group(2);

            regex = ".*:([0-9]+)";
            p = Pattern.compile(regex, Pattern.MULTILINE | Pattern.DOTALL);
            m = p.matcher(memberName);

            if (!m.matches()) {
                throw new Exception("Cannot found the workers' port");
            }

            //check the jmx ports if we need it
            if (!CliControl.FORCE_RESTARTS && !Objects.equals(jmxObjectName, "")) {

                //calculate JMX port
                jmxPort = Integer.parseInt(m.group(1)) + 300;

                //check if port exists
                try (HelperJmxClient jmxClient = new HelperJmxClient()) {

                    int count = 0;
                    String error = "";
                    while (count++ < 3) {
                        String jMXServiceURL = "service:jmx:rmi:///jndi/rmi://:" + jmxPort + "/jmxrmi";
                        jmxClient.connectService(jMXServiceURL);
                        if (!jmxClient.checkBeanExists(jmxObjectName)) {
                            error = "Cannot found the required MBean " + jMXServiceURL + ":" + jmxObjectName;
                            HelperLogger.loggerStdOut.info(
                                    error + "\nRetrying after " + CliControl.WAIT_AFTER_ERROR + " seconds...");
                            CliControl.sleep(CliControl.WAIT_AFTER_ERROR);
                        } else {
                            error = "";
                            break;
                        }
                    }
                    if (!Objects.equals(error, "")) {
                        throw new Exception(error);
                    }

                }
            } else {
                jmxPort = -1;
            }

            //add Worker into workers
            if (Objects.equals(clusterName, "vizqlserver-cluster")) {
                workers.add(new WorkerVizql(memberName, route, nonce, jmxPort));
            } else if (Objects.equals(clusterName, "dataserver-cluster")) {
                workers.add(new WorkerDataServer(memberName, route, nonce, jmxPort));
            } else if (Objects.equals(clusterName, "local-vizportal")) {
                workers.add(new WorkerVizportal(memberName, route, nonce, jmxPort));
            }
        }
    }
    return workers;
}

From source file:org.jbpm.designer.web.server.CalledElementServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String profileName = Utils.getDefaultProfileName(req.getParameter("profile"));
    String processPackage = req.getParameter("ppackage");
    String processId = req.getParameter("pid");
    String action = req.getParameter("action");

    if (profile == null) {
        profile = _profileService.findProfile(req, profileName);
    }/*from  w ww.j a v a 2s . c om*/
    if (action != null && action.equals("openprocessintab")) {
        String retValue = "";
        List<String> allPackageNames = ServletUtil.getPackageNamesFromRepository(profile);
        if (allPackageNames != null && allPackageNames.size() > 0) {
            for (String packageName : allPackageNames) {
                List<String> allProcessesInPackage = ServletUtil.getAllProcessesInPackage(packageName, profile);
                if (allProcessesInPackage != null && allProcessesInPackage.size() > 0) {
                    for (String p : allProcessesInPackage) {
                        Asset<String> processContent = ServletUtil.getProcessSourceContent(p, profile);
                        Pattern idPattern = Pattern.compile("<\\S*process[^\"]+id=\"([^\"]+)\"",
                                Pattern.MULTILINE);
                        Matcher idMatcher = idPattern.matcher(processContent.getAssetContent());
                        if (idMatcher.find()) {
                            String pid = idMatcher.group(1);
                            String pidcontent = ServletUtil.getProcessImageContent(packageName, pid, profile);
                            if (pid != null && pid.equals(processId)) {
                                String uniqueId = processContent.getUniqueId();
                                if (Base64.isBase64(uniqueId)) {
                                    byte[] decoded = Base64.decodeBase64(uniqueId);
                                    try {
                                        uniqueId = new String(decoded, "UTF-8");
                                    } catch (UnsupportedEncodingException e) {
                                        e.printStackTrace();
                                    }
                                }
                                retValue = processContent.getName() + "." + processContent.getAssetType() + "|"
                                        + uniqueId;
                                break;
                            }
                        }
                    }
                }
            }
        }
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/plain");
        resp.getWriter().write(retValue);
    } else if (action != null && action.equals("showruleflowgroups")) {
        //Query for RuleFlowGroups
        final List<RefactoringPageRow> results = queryService.query("FindRuleFlowNamesQuery",
                new HashSet<ValueIndexTerm>() {
                    {
                        add(new ValueRuleAttributeIndexTerm("ruleflow-group"));
                        add(new ValueRuleAttributeValueIndexTerm("*"));
                    }
                }, true);

        final List<String> ruleFlowGroupNames = new ArrayList<String>();
        for (RefactoringPageRow row : results) {
            ruleFlowGroupNames.add((String) row.getValue());
        }
        Collections.sort(ruleFlowGroupNames);

        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json");
        resp.getWriter().write(getRuleFlowGroupsInfoAsJSON(ruleFlowGroupNames).toString());

    } else if (action != null && action.equals("showdatatypes")) {
        final List<RefactoringPageRow> results2 = queryService.query("DesignerFindTypesQuery",
                new HashSet<ValueIndexTerm>() {
                    {
                        add(new ValueTypeIndexTerm("*"));
                    }
                }, true);
        final List<String> dataTypeNames = new ArrayList<String>();
        for (RefactoringPageRow row : results2) {
            dataTypeNames.add((String) row.getValue());
        }
        Collections.sort(dataTypeNames);
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json");
        resp.getWriter().write(getDataTypesInfoAsJSON(dataTypeNames).toString());
    } else {
        String retValue = "false";
        List<String> allPackageNames = ServletUtil.getPackageNamesFromRepository(profile);
        Map<String, String> processInfo = new HashMap<String, String>();
        if (allPackageNames != null && allPackageNames.size() > 0) {
            for (String packageName : allPackageNames) {
                List<String> allProcessesInPackage = ServletUtil.getAllProcessesInPackage(packageName, profile);
                if (allProcessesInPackage != null && allProcessesInPackage.size() > 0) {
                    for (String p : allProcessesInPackage) {
                        Asset<String> processContent = ServletUtil.getProcessSourceContent(p, profile);
                        Pattern idPattern = Pattern.compile("<\\S*process[^\"]+id=\"([^\"]+)\"",
                                Pattern.MULTILINE);
                        Matcher idMatcher = idPattern.matcher(processContent.getAssetContent());
                        if (idMatcher.find()) {
                            String pid = idMatcher.group(1);
                            String pidcontent = ServletUtil
                                    .getProcessImageContent(processContent.getAssetLocation(), pid, profile);
                            if (pid != null && !(packageName.equals(processPackage) && pid.equals(processId))) {
                                processInfo.put(pid + "|" + processContent.getAssetLocation(),
                                        pidcontent != null ? pidcontent : "");
                            }
                        }
                    }

                }
            }
        }
        retValue = getProcessInfoAsJSON(processInfo).toString();
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json");
        resp.getWriter().write(retValue);
    }
}

From source file:pl.otros.logview.gui.message.pattern.PropertyPatternMessageColorizer.java

public void init(InputStream in) throws ConfigurationException {
    propertiesConfiguration = new PropertiesConfiguration();
    propertiesConfiguration.setDelimiterParsingDisabled(true);
    propertiesConfiguration.load(in, "UTF-8");
    configuration = new DataConfiguration(propertiesConfiguration);
    configuration.setDelimiterParsingDisabled(true);
    String pa = configuration.getString(PROP_PATTERN);
    int flags = 0;
    flags = flags | (configuration.getBoolean(PROP_PATTERN_CANON_EQ, false) ? Pattern.CANON_EQ : 0);
    flags = flags// w w  w.  ja  v  a  2 s  .  c o  m
            | (configuration.getBoolean(PROP_PATTERN_CASE_INSENSITIVE, false) ? Pattern.CASE_INSENSITIVE : 0);
    flags = flags | (configuration.getBoolean(PROP_PATTERN_COMMENTS, false) ? Pattern.COMMENTS : 0);
    flags = flags | (configuration.getBoolean(PROP_PATTERN_DOTALL, false) ? Pattern.DOTALL : 0);
    flags = flags | (configuration.getBoolean(PROP_PATTERN_LITERAL, false) ? Pattern.LITERAL : 0);
    flags = flags | (configuration.getBoolean(PROP_PATTERN_MULTILINE, false) ? Pattern.MULTILINE : 0);
    flags = flags | (configuration.getBoolean(PROP_PATTERN_UNICODE_CASE, false) ? Pattern.UNICODE_CASE : 0);
    flags = flags | (configuration.getBoolean(PROP_PATTERN_UNIX_LINES, false) ? Pattern.UNIX_LINES : 0);

    pattern = Pattern.compile(pa, flags);
    groupCount = countGroups(pattern);
    name = configuration.getString(PROP_NAME, "NAME NOT SET!");
    description = configuration.getString(PROP_DESCRIPTION, "DESCRIPTION NOT SET!");
    testMessage = configuration.getString(PROP_TEST_MESSAGE, "");
    version = configuration.getInt(PROP_VERSION, 1);
}

From source file:de.ingrid.iplug.csw.dsc.cache.impl.AbstractUpdateStrategy.java

/**
 * Create a filter Document from a filter string. Replace any filter
 * variables. TODO: if there should be more variables, this could be done
 * more generic//  w  ww. j  a  va 2 s .c  o m
 * 
 * @param filterStr
 * @return Document
 * @throws Exception
 */
protected Document createFilterDocument(String filterStr) throws Exception {

    ExecutionContext context = this.getExecutionContext();

    if (this.docBuilder == null) {
        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        docBuilder = docBuilderFactory.newDocumentBuilder();
    }

    // replace last update date variable
    Pattern lastUpdateDatePattern = Pattern.compile("\\{LAST_UPDATE_DATE\\}", Pattern.MULTILINE);
    Matcher matcher = lastUpdateDatePattern.matcher(filterStr);
    if (matcher.find()) {
        Date lastUpdateDate = context.getLastExecutionDate();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        filterStr = matcher.replaceAll(df.format(lastUpdateDate));
    }

    return docBuilder.parse(new InputSource(new StringReader(filterStr)));
}