/** * Get the URLs for all the resources that a browser would automatically * download following the download of the HTML content, that is: images, * stylesheets, javascript files, applets, etc... * <p> * N.B. The Iterator returns URLs, but the Collection will contain objects * of class URLString. * * @param userAgent * User Agent * @param html * HTML code * @param baseUrl * Base URL from which the HTML code was obtained * @param coll * Collection - will contain URLString objects, not URLs * @param encoding Charset * @return an Iterator for the resource URLs * @throws HTMLParseException when parsing the <code>html</code> fails */ public Iterator<URL> getEmbeddedResourceURLs( String userAgent, byte[] html, URL baseUrl, Collection<URLString> coll, String encoding) throws HTMLParseException { return getEmbeddedResourceURLs(userAgent, html, baseUrl, new URLCollection(coll), encoding); }
boolean b; try { b = this.add(ConversionUtils.makeRelativeURL(baseUrl, url)); } catch (MalformedURLException mfue) {
@Override public void onImport(CSSImportRule rule) { final String location = rule.getLocationString(); if (!StringUtils.isEmpty(location)) { urls.addURL(location, baseUrl); } }
/** * @see org.apache.jmeter.protocol.http.parser.LinkExtractorParser#getEmbeddedResourceURLs * (java.lang.String, byte[], java.net.URL, java.lang.String) */ @Override public Iterator<URL> getEmbeddedResourceURLs(String userAgent, byte[] data, final URL baseUrl, String encoding) throws LinkExtractorParseException { try { final String cssContent = new String(data, encoding); final Charset charset = Charset.forName(encoding); final Triple<String, URL, Charset> triple = ImmutableTriple.of( cssContent, baseUrl, charset); final URLCollection urlCollection = orDefault(CSS_URL_CACHE.get(triple), EMPTY_URL_COLLECTION); if (LOG.isDebugEnabled()) { LOG.debug("Parsed:" + baseUrl + ", got:" + StringUtils.join(urlCollection, ",")); } return urlCollection.iterator(); } catch (Exception e) { throw new LinkExtractorParseException(e); } }
/** * {@inheritDoc} */ @Override public Iterator<URL> getEmbeddedResourceURLs(String userAgent, byte[] html, URL baseUrl, URLCollection urls, String encoding) throws HTMLParseException { Document dom; try { dom = (Document) getDOM(html, encoding); } catch (SAXException se) { throw new HTMLParseException(se); } // Now parse the DOM tree scanNodes(dom, urls, baseUrl); return urls.iterator(); }
private void extractAttribute(Element tag, String attributeName) { String url = tag.attr(attributeName); String normalizedUrl = normalizeUrlValue(url); if(normalizedUrl != null) { urls.addURL(normalizedUrl, baseUrl.url); } }
@Override public Iterator<URL> getEmbeddedResourceURLs(String userAgent, byte[] html, URL baseUrl, URLCollection coll, String encoding) throws HTMLParseException { try { // TODO Handle conditional comments for IE String contents = new String(html,encoding); Document doc = Jsoup.parse(contents); JMeterNodeVisitor nodeVisitor = new JMeterNodeVisitor(new URLPointer(baseUrl), coll); new NodeTraversor(nodeVisitor).traverse(doc); return coll.iterator(); } catch (Exception e) { throw new HTMLParseException(e); } } }
return getEmbeddedResourceURLs(userAgent, html, baseUrl, new URLCollection(col),encoding);
private void extractAttribute(Tag tag, String attributeName) { CharSequence url = tag.getAttributeValue(attributeName); String normalizedUrl = normalizeUrlValue(url); if(normalizedUrl != null) { urls.addURL(normalizedUrl, baseUrl.url); } }
@Override public Iterator<URL> getEmbeddedResourceURLs(String userAgent, byte[] html, URL baseUrl, URLCollection coll, String encoding) throws HTMLParseException { try { Float ieVersion = extractIEVersion(userAgent); String contents = new String(html,encoding); LagartoParser lagartoParser = new LagartoParser(contents.toCharArray()); LagartoDomBuilderConfig config = new LagartoDomBuilderConfig(); config.setCaseSensitive(false); // Conditional comments only apply for IE < 10 config.setEnableConditionalComments(isEnableConditionalComments(ieVersion)); if(ieVersion != null) { config.setCondCommentIEVersion(ieVersion); } lagartoParser.setConfig(config); JMeterTagVisitor tagVisitor = new JMeterTagVisitor(new URLPointer(baseUrl), coll, ieVersion); lagartoParser.parse(tagVisitor); return coll.iterator(); } catch (LagartoException e) { // TODO is it the best way ? https://bz.apache.org/bugzilla/show_bug.cgi?id=55634 if(log.isDebugEnabled()) { log.debug("Error extracting embedded resource URLs from:'"+baseUrl+"', probably not text content, message:"+e.getMessage()); } return Collections.<URL>emptyList().iterator(); } catch (Exception e) { throw new HTMLParseException(e); } } }
cssContent, readerSettings); final URLCollection urls = new URLCollection(new ArrayList<>());
urls.addURL(getValue(attrs, ATT_SRC), baseUrl); break; urls.addURL(getValue(attrs, "code"), baseUrl); break; String data = getValue(attrs, "codebase"); if(!StringUtils.isEmpty(data)) { urls.addURL(data, baseUrl); urls.addURL(data, baseUrl); String typ = getValue(attrs, ATT_TYPE); if ((src != null) && ATT_IS_IMAGE.equalsIgnoreCase(typ)) { urls.addURL(src, baseUrl); urls.addURL(getValue(attrs, ATT_HREF), baseUrl); break; urls.addURL(getValue(attrs, ATT_SRC), baseUrl); break; urls.addURL(getValue(attrs, ATT_SRC), baseUrl); break; urls.addURL(getValue(attrs, ATT_SRC), baseUrl); break; urls.addURL(back, baseUrl);
public static void extractStyleURLs(final URL baseUrl, final URLCollection urls, String styleTagStr) { Perl5Matcher matcher = JMeterUtils.getMatcher(); Pattern pattern = JMeterUtils.getPatternCache().getPattern( "URL\\(\\s*('|\")(.*)('|\")\\s*\\)", // $NON-NLS-1$ Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.SINGLELINE_MASK | Perl5Compiler.READ_ONLY_MASK); PatternMatcherInput input = null; input = new PatternMatcherInput(styleTagStr); while (matcher.contains(input, pattern)) { MatchResult match = matcher.getMatch(); // The value is in the second group String styleUrl = match.group(2); urls.addURL(styleUrl, baseUrl); } } }