Package org.ametys.web.url
Class UrlPreviewComponent
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.web.url.UrlPreviewComponent
-
- All Implemented Interfaces:
LogEnabled,Component,Contextualizable
public class UrlPreviewComponent extends AbstractLogEnabled implements Component, Contextualizable
Component to parse a HTML page to get its meta for preview
-
-
Constructor Summary
Constructors Constructor Description UrlPreviewComponent()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 requestvoidcontextualize(Context context)InputStreamconvertIcoToPng(InputStream is)Convert an file.ico into a file.pngStringgetFavicon(String url)Fetch and parse the HTML page at given url to get the favicon urlUrlPreviewgetUrlPreview(String url, String lang)Fetch and parse the HTML page at given url to get theUrlPreviewMap<String,String>parseUrl(String url, String lang)Fetch and parse the HTML page at given url for preview-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Constructor Detail
-
UrlPreviewComponent
public UrlPreviewComponent()
-
-
Method Detail
-
contextualize
public void contextualize(Context context) throws ContextException
- Specified by:
contextualizein interfaceContextualizable- Throws:
ContextException
-
getUrlPreview
public UrlPreview getUrlPreview(String url, String lang) throws HttpStatusException, IOException
Fetch and parse the HTML page at given url to get theUrlPreview- Parameters:
url- the url to parselang- the language- Returns:
- the
UrlPreview - Throws:
HttpStatusException- if the HTTP request resulted in a not OK HTTP response.IOException- if an error occured while parsing HTML page
-
getFavicon
public String getFavicon(String url) throws IOException
Fetch and parse the HTML page at given url to get the favicon url- Parameters:
url- the url to parse- Returns:
- the favicon url or null if not found
- Throws:
HttpStatusException- if the HTTP request resulted in a not OK HTTP response.IOException- if an error occured while parsing HTML page
-
convertIcoToPng
public InputStream convertIcoToPng(InputStream is) throws IOException
Convert an file.ico into a file.png- Parameters:
is- the input stream of the file.ico- Returns:
- the input stream of the file.png
- Throws:
IOException- if failed to convert .ico
-
parseUrl
public Map<String,String> parseUrl(String url, String lang)
Fetch and parse the HTML page at given url for preview- Parameters:
url- the url to parselang- the language- Returns:
- the page information for preview
-
_getConnection
private Connection _getConnection(String url, String lang)
-
_getDescription
private String _getDescription(Document doc)
-
_getImageUrl
private String _getImageUrl(Document doc)
-
_getFavicon
private String _getFavicon(Document doc, URL url)
-
_getUserAgent
private String _getUserAgent()
Get the user agent from current request- Returns:
- the user agent
-
-