View Javadoc

1   package com.bradmcevoy.http.webdav;
2   
3   import org.slf4j.Logger;
4   import org.slf4j.LoggerFactory;
5   
6   /**
7    * 
8    * @author brad
9    * 
10   * Represents the destination of a MOVE or COPY method
11   * 
12   * The target url is parsed into the 3 components, host, parent url and name
13   * to make it easier to differentiate between the name and folder of the destination
14   */
15  class Dest {
16      
17      private static final Logger log = LoggerFactory.getLogger(Dest.class);
18      
19      public final String host;
20      
21      /**
22       * path of the parent folder
23       */
24      public final String url;
25      
26      /**
27       * the name portion of the destination
28       */
29      public final String name;
30      
31      
32      
33      public Dest(String sourceHost, String sDest ) {
34          log.debug("sDest: " + sDest);
35          String sUrl;
36          if( sDest.endsWith("/") ) sDest = sDest.substring(0,sDest.length()-1);
37          if( sDest.contains("http://") ) {
38              String s = sDest.replace("http://","");
39              int pos = s.indexOf(":");
40              if( pos > 0 ) {
41                  host = s.substring(0,pos);
42                  pos = s.indexOf("/");
43              } else {
44                  pos = s.indexOf("/");
45                  host = s.substring(0,pos);
46              }
47              sUrl = s.substring(pos);
48          } else {
49              host = sourceHost;
50              sUrl = sDest;
51          }
52          int pos = sUrl.lastIndexOf("/");
53          if( pos <= 0 ) {
54              url = "/";
55          } else {
56              url = sUrl.substring(0,pos);
57          }
58          name = sUrl.substring(pos+1);
59      }
60  }