001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.util.parse.metapattern.parsers; 018 019import org.apache.wicket.util.parse.metapattern.Group; 020import org.apache.wicket.util.parse.metapattern.MetaPattern; 021 022/** 023 * Matches a 'word' surrounded by whitespace. See <a 024 * href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html" 025 * >java.util.regex.Pattern </a> for more details on what 'word' means. 026 * 027 * @author Jonathan Locke 028 */ 029public final class WordParser extends MetaPatternParser 030{ 031 /** 032 * Make it a group to be able to access the word without surrounding whitespace 033 */ 034 private static final Group word = new Group(MetaPattern.WORD); 035 036 /** Parse word surrounded by whitespace */ 037 private static final MetaPattern wordPattern = new MetaPattern(MetaPattern.OPTIONAL_WHITESPACE, 038 word, MetaPattern.OPTIONAL_WHITESPACE); 039 040 /** 041 * Construct. 042 * 043 * @param input 044 * to parse 045 */ 046 public WordParser(final CharSequence input) 047 { 048 super(wordPattern, input); 049 } 050 051 /** 052 * Gets the word including the optional whitespace surrounding the word. 053 * 054 * @return the word surrounded by whitespace 055 */ 056 public String getWord() 057 { 058 return word.get(matcher()); 059 } 060}