Example usage for org.apache.wicket.util.parse.metapattern MetaPattern MetaPattern

List of usage examples for org.apache.wicket.util.parse.metapattern MetaPattern MetaPattern

Introduction

In this page you can find the example usage for org.apache.wicket.util.parse.metapattern MetaPattern MetaPattern.

Prototype

public MetaPattern(final List<MetaPattern> patterns) 

Source Link

Document

Constructs from a list of MetaPatterns

Usage

From source file:com.locke.tricks.u.U.java

License:Apache License

@SuppressWarnings("unchecked")
public U() {//from   ww  w  .  j av  a  2  s  .c  o m

    final IColumn<Utility>[] columns = new IColumn[2];
    columns[0] = new PropertyColumn<Utility>(new Model<String>("Code"), "code", "code");
    columns[1] = new PropertyColumn<Utility>(new Model<String>("Output"), "output", "output");

    final DataTable<Utility> dataTable = new DataTable<Utility>("utilities", columns,
            this.utilitiesDataProvider, Integer.MAX_VALUE);
    dataTable.addTopToolbar(new HeadersToolbar(dataTable, new ISortStateLocator() {

        private ISortState sortState = new SingleSortState();

        public ISortState getSortState() {
            return this.sortState;
        }

        public void setSortState(final ISortState state) {
            this.sortState = state;
        }
    }));
    add(dataTable);

    this.utilities.add(new Utility("Time.now().toString()") {

        @Override
        public String getOutput() {
            return Time.now().toString();
        }
    });
    this.utilities.add(new Utility("Duration.ONE_WEEK.toString()") {

        @Override
        public String getOutput() {
            return Duration.ONE_WEEK.toString();
        }
    });
    this.utilities.add(new Utility("Duration.ONE_WEEK.add(Duration.ONE_DAY).toString()") {

        @Override
        public String getOutput() {
            return Duration.ONE_WEEK.add(Duration.ONE_DAY).toString();
        }
    });
    this.utilities.add(new Utility("Time.now().add(Duration.ONE_WEEK).toString()") {

        @Override
        public String getOutput() {
            return Time.now().add(Duration.ONE_WEEK).toString();
        }
    });
    this.utilities.add(new Utility("Bytes.valueOf(\"512K\") + Bytes.megabytes(1.3)") {

        @Override
        public String getOutput() {
            return Bytes.bytes(Bytes.valueOf("512K").bytes() + Bytes.megabytes(1.3).bytes()).toString();
        }
    });
    this.utilities.add(new Utility("Parsing \'13 + 13\' using MetaPattern") {

        @Override
        public String getOutput() {
            final IntegerGroup a = new IntegerGroup(MetaPattern.DIGITS);
            final IntegerGroup b = new IntegerGroup(MetaPattern.DIGITS);
            final MetaPattern sum = new MetaPattern(new MetaPattern[] { a, MetaPattern.OPTIONAL_WHITESPACE,
                    MetaPattern.PLUS, MetaPattern.OPTIONAL_WHITESPACE, b });
            final Matcher matcher = sum.matcher("13 + 13");
            if (matcher.matches()) {
                return Integer.toString(a.getInt(matcher) + b.getInt(matcher));
            }
            return "Failed to match.";
        }
    });
}

From source file:org.wicketstuff.rest.resource.urlsegments.FixedURLSegment.java

License:Apache License

@Override
protected MetaPattern loadMetaPattern() {
    return new MetaPattern(Pattern.quote(this.toString()));
}

From source file:org.wicketstuff.rest.resource.urlsegments.MultiParamSegment.java

License:Apache License

@Override
protected MetaPattern loadMetaPattern() {
    List<MetaPattern> patterns = new ArrayList<MetaPattern>();

    this.subSegments = Collections.unmodifiableList(loadSubSegments(toString()));

    for (AbstractURLSegment segment : subSegments) {
        patterns.add(segment.getMetaPattern());
    }//from w  w w.ja  v a2 s.  c o  m

    return new MetaPattern(patterns);
}

From source file:org.wicketstuff.rest.resource.urlsegments.MultiParamSegment.java

License:Apache License

/**
 * Returns segment meta pattern with regexp group to support named-capturing.
 * /*from  w w  w  . j a  v a 2  s  . c  om*/
 * @return
 *       the meta pattern.
 */
public MetaPattern getMetaPatternWithGroups() {
    List<MetaPattern> patterns = new ArrayList<MetaPattern>();

    for (AbstractURLSegment segment : subSegments) {
        MetaPattern metaPattern = segment.getMetaPattern();

        if (segment instanceof ParamSegment) {
            metaPattern = new Group(metaPattern);
        }

        patterns.add(metaPattern);
    }

    return new MetaPattern(patterns);
}

From source file:org.wicketstuff.rest.resource.urlsegments.ParamSegment.java

License:Apache License

@Override
protected MetaPattern loadMetaPattern() {
    String segmentContent = this.toString();
    int semicolonIndex = segmentContent.indexOf(':');

    if (semicolonIndex < 0)
        return MetaPattern.ANYTHING_NON_EMPTY;

    String regExp = segmentContent.substring(semicolonIndex + 1, segmentContent.length() - 1);
    Matcher matcher = REGEXP_BODY.matcher(regExp);

    matcher.matches();// w  w w.  j  a  v  a 2 s .  c om

    String group = matcher.group();

    return new MetaPattern(group);
}

From source file:org.wicketstuff.rest.SegmentClassesTest.java

License:Apache License

@Test
public void testStandardUrlSegmentPattern() {
    MetaPattern pattern = new MetaPattern(AbstractURLSegment.SEGMENT_PARAMETER);

    Matcher matcher = pattern.matcher("");
    assertFalse(matcher.matches());//ww  w. j a  v  a2  s .c om

    matcher = pattern.matcher("seg&ment");
    assertFalse(matcher.matches());

    matcher = pattern.matcher("segment:");
    assertFalse(matcher.matches());

    matcher = pattern.matcher("{*}");
    assertFalse(matcher.matches());

    matcher = pattern.matcher("{segment}");
    assertTrue(matcher.matches());

    matcher = pattern.matcher("{segment0} a segment {segment1} another segment {segment2}");
    assertTrue(matcher.find());

    matcher.reset();
    assertFalse(matcher.matches());

    matcher = pattern.matcher("{117}");
    assertFalse(matcher.matches());

    pattern = new MetaPattern(AbstractURLSegment.REGEXP_BODY);
    matcher = pattern.matcher("[0-9]*:abba");
    assertTrue(matcher.matches());

    matcher = pattern.matcher("^\\(?\\d{3}\\)?[ -]?\\d{3}[ -]?\\d{4}$anotherseg");
    assertTrue(matcher.matches());
}