1 27 28 package org.objectweb.clif.protocol.http.lib; 29 30 import java.net.URI ; 31 import java.util.Vector ; 32 import java.util.regex.Matcher ; 33 import java.util.regex.Pattern ; 34 35 38 public class HttpUtil { 39 40 private HtmlParser parser = null; 41 private Vector domainHtmlLinks = new Vector (); 42 private Object [] links; 43 private String link; 44 private int i; 45 46 public String relativeToAbsolute(String relative, String url) 47 throws Exception { 48 49 URI base = new URI (url); 50 return base.resolve(new URI (relative)).toString(); 51 } 52 53 public Object [] getLinks(String arg) throws Exception { 54 55 return HtmlParser.getInstance().getLinks(arg); 56 } 57 58 public Object [] getFields(String arg) throws Exception { 59 60 return HtmlParser.getInstance().getFields(arg); 61 } 62 63 public Object [] getTags(String [] arg) throws Exception { 64 65 return HtmlParser.getInstance().getTags(arg); 66 } 67 68 77 public Object [] getDomainHtmlLinks(String arg, String host) 78 throws Exception { 79 80 domainHtmlLinks = new Vector (); 81 links = HtmlParser.getInstance().getLinks(arg); 82 83 for (i = 0; i < links.length; i++) { 84 link = (String ) links[i]; 85 86 if (((link.indexOf("http://") == -1) || (link.indexOf(host) != -1)) 87 && (link.endsWith(".html") 88 || link.endsWith(".htm") 89 || link.endsWith("/"))) { 90 domainHtmlLinks.add(link); 91 } 92 } 93 94 return domainHtmlLinks.toArray(); 95 } 96 97 public Object [] regExp(String exp, String input) { 98 Pattern p = Pattern.compile(exp); 99 Matcher m = p.matcher(input); 100 101 while (m.find()) { 102 System.out.println(m.group()); 103 } 104 105 return null; 106 } 107 108 } 109 | Popular Tags |