Java Code Examples for java.util.regex.Matcher#pattern()

The following examples show how to use java.util.regex.Matcher#pattern() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContextualPatch.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void parseNormalRange(Hunk hunk, Matcher m) {
    if (m.pattern() == normalAddRangePattern) {
        hunk.baseStart = Integer.parseInt(m.group(1));
        hunk.baseCount = 0;
        hunk.modifiedStart = Integer.parseInt(m.group(2));
        hunk.modifiedCount = Integer.parseInt(m.group(3)) - hunk.modifiedStart + 1;
    } else if (m.pattern() == normalDeleteRangePattern) {
        hunk.baseStart = Integer.parseInt(m.group(1));
        hunk.baseCount = Integer.parseInt(m.group(2)) - hunk.baseStart + 1;
        hunk.modifiedStart = Integer.parseInt(m.group(3));
        hunk.modifiedCount = 0;
    } else {
        hunk.baseStart = Integer.parseInt(m.group(1));
        if (m.group(3) != null) {
            hunk.baseCount = Integer.parseInt(m.group(3)) - hunk.baseStart + 1;
        } else {
            hunk.baseCount = 1;
        }
        hunk.modifiedStart = Integer.parseInt(m.group(4));
        if (m.group(6) != null) {
            hunk.modifiedCount = Integer.parseInt(m.group(6)) - hunk.modifiedStart + 1;
        } else {
            hunk.modifiedCount = 1;
        }
    }
}
 
Example 2
Source File: PatchFile.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void parseNormalRange(Hunk hunk, Matcher m) {
    if (m.pattern() == normalAddRangePattern) {
        hunk.baseStart = Integer.parseInt(m.group(1));
        hunk.baseCount = 0;
        hunk.modifiedStart = Integer.parseInt(m.group(2));
        hunk.modifiedCount = Integer.parseInt(m.group(3))
                - hunk.modifiedStart + 1;
    } else if (m.pattern() == normalDeleteRangePattern) {
        hunk.baseStart = Integer.parseInt(m.group(1));
        hunk.baseCount = Integer.parseInt(m.group(2)) - hunk.baseStart
                + 1;
        hunk.modifiedStart = Integer.parseInt(m.group(3));
        hunk.modifiedCount = 0;
    } else {
        hunk.baseStart = Integer.parseInt(m.group(1));
        if (m.group(3) != null) {
            hunk.baseCount = Integer.parseInt(m.group(3))
                    - hunk.baseStart
                    + 1;
        } else {
            hunk.baseCount = 1;
        }
        hunk.modifiedStart = Integer.parseInt(m.group(4));
        if (m.group(6) != null) {
            hunk.modifiedCount = Integer.parseInt(m.group(6))
                    - hunk.modifiedStart + 1;
        } else {
            hunk.modifiedCount = 1;
        }
    }
}
 
Example 3
Source File: BCSMessageParser.java    From banking-swift-messages-java with MIT License 5 votes vote down vote up
public BCSMessage parseMessage(String messageText) throws BCSMessageParseException {
    // join multiline to one line
    String oneLineMessageText = messageText.replaceAll("\\n", "");
    Matcher matcher = BUSINESS_TRANSACTION_CODE_PATTERN.matcher(oneLineMessageText);
    if (!matcher.matches()) {
        throw new BCSMessageParseException("messageText " + messageText + " didn't match " + matcher.pattern());
    }
    String messageBTC = matcher.group(1);
    String messageContent = matcher.group(2);

    Map<String, String> messageFieldMap = new HashMap<>();

    int parseIndex = 0;
    Matcher messageFieldMatcher = FIELD_PATTERN.matcher(messageContent);
    while (messageFieldMatcher.region(parseIndex, messageContent.length()).find()) {
        parseIndex = messageFieldMatcher.end();
        String fieldId = messageFieldMatcher.group(2);
        String fieldContent = messageFieldMatcher.group(3);
        if(messageFieldMap.containsKey(fieldId)){
            throw new BCSMessageParseException("duplicate field " + fieldId);
        }

        messageFieldMap.put(fieldId, fieldContent);
    }

    if (parseIndex != messageContent.length()) {
        throw new BCSMessageParseException("unparsed message part " + messageContent.substring(parseIndex));
    }

    return new BCSMessage(messageBTC, messageFieldMap);

}
 
Example 4
Source File: Path.java    From olat with Apache License 2.0 4 votes vote down vote up
/**
 * Read all parameters from the matched path.
 * 
 * @param match
 */
private void getParameters(final Matcher match) {
    final Pattern pattern = match.pattern();
    if (feedPattern.equals(pattern)) {
        // {feedId}/feed.rss
        type = FEED;
        feedId = Long.parseLong(match.group(1));
        // The feed file name is constant, hence not needed
    } else if (feedMediaPattern.equals(pattern)) {
        // {feedId}/icon.jpg
        type = FEED_MEDIA;
        feedId = Long.parseLong(match.group(1));
        iconFileName = match.group(2);
    } else if (itemMediaPattern.equals(pattern)) {
        // {feedId}/{itemId}/ruby.mp3
        type = ITEM_MEDIA;
        feedId = Long.parseLong(match.group(1));
        setItemId(match.group(2));
        itemFileName = match.group(3);

    } else if (authFeedPattern.equals(pattern)) {
        // {identityKey}/{token}/{feedId}/feed.rss
        type = AUTHENTICATED_FEED;
        identityKey = Long.parseLong(match.group(1));
        token = match.group(2);
        feedId = Long.parseLong(match.group(3));
    } else if (authFeedMediaPattern.equals(pattern)) {
        // {identityKey}/{token}/{feedId}/icon.jpg
        type = AUTHENTICATED_FEED_MEDIA;
        identityKey = Long.parseLong(match.group(1));
        token = match.group(2);
        feedId = Long.parseLong(match.group(3));
        iconFileName = match.group(4);
    } else if (authItemMediaPattern.equals(pattern)) {
        // {identityKey}/{token}/{feedId}/{itemId}/ruby.mp3
        type = AUTHENTICATED_ITEM_MEDIA;
        identityKey = Long.parseLong(match.group(1));
        token = match.group(2);
        feedId = Long.parseLong(match.group(3));
        setItemId(match.group(4));
        itemFileName = match.group(5);

    } else if (courseFeedPattern.equals(pattern)) {
        // coursenode/{courseId}/{nodeId}/{feedId}/feed.rss
        type = COURSE_FEED;
        courseId = Long.parseLong(match.group(1));
        nodeId = match.group(2);
        feedId = Long.parseLong(match.group(3));
    } else if (courseFeedMediaPattern.equals(pattern)) {
        // coursenode/{courseId}/{nodeId}/{feedId}/icon.jpg
        type = COURSE_FEED_MEDIA;
        courseId = Long.parseLong(match.group(1));
        nodeId = match.group(2);
        feedId = Long.parseLong(match.group(3));
        iconFileName = match.group(4);
    } else if (courseItemMediaPattern.equals(pattern)) {
        // coursenode/{courseId}/{nodeId}/{feedId}/{itemId}/ruby.mp3
        type = COURSE_ITEM_MEDIA;
        courseId = Long.parseLong(match.group(1));
        nodeId = match.group(2);
        feedId = Long.parseLong(match.group(3));
        setItemId(match.group(4));
        itemFileName = match.group(5);

    } else if (authCourseFeedPattern.equals(pattern)) {
        // coursenode/{identityKey}/{token}/{courseId}/{nodeId}/{feedId}/feed.rss
        type = AUTHENTICATED_COURSE_FEED;
        identityKey = Long.parseLong(match.group(1));
        token = match.group(2);
        courseId = Long.parseLong(match.group(3));
        nodeId = match.group(4);
        feedId = Long.parseLong(match.group(5));
    } else if (authCourseFeedMediaPattern.equals(pattern)) {
        // coursenode/{identityKey}/{token}/{courseId}/{nodeId}/{feedId}/icon.jpg
        type = AUTHENTICATED_COURSE_ICON;
        identityKey = Long.parseLong(match.group(1));
        token = match.group(2);
        courseId = Long.parseLong(match.group(3));
        nodeId = match.group(4);
        feedId = Long.parseLong(match.group(5));
        iconFileName = match.group(6);
    } else if (authCourseItemMediaPattern.equals(pattern)) {
        // coursenode/{identityKey}/{token}/{courseId}/{nodeId}/{feedId}/{itemId}/ruby.mp3
        type = AUTHENTICATED_COURSE_ITEM;
        identityKey = Long.parseLong(match.group(1));
        token = match.group(2);
        courseId = Long.parseLong(match.group(3));
        nodeId = match.group(4);
        feedId = Long.parseLong(match.group(5));
        setItemId(match.group(6));
        itemFileName = match.group(7);
    }
}
 
Example 5
Source File: Path.java    From olat with Apache License 2.0 4 votes vote down vote up
/**
 * Read all parameters from the matched path.
 * 
 * @param match
 */
private void getParameters(final Matcher match) {
    final Pattern pattern = match.pattern();
    if (feedPattern.equals(pattern)) {
        // {feedId}/feed.rss
        type = FEED;
        feedId = Long.parseLong(match.group(1));
        // The feed file name is constant, hence not needed
    } else if (feedMediaPattern.equals(pattern)) {
        // {feedId}/icon.jpg
        type = FEED_MEDIA;
        feedId = Long.parseLong(match.group(1));
        iconFileName = match.group(2);
    } else if (itemMediaPattern.equals(pattern)) {
        // {feedId}/{itemId}/ruby.mp3
        type = ITEM_MEDIA;
        feedId = Long.parseLong(match.group(1));
        setItemId(match.group(2));
        itemFileName = match.group(3);

    } else if (authFeedPattern.equals(pattern)) {
        // {identityKey}/{token}/{feedId}/feed.rss
        type = AUTHENTICATED_FEED;
        identityKey = Long.parseLong(match.group(1));
        token = match.group(2);
        feedId = Long.parseLong(match.group(3));
    } else if (authFeedMediaPattern.equals(pattern)) {
        // {identityKey}/{token}/{feedId}/icon.jpg
        type = AUTHENTICATED_FEED_MEDIA;
        identityKey = Long.parseLong(match.group(1));
        token = match.group(2);
        feedId = Long.parseLong(match.group(3));
        iconFileName = match.group(4);
    } else if (authItemMediaPattern.equals(pattern)) {
        // {identityKey}/{token}/{feedId}/{itemId}/ruby.mp3
        type = AUTHENTICATED_ITEM_MEDIA;
        identityKey = Long.parseLong(match.group(1));
        token = match.group(2);
        feedId = Long.parseLong(match.group(3));
        setItemId(match.group(4));
        itemFileName = match.group(5);

    } else if (courseFeedPattern.equals(pattern)) {
        // coursenode/{courseId}/{nodeId}/{feedId}/feed.rss
        type = COURSE_FEED;
        courseId = Long.parseLong(match.group(1));
        nodeId = match.group(2);
        feedId = Long.parseLong(match.group(3));
    } else if (courseFeedMediaPattern.equals(pattern)) {
        // coursenode/{courseId}/{nodeId}/{feedId}/icon.jpg
        type = COURSE_FEED_MEDIA;
        courseId = Long.parseLong(match.group(1));
        nodeId = match.group(2);
        feedId = Long.parseLong(match.group(3));
        iconFileName = match.group(4);
    } else if (courseItemMediaPattern.equals(pattern)) {
        // coursenode/{courseId}/{nodeId}/{feedId}/{itemId}/ruby.mp3
        type = COURSE_ITEM_MEDIA;
        courseId = Long.parseLong(match.group(1));
        nodeId = match.group(2);
        feedId = Long.parseLong(match.group(3));
        setItemId(match.group(4));
        itemFileName = match.group(5);

    } else if (authCourseFeedPattern.equals(pattern)) {
        // coursenode/{identityKey}/{token}/{courseId}/{nodeId}/{feedId}/feed.rss
        type = AUTHENTICATED_COURSE_FEED;
        identityKey = Long.parseLong(match.group(1));
        token = match.group(2);
        courseId = Long.parseLong(match.group(3));
        nodeId = match.group(4);
        feedId = Long.parseLong(match.group(5));
    } else if (authCourseFeedMediaPattern.equals(pattern)) {
        // coursenode/{identityKey}/{token}/{courseId}/{nodeId}/{feedId}/icon.jpg
        type = AUTHENTICATED_COURSE_ICON;
        identityKey = Long.parseLong(match.group(1));
        token = match.group(2);
        courseId = Long.parseLong(match.group(3));
        nodeId = match.group(4);
        feedId = Long.parseLong(match.group(5));
        iconFileName = match.group(6);
    } else if (authCourseItemMediaPattern.equals(pattern)) {
        // coursenode/{identityKey}/{token}/{courseId}/{nodeId}/{feedId}/{itemId}/ruby.mp3
        type = AUTHENTICATED_COURSE_ITEM;
        identityKey = Long.parseLong(match.group(1));
        token = match.group(2);
        courseId = Long.parseLong(match.group(3));
        nodeId = match.group(4);
        feedId = Long.parseLong(match.group(5));
        setItemId(match.group(6));
        itemFileName = match.group(7);
    }
}
 
Example 6
Source File: IRtransGenericBindingProvider.java    From openhab1-addons with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Parses the binding config.
 *
 * @param config the config
 * @param item the item
 * @param bindingConfig the binding config
 * @throws BindingConfigParseException the binding config parse exception
 */
private void parseBindingConfig(IRtransBindingConfig config, Item item, String bindingConfig)
        throws BindingConfigParseException {

    String commandAsString = null;
    String host = null;
    String port = null;
    String led = null;
    String remote = null;
    String irCommand = null;
    Leds ledType = Leds.DEFAULT;

    if (bindingConfig != null) {

        Matcher actionMatcher = ACTION_CONFIG_PATTERN.matcher(bindingConfig);
        Matcher statusMatcher = STATUS_CONFIG_PATTERN.matcher(bindingConfig);

        if ((!actionMatcher.matches() && !statusMatcher.matches())) {
            throw new BindingConfigParseException(
                    getBindingType() + " binding configuration must consist of five [config="
                            + statusMatcher.pattern() + "] or six parts [config=" + actionMatcher.pattern() + "]");
        } else {
            if (actionMatcher.matches()) {
                commandAsString = actionMatcher.group(1);
                host = actionMatcher.group(2);
                port = actionMatcher.group(3);
                led = actionMatcher.group(4);
                remote = actionMatcher.group(5);
                irCommand = actionMatcher.group(6);
            } else if (statusMatcher.matches()) {
                host = statusMatcher.group(1);
                port = statusMatcher.group(2);
                led = statusMatcher.group(3);
                remote = statusMatcher.group(4);
                irCommand = statusMatcher.group(5);
            }

            if (led.equals("*")) {
                ledType = Leds.ALL;
            } else {
                ledType = Leds.valueOf(led);
            }

            IRtransBindingConfigElement newElement = new IRtransBindingConfigElement(host, port, ledType, remote,
                    irCommand, item.getAcceptedDataTypes());

            Command command = null;
            if (commandAsString == null) {
                // for those configuration strings that are not really linked to a openHAB command we
                // create a dummy Command to be able to store the configuration information
                // I have choosen to do that with NumberItems
                NumberItem dummy = new NumberItem(Integer.toString(counter));
                command = createCommandFromString(dummy, Integer.toString(counter));
                counter++;
                config.put(command, newElement);
            } else {
                command = createCommandFromString(item, commandAsString);
                config.put(command, newElement);
            }

            config.put(command, newElement);

        }
    } else {
        return;
    }

}