public class UrlPreviewComponent extends AbstractLogEnabled implements Component, Contextualizable
Modifier and Type | Field and Description |
---|---|
private Context |
_context |
static String |
ROLE
The avalon role
|
Constructor and Description |
---|
UrlPreviewComponent() |
Modifier and Type | Method and Description |
---|---|
private Connection |
_getConnection(String url,
String lang) |
private String |
_getDescription(Document doc) |
private String |
_getFavicon(Document doc,
URL url) |
private String |
_getImageUrl(Document doc) |
private String |
_getTitle(Document doc) |
private String |
_getUserAgent()
Get the user agent from current request
|
void |
contextualize(Context context) |
InputStream |
convertIcoToPng(InputStream is)
Convert an file.ico into a file.png
|
String |
getFavicon(String url)
Fetch and parse the HTML page at given url to get the favicon url
|
UrlPreview |
getUrlPreview(String url,
String lang)
Fetch and parse the HTML page at given url to get the
UrlPreview |
Map<String,String> |
parseUrl(String url,
String lang)
Fetch and parse the HTML page at given url for preview
|
getLogger, setLogger
public UrlPreviewComponent()
public void contextualize(Context context) throws ContextException
contextualize
in interface Contextualizable
ContextException
public UrlPreview getUrlPreview(String url, String lang) throws HttpStatusException, IOException
UrlPreview
url
- the url to parselang
- the languageUrlPreview
HttpStatusException
- if the HTTP request resulted in a not OK HTTP response.IOException
- if an error occured while parsing HTML pagepublic String getFavicon(String url) throws IOException
url
- the url to parseHttpStatusException
- if the HTTP request resulted in a not OK HTTP response.IOException
- if an error occured while parsing HTML pagepublic InputStream convertIcoToPng(InputStream is) throws IOException
is
- the input stream of the file.icoIOException
- if failed to convert .icopublic Map<String,String> parseUrl(String url, String lang)
url
- the url to parselang
- the languageprivate Connection _getConnection(String url, String lang)
private String _getDescription(Document doc)
private String _getImageUrl(Document doc)
private String _getFavicon(Document doc, URL url)
private String _getUserAgent()