001: /*
002: * Portions Copyright 2000-2007 Sun Microsystems, Inc. All Rights
003: * Reserved. Use is subject to license terms.
004: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License version
008: * 2 only, as published by the Free Software Foundation.
009: *
010: * This program is distributed in the hope that it will be useful, but
011: * WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * General Public License version 2 for more details (a copy is
014: * included at /legal/license.txt).
015: *
016: * You should have received a copy of the GNU General Public License
017: * version 2 along with this work; if not, write to the Free Software
018: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019: * 02110-1301 USA
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
022: * Clara, CA 95054 or visit www.sun.com if you need additional
023: * information or have any questions.
024: */
025: /*
026: * AttributeFieldParser.java
027: *
028: * Created on February 19, 2002, 10:09 AM
029: */
030:
031: package gov.nist.javax.sdp.parser;
032:
033: import gov.nist.javax.sdp.fields.*;
034: import gov.nist.core.*;
035:
036: /**
037: * Attribute field parser.
038: * @version 1.0
039: */
040: public class AttributeFieldParser extends SDPParser {
041: /**
042: * Creates new AttributeFieldParser.
043: * @param attributeField string to be parsed
044: */
045: public AttributeFieldParser(String attributeField) {
046:
047: this .lexer = new Lexer("charLexer", attributeField);
048: }
049:
050: /** Default constructor. */
051: protected AttributeFieldParser() {
052:
053: }
054:
055: /**
056: * Perform the attribute field parsing
057: * @return the parsed attribute field
058: * @exception ParseException if a parsing error occurs
059: */
060: public AttributeField attributeField() throws ParseException {
061: AttributeField attributeField = new AttributeField();
062:
063: this .lexer.match('a');
064:
065: this .lexer.SPorHT();
066: this .lexer.match('=');
067:
068: this .lexer.SPorHT();
069:
070: NameValue nameValue = new NameValue();
071:
072: int ptr = this .lexer.markInputPosition();
073: try {
074: String name = lexer.getNextToken(':');
075: this .lexer.consume(1);
076: String value = lexer.getRest();
077: nameValue = new NameValue(name.trim(), value.trim());
078: } catch (ParseException ex) {
079: this .lexer.rewindInputPosition(ptr);
080: String rest = this .lexer.getRest();
081: if (rest == null)
082: throw new ParseException(this .lexer.getBuffer(),
083: this .lexer.getPtr());
084: nameValue = new NameValue(rest.trim(), null);
085: }
086: attributeField.setAttribute(nameValue);
087:
088: this .lexer.SPorHT();
089:
090: return attributeField;
091: }
092:
093: /**
094: * Perform the attribute field parsing
095: * @return the parsed attribute field
096: * @exception ParseException if a parsing error occurs
097: */
098: public SDPField parse() throws ParseException {
099: return this.attributeField();
100: }
101:
102: }
|