Code with Finding: |
class HttpAccept { /** * parse. * @exception HttpParserException if parsing failed. */ protected void parse() throws HttpParserException { ParseState ps = new ParseState(roff, rlen); // We need to do our own MIME type parsing, to avoid ambiguities ! // Get the type: ps.separator = (byte) '/'; ps.spaceIsSep = false; if ( HttpParser.nextItem(raw, ps) < 0 ) error("Invalid Accept: has no type."); String type = new String(raw, 0, ps.start, ps.end-ps.start); // Get the subtype: ps.prepare(); ps.separator = (byte) ';'; if ( HttpParser.nextItem(raw, ps) < 0 ) error("Invalid accept: no subtype"); String subtype = new String(raw, 0, ps.start, ps.end-ps.start); // Get the parameters: ParseState it = new ParseState(); it.separator = (byte) '='; it.spaceIsSep = false; ps.prepare(); Vector vparams = new Vector(4); Vector vvalues = new Vector(4); boolean accept = false; while (HttpParser.nextItem(raw, ps) >= 0) { it.ioff = ps.start; it.bufend = ps.end; if ( HttpParser.nextItem(raw, it) < 0 ) error("Invalid parameter: no param name."); // The Hack ! String param = new String(raw, 0, it.start, it.end-it.start); if ( param.equalsIgnoreCase("q") ) { // Switching to accept-params accept = true; break ; } vparams.addElement(new String(raw, 0, it.start, it.end-it.start)); it.prepare(); if ( HttpParser.nextItem(raw, it) < 0 ) error("Invalid parameter: no value."); vvalues.addElement(new String(raw, 0, it.start, it.end-it.start)); ps.prepare(); } if ( vparams.size() > 0 ) { String pparams[] = new String[vparams.size()]; String pvalues[] = new String[pparams.length]; vparams.copyInto(pparams); vvalues.copyInto(pvalues); this.type = new MimeType(type, subtype, pparams, pvalues); } else { this.type = new MimeType(type, subtype); } // Parse remaining accept parameters: if ( accept ) { vparams.setSize(0); vvalues.setSize(0); // Hack to finish with the q parameter it.prepare(); if ( HttpParser.nextItem(raw, it) < 0 ) error("Invalid accept parameter: no value."); vparams.addElement("q"); vvalues.addElement(new String(raw, 0, it.start, it.end-it.start)); it.prepare(); while (HttpParser.nextItem(raw, ps) >= 0) { it.ioff = ps.start; it.bufend = ps.end; if ( HttpParser.nextItem(raw, it) < 0 ) error("Invalid accept parameter: no name."); vparams.addElement(new String(raw,0,it.start,it.end-it.start)); it.prepare(); if (HttpParser.nextItem(raw, it) < 0 ) error("Invalid accept parameter: no value."); vvalues.addElement(new String(raw,0,it.start,it.end-it.start)); ps.prepare(); } this.aparams = new String[vparams.size()]; this.avalues = new String[aparams.length]; vparams.copyInto(aparams); vvalues.copyInto(avalues); } }
}
|