public class NetHelper extends Object
Modifier and Type | Field and Description |
---|---|
static String |
HEADER_DATE |
static String |
HEADER_ETAG |
static String |
HEADER_IF_MODIFIED_SINCE |
static String |
HEADER_IF_MODIFIED_SINCE_ETAG |
static String |
HEADER_LAST_MODIFIED |
static String |
JAVLO_USER_AGENT |
protected static Logger |
logger
create a static logger.
|
Constructor and Description |
---|
NetHelper() |
Modifier and Type | Method and Description |
---|---|
static boolean |
canReach(String url)
check if the given url can be reached.
|
static List<String> |
extractExternalURL(URL inURL,
String content) |
static List<VisualResource> |
extractImage(URL inURL,
String content,
boolean needSize) |
static List<URL> |
extractMostSimilarLinks(URL url) |
static List<String> |
extractURL(URL inURL,
String content) |
static URL |
followURL(URL url)
follow redirection and return final url
|
static String |
getContentType(URL url) |
static javax.servlet.http.Cookie |
getCookie(javax.servlet.http.HttpServletRequest request,
String name) |
static List<URL> |
getExternalLinks(String content) |
static int |
getIpAsInt(String ip)
convert a ip in string (192.168.0.1) to a integer value.
|
static List<URL> |
getLinks(String content,
String inURL) |
static List<URL> |
getLinksFromText(String content) |
static String |
getLocalCopyOfPageImage(ContentContext ctx,
URL inURL,
String content,
CRC32 crc32,
boolean preferVertical,
boolean needVertical)
analyse a page and retreive a image
|
static String |
getLocalCopyOfPageImage(String cacheFolder,
String dataFolder,
URL pageURL,
URL imageURL,
String content,
CRC32 crc32,
boolean preferVertical,
boolean needVertical)
analyse a page and retreive a image
|
static String |
getPageDescription(String content)
extract the title of a web page.
|
static PageMeta |
getPageMeta(URL url) |
static String |
getPageTitle(String content)
extract the title of a web page.
|
static String |
getPageTitle(URL url)
extract the title of a web page.
|
static boolean |
ipInRange(String ip,
String range)
check if a ip is in a specific range
|
static boolean |
isConnected()
check internet connection with stable server.
|
static boolean |
isIPAccepted(ContentContext ctx) |
static boolean |
isMobile(String userAgent) |
static boolean |
isRobot(String userAgent) |
static boolean |
isURLValid(URL url) |
static boolean |
isURLValid(URL url,
boolean only404) |
static boolean |
isUserAgentRobot(String userAgent) |
static void |
main(String[] args) |
static String |
postJsonRequest(URL url,
String userAgent,
Map<String,String> header,
String json) |
static Long |
readDate(URL url) |
static com.google.gson.JsonElement |
readJson(URL url)
read a page a put content in a String.
|
static String |
readPage(String inURL,
boolean cssInline) |
static String |
readPage(URL url) |
static String |
readPage(URL url,
boolean cssInline,
String userAgent) |
static void |
readPage(URL url,
OutputStream out)
read a page a put content in a Stream.
|
static String |
readPage(URL url,
String userName,
String password) |
static String |
readPageForMailing(URL url) |
static String |
readPageForMailing(URL url,
String token) |
static String |
readPageForMailing(URL url,
String login,
String pwd) |
static String |
readPageGet(URL url) |
static String |
readPageGet(URL url,
boolean checkReturnCode) |
static String |
readPageGet(URLConnection conn,
boolean checkReturnCode) |
static String |
readPageGetFollowRedirect(URL url) |
static String |
readPageNoError(URL url) |
static String |
readPageWithGet(URL url)
read a page a put content in a Stream.
|
static URL |
removeParams(URL url)
remove params of a url
|
static void |
sendMail(GlobalContext globalContext,
javax.mail.internet.InternetAddress from,
javax.mail.internet.InternetAddress to,
javax.mail.internet.InternetAddress cc,
javax.mail.internet.InternetAddress bcc,
String subject,
String content) |
static void |
sendMail(GlobalContext globalContext,
javax.mail.internet.InternetAddress from,
javax.mail.internet.InternetAddress to,
javax.mail.internet.InternetAddress cc,
javax.mail.internet.InternetAddress bcc,
String subject,
String content,
String contentTxt,
boolean isHTML) |
static void |
sendMailToAdministrator(GlobalContext globalContext,
javax.mail.internet.InternetAddress from,
String subject,
String content) |
static void |
sendMailToAdministrator(GlobalContext globalContext,
String subject,
String content) |
static void |
sendPageByMailing(ContentContext ctx,
MenuElement page,
String sender,
String recipient,
Map<String,Object> params) |
static void |
sendRedirectPermanently(javax.servlet.http.HttpServletResponse response,
String url) |
static void |
sendRedirectTemporarily(javax.servlet.http.HttpServletResponse response,
String url) |
static void |
sendXHTMLMail(ContentContext ctx,
javax.mail.internet.InternetAddress from,
javax.mail.internet.InternetAddress to,
javax.mail.internet.InternetAddress cc,
javax.mail.internet.InternetAddress bcc,
String subject,
String content,
String templateName) |
static Company |
validVATEuroparlEU(ContentContext ctx,
String vat) |
public static final String JAVLO_USER_AGENT
protected static Logger logger
public static final String HEADER_DATE
public static final String HEADER_LAST_MODIFIED
public static final String HEADER_IF_MODIFIED_SINCE
public static final String HEADER_ETAG
public static final String HEADER_IF_MODIFIED_SINCE_ETAG
public static String readPageForMailing(URL url) throws Exception
Exception
public static String readPageForMailing(URL url, String login, String pwd) throws Exception
Exception
public static String readPageForMailing(URL url, String token) throws Exception
Exception
public static String readPageGet(URLConnection conn, boolean checkReturnCode) throws Exception
Exception
public static URL followURL(URL url) throws Exception
url
- Exception
public static String readPageGetFollowRedirect(URL url) throws Exception
Exception
public static String readPageGet(URL url, boolean checkReturnCode) throws Exception
Exception
public static String readPage(URL url, String userName, String password) throws Exception
Exception
public static String readPage(String inURL, boolean cssInline) throws Exception
Exception
public static String readPage(URL url, boolean cssInline, String userAgent) throws Exception
Exception
public static String postJsonRequest(URL url, String userAgent, Map<String,String> header, String json) throws Exception
Exception
public static com.google.gson.JsonElement readJson(URL url) throws Exception
url
- a valid URLIOException
Exception
public static void readPage(URL url, OutputStream out) throws Exception
out
- the output stream, it receive the url inputstreamIOException
Exception
public static String readPageWithGet(URL url)
out
- the output stream, it receive the url inputstreamIOException
public static String getPageTitle(URL url) throws Exception
url
- Exception
public static String getPageTitle(String content)
URL
- public static String getPageDescription(String content)
URL
- public static boolean isUserAgentRobot(String userAgent)
public static List<VisualResource> extractImage(URL inURL, String content, boolean needSize)
public static String getLocalCopyOfPageImage(ContentContext ctx, URL inURL, String content, CRC32 crc32, boolean preferVertical, boolean needVertical)
URL
- the url of the pagecontent
- the contentpublic static List<URL> extractMostSimilarLinks(URL url) throws Exception
Exception
public static String getLocalCopyOfPageImage(String cacheFolder, String dataFolder, URL pageURL, URL imageURL, String content, CRC32 crc32, boolean preferVertical, boolean needVertical)
URL
- the url of the pagecontent
- the contentpublic static boolean isURLValid(URL url)
public static boolean isURLValid(URL url, boolean only404)
public static boolean isConnected()
public static boolean canReach(String url)
url
- public static void sendMailToAdministrator(GlobalContext globalContext, String subject, String content) throws javax.mail.internet.AddressException
javax.mail.internet.AddressException
public static void sendMailToAdministrator(GlobalContext globalContext, javax.mail.internet.InternetAddress from, String subject, String content)
public static void sendXHTMLMail(ContentContext ctx, javax.mail.internet.InternetAddress from, javax.mail.internet.InternetAddress to, javax.mail.internet.InternetAddress cc, javax.mail.internet.InternetAddress bcc, String subject, String content, String templateName) throws Exception
Exception
public static void sendMail(GlobalContext globalContext, javax.mail.internet.InternetAddress from, javax.mail.internet.InternetAddress to, javax.mail.internet.InternetAddress cc, javax.mail.internet.InternetAddress bcc, String subject, String content)
public static void sendMail(GlobalContext globalContext, javax.mail.internet.InternetAddress from, javax.mail.internet.InternetAddress to, javax.mail.internet.InternetAddress cc, javax.mail.internet.InternetAddress bcc, String subject, String content, String contentTxt, boolean isHTML)
public static void sendRedirectPermanently(javax.servlet.http.HttpServletResponse response, String url)
public static void sendRedirectTemporarily(javax.servlet.http.HttpServletResponse response, String url)
public static javax.servlet.http.Cookie getCookie(javax.servlet.http.HttpServletRequest request, String name)
public static boolean isRobot(String userAgent)
public static boolean isMobile(String userAgent)
public static void sendPageByMailing(ContentContext ctx, MenuElement page, String sender, String recipient, Map<String,Object> params) throws Exception
Exception
public static int getIpAsInt(String ip)
ip
- public static boolean ipInRange(String ip, String range)
ip
- range
- public static boolean isIPAccepted(ContentContext ctx)
public static Company validVATEuroparlEU(ContentContext ctx, String vat) throws MalformedURLException, Exception
MalformedURLException
Exception
Copyright © 2012-2018. All Rights Reserved.