Package org.javlo.helper
Class NetHelper
- java.lang.Object
 - 
- org.javlo.helper.NetHelper
 
 
- 
public class NetHelper extends Object
 
- 
- 
Field Summary
Fields Modifier and Type Field Description static StringHEADER_DATEstatic StringHEADER_ETAGstatic StringHEADER_IF_MODIFIED_SINCEstatic StringHEADER_IF_MODIFIED_SINCE_ETAGstatic StringHEADER_LAST_MODIFIEDstatic StringJAVLO_USER_AGENTprotected static Loggerloggercreate a static logger.static StringMOZILLA_USER_AGENT 
- 
Constructor Summary
Constructors Constructor Description NetHelper() 
- 
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancanReach(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 URLfollowURL(URL url)follow redirection and return final urlstatic StringgetContentType(URL url)static javax.servlet.http.CookiegetCookie(javax.servlet.http.HttpServletRequest request, String name)static List<URL>getExternalLinks(String content)static StringgetIp(javax.servlet.http.HttpServletRequest request)static intgetIpAsInt(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 StringgetLocalCopyOfPageImage(String cacheFolder, String dataFolder, URL pageURL, URL imageURL, String content, CRC32 crc32, boolean preferVertical, boolean needVertical)analyse a page and retreive a imagestatic StringgetLocalCopyOfPageImage(ContentContext ctx, URL inURL, String content, CRC32 crc32, boolean preferVertical, boolean needVertical)analyse a page and retreive a imagestatic StringgetPageDescription(String content)extract the title of a web page.static PageMetagetPageMeta(URL url)static StringgetPageTitle(String content)extract the title of a web page.static StringgetPageTitle(URL url)extract the title of a web page.static booleaninsertEtag(ContentContext ctx, File file, String secondaryHash)insert and check ETagstatic booleaninsertEtag(ContentContext ctx, MenuElement page)static booleanipInRange(String ip, String range)check if a ip is in a specific rangestatic booleanisConnected()check internet connection with stable server.static booleanisIPAccepted(ContentContext ctx)static booleanisMobile(String userAgent)static booleanisRobot(String userAgent)static booleanisURLValid(URL url)static booleanisURLValid(URL url, boolean only404)static booleanisUserAgentRobot(String userAgent)static voidmain(String[] args)static voidnocheckCertificatHttps()static StringpostJsonRequest(URL url, String userAgent, Map<String,String> header, String json)static LongreadDate(URL url)static com.google.gson.JsonElementreadJson(URL url)read a page a put content in a String.static StringreadPage(String inURL, boolean cssInline)static StringreadPage(URL url)static StringreadPage(URL url, boolean cssInline, String userAgent)static voidreadPage(URL url, OutputStream out)read a page a put content in a Stream.static StringreadPage(URL url, String userName, String password)static StringreadPageForMailing(URL url)static StringreadPageForMailing(URL url, String token)static StringreadPageForMailing(URL url, String login, String pwd)static StringreadPageGet(URL url)static StringreadPageGet(URLConnection conn, boolean checkReturnCode)static StringreadPageGet(URL url, boolean checkReturnCode)static StringreadPageGetFollowRedirect(URL url)static StringreadPageNoError(URL url)static StringreadPageWithGet(URL url)read a page a put content in a Stream.static URLremoveParams(URL url)remove params of a urlstatic booleansendMail(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 booleansendMail(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 voidsendMailToAdministrator(GlobalContext globalContext, String subject, String content)static voidsendMailToAdministrator(GlobalContext globalContext, javax.mail.internet.InternetAddress from, String subject, String content)static voidsendPageByMailing(ContentContext ctx, MenuElement page, String sender, String recipient, Map<String,Object> params)static voidsendRedirectPermanently(javax.servlet.http.HttpServletResponse response, String url)static voidsendRedirectTemporarily(javax.servlet.http.HttpServletResponse response, String url)static voidsendXHTMLMail(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 voidsetJsonContentType(javax.servlet.http.HttpServletResponse response)static booleantestPort(String host, int port)static CompanyvalidVATEuroparlEU(ContentContext ctx, String vat)static voidwriteURLToStream(URL url, OutputStream out) 
 - 
 
- 
- 
Field Detail
- 
JAVLO_USER_AGENT
public static final String JAVLO_USER_AGENT
- See Also:
 - Constant Field Values
 
 
- 
MOZILLA_USER_AGENT
public static final String MOZILLA_USER_AGENT
- See Also:
 - Constant Field Values
 
 
- 
logger
protected static Logger logger
create a static logger. 
- 
HEADER_DATE
public static final String HEADER_DATE
- See Also:
 - Constant Field Values
 
 
- 
HEADER_LAST_MODIFIED
public static final String HEADER_LAST_MODIFIED
- See Also:
 - Constant Field Values
 
 
- 
HEADER_IF_MODIFIED_SINCE
public static final String HEADER_IF_MODIFIED_SINCE
- See Also:
 - Constant Field Values
 
 
- 
HEADER_ETAG
public static final String HEADER_ETAG
- See Also:
 - Constant Field Values
 
 
- 
HEADER_IF_MODIFIED_SINCE_ETAG
public static final String HEADER_IF_MODIFIED_SINCE_ETAG
- See Also:
 - Constant Field Values
 
 
 - 
 
- 
Method Detail
- 
readPageForMailing
public static String readPageForMailing(URL url) throws Exception
- Throws:
 Exception
 
- 
readPageForMailing
public static String readPageForMailing(URL url, String login, String pwd) throws Exception
- Throws:
 Exception
 
- 
readPageForMailing
public static String readPageForMailing(URL url, String token) throws Exception
- Throws:
 Exception
 
- 
readPageGet
public static String readPageGet(URLConnection conn, boolean checkReturnCode) throws Exception
- Throws:
 Exception
 
- 
followURL
public static URL followURL(URL url) throws Exception
follow redirection and return final url- Parameters:
 url-- Returns:
 - Throws:
 Exception
 
- 
readPageGetFollowRedirect
public static String readPageGetFollowRedirect(URL url) throws Exception
- Throws:
 Exception
 
- 
readPageGet
public static String readPageGet(URL url, boolean checkReturnCode) throws Exception
- Throws:
 Exception
 
- 
readPage
public static String readPage(URL url, String userName, String password) throws Exception
- Throws:
 Exception
 
- 
readPage
public static String readPage(String inURL, boolean cssInline) throws Exception
- Throws:
 Exception
 
- 
readPage
public static String readPage(URL url, boolean cssInline, String userAgent) throws Exception
- Throws:
 Exception
 
- 
postJsonRequest
public static String postJsonRequest(URL url, String userAgent, Map<String,String> header, String json) throws Exception
- Throws:
 Exception
 
- 
nocheckCertificatHttps
public static void nocheckCertificatHttps() throws NoSuchAlgorithmException, KeyManagementException 
- 
writeURLToStream
public static void writeURLToStream(URL url, OutputStream out) throws Exception
- Throws:
 Exception
 
- 
readJson
public static com.google.gson.JsonElement readJson(URL url) throws Exception
read a page a put content in a String.- Parameters:
 url- a valid URL- Returns:
 - code returned by the http request on the URL.
 - Throws:
 IOExceptionException
 
- 
setJsonContentType
public static void setJsonContentType(javax.servlet.http.HttpServletResponse response)
 
- 
readPage
public static void readPage(URL url, OutputStream out) throws Exception
read a page a put content in a Stream.- Parameters:
 out- the output stream, it receive the url inputstream- Throws:
 IOExceptionException
 
- 
readPageWithGet
public static String readPageWithGet(URL url)
read a page a put content in a Stream.- Parameters:
 out- the output stream, it receive the url inputstream- Returns:
 - code returned by the http request on the URL.
 - Throws:
 IOException
 
- 
getPageTitle
public static String getPageTitle(URL url) throws Exception
extract the title of a web page.- Parameters:
 url-- Returns:
 - the title of the page.
 - Throws:
 Exception
 
- 
getPageTitle
public static String getPageTitle(String content)
extract the title of a web page.- Parameters:
 URL-- Returns:
 - the title of the page.
 
 
- 
getPageDescription
public static String getPageDescription(String content)
extract the title of a web page.- Parameters:
 URL-- Returns:
 - the title of the page.
 
 
- 
isUserAgentRobot
public static boolean isUserAgentRobot(String userAgent)
 
- 
extractImage
public static List<VisualResource> extractImage(URL inURL, String content, boolean needSize)
 
- 
getLocalCopyOfPageImage
public static String getLocalCopyOfPageImage(ContentContext ctx, URL inURL, String content, CRC32 crc32, boolean preferVertical, boolean needVertical)
analyse a page and retreive a image- Parameters:
 URL- the url of the pagecontent- the content- Returns:
 - the uri to the local file
 
 
- 
extractMostSimilarLinks
public static List<URL> extractMostSimilarLinks(URL url) throws Exception
- Throws:
 Exception
 
- 
getLocalCopyOfPageImage
public 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- Parameters:
 URL- the url of the pagecontent- the content- Returns:
 - the uri to the local file
 
 
- 
isURLValid
public static boolean isURLValid(URL url)
 
- 
isURLValid
public static boolean isURLValid(URL url, boolean only404)
 
- 
isConnected
public static boolean isConnected()
check internet connection with stable server.- Returns:
 
 
- 
canReach
public static boolean canReach(String url)
check if the given url can be reached.- Parameters:
 url-- Returns:
 
 
- 
sendMailToAdministrator
public static void sendMailToAdministrator(GlobalContext globalContext, String subject, String content) throws javax.mail.internet.AddressException
- Throws:
 javax.mail.internet.AddressException
 
- 
sendMailToAdministrator
public static void sendMailToAdministrator(GlobalContext globalContext, javax.mail.internet.InternetAddress from, String subject, String content)
 
- 
sendXHTMLMail
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
- Throws:
 Exception
 
- 
sendMail
public static boolean 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)
 
- 
sendMail
public static boolean 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)
 
- 
sendRedirectPermanently
public static void sendRedirectPermanently(javax.servlet.http.HttpServletResponse response, String url) 
- 
sendRedirectTemporarily
public static void sendRedirectTemporarily(javax.servlet.http.HttpServletResponse response, String url) 
- 
getCookie
public static javax.servlet.http.Cookie getCookie(javax.servlet.http.HttpServletRequest request, String name) 
- 
isRobot
public static boolean isRobot(String userAgent)
 
- 
isMobile
public static boolean isMobile(String userAgent)
 
- 
sendPageByMailing
public static void sendPageByMailing(ContentContext ctx, MenuElement page, String sender, String recipient, Map<String,Object> params) throws Exception
- Throws:
 Exception
 
- 
getIpAsInt
public static int getIpAsInt(String ip)
convert a ip in string (192.168.0.1) to a integer value.- Parameters:
 ip-- Returns:
 
 
- 
ipInRange
public static boolean ipInRange(String ip, String range)
check if a ip is in a specific range- Parameters:
 ip-range-- Returns:
 
 
- 
isIPAccepted
public static boolean isIPAccepted(ContentContext ctx)
 
- 
validVATEuroparlEU
public static Company validVATEuroparlEU(ContentContext ctx, String vat) throws MalformedURLException, Exception
- Throws:
 MalformedURLExceptionException
 
- 
insertEtag
public static boolean insertEtag(ContentContext ctx, File file, String secondaryHash) throws IOException
insert and check ETag- Parameters:
 ctx-file-secondaryHash-- Returns:
 - true if content in cache (>> stop rendering)
 - Throws:
 IOException
 
- 
testPort
public static boolean testPort(String host, int port)
 
- 
insertEtag
public static boolean insertEtag(ContentContext ctx, MenuElement page) throws Exception
- Throws:
 Exception
 
- 
getIp
public static String getIp(javax.servlet.http.HttpServletRequest request)
 
 - 
 
 -