1 package org.sapia.magnet.domain; 2 3 import java.util.Collection ; 6 import java.util.Iterator ; 7 import java.util.TreeSet ; 8 9 import org.sapia.magnet.render.RenderingException; 12 13 14 25 public class HttpProtocolHandler implements ProtocolHandlerIF { 26 27 36 public Collection resolveResources(Path aPath, String aSortingOrder) throws RenderingException { 37 if (aPath == null) { 39 throw new IllegalArgumentException ("The path object passed in null"); 40 } else if (!aPath.getProtocol().equals(Path.PROTOCOL_HTTP)) { 41 throw new IllegalArgumentException ("The protocol of the path is not 'http' but " + aPath.getProtocol()); 42 } else if (aPath.getDirectory() == null) { 43 throw new IllegalArgumentException ("The directory of the path passed in is null"); 44 } 45 46 TreeSet someResources; 48 if (aSortingOrder != null && aSortingOrder.equals(Path.SORTING_ASCENDING)) { 49 someResources = new TreeSet (new Resource.AscendingComparator()); 50 } else if (aSortingOrder != null && aSortingOrder.equals(Path.SORTING_DESCENDING)) { 51 someResources = new TreeSet (new Resource.DescendingComparator()); 52 } else { 53 someResources = new TreeSet (); 54 } 55 int anIndex = 0; 56 57 for (Iterator it = aPath.getIncludes().iterator(); it.hasNext(); ) { 58 StringBuffer anURL = new StringBuffer (); 59 anURL.append(Path.PROTOCOL_HTTP).append("://"). 60 append(aPath.getHost()). 61 append(aPath.getDirectory()).append("/"). 62 append(((Include) it.next()).getPattern()); 63 someResources.add(new Resource(anURL.toString(), anIndex++)); 64 } 65 66 return someResources; 67 } 68 } | Popular Tags |