View Javadoc

1   // ========================================================================
2   // Copyright (c) 2008-2009 Mort Bay Consulting Pty. Ltd.
3   // ------------------------------------------------------------------------
4   // All rights reserved. This program and the accompanying materials
5   // are made available under the terms of the Eclipse Public License v1.0
6   // and Apache License v2.0 which accompanies this distribution.
7   // The Eclipse Public License is available at 
8   // http://www.eclipse.org/legal/epl-v10.html
9   // The Apache License v2.0 is available at
10  // http://www.opensource.org/licenses/apache2.0.php
11  // You may elect to redistribute this code under either of these licenses. 
12  // ========================================================================
13  
14  package org.eclipse.jetty.client.webdav;
15  
16  import java.io.IOException;
17  
18  import org.eclipse.jetty.client.HttpExchange;
19  import org.eclipse.jetty.io.Buffer;
20  import org.eclipse.jetty.util.log.Log;
21  import org.eclipse.jetty.util.log.Logger;
22  
23  
24  public class WebdavSupportedExchange extends HttpExchange
25  {
26      private static final Logger LOG = Log.getLogger(WebdavSupportedExchange.class);
27  
28      private boolean _webdavSupported = false;
29      private boolean _isComplete = false;
30  
31      @Override
32      protected void onResponseHeader(Buffer name, Buffer value) throws IOException
33      {
34          if (LOG.isDebugEnabled())
35              LOG.debug("WebdavSupportedExchange:Header:" + name.toString() + " / " + value.toString() );
36          if ( "DAV".equals( name.toString() ) )
37          {
38              if ( value.toString().indexOf( "1" ) >= 0 || value.toString().indexOf( "2" ) >= 0 )
39              {
40                  _webdavSupported = true;
41              }
42          }
43  
44          super.onResponseHeader(name, value);
45      }
46  
47      public void waitTilCompletion() throws InterruptedException
48      {
49          synchronized (this)
50          {
51              while ( !_isComplete)
52              {
53                  this.wait();
54              }
55          }
56      }
57  
58      @Override
59      protected void onResponseComplete() throws IOException
60      {
61          _isComplete = true;
62  
63          super.onResponseComplete();
64      }
65  
66      public boolean isWebdavSupported()
67      {
68          return _webdavSupported;
69      }
70  }