KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > magnet > domain > HttpProtocolHandler


1 package org.sapia.magnet.domain;
2
3 // Import of Sun's JDK classes
4
// ---------------------------
5
import java.util.Collection JavaDoc;
6 import java.util.Iterator JavaDoc;
7 import java.util.TreeSet JavaDoc;
8
9 // Import of Sapia's magnet classes
10
// --------------------------------
11
import org.sapia.magnet.render.RenderingException;
12
13
14 /**
15  *
16  *
17  * @author Jean-Cedric Desrochers
18  *
19  * <dl>
20  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
21  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
22  * <a HREF="http://www.sapia-oss.org/license.html" target="sapia-license">license page</a> at the Sapia OSS web site</dd></dt>
23  * </dl>
24  */

25 public class HttpProtocolHandler implements ProtocolHandlerIF {
26
27   /**
28    * Handle the rendering of the path object for a specific protocol by
29    * resolving the resources of the path.
30    *
31    * @param aPath The path object to render.
32    * @param aSortingOrder The sorting order of the collection to return.
33    * @return The collection of <CODE>Resource</CODE> objects.
34    * @exception RenderingException If an error occurs while resolving the path.
35    */

36   public Collection JavaDoc resolveResources(Path aPath, String JavaDoc aSortingOrder) throws RenderingException {
37     // Validate the arguments
38
if (aPath == null) {
39       throw new IllegalArgumentException JavaDoc("The path object passed in null");
40     } else if (!aPath.getProtocol().equals(Path.PROTOCOL_HTTP)) {
41       throw new IllegalArgumentException JavaDoc("The protocol of the path is not 'http' but " + aPath.getProtocol());
42     } else if (aPath.getDirectory() == null) {
43       throw new IllegalArgumentException JavaDoc("The directory of the path passed in is null");
44     }
45
46     // Create the resources for the included files
47
TreeSet JavaDoc someResources;
48     if (aSortingOrder != null && aSortingOrder.equals(Path.SORTING_ASCENDING)) {
49       someResources = new TreeSet JavaDoc(new Resource.AscendingComparator());
50     } else if (aSortingOrder != null && aSortingOrder.equals(Path.SORTING_DESCENDING)) {
51       someResources = new TreeSet JavaDoc(new Resource.DescendingComparator());
52     } else {
53       someResources = new TreeSet JavaDoc();
54     }
55     int anIndex = 0;
56
57     for (Iterator JavaDoc it = aPath.getIncludes().iterator(); it.hasNext(); ) {
58       StringBuffer JavaDoc anURL = new StringBuffer JavaDoc();
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