QueryTokenizer.java 2.62 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.scene7.is.util.error.Scaffold
 *  com.scene7.is.util.text.ParameterException
 *  com.scene7.is.util.text.ParsingException
 */
package com.scene7.is.ps.provider.parsers;

import com.scene7.is.util.error.Scaffold;
import com.scene7.is.util.text.ParameterException;
import com.scene7.is.util.text.ParsingException;
import java.io.IOException;
import java.io.Reader;
import java.io.StreamTokenizer;
import java.io.StringReader;

public class QueryTokenizer {
    private StreamTokenizer tokenizer;
    private String paramName;
    private String paramValue;

    public QueryTokenizer(String query) {
        this.tokenizer = new StreamTokenizer(new StringReader(query));
        this.tokenizer.resetSyntax();
        this.tokenizer.resetSyntax();
        this.tokenizer.wordChars(97, 122);
        this.tokenizer.wordChars(65, 90);
        this.tokenizer.wordChars(48, 57);
        this.tokenizer.wordChars(37, 37);
        this.tokenizer.wordChars(36, 36);
        this.tokenizer.wordChars(45, 45);
        this.tokenizer.wordChars(95, 95);
        this.tokenizer.wordChars(46, 46);
        this.tokenizer.wordChars(44, 44);
        this.tokenizer.wordChars(47, 47);
        this.nextToken();
        if (this.tokenizer.ttype == 63) {
            this.nextToken();
        }
        while (this.tokenizer.ttype == 38) {
            this.nextToken();
        }
    }

    public boolean hasMoreTokens() {
        return this.tokenizer.ttype != -1;
    }

    public boolean nextTokenPair() throws ParsingException, ParameterException {
        this.validateToken(-3);
        this.paramName = this.tokenizer.sval;
        this.nextToken();
        this.validateToken(61);
        this.nextToken();
        this.validateToken(-3);
        this.paramValue = this.tokenizer.sval;
        while (this.nextToken() == 38) {
        }
        return this.hasMoreTokens();
    }

    public String getName() {
        return this.paramName;
    }

    public String getValue() {
        return this.paramValue;
    }

    private int nextToken() {
        try {
            return this.tokenizer.nextToken();
        }
        catch (IOException e) {
            throw Scaffold.error((Throwable)e);
        }
    }

    private void validateToken(int expected) throws ParsingException {
        if (this.tokenizer.ttype != expected) {
            if (this.tokenizer.ttype >= 32) {
                throw new ParsingException(0, "'" + (char)this.tokenizer.ttype + "'", null);
            }
            throw new ParsingException(0, "0x" + Integer.toHexString(this.tokenizer.ttype), null);
        }
    }
}