Package org.jrdf.util.boundary

Examples of org.jrdf.util.boundary.RegexMatcher


            throw new RuntimeException(e);
        }
    }

    public void parseLine(String line) {
        final RegexMatcher startMolecule = regexMatcherFactory.createMatcher(START_MOLECULE, line);
        if (startMolecule.matches()) {
            handleStartMolecule();
        } else {
            final RegexMatcher tripleMatcher = regexMatcherFactory.createMatcher(TRIPLE_REGEX, line);
            if (tripleMatcher.matches()) {
                handleTriple(tripleMatcher, line);
            } else {
                final RegexMatcher endMolecule = regexMatcherFactory.createMatcher(END_MOLECULE, line);
                if (endMolecule.matches()) {
                    handleEndMolecule();
                }
            }
        }
    }
View Full Code Here


        return regexFactory.createMatcher(pattern, s).matches();
    }

    public String[] parse(String s) {
        checkNotEmptyString("s", s);
        RegexMatcher matcher = regexFactory.createMatcher(pattern, s);
        String[] values = new String[LITERAL_VALUES_LENGTH];
        if (matcher.matches()) {
            String ntriplesLiteral = matcher.group(LITERAL_INDEX);
            values[0] = nTripleUtil.unescapeLiteral(ntriplesLiteral);
            values[1] = matcher.group(LANGUAGE_INDEX);
            values[2] = getDatatypeString(matcher);
        }
        return values;
    }
View Full Code Here

        regexMatcherFactory = newRegexMatcherFactory;
        listener = newListener;
    }

    public boolean handlePrefix(final CharSequence line) {
        final RegexMatcher prefixMatcher = regexMatcherFactory.createMatcher(PREFIX_REGEX, line);
        final boolean matched = prefixMatcher.matches();
        if (matched) {
            final String prefix = prefixMatcher.group(PREFIX_GROUP);
            final String uri = prefixMatcher.group(URI_GROUP);
            listener.handleNamespace(prefix, uri);
        }
        return matched;
    }
View Full Code Here

    // This is a duplicate with TripleParserImpl - but it will stop being a duplicate when all the features of N3 are
    // implemented (such as blank nodes, short hand for predicates, etc).
    public Triple parseTriple(final CharSequence line) {
        try {
            final RegexMatcher regexMatcher = regexMatcherFactory.createMatcher(TRIPLE_REGEX, line);
            if (regexMatcher.matches()) {
                final RegexMatcher matcher1 = tripleParser.createMatcher(regexMatcher, SUBJECT_REGEX, SUBJECT_GROUP);
                final RegexMatcher matcher2 = tripleParser.createMatcher(regexMatcher, PREDICATE_REGEX,
                    PREDICATE_GROUP);
                final RegexMatcher matcher3 = tripleParser.createMatcher(regexMatcher, OBJECT_REGEX, OBJECT_GROUP);
                return tripleParser.parseTripleLine(matcher1, matcher2, matcher3);
            }
            return null;
        } catch (ParseException e) {
            throw new RuntimeException(e);
View Full Code Here

        literalParser = newLiteralParser;
    }

    public ObjectNode parseNode(final CharSequence line) throws ParseException {
        checkNotNull(line);
        final RegexMatcher regexMatcher = factory.createMatcher(REGEX, line);
        if (regexMatcher.matches()) {
            return parseObject(regexMatcher);
        } else {
            throw new IllegalArgumentException("Couldn't match line: " + line);
        }
    }
View Full Code Here

        return regexFactory.createMatcher(pattern, s).matches();
    }

    public String[] parse(final String s) {
        checkNotEmptyString("s", s);
        final RegexMatcher matcher = regexFactory.createMatcher(pattern, s);
        final String[] values = new String[LITERAL_VALUES_LENGTH];
        if (matcher.matches()) {
            final String ntriplesLiteral = matcher.group(LITERAL_INDEX);
            values[0] = nTripleUtil.unescapeLiteral(ntriplesLiteral);
            values[1] = matcher.group(LANGUAGE_INDEX);
            values[2] = matcher.group(DATATYPE_INDEX);
        }
        return values;
    }
View Full Code Here

            throw new ParseException("Failed to create URI Reference: " + s, PREFIX_GROUP);
        }
    }

    public URIReference parseURIReferenceWithNamespace(String s) throws ParseException {
        final RegexMatcher regexMatcher = matcherFactory.createMatcher(REGEX, s);
        if (regexMatcher.matches()) {
            final String fullURI = listener.getFullURI(regexMatcher.group(PREFIX_GROUP));
            final String local = regexMatcher.group(LOCAL_GROUP);
            return parseURIReference(fullURI + local);
        } else {
            return null;
        }
    }
View Full Code Here

        this.regexMatcherFactory = newRegexMatcherFactory;
    }

    public String unescapeLiteral(String literal) {
        checkNotNull(literal);
        RegexMatcher matcher = regexMatcherFactory.createMatcher(LITERAL_ESCAPE_REGEX, literal);
        if (!matcher.find()) {
            return literal;
        } else {
            return hasCharactersToEscape(matcher);
        }
    }
View Full Code Here

    }


    public Triple parseTriple(final CharSequence line) {
        try {
            final RegexMatcher regexMatcher = regexMatcherFactory.createMatcher(TRIPLE_REGEX, line);
            if (regexMatcher.matches()) {
                final RegexMatcher matcher1 = tripleParser.createMatcher(regexMatcher, SUBJECT_REGEX, SUBJECT_GROUP);
                final RegexMatcher matcher2 = tripleParser.createMatcher(regexMatcher, PREDICATE_REGEX,
                    PREDICATE_GROUP);
                final RegexMatcher matcher3 = tripleParser.createMatcher(regexMatcher, OBJECT_REGEX, OBJECT_GROUP);
                return tripleParser.parseTripleLine(matcher1, matcher2, matcher3);
            }
            return null;
        } catch (ParseException e) {
            throw new RuntimeException(e);
View Full Code Here

TOP

Related Classes of org.jrdf.util.boundary.RegexMatcher

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.