KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nl > hippo > cms > workflows > shared > URIUtil


1 package nl.hippo.cms.workflows.shared;
2
3 import java.io.IOException JavaDoc;
4 import nl.hippo.cocoon.webdav.WebDAVHelper;
5 import org.apache.commons.httpclient.HttpState;
6
7 public class URIUtil
8 {
9     
10     public static String JavaDoc getLiveURI(String JavaDoc uri)
11     {
12         return uri.replaceFirst("\\.preview/", ".www/");
13     }
14     
15     public static String JavaDoc getHistoryURI(String JavaDoc uri)
16     {
17         return uri.replaceFirst("\\.preview/", ".history/");
18     }
19     
20     public static String JavaDoc getArchiveURI(String JavaDoc uri)
21     {
22         return uri.replaceFirst("\\.preview/", ".archive/");
23     }
24
25     public static String JavaDoc getHTTPURI(String JavaDoc uri)
26     {
27         String JavaDoc result;
28         if (uri.startsWith("webdav:"))
29         {
30             result = "http:" + uri.substring(7);
31         }
32         else
33         {
34             result = uri;
35         }
36         return result;
37     }
38
39     public static String JavaDoc getPrettyPath(String JavaDoc uri, String JavaDoc baseUri, HttpState httpState) throws IOException JavaDoc
40     {
41         String JavaDoc caption = WebDAVHelper.propfindAsString(uri, "http://hippo.nl/cms/1.0", "caption", httpState);
42         String JavaDoc displayname = WebDAVHelper.propfindAsString(uri, "DAV:", "displayname", httpState);
43         String JavaDoc prettyPath = (caption == null || caption.equals("")) ? displayname : caption;
44         
45         uri = uri.substring(0, uri.lastIndexOf('/') + 1);
46         while (!uri.equals(baseUri))
47         {
48             caption = WebDAVHelper.propfindAsString(uri, "http://hippo.nl/cms/1.0", "caption", httpState);
49             displayname = WebDAVHelper.propfindAsString(uri, "DAV:", "displayname", httpState);
50             prettyPath = ((caption == null || caption.equals("")) ? displayname : caption) + " > " + prettyPath;
51             
52             int startOfLastPathPart = uri.lastIndexOf('/', uri.length() - 2) + 1;
53             uri = uri.substring(0, startOfLastPathPart);
54         }
55         return prettyPath;
56     }
57
58     private URIUtil()
59     {
60         super();
61     }
62
63 }
64
Popular Tags