Author: pmouawad
Date: Sun Mar 27 18:55:03 2016
New Revision: 1736807
URL: http://svn.apache.org/viewvc?rev=1736807&view=rev
Log:
Bug 59140 - Parallel Download : Add CSS Parsing to extract links from CSS files
Use Browser Compliant mode
Create internal class instead of inlined one
Bugzilla Id: 59140
Modified:
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/CssParser.java
Modified:
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/CssParser.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/CssParser.java?rev=1736807&r1=1736806&r2=1736807&view=diff
==============================================================================
---
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/CssParser.java
(original)
+++
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/CssParser.java
Sun Mar 27 18:55:03 2016
@@ -39,6 +39,7 @@ import com.helger.css.decl.visit.Default
import com.helger.css.handler.LoggingCSSParseExceptionCallback;
import com.helger.css.parser.ParseException;
import com.helger.css.reader.CSSReader;
+import com.helger.css.reader.CSSReaderSettings;
import com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler;
/**
@@ -49,6 +50,31 @@ public class CssParser implements LinkEx
private static final boolean IGNORE_UNRECOVERABLE_PARSING_ERROR =
JMeterUtils.getPropDefault("httpsampler.ignore_failed_embedded_resource",
false); //$NON-NLS-1$
private static final Logger LOG = LoggingManager.getLoggerForClass();
+ private static final class CustomLoggingCSSParseExceptionCallback extends
LoggingCSSParseExceptionCallback {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -9111232037888068394L;
+ private URL cssUrl;
+
+ /**
+ * @param cssUrl {@link URL}
+ */
+ public CustomLoggingCSSParseExceptionCallback(URL cssUrl) {
+ this.cssUrl = cssUrl;
+ }
+ /**
+ * @see
com.helger.css.handler.LoggingCSSParseExceptionCallback#onException(com.helger.css.parser.ParseException)
+ */
+ @Override
+ public void onException(ParseException ex) {
+ if(IGNORE_UNRECOVERABLE_PARSING_ERROR) {
+ LOG.warn("Failed to parse CSS: " + cssUrl + ", " +
LoggingCSSParseErrorHandler.createLoggingStringParseError (ex));
+ } else {
+ throw new IllegalStateException("Failed to parse CSS: " +
cssUrl + ", " + LoggingCSSParseErrorHandler.createLoggingStringParseError (ex));
+ }
+ }
+ }
/**
*
*/
@@ -67,32 +93,13 @@ public class CssParser implements LinkEx
final URL baseUrl, String encoding) throws
LinkExtractorParseException {
try {
String cssContent = new String(data, encoding);
- final CascadingStyleSheet aCSS = CSSReader.readFromString(
- cssContent,
- Charset.forName(encoding),
- ECSSVersion.CSS30,
- new LoggingCSSParseErrorHandler(),
- new LoggingCSSParseExceptionCallback(){
-
- /**
- *
- */
- private static final long serialVersionUID =
-9111232037888068394L;
-
- /**
- * @see
com.helger.css.handler.LoggingCSSParseExceptionCallback#onException(com.helger.css.parser.ParseException)
- */
- @Override
- public void onException(ParseException ex) {
- if(IGNORE_UNRECOVERABLE_PARSING_ERROR) {
- LOG.warn("Failed to parse CSS: " + baseUrl +
", " + LoggingCSSParseErrorHandler.createLoggingStringParseError (ex));
- } else {
- throw new IllegalStateException("Failed to
parse CSS: " + baseUrl + ", " +
LoggingCSSParseErrorHandler.createLoggingStringParseError (ex));
- }
- }
-
- }
- );
+ final CascadingStyleSheet aCSS =
CSSReader.readFromStringStream(cssContent,
+ new CSSReaderSettings()
+ .setBrowserCompliantMode(true)
+ .setFallbackCharset(Charset.forName(encoding))
+ .setCSSVersion (ECSSVersion.CSS30)
+ .setCustomErrorHandler(new
LoggingCSSParseErrorHandler())
+ .setCustomExceptionHandler (new
CustomLoggingCSSParseExceptionCallback(baseUrl)));
final List<URLString> list = new ArrayList<URLString>();
final URLCollection urlCollection = new URLCollection(list);
if(aCSS != null) {
@@ -117,8 +124,8 @@ public class CssParser implements LinkEx
}
if(LOG.isDebugEnabled()) {
StringBuilder builder = new StringBuilder();
- for (Iterator iterator = urlCollection.iterator();
iterator.hasNext();) {
- URL urlString = (URL) iterator.next();
+ for (Iterator<URL> iterator = urlCollection.iterator();
iterator.hasNext();) {
+ URL urlString = iterator.next();
builder.append(urlString).append(",");
}
LOG.debug("Parsed:"+baseUrl+", got:"+builder.toString());