/** * {@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(); }
/** * 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); }
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 { 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); } } }
@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); } } }
/** * @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); } }
private static HTTPSamplerBase createFormUrlConfig(Node tempNode, URL context) throws MalformedURLException { NamedNodeMap atts = tempNode.getAttributes(); if (atts.getNamedItem("action") == null) { // $NON-NLS-1$ throw new MalformedURLException(); } String action = atts.getNamedItem("action").getNodeValue(); // $NON-NLS-1$ return createUrlFromAnchor(action, context); }
/** * Match the input argument against the pattern using String.equals() or pattern matching if that fails * using case-insensitive matching. * * @param arg input string * @param pat pattern string * * @return true if input matches the pattern */ public static boolean isEqualOrMatches(String arg, String pat){ return isEqualOrMatches(arg, pat, JMeterUtils.getMatcher(), JMeterUtils.getPatternCache()); }
@Override public Iterator<URL> iterator() { return new UrlIterator(coll.iterator()); }
/** {@inheritDoc} */ @Override public int compareTo(URLString o) { return urlAsString.compareTo(o.toString()); }
/** * Adds the URL to the Collection, first wrapping it in the URLString class * * @param u * URL to add * @return boolean condition returned by the add() method of the underlying * collection */ public boolean add(URL u) { return coll.add(new URLString(u)); }
public static List<HTTPSamplerBase> createURLFromForm(Node doc, URL context) { String selectName = null; LinkedList<HTTPSamplerBase> urlConfigs = new LinkedList<>(); recurseForm(doc, urlConfigs, context, selectName, false); return urlConfigs; }
@Override public URL next() { return iter.next().getURL(); }
@Override public void script(Tag tag, CharSequence body) { if (!enabled.peek().booleanValue()) { return; } extractAttribute(tag, ATT_SRC); }
@Override public void onImport(CSSImportRule rule) { final String location = rule.getLocationString(); if (!StringUtils.isEmpty(location)) { urls.addURL(location, baseUrl); } }
/** * Match the input argument against the pattern using String.equals() or pattern matching if that fails * using case-insensitive matching. * * @param arg input string * @param pat pattern string * * @return true if input matches the pattern */ public static boolean isEqualOrMatchesCaseBlind(String arg, String pat){ return isEqualOrMatchesCaseBlind(arg, pat, JMeterUtils.getMatcher(), JMeterUtils.getPatternCache()); }
/** * Gets parser from {@link HTTPSampleResult#getMediaType()}. * Returns null if no parser defined for it * @param res {@link HTTPSampleResult} * @return {@link LinkExtractorParser} * @throws LinkExtractorParseException */ private LinkExtractorParser getParser(HTTPSampleResult res) throws LinkExtractorParseException { String parserClassName = PARSERS_FOR_CONTENT_TYPE.get(res.getMediaType()); if (!StringUtils.isEmpty(parserClassName)) { return BaseParser.getParser(parserClassName); } return null; }
private void extractAttribute(Tag tag, String attributeName) { CharSequence url = tag.getAttributeValue(attributeName); String normalizedUrl = normalizeUrlValue(url); if(normalizedUrl != null) { urls.addURL(normalizedUrl, baseUrl.url); } }
return getEmbeddedResourceURLs(userAgent, html, baseUrl, new URLCollection(col),encoding);
/** * Arguments match if the input name matches the corresponding pattern name * and the input value matches the pattern value, where the matching is done * first using String equals, and then Regular Expression matching if the equals test fails. * * @param arg - input Argument * @param patternArg - pattern to match against * @return true if both name and value match */ public static boolean isArgumentMatched(Argument arg, Argument patternArg) { final Perl5Matcher matcher = JMeterUtils.getMatcher(); final PatternCacheLRU patternCache = JMeterUtils.getPatternCache(); return isEqualOrMatches(arg.getName(), patternArg.getName(), matcher, patternCache) && isEqualOrMatches(arg.getValue(), patternArg.getValue(), matcher, patternCache); }