Package org.apache.wicket.util.parse.metapattern

Examples of org.apache.wicket.util.parse.metapattern.MetaPattern


    // Create group for value pattern
    value = new Group(valuePattern);

    // Pattern for =<value>
    final MetaPattern variableAssignment = new MetaPattern(new MetaPattern[] {
        MetaPattern.OPTIONAL_WHITESPACE, MetaPattern.EQUALS,
        MetaPattern.OPTIONAL_WHITESPACE, value });

    // Set parse pattern to <key>=<value>?
    setPattern(new MetaPattern(new MetaPattern[] { MetaPattern.OPTIONAL_WHITESPACE, key,
        new OptionalMetaPattern(variableAssignment), MetaPattern.OPTIONAL_WHITESPACE }));
  }
View Full Code Here


    // Create group for value pattern
    value = new Group(valuePattern);

    // Pattern for =<value>
    final MetaPattern variableAssignment = new MetaPattern(new MetaPattern[] {
        MetaPattern.OPTIONAL_WHITESPACE, MetaPattern.EQUALS,
        MetaPattern.OPTIONAL_WHITESPACE, value });

    // Set parse pattern to <key>=<value>?
    setPattern(new MetaPattern(new MetaPattern[] { MetaPattern.OPTIONAL_WHITESPACE, key,
        new OptionalMetaPattern(variableAssignment), MetaPattern.OPTIONAL_WHITESPACE }));
  }
View Full Code Here

    // Create group for value pattern
    value = new Group(valuePattern);

    // Pattern for =<value>
    final MetaPattern variableAssignment = new MetaPattern(MetaPattern.OPTIONAL_WHITESPACE,
      MetaPattern.EQUALS, MetaPattern.OPTIONAL_WHITESPACE, value);

    // Set parse pattern to <key>=<value>?
    setPattern(new MetaPattern(MetaPattern.OPTIONAL_WHITESPACE, key, new OptionalMetaPattern(
      variableAssignment), MetaPattern.OPTIONAL_WHITESPACE));
  }
View Full Code Here

    // Create group for value pattern
    value = new Group(valuePattern);

    // Pattern for =<value>
    final MetaPattern variableAssignment = new MetaPattern(MetaPattern.OPTIONAL_WHITESPACE,
      MetaPattern.EQUALS, MetaPattern.OPTIONAL_WHITESPACE, value);

    // Set parse pattern to <key>=<value>?
    setPattern(new MetaPattern(MetaPattern.OPTIONAL_WHITESPACE, key, new OptionalMetaPattern(
      variableAssignment), MetaPattern.OPTIONAL_WHITESPACE));
  }
View Full Code Here

{

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

    Matcher matcher = pattern.matcher("");
    assertFalse(matcher.matches());

    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());
  }
View Full Code Here

    ParamSegment paramSegment = (ParamSegment)segment;

    assertEquals(paramSegment.getParamName(), "id");
    assertEquals(paramSegment.getMetaPattern().toString(), "[0-9]*:abba");

    MetaPattern metaPattern = paramSegment.getMetaPattern();

    assertTrue(metaPattern.matcher("1:abba").matches());
    assertTrue(metaPattern.matcher("1234521:abba").matches());
    assertTrue(metaPattern.matcher(":abba").matches());

    String segmentMultiParam = "{segment0}asegment{segment1:^\\(?\\d{3}\\)?[ -]?\\d{3}[ -]?\\d{4}$}anotherseg";
    segment = AbstractURLSegment.newSegment(segmentMultiParam);

    assertTrue(segment instanceof MultiParamSegment);

    MultiParamSegment multiParamSegment = (MultiParamSegment)segment;
    List<AbstractURLSegment> subSegments = multiParamSegment.getSubSegments();

    assertEquals(4, subSegments.size());
    metaPattern = subSegments.get(2).getMetaPattern();
    assertEquals(metaPattern.toString(), "^\\(?\\d{3}\\)?[ -]?\\d{3}[ -]?\\d{4}$");

    segmentMultiParam = "filename-{symbolicName:[a-z]+}-{version:\\d\\.\\d\\.\\d}{extension:\\.[a-z]+}";
    segment = AbstractURLSegment.newSegment(segmentMultiParam);
    multiParamSegment = (MultiParamSegment)segment;
    metaPattern = multiParamSegment.getMetaPatternWithGroups();

    String fileName = "filename-gsaon-1.2.3.zip";
    Matcher matcher = metaPattern.matcher(fileName);

    assertTrue(matcher.matches());

    // testing segment parsing with regular expressions         
    assertEquals("gsaon", matcher.group(1));
    assertEquals("1.2.3", matcher.group(2));
    assertEquals(".zip", matcher.group(3));


    matcher = metaPattern.matcher("gsaon-1.2.3.zip");

    assertFalse(matcher.matches());
   


View Full Code Here

  }

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

    for (AbstractURLSegment segment : subSegments)
    {
      patterns.add(segment.getMetaPattern());
    }

    return new MetaPattern(patterns);
  }
View Full Code Here

  {
    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);
  }
View Full Code Here

  @Override
  public void visit(MultiParamSegment segment)
  {
    String segmentValue = segmentActualValue(segment);
   
    MetaPattern metaPatternWithGroups = segment.getMetaPatternWithGroups();
    Matcher matcher = metaPatternWithGroups.matcher(segmentValue);

    if(isSegmentValid = matcher.matches())
    {
      List<ParamSegment> paramSegments = new ArrayList<>();
      CollectionUtils.filterCollectionByType(segment.getSubSegments(),
View Full Code Here

TOP

Related Classes of org.apache.wicket.util.parse.metapattern.MetaPattern

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.