3 import net
.bzzt
.ical
.services
.IcalendarValidationService
;
5 import org
.apache
.commons
.httpclient
.Header
;
6 import org
.apache
.commons
.httpclient
.HeaderElement
;
7 import org
.apache
.commons
.httpclient
.HttpClient
;
8 import org
.apache
.commons
.httpclient
.NameValuePair
;
9 import org
.apache
.commons
.httpclient
.URI
;
10 import org
.apache
.commons
.httpclient
.URIException
;
11 import org
.apache
.commons
.httpclient
.methods
.GetMethod
;
12 import org
.apache
.commons
.lang
.StringUtils
;
13 import org
.apache
.commons
.logging
.Log
;
14 import org
.apache
.commons
.logging
.LogFactory
;
15 import org
.apache
.wicket
.PageParameters
;
16 import org
.apache
.wicket
.markup
.html
.WebMarkupContainer
;
17 import org
.apache
.wicket
.markup
.html
.WebPage
;
18 import org
.wicketstuff
.annotation
.mount
.MountPath
;
19 import org
.wicketstuff
.annotation
.strategy
.MountMixedParam
;
20 import org
.wicketstuff
.annotation
.strategy
.MountQueryString
;
22 @MountPath(path
= "urlvalidate")
23 //MountMixedParams didn't work behind apache proxypass when the url contained a %2F
25 public class UrlValidationPage
extends ValidatorLayoutPage
{
26 private static final Log LOG
= LogFactory
.getLog(UrlValidationPage
.class);
28 public UrlValidationPage(PageParameters parameters
)
31 String url
= getUrl(parameters
);
34 init(new URI(url
, true));
41 } catch (URIException e
) {
46 private String
getUrl(PageParameters parameters
) {
47 Object url
= parameters
.get("url");
52 else if (url
instanceof String
)
56 else if (url
instanceof String
[])
58 String
[] urls
= (String
[]) url
;
59 if (urls
!= null && urls
.length
> 0)
67 private void init(URI uri
) {
68 GetMethod method
= new GetMethod();
71 } catch (Exception e
) {
75 HttpClient client
= new HttpClient();
77 client
.executeMethod(method
);
78 } catch (Exception e
) {
82 add(new UrlFormPanel("urlForm", uri
));
84 method
.getResponseCharSet();
87 LOG
.info("Validating url " + uri
);
88 Header contentType
= method
.getResponseHeader("Content-Type");
89 String charSet
= null;
90 if (contentType
!= null)
92 HeaderElement
[] headerElements
= contentType
.getElements();
93 if (headerElements
.length
> 0)
95 NameValuePair parameter
= headerElements
[0].getParameterByName("charset");
96 if (parameter
!= null)
98 charSet
= parameter
.getValue();
103 if (StringUtils
.isBlank(charSet
))
108 add(IcalendarValidationService
.getValidationResult("result", method
.getResponseBodyAsStream(), charSet
));
109 } catch (Exception e
) {
110 add(new WebMarkupContainer("result"));
112 LOG
.error(e
.getMessage(), e
);