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  
22  
23  public class WebdavSupportedExchange extends HttpExchange
24  {
25      private boolean _webdavSupported = false;
26      private boolean _isComplete = false;
27  
28      @Override
29      protected void onResponseHeader(Buffer name, Buffer value) throws IOException
30      {
31          if (Log.isDebugEnabled())
32              Log.debug("WebdavSupportedExchange:Header:" + name.toString() + " / " + value.toString() );
33          if ( "DAV".equals( name.toString() ) )
34          {
35              if ( value.toString().indexOf( "1" ) >= 0 || value.toString().indexOf( "2" ) >= 0 )
36              {
37                  _webdavSupported = true;
38              }
39          }
40  
41          super.onResponseHeader(name, value);
42      }
43  
44      public void waitTilCompletion() throws InterruptedException
45      {
46          synchronized (this)
47          {
48              while ( !_isComplete)
49              {
50                  this.wait();
51              }
52          }
53      }
54  
55      @Override
56      protected void onResponseComplete() throws IOException
57      {
58          _isComplete = true;
59  
60          super.onResponseComplete();
61      }
62  
63      public boolean isWebdavSupported()
64      {
65          return _webdavSupported;
66      }
67  }