mirror of
https://github.com/Rogiel/httpchannel
synced 2025-12-05 23:22:51 +00:00
Implements uptobox.com upload service
This commit is contained in:
@@ -5,18 +5,31 @@ package com.rogiel.httpchannel.util;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class Filesizes {
|
||||
public static long kb(long kb) {
|
||||
return kb * 1024;
|
||||
public static long kb(double kb) {
|
||||
return (long) (kb * 1024);
|
||||
}
|
||||
|
||||
public static long mb(long mb) {
|
||||
|
||||
public static long mb(double mb) {
|
||||
return kb(mb) * 1024;
|
||||
}
|
||||
|
||||
public static long gb(long gb) {
|
||||
|
||||
public static long gb(double gb) {
|
||||
return mb(gb) * 1024;
|
||||
}
|
||||
|
||||
public static long auto(double value, String unit) {
|
||||
unit = unit.toUpperCase().trim().substring(0, 1);
|
||||
switch (unit) {
|
||||
case "K":
|
||||
return kb(value);
|
||||
case "M":
|
||||
return mb(value);
|
||||
case "G":
|
||||
return gb(value);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,10 @@ public class HTMLPage {
|
||||
return filtered;
|
||||
}
|
||||
|
||||
public boolean containsPlain(Pattern pattern) {
|
||||
return pattern.matcher(asString()).find();
|
||||
}
|
||||
|
||||
public boolean contains(final Pattern pattern) {
|
||||
return !filter(Node.class, new ContainsFilter(pattern)).isEmpty();
|
||||
}
|
||||
@@ -90,6 +94,21 @@ public class HTMLPage {
|
||||
.quote(text.toLowerCase())))).isEmpty();
|
||||
}
|
||||
|
||||
public String findPlain(final Pattern pattern, int n) {
|
||||
final Matcher matcher = pattern.matcher(asString());
|
||||
if (matcher.find())
|
||||
return matcher.group(n);
|
||||
return null;
|
||||
}
|
||||
|
||||
public int findIntPlain(final Pattern pattern, int n) {
|
||||
return Integer.parseInt(findPlain(pattern, n));
|
||||
}
|
||||
|
||||
public double findDoublePlain(final Pattern pattern, int n) {
|
||||
return Double.parseDouble(findPlain(pattern, n));
|
||||
}
|
||||
|
||||
public String find(final Pattern pattern, int n) {
|
||||
for (final Node tag : filter(Tag.class, new ContainsFilter(pattern))) {
|
||||
final Matcher matcher = pattern.matcher(tag.getText());
|
||||
@@ -200,6 +219,10 @@ public class HTMLPage {
|
||||
return ((TextareaTag) getTagByID(id)).getStringText();
|
||||
}
|
||||
|
||||
public String getTextareaValueByName(String name) {
|
||||
return ((TextareaTag) getTagByName(name)).getStringText();
|
||||
}
|
||||
|
||||
public Tag getTagByID(final String id) {
|
||||
for (final Tag tag : filter(Tag.class, new IDFilter(id))) {
|
||||
return tag;
|
||||
@@ -257,4 +280,25 @@ public class HTMLPage {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String asString() {
|
||||
StringBuffer buff = new StringBuffer();
|
||||
for (int i = 0; i < nodes.size(); i++) {
|
||||
// final String content = nodes.elementAt(i).toPlainTextString()
|
||||
// .replaceAll("\n", "").replaceAll("\\t", "").trim();
|
||||
// if (content.length() > 0) {
|
||||
// buff.append(" ").append(content);
|
||||
// }
|
||||
final String[] lines = nodes.elementAt(i).toPlainTextString()
|
||||
.split("\n");
|
||||
for (final String line : lines) {
|
||||
final String processed = line.trim();
|
||||
if (processed.length() > 0) {
|
||||
buff.append(line.trim()).append(" ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return buff.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user