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:imdbplugin.ImdbParser.java

private int getFileSize(final String server) {
    final String[] fileNames = new String[] { "aka-titles", "ratings" };
    final Integer[] fileSizes = new Integer[] { 5950067, 5067908 };

    try {//from   ww w .  ja  va 2 s .  com

        int size = 0;
        final String filesizes = new String(IOUtilities.loadFileFromHttpServer(new URL(server + "filesizes")));

        for (int i = 0; i < fileNames.length; i++) {
            final Matcher m = Pattern.compile("^" + fileNames[i] + "\\.list\\W(\\d*)$", Pattern.MULTILINE)
                    .matcher(filesizes);

            if (m.find()) {
                size += Integer.parseInt(m.group(1));
            } else {
                size += fileSizes[i];
            }
        }
        return size;
    } catch (IOException e) {
        e.printStackTrace();
    }

    // if an exception occurred, return the default sizes
    int size = 0;
    for (int i = 0; i < fileSizes.length; i++) {
        size += fileSizes[i];
    }
    return size;
}

From source file:org.opennms.web.rest.AcknowledgmentRestServiceTest.java

@Test
@JUnitTemporaryDatabase/*  w  ww .j av a 2 s  .  co m*/
public void testAcknowlegeNotification() throws Exception {
    final Pattern p = Pattern.compile("^.*<answeredBy>(.*?)</answeredBy>.*$",
            Pattern.DOTALL & Pattern.MULTILINE);
    sendData(POST, MediaType.APPLICATION_FORM_URLENCODED, "/acks", "notifId=1&action=ack");
    String xml = sendRequest(GET, "/notifications/1", new HashMap<String, String>(), 200);
    Matcher m = p.matcher(xml);
    assertTrue(m.matches());
    assertTrue(m.group(1).equals("admin"));
    sendData(POST, MediaType.APPLICATION_FORM_URLENCODED, "/acks", "notifId=1&action=unack");
    xml = sendRequest(GET, "/notifications/1", new HashMap<String, String>(), 200);
    m = p.matcher(xml);
    assertFalse(m.matches());
}

From source file:net.sourceforge.jwbf.actions.mw.queries.GetImagelinkTitles.java

/**
 * gets the information about a follow-up page from a provided api response.
 * If there is one, a new request is added to msgs by calling generateRequest.
 *   /*from   w ww. j a v a 2s. com*/
 * @param s   text for parsing
 */
protected void parseHasMore(final String s) {

    System.out.println(s);

    // get the ilcontinue-value

    Pattern p = Pattern.compile(
            "<query-continue>.*?" + "<imageusage *iucontinue=\"([^\"]*)\" */>" + ".*?</query-continue>",
            Pattern.DOTALL | Pattern.MULTILINE);

    Matcher m = p.matcher(s);

    if (m.find()) {
        nextPageInfo = m.group(1);
    }

}

From source file:net.sourceforge.jwbf.actions.mw.queries.GetTemplateUserTitles.java

/**
 * gets the information about a follow-up page from a provided api response.
 * If there is one, a new request is added to msgs by calling generateRequest.
 *   //from   w  ww  .  j a  v  a 2  s . c  om
 * @param s   text for parsing
 */
protected void parseHasMore(final String s) {

    // get the eicontinue-value

    Pattern p = Pattern.compile(
            "<query-continue>.*?" + "<embeddedin *eicontinue=\"([^\"]*)\" */>" + ".*?</query-continue>",
            Pattern.DOTALL | Pattern.MULTILINE);

    Matcher m = p.matcher(s);

    if (m.find()) {
        nextPageInfo = m.group(1);
    }

}

From source file:com.logsniffer.event.publisher.MailPublisherTest.java

@Test
public void testMailPublishing() throws PublishException {
    final Event event = new Event();
    event.setId("3");
    event.setLogPath("path.log");
    event.setLogSourceId(7);//  w  w  w  .  j  a  v  a  2s . c  o m
    event.setSnifferId(5);
    final Map<String, Serializable> data = new HashMap<String, Serializable>();
    data.put("key1", "abc");
    data.put("key3", "def");
    event.putAll(data);
    final List<LogEntry> entries = new ArrayList<LogEntry>();
    final LogEntry e1 = new LogEntry();
    e1.setRawContent("e1");
    final LogEntry e2 = new LogEntry();
    e2.setRawContent("e2");
    entries.add(e1);
    entries.add(e2);
    event.setEntries(entries);

    mailPublisher.setSubject("Subject: $event.lf_entries[0].lf_raw");
    mailPublisher.setFrom("fromme $event");
    mailPublisher.setTo("tome$event,toyou");

    final MailPublisher clonePublisher = configManager.createBeanFromJSON(MailPublisher.class,
            configManager.saveBeanToJSON(mailPublisher));
    clonePublisher.publish(event);

    Mockito.verify(mailSender).send(Mockito.argThat(new BaseMatcher<SimpleMailMessage>() {

        @Override
        public boolean matches(final Object arg0) {
            final SimpleMailMessage mail = (SimpleMailMessage) arg0;
            if (!mail.getSubject().equals("Subject: " + e1.getRawContent())) {
                return false;
            }
            final Pattern textPattern = Pattern.compile(
                    "[^\n]+/c/sniffers/5/events/#/3\n\n" + "Log entries:\n" + "\\s*e1\n" + "\\s*e2\n\\s*",
                    Pattern.CASE_INSENSITIVE + Pattern.DOTALL + Pattern.MULTILINE);
            if (!textPattern.matcher(mail.getText()).matches()) {
                return false;
            }
            return mail.getFrom().equals("fromme $event") && mail.getTo().length == 2
                    && mail.getTo()[0].equals("tome$event") && mail.getTo()[1].equals("toyou");
        }

        @Override
        public void describeTo(final Description arg0) {
        }
    }));

}

From source file:de.ist.clonto.webwiki.InfoboxParser.java

private String replaceHTMLComments(String text) {
    text = Pattern.compile("<!--.*?-->", Pattern.MULTILINE | Pattern.DOTALL).matcher(text).replaceAll("");

    return text;/*from   w  w  w  . ja v a  2s.  c o  m*/
}

From source file:org.opennms.web.rest.v1.AcknowledgmentRestServiceIT.java

@Test
@JUnitTemporaryDatabase//from  w w w. ja  v a  2  s  . c  om
public void testAcknowlegeNotification() throws Exception {
    final Pattern p = Pattern.compile("^.*<answeredBy>(.*?)</answeredBy>.*$",
            Pattern.DOTALL & Pattern.MULTILINE);
    sendData(POST, MediaType.APPLICATION_FORM_URLENCODED, "/acks", "notifId=1&action=ack", 200);
    String xml = sendRequest(GET, "/notifications/1", new HashMap<String, String>(), 200);
    Matcher m = p.matcher(xml);
    assertTrue(m.matches());
    assertTrue(m.group(1).equals("admin"));
    sendData(POST, MediaType.APPLICATION_FORM_URLENCODED, "/acks", "notifId=1&action=unack", 200);
    xml = sendRequest(GET, "/notifications/1", new HashMap<String, String>(), 200);
    m = p.matcher(xml);
    assertFalse(m.matches());
}

From source file:org.openrdf.repository.sparql.query.SPARQLQuery.java

protected Set<String> getBindingNames() {
    if (bindings.size() == 0)
        return Collections.EMPTY_SET;
    Set<String> names = new HashSet<String>();
    String qry = query;/*  w  w  w .  j  ava 2 s.  c om*/
    int b = qry.indexOf('{');
    String select = qry.substring(0, b);
    for (String name : bindings.getBindingNames()) {
        String replacement = getReplacement(bindings.getValue(name));
        if (replacement != null) {
            String pattern = ".*[\\?\\$]" + name + "\\W.*";
            if (Pattern.compile(pattern, Pattern.MULTILINE | Pattern.DOTALL).matcher(select).matches()) {
                names.add(name);
            }
        }
    }
    return names;
}

From source file:com.andrada.sitracker.reader.SamlibAuthorPageReader.java

@Nullable
@Override//from ww w  .  j  av  a 2s.  c  om
public String getAuthorImageUrl(String authorUrl) {
    authorUrl = authorUrl.replace(Constants.AUTHOR_PAGE_URL_ENDING_WO_SLASH, "");
    authorUrl = authorUrl.replace(Constants.AUTHOR_PAGE_ALT_URL_ENDING_WO_SLASH, "");
    Pattern pattern = Pattern.compile(Constants.AUTHOR_IMAGE_REGEX, Pattern.MULTILINE);
    Matcher matcher = pattern.matcher(pageContent);
    String imageUrl = null;
    if (matcher.find()) {
        imageUrl = (matcher.group(2));
        if (imageUrl != null)
            imageUrl = authorUrl + imageUrl;
    }
    return imageUrl;
}

From source file:nl.esciencecenter.ptk.csv.CSVData.java

public void parseText(String csvText) throws IOException {
    // Extended CSV !
    // Pass I: remove comments including the ending newline!
    Pattern pat = Pattern.compile("^#.*\n", Pattern.MULTILINE);
    csvText = pat.matcher(csvText).replaceAll("");

    // todo: check how jackson can parse alternative field separators;
    if (fieldSeparators != null) {
        // csvText=csvText.replaceAll(",","_");

        for (String sep : fieldSeparators) {
            // lazy replace
            csvText = csvText.replaceAll(sep, ",");
        }/*from   ww  w  .  j  a  v  a2 s.c  o  m*/
    }

    // Not needed: Pass II: remove empty lines as a result of the
    // pat=Pattern.compile("\n\n",Pattern.MULTILINE);
    // newTxt=pat.matcher(newTxt).replaceAll("");

    // ObjectMapper mapper=new ObjectMapper();
    CsvMapper mapper = new CsvMapper();
    mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);

    MappingIterator<Object[]> it = mapper.reader(Object[].class).readValues(csvText);

    if (it.hasNext() == false) {
        throw new IOException("Empty text or csv text contains no headers!");
    }

    // read header:
    Object headers[] = it.next();

    StringList list = new StringList();
    for (int i = 0; i < headers.length; i++) {
        list.add(headers[i].toString());
    }

    logger.debugPrintf("Headers=%s\n", list.toString("<>"));
    headerList = list;

    data = new ArrayList<String[]>();

    // check header values.
    while (it.hasNext()) {
        Object line[] = it.next();
        String row[] = new String[line.length];

        for (int j = 0; j < line.length; j++) {
            Object value = line[j];
            if (value != null) {
                row[j] = value.toString();
            }
        }
        data.add(row);
    }

    logger.debugPrintf("Read %d number of rows\n", data.size());
}