|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.myjavatools.lib.Web
public class Web
| Field Summary | |
|---|---|
protected static java.util.regex.Pattern |
HTML_CHARSET_PATTERN
|
protected static java.util.regex.Pattern |
XML_CHARSET_PATTERN
|
| Constructor Summary | |
|---|---|
Web()
|
|
| Method Summary | |
|---|---|
static java.lang.String |
downloadFile(java.lang.String url,
java.lang.String filename)
Downloads a file from a specified URL |
static java.lang.String |
downloadFile(java.net.URL url,
java.lang.String filename)
Downloads a file from a specified URL |
static java.lang.String |
getCharsetByEncoding(java.lang.String encoding)
Deprecated. should use java.nio.Charset |
static java.lang.String |
getEncodingByCharset(java.lang.String charset)
gets Java encoding given an IANA charset |
static java.lang.String |
getHtmlCharset(java.lang.CharSequence s)
Detects charset from html contents |
static java.lang.String |
getHtmlEncoding(java.lang.CharSequence s)
gets Java encoding of HTML contents |
static java.io.InputStream |
getUrlInputStream(java.net.URL url)
gets an input stream for a given url |
static java.lang.String |
getXmlCharset(java.lang.CharSequence s)
Detects charset from xml contents |
static java.lang.String |
getXmlEncoding(java.lang.CharSequence s)
gets Java encoding of XML data |
static java.lang.String |
quote(java.lang.String s)
surrounds a string with single quotes (apostrophes), which is convenient for generating Javascript code, but just senseless otherwise. |
static void |
sendMail(java.lang.String from,
java.lang.String to,
java.lang.String subj,
java.lang.String message)
sendMail sends emails. |
static java.lang.String |
toWebReadable(java.lang.String s)
converts a string into something that could be literally placed into a web page, that is, replaces CR with CRLF (to be polite with browser's 'view source'), replaces all '<' with "<", and html-encodes (dddd;) characters above low-ascii. |
static java.lang.String |
url(java.lang.String href,
java.util.Collection nvPairList)
produces a GET request string for a uri and a collection of parameters |
static java.lang.String |
url(java.lang.String uri,
java.lang.String... paramvalue)
produces a GET request string for a uri and request parameters |
static java.lang.String |
urlEncode(java.lang.String name,
java.lang.String value)
converts a name-value pair into an element of url string |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static java.util.regex.Pattern HTML_CHARSET_PATTERN
protected static java.util.regex.Pattern XML_CHARSET_PATTERN
| Constructor Detail |
|---|
public Web()
| Method Detail |
|---|
public static java.lang.String getHtmlCharset(java.lang.CharSequence s)
s - the char sequence with html content
getHtmlCharset("")
returns "shift-jis".public static java.lang.String getXmlCharset(java.lang.CharSequence s)
s - the char sequence with html content
getXmlCharset("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
returns "utf-8".public static java.lang.String getCharsetByEncoding(java.lang.String encoding)
encoding - the Java charset
public static java.lang.String getEncodingByCharset(java.lang.String charset)
charset - the IANA charset
public static java.lang.String getHtmlEncoding(java.lang.CharSequence s)
s - HTML data
getHtmlCharset("")
returns "SJIS".public static java.lang.String getXmlEncoding(java.lang.CharSequence s)
s - XML data (first line is enough)
getXmlEncoding("?xml version=\"1.0\" encoding=\"UTF-8"?>")
will return "UTF8".
public static java.io.InputStream getUrlInputStream(java.net.URL url)
throws java.io.IOException,
java.lang.InstantiationException
url - the universal resource locator
java.io.IOException
java.lang.InstantiationException - getUrlInputStream(new URL("http://www.google.com/images/logo.gif"))
will return an input stream that contains the Google gif.
public static java.lang.String downloadFile(java.net.URL url,
java.lang.String filename)
url - URL that points to a resourcefilename - the name of the file to store the contents
downloadFile(new URL("http://www.google.com/images/logo.gif"), "googlelogo.gif")
will download the gif, store it into the file, and return an empty string.
public static java.lang.String downloadFile(java.lang.String url,
java.lang.String filename)
url - URL string that points to a resourcefilename - the name of the file to store the contents
downloadFile("http://www.google.com/images/logo.gif", "googlelogo.gif")
will download the gif, store it into the file, and return an empty string.
public static void sendMail(java.lang.String from,
java.lang.String to,
java.lang.String subj,
java.lang.String message)
throws java.net.MalformedURLException,
java.io.IOException
from - sender addressto - receiver addresssubj - message subjectmessage - message body
java.io.MalformedURLException
java.io.IOException
java.net.MalformedURLException
public static final java.lang.String urlEncode(java.lang.String name,
java.lang.String value)
name - parameter namevalue - parameter value
urlEncode("dir", "C:\\Program Files"")
will return "dir=C%3A%5CProgram+Files".
public static final java.lang.String url(java.lang.String href,
java.util.Collection nvPairList)
href - url where to send the requestnvPairList - a collection of (already url-encoded) name-value pair
strings that look like "name=value"
urlEncode("http://example.myjavatools.com/mycomputer",
new ArrayList(new String[] {"dir=C%3A%5CProgram+Files", "cmd=dir+*"}))
will return "http://example.myjavatools.com/mycomputer?dir=C%3A%5CProgram+Files&cmd=dir+*".
public static final java.lang.String url(java.lang.String uri,
java.lang.String... paramvalue)
uri - where to send the requestparamvalue - String...
(etc)
urlEncode("http://example.myjavatools.com/mycomputer",
"dir, "C:\Program Files"))
will return "http://example.myjavatools.com/mycomputer?dir=C%3A%5CProgram+Files".urlEncode("http://example.myjavatools.com/mycomputer",
"dir, "C:\Program Files", "cmd", "dir *")
will return "http://example.myjavatools.com/mycomputer?dir=C%3A%5CProgram+Files&cmd=dir+*".urlEncode("http://mycomputer",
"dir, "C:\Program Files", "cmd", "dir *", "login", "root", "password", "urowned")
will return "http://mycomputer?dir=C%3A%5CProgram+Files&cmd=dir+*&login=root&password=urowned".public static final java.lang.String toWebReadable(java.lang.String s)
s - string to convert
public static final java.lang.String quote(java.lang.String s)
s - string to quote
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||