private int consumeIndex() { String indexS = tq.chompTo(")").trim(); Validate.isTrue(StringUtil.isNumeric(indexS), "Index must be numeric"); return Integer.parseInt(indexS); }
void processResponseHeaders(Map<String, List<String>> resHeaders) { for (Map.Entry<String, List<String>> entry : resHeaders.entrySet()) { String name = entry.getKey(); if (name == null) continue; // http/1.1 line List<String> values = entry.getValue(); if (name.equalsIgnoreCase("Set-Cookie")) { for (String value : values) { if (value == null) continue; TokenQueue cd = new TokenQueue(value); String cookieName = cd.chompTo("=").trim(); String cookieVal = cd.consumeTo(";").trim(); // ignores path, date, domain, validateTLSCertificates et al. req'd? // name not blank, value not null if (cookieName.length() > 0) cookie(cookieName, cookieVal); } } for (String value : values) { addHeader(name, value); } } }
private void cssNthChild(boolean backwards, boolean ofType) { String argS = normalize(tq.chompTo(")")); Matcher mAB = NTH_AB.matcher(argS); Matcher mB = NTH_B.matcher(argS);
private void parseComment() { tq.consume("<!--"); String data = tq.chompTo("->"); if (data.endsWith("-")) // i.e. was --> data = data.substring(0, data.length() - 1); Comment comment = new Comment(data, baseUri); annotate(comment); // TODO - should annotations even apply to comments? lines(comment, data); add(comment); }
private void parseComment() { tq.consume("<!--"); String data = tq.chompTo("->"); if (data.endsWith("-")) // i.e. was --> data = data.substring(0, data.length() - 1); Comment comment = new Comment(data, baseUri); annotate(comment); // TODO - should annotations even apply to comments? lines(comment, data); add(comment); }
private void parseComment() { tq.consume("<!--"); String data = tq.chompTo("->"); if (data.endsWith("-")) // i.e. was --> data = data.substring(0, data.length() - 1); Comment comment = new Comment(data, baseUri); annotate(comment); // TODO - should annotations even apply to comments? lines(comment, data); add(comment); }
private void parseXmlDecl() { tq.consume("<"); Character firstChar = tq.consume(); // <? or <!, from initial match. boolean procInstr = firstChar.toString().equals("!"); String data = tq.chompTo(">"); XmlDeclaration decl = new XmlDeclaration(data, baseUri, procInstr); annotate(decl); // TODO - should annotations even apply to declarations? lines(decl, data); add(decl); }
private void parseXmlDecl() { tq.consume("<"); Character firstChar = tq.consume(); // <? or <!, from initial match. boolean procInstr = firstChar.toString().equals("!"); String data = tq.chompTo(">"); XmlDeclaration decl = new XmlDeclaration(data, baseUri, procInstr); annotate(decl); // TODO - should annotations even apply to declarations? lines(decl, data); add(decl); }
private void parseXmlDecl() { tq.consume("<"); Character firstChar = tq.consume(); // <? or <!, from initial match. boolean procInstr = firstChar.toString().equals("!"); String data = tq.chompTo(">"); XmlDeclaration decl = new XmlDeclaration(data, baseUri, procInstr); annotate(decl); // TODO - should annotations even apply to declarations? lines(decl, data); add(decl); }
private void parseCdata() { tq.consume("<![CDATA["); String rawText = tq.chompTo("]]>"); TextNode textNode = new TextNode(rawText, baseUri); // constructor does not escape if (pendingAnnotation != null) pendingAnnotation.apply(textNode); lines(textNode, rawText); add(textNode); }
private void parseEndTag() { tq.consume("</"); String tagName = tq.consumeTagName(); tq.chompTo(">"); if (!Strings.empty(tagName)) { Tag tag = Tag.valueOf(tagName); popStackToClose(tag); } }
private void parseCdata() { tq.consume("<![CDATA["); String rawText = tq.chompTo("]]>"); TextNode textNode = new TextNode(rawText, baseUri); // constructor does not escape if (pendingAnnotation != null) pendingAnnotation.apply(textNode); lines(textNode, rawText); add(textNode); }
private void parseEndTag() { tq.consume("</"); String tagName = tq.consumeTagName(); tq.chompTo(">"); if (!Strings.empty(tagName)) { Tag tag = Tag.valueOf(tagName); popStackToClose(tag); } }
private void parseCdata() { tq.consume("<![CDATA["); String rawText = tq.chompTo("]]>"); TextNode textNode = new TextNode(rawText, baseUri); // constructor does not escape if (pendingAnnotation != null) pendingAnnotation.apply(textNode); lines(textNode, rawText); add(textNode); }
private void parseEndTag() { tq.consume("</"); String tagName = tq.consumeTagName(); tq.chompTo(">"); if (!Strings.empty(tagName)) { Tag tag = Tag.valueOf(tagName); popStackToClose(tag); } }
private Attribute parseAttribute() { whitespace(); String key = tq.consumeAttributeKey(); String value = ""; whitespace(); if (tq.matchChomp("=")) { whitespace(); if (tq.matchChomp(SQ)) { value = tq.chompTo(SQ); } else if (tq.matchChomp(DQ)) { value = tq.chompTo(DQ); } else { StringBuilder valueAccum = new StringBuilder(); // no ' or " to look for, so scan to end tag or space (or end of stream) while (!tq.matchesAny("<", "/>", ">") && !tq.matchesWhitespace() && !tq.isEmpty()) { valueAccum.append(tq.consume()); } value = valueAccum.toString(); } whitespace(); } if (!Strings.empty(key)) return Attribute.createFromEncoded(key, value); else { tq.consume(); // unknown char, keep popping so not get stuck return null; } }
private Attribute parseAttribute() { whitespace(); String key = tq.consumeAttributeKey(); String value = ""; whitespace(); if (tq.matchChomp("=")) { whitespace(); if (tq.matchChomp(SQ)) { value = tq.chompTo(SQ); } else if (tq.matchChomp(DQ)) { value = tq.chompTo(DQ); } else { StringBuilder valueAccum = new StringBuilder(); // no ' or " to look for, so scan to end tag or space (or end of stream) while (!tq.matchesAny("<", "/>", ">") && !tq.matchesWhitespace() && !tq.isEmpty()) { valueAccum.append(tq.consume()); } value = valueAccum.toString(); } whitespace(); } if (!Strings.empty(key)) return Attribute.createFromEncoded(key, value); else { tq.consume(); // unknown char, keep popping so not get stuck return null; } }
private Attribute parseAttribute() { whitespace(); String key = tq.consumeAttributeKey(); String value = ""; whitespace(); if (tq.matchChomp("=")) { whitespace(); if (tq.matchChomp(SQ)) { value = tq.chompTo(SQ); } else if (tq.matchChomp(DQ)) { value = tq.chompTo(DQ); } else { StringBuilder valueAccum = new StringBuilder(); // no ' or " to look for, so scan to end tag or space (or end of stream) while (!tq.matchesAny("<", "/>", ">") && !tq.matchesWhitespace() && !tq.isEmpty()) { valueAccum.append(tq.consume()); } value = valueAccum.toString(); } whitespace(); } if (!Strings.empty(key)) return Attribute.createFromEncoded(key, value); else { tq.consume(); // unknown char, keep popping so not get stuck return null; } }