private List<Element> filterByElementNameIfConfigured(Source source) { if (filterElementName) { return source.getAllElements(elementNameFilter); } return source.getAllElements(); }
public List<Element> getAllElements(StartTagType startTagType) { return fSource.getAllElements(startTagType); }
public List<Element> getAllElements() { return fSource.getAllElements(); }
public static List<String> getForms(ZestResponse response) { List<String> list = new ArrayList<String>(); Source src = new Source(response.getHeaders() + response.getBody()); List<Element> formElements = src.getAllElements(HTMLElementName.FORM); int formId = 0; while (formElements != null && formId < formElements.size()) { // TODO support form names // Element form = formElements.get(formId); list.add(Integer.toString(formId)); formId++; } return list; }
public static OGObject parse(Source source,Set<String> unescapeHtml){ Element htmlTag = source.getFirstElement(HTMLElementName.HTML); List<Element> elementList = source.getAllElements(HTMLElementName.META); Map<String,String> datamap = new HashMap<String,String>(); String ogPrefix = findOpenGraphNamespacePrefix(htmlTag); for (Element elem : elementList){ String attrVal = elem.getAttributeValue("property"); if (attrVal!=null && attrVal.startsWith(ogPrefix)){ String content = elem.getAttributeValue("content"); String name = attrVal.substring(OG_PREFIX_CHAR_COUNT); datamap.put(name, content); } } return parse(datamap,unescapeHtml); }
private String processScopedCss(Source doc) { final String[] scopedCss = new String[1]; doc.getAllElements().stream() .filter(TemplateParser::isScopedStyleElement) .peek(styleScoped -> { String css = styleScoped.getContent().toString().trim(); if (!css.isEmpty()) { String lang = styleScoped.getAttributeValue("lang"); if ("scss".equalsIgnoreCase(lang)) { // lang="scss" css = scssToCss(css); } TemplateScopedCssParser scopedCssParser = new TemplateScopedCssParser(messager); Optional<ScopedCssResult> scopedCssResult = scopedCssParser.parse( context.getComponentTypeElement(), css); if (scopedCssResult.isPresent()) { context.getMandatoryAttributes().putAll(scopedCssResult.get().mandatoryAttributes); scopedCss[0] = scopedCssResult.get().scopedCss; } } }) .forEach(outputDocument::remove); return scopedCss[0]; }
/** * Add java imports in the template to the context. * * @param doc The document to process */ private void processImports(Source doc) { doc .getAllElements() .stream() .filter(element -> "vue-gwt:import".equalsIgnoreCase(element.getName())) .peek(importElement -> { String classAttributeValue = importElement.getAttributeValue("class"); if (classAttributeValue != null) { context.addImport(classAttributeValue); } String staticAttributeValue = importElement.getAttributeValue("static"); if (staticAttributeValue != null) { context.addStaticImport(staticAttributeValue); } }) .forEach(outputDocument::remove); }
List<Element> elements = source.getAllElements(HTMLElementName.A); for (Element el : elements) { resourcesfound |= processAttributeElement(message, depth, baseURL, el, "href"); elements = source.getAllElements(HTMLElementName.AREA); for (Element el : elements) { resourcesfound |= processAttributeElement(message, depth, baseURL, el, "href"); elements = source.getAllElements(HTMLElementName.FRAME); for (Element el : elements) { resourcesfound |= processAttributeElement(message, depth, baseURL, el, "src"); elements = source.getAllElements(HTMLElementName.IFRAME); for (Element el : elements) { resourcesfound |= processAttributeElement(message, depth, baseURL, el, "src"); elements = source.getAllElements(HTMLElementName.LINK); for (Element el : elements) { resourcesfound |= processAttributeElement(message, depth, baseURL, el, "href"); elements = source.getAllElements(HTMLElementName.SCRIPT); for (Element el : elements) { resourcesfound |= processAttributeElement(message, depth, baseURL, el, "src"); elements = source.getAllElements(HTMLElementName.IMG); for (Element el : elements) { resourcesfound |= processAttributeElement(message, depth, baseURL, el, "src"); elements = source.getAllElements(HTMLElementName.META);
public static List<String> getFields(ZestResponse response, int formId) { List<String> list = new ArrayList<String>(); Source src = new Source(response.getHeaders() + response.getBody()); List<Element> formElements = src.getAllElements(HTMLElementName.FORM); if (formElements != null && formId < formElements.size()) { Element form = formElements.get(formId); List<Element> inputElements = form.getAllElements(HTMLElementName.INPUT); String field; for (Element inputElement : inputElements) { field = inputElement.getAttributeValue("ID"); if (field == null || field.length() == 0) { field = inputElement.getAttributeValue("NAME"); } if (field != null && field.length() > 0) { list.add(field); } } } return list; } }
public List<AntiCsrfToken> getTokensFromResponse(HttpMessage msg, Source source) { List<AntiCsrfToken> list = new ArrayList<>(); List<Element> formElements = source.getAllElements(HTMLElementName.FORM);
List<Element> trgEntries = trgHtml.getAllElements(HTMLElementName.P); List<Element> srcEntries = srcHtml.getAllElements(HTMLElementName.P);
public String getTokenValue(HttpMessage tokenMsg, String tokenName) { String response = tokenMsg.getResponseHeader().toString() + tokenMsg.getResponseBody().toString(); Source source = new Source(response); List<Element> formElements = source.getAllElements(HTMLElementName.FORM); if (formElements != null && formElements.size() > 0) { // Loop through all of the FORM tags for (Element formElement : formElements) { List<Element> inputElements = formElement.getAllElements(HTMLElementName.INPUT); if (inputElements != null && inputElements.size() > 0) { // Loop through all of the INPUT elements for (Element inputElement : inputElements) { String id = inputElement.getAttributeValue("ID"); if (id != null && id.equalsIgnoreCase(tokenName)) { return inputElement.getAttributeValue("VALUE"); } String name = inputElement.getAttributeValue("NAME"); if (name != null && name.equalsIgnoreCase(tokenName)) { return inputElement.getAttributeValue("VALUE"); } } } } } return null; }
private String removeNotAllowedTags(String htmlFragment, URI docUri) { Source source = new Source(htmlFragment); OutputDocument outputDocument = new OutputDocument(source); List<Element> elements = source.getAllElements();
@Override public String assign(ZestResponse response, ZestRuntime runtime) throws ZestAssignFailException { if (response == null) { throw new ZestAssignFailException(this, "Null response"); } Source src = new Source(response.getHeaders() + response.getBody()); List<Element> formElements = src.getAllElements(HTMLElementName.FORM); if (formElements != null && fieldDefinition.getFormIndex() < formElements.size()) { Element form = formElements.get(fieldDefinition.getFormIndex()); List<Element> inputElements = form.getAllElements(HTMLElementName.INPUT); for (Element inputElement : inputElements) { if (fieldDefinition.getFieldName().equals(inputElement.getAttributeValue("ID")) || fieldDefinition .getFieldName() .equals(inputElement.getAttributeValue("NAME"))) { // Got it return inputElement.getAttributeValue("VALUE"); } } } return null; } }
html.fullSequentialParse(); List<Element> paragraphs = html.getAllElements(HTMLElementName.P);
List<Element> forms = source.getAllElements(HTMLElementName.FORM);
public static int[] getCharOffsets(String html) { int[] res = new int[html.length()]; Source source = new Source(html); List<Element> elems = source.getAllElements(); for (int i=0; i < res.length; ++i) { res[i] = i; } for (Element elem : elems) { StartTag startTag = elem.getStartTag(); Span startSpan = getSpan(startTag); EndTag stopTag = elem.getEndTag(); Span stopSpan = getSpan(stopTag); for (int i=startSpan.getStart(); i < startSpan.getStop(); ++i) { res[i] -= (startSpan.getLength() - (startSpan.getStop()-i)); } for (int i=startSpan.getStop(); i < stopSpan.getStart(); ++i) { res[i] -= startSpan.getLength(); } for (int i=stopSpan.getStart(); i < stopSpan.getStop(); ++i) { res[i] -= (stopSpan.getLength() - (stopSpan.getStop()-i)) ; } for (int i=stopSpan.getStop(); i < html.length(); ++i) { res[i] -= (startSpan.getLength() + stopSpan.getLength()); } } return res; }