|
What this is
Other links
The source code
// $Header: /home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/parser/HtmlParsingUtils.java,v 1.10 2004/02/16 13:47:18 sebb Exp $
/*
* Copyright 2003-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.jmeter.protocol.http.parser;
import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
import org.apache.jmeter.config.Argument;
import org.apache.jmeter.junit.JMeterTestCase;
import org.apache.jmeter.protocol.http.sampler.HTTPSampler;
import org.apache.jmeter.testelement.property.PropertyIterator;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.jorphan.util.JOrphanUtils;
import org.apache.log.Logger;
import org.apache.oro.text.PatternCacheLRU;
import org.apache.oro.text.regex.MalformedPatternException;
import org.apache.oro.text.regex.Perl5Compiler;
import org.apache.oro.text.regex.Perl5Matcher;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.tidy.Tidy;
import org.xml.sax.SAXException;
/**
* @author Michael Stover
* Created June 14, 2001
* @version $Revision: 1.10 $ Last updated: $Date: 2004/02/16 13:47:18 $
*/
public final class HtmlParsingUtils
{
transient private static Logger log = LoggingManager.getLoggerForClass();
protected static String utfEncodingName;
/* NOTUSED
private int compilerOptions =
Perl5Compiler.CASE_INSENSITIVE_MASK
| Perl5Compiler.MULTILINE_MASK
| Perl5Compiler.READ_ONLY_MASK;
*/
private static PatternCacheLRU patternCache =
new PatternCacheLRU(1000, new Perl5Compiler());
private static ThreadLocal localMatcher = new ThreadLocal()
{
protected Object initialValue()
{
return new Perl5Matcher();
}
};
/**
* Private constructor to prevent instantiation.
*/
private HtmlParsingUtils()
{
}
public static synchronized boolean isAnchorMatched(
HTTPSampler newLink,
HTTPSampler config)
throws MalformedPatternException
{
boolean ok = true;
Perl5Matcher matcher = (Perl5Matcher) localMatcher.get();
PropertyIterator iter = config.getArguments().iterator();
String query = null;
try
{
query = JOrphanUtils.decode(newLink.getQueryString(),"UTF-8");
}
catch (UnsupportedEncodingException e)
{
// UTF-8 unsupported? You must be joking!
log.error("UTF-8 encoding not supported!");
throw new Error("Should not happen: "+e.toString());
}
if (query == null && config.getArguments().getArgumentCount() > 0)
{
return false;
}
while (iter.hasNext())
{
Argument item = (Argument) iter.next().getObjectValue();
if (query.indexOf(item.getName() + "=") == -1)
{
if (!(ok =
ok
&& matcher.contains(
query,
patternCache.getPattern(
item.getName(),
Perl5Compiler.READ_ONLY_MASK))))
{
return false;
}
}
}
if (config.getDomain() != null
&& config.getDomain().length() > 0
&& !newLink.getDomain().equals(config.getDomain()))
{
if (!(ok =
ok
&& matcher.matches(
newLink.getDomain(),
patternCache.getPattern(
config.getDomain(),
Perl5Compiler.READ_ONLY_MASK))))
{
return false;
}
}
if (!newLink.getPath().equals(config.getPath())
&& !matcher.matches(
newLink.getPath(),
patternCache.getPattern(
"[/]*" + config.getPath(),
Perl5Compiler.READ_ONLY_MASK)))
{
return false;
}
if (!(ok =
ok
&& matcher.matches(
newLink.getProtocol(),
patternCache.getPattern(
config.getProtocol(),
Perl5Compiler.READ_ONLY_MASK))))
{
return false;
}
return ok;
}
public static synchronized boolean isArgumentMatched(
Argument arg,
Argument patternArg)
throws MalformedPatternException
{
Perl5Matcher matcher = (Perl5Matcher) localMatcher.get();
return (
arg.getName().equals(patternArg.getName())
|| matcher.matches(
arg.getName(),
patternCache.getPattern(
patternArg.getName(),
Perl5Compiler.READ_ONLY_MASK)))
&& (arg.getValue().equals(patternArg.getValue())
|| matcher.matches(
(String) arg.getValue(),
patternCache.getPattern(
(String) patternArg.getValue(),
Perl5Compiler.READ_ONLY_MASK)));
}
/**
* Returns
|
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.