001package Torello.HTML.NodeSearch; 002 003import java.util.*; 004import java.util.regex.Pattern; 005import java.util.function.Predicate; 006 007import Torello.HTML.*; 008import Torello.Java.LV; 009 010/** 011 * {@code Static} methods for building an {@link HNLIInclusive} (which also extends the basic 012 * {@code Iterator}) for retrieving sub HTML-Vector's using match-critera which specify 013 * HTML Tag Attribute <B STYLE='color:red'>name</B> and <B STYLE='color:red'>value</B> 014 * requirements. 015 * 016 * <BR /><BR /><EMBED CLASS='external-html' DATA-FILE-ID=InnerTagInclusiveIterator> 017 */ 018@Torello.JavaDoc.JDHeaderBackgroundImg 019@Torello.JavaDoc.StaticFunctional 020public class InnerTagInclusiveIterator 021{ 022 private InnerTagInclusiveIterator() { } 023 024 // **** CRITERIA: htmlTag 025 public static HNLIInclusive get(Vector<? extends HTMLNode> html, String htmlTag, String innerTag) 026 { return GET(html, ARGCHECK.htmlTag(htmlTag), ARGCHECK.innerTag(innerTag), ARGCHECK.TRUE); } 027 028 public static HNLIInclusive get(Vector<? extends HTMLNode> html, String htmlTag, String innerTag, TextComparitor tc, String... compareStr) 029 { return GET(html, ARGCHECK.htmlTag(htmlTag), ARGCHECK.innerTag(innerTag), ARGCHECK.TC(tc, compareStr)); } 030 031 public static HNLIInclusive get(Vector<? extends HTMLNode> html, String htmlTag, String innerTag, Pattern p) 032 { return GET(html, ARGCHECK.htmlTag(htmlTag), ARGCHECK.innerTag(innerTag), ARGCHECK.REGEX(p)); } 033 034 public static HNLIInclusive get(Vector<? extends HTMLNode> html, String htmlTag, String innerTag, Predicate<String> attributeValuePred) 035 { return GET(html, ARGCHECK.htmlTag(htmlTag), ARGCHECK.innerTag(innerTag), attributeValuePred); } 036 037 public static HNLIInclusive get(Vector<? extends HTMLNode> html, Predicate<TagNode> p, String... htmlTags) 038 { return GET(html, p, ARGCHECK.htmlTags(htmlTags)); } 039 040 // **** CRITERIA: htmlTag null 041 public static HNLIInclusive get(Vector<? extends HTMLNode> html, String innerTag) 042 { return GET(html, null, ARGCHECK.innerTag(innerTag), ARGCHECK.TRUE); } 043 044 public static HNLIInclusive get(Vector<? extends HTMLNode> html, String innerTag, TextComparitor tc, String... compareStr) 045 { return GET(html, null, ARGCHECK.innerTag(innerTag), ARGCHECK.TC(tc, compareStr)); } 046 047 public static HNLIInclusive get(Vector<? extends HTMLNode> html, String innerTag, Pattern p) 048 { return GET(html, null, ARGCHECK.innerTag(innerTag), ARGCHECK.REGEX(p)); } 049 050 public static HNLIInclusive get(Vector<? extends HTMLNode> html, String innerTag, Predicate<String> attributeValuePred) 051 { return GET(html, null, ARGCHECK.innerTag(innerTag), attributeValuePred); } 052 053 public static HNLIInclusive get(Vector<? extends HTMLNode> html, Predicate<TagNode> p) 054 { return GET(html, p); } 055 056 // ************************************************************************************** 057 // private builder methods 058 // ************************************************************************************** 059 060 private static HNLIInclusive GET 061 (Vector<? extends HTMLNode> html, String htmlTag, String innerTag, Predicate<String> compare) 062 { 063 InclusiveException.check(htmlTag); 064 065 if (htmlTag == null) 066 return new HNLIInclusive( 067 html, (TagNode tn) -> 068 { 069 String innerTagValue = tn.AVOPT(innerTag); 070 return (innerTagValue != null) && compare.test(innerTagValue); 071 } 072 ); 073 else 074 return new HNLIInclusive( 075 html, (TagNode tn) -> 076 { 077 if (! htmlTag.equals(tn.tok)) return false; 078 String innerTagValue = tn.AVOPT(innerTag); 079 return (innerTagValue != null) && compare.test(innerTagValue); 080 } 081 ); 082 } 083 084 private static HNLIInclusive GET 085 (Vector<? extends HTMLNode> html, Predicate<TagNode> p, String... htmlTags) 086 { 087 InclusiveException.check(htmlTags); 088 089 Predicate<TagNode> p2 = (htmlTags.length == 0) 090 ? p 091 : (TagNode tn) -> tn.isTag(TC.OpeningTags, htmlTags) && p.test(tn); 092 093 return new HNLIInclusive(html, p2); 094 } 095 096}