use of java.util.regex.Pattern in project androidquery by androidquery.
the class AbstractAjaxCallback method getCharset.
//This is an adhoc way to get charset without html parsing library, might not cover all cases.
private String getCharset(String html) {
String pattern = "<meta [^>]*http-equiv[^>]*\"Content-Type\"[^>]*>";
Pattern p = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(html);
if (!m.find())
return null;
String tag = m.group();
return parseCharset(tag);
}
use of java.util.regex.Pattern in project openhab1-addons by openhab.
the class HDanywhereBinding method internalReceiveCommand.
@Override
protected void internalReceiveCommand(String itemName, Command command) {
HDanywhereBindingProvider provider = findFirstMatchingBindingProvider(itemName);
if (provider == null) {
logger.trace("doesn't find matching binding provider [itemName={}, command={}]", itemName, command);
return;
}
List<String> hosts = provider.getHosts(itemName);
int sourcePort = Integer.valueOf(command.toString());
for (String aHost : hosts) {
Integer numberOfPorts = matrixCache.get(aHost);
if (numberOfPorts == null) {
// we default to the smallest matrix currently sold by HDanywhere
numberOfPorts = 4;
}
if (sourcePort > numberOfPorts) {
// nice try - we can switch to a port that does not physically exist
logger.warn("{} goes beyond the physical number of {} ports available on the matrix {}", new Object[] { sourcePort, numberOfPorts, aHost });
} else {
List<Integer> ports = provider.getPorts(aHost, itemName);
String httpMethod = "GET";
String url = "http://" + aHost + "/switch.cgi?command=3&data0=";
for (Integer aPort : ports) {
url = url + aPort.toString() + "&data1=";
url = url + command.toString() + "&checksum=";
int checksum = 3 + aPort + sourcePort;
url = url + String.valueOf(checksum);
if (isNotBlank(httpMethod) && isNotBlank(url)) {
String response = HttpUtil.executeUrl(httpMethod, url, null, null, null, timeout);
Pattern p = Pattern.compile("The output " + aPort + " select input (.*).");
Matcher m = p.matcher(response);
while (m.find()) {
List<Class<? extends State>> stateTypeList = new ArrayList<Class<? extends State>>();
stateTypeList.add(DecimalType.class);
State state = TypeParser.parseState(stateTypeList, m.group(1));
if (!portMappingCache.containsKey(aHost + ":" + aPort)) {
portMappingCache.put(aHost + ":" + aPort, Integer.valueOf(m.group(1)));
eventPublisher.postUpdate(itemName, state);
} else {
int cachedValue = portMappingCache.get(aHost + ":" + aPort);
if (cachedValue != Integer.valueOf(m.group(1))) {
portMappingCache.put(aHost + ":" + aPort, Integer.valueOf(m.group(1)));
eventPublisher.postUpdate(itemName, state);
}
}
}
}
}
}
}
}
use of java.util.regex.Pattern in project platform_frameworks_base by android.
the class PatternsTest method testIanaTopLevelDomains_matchesIriTLD.
@SmallTest
public void testIanaTopLevelDomains_matchesIriTLD() throws Exception {
Pattern pattern = Pattern.compile(Patterns.IANA_TOP_LEVEL_DOMAINS);
assertTrue("Should match IRI TLD", pattern.matcher("한국").matches());
}
use of java.util.regex.Pattern in project platform_frameworks_base by android.
the class PatternsTest method testIanaTopLevelDomains_matchesValidNewTld.
@SmallTest
public void testIanaTopLevelDomains_matchesValidNewTld() throws Exception {
Pattern pattern = Pattern.compile(Patterns.IANA_TOP_LEVEL_DOMAINS);
assertTrue("Should match 'me'", pattern.matcher("me").matches());
}
use of java.util.regex.Pattern in project platform_frameworks_base by android.
the class PatternsTest method testIanaTopLevelDomains_doesNotMatchWrongTld.
@SmallTest
public void testIanaTopLevelDomains_doesNotMatchWrongTld() throws Exception {
Pattern pattern = Pattern.compile(Patterns.IANA_TOP_LEVEL_DOMAINS);
assertFalse("Should not match 'mem'", pattern.matcher("mem").matches());
}
Aggregations