You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by un...@apache.org on 2004/01/15 14:26:39 UTC

cvs commit: cocoon-2.1/src/blocks/webdav/java/org/apache/cocoon/components/source/impl WebDAVSource.java

unico       2004/01/15 05:26:39

  Modified:    src/blocks/webdav/java/org/apache/cocoon/components/source/impl
                        WebDAVSource.java
  Log:
  fix npe if no source credential
  improve logging
  getChild method should not check for child existence. 
  For instance, you should be able to do parent.getChild("newchild").makeCollection() etc.
  
  Revision  Changes    Path
  1.16      +25 -32    cocoon-2.1/src/blocks/webdav/java/org/apache/cocoon/components/source/impl/WebDAVSource.java
  
  Index: WebDAVSource.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/webdav/java/org/apache/cocoon/components/source/impl/WebDAVSource.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- WebDAVSource.java	22 Dec 2003 15:44:42 -0000	1.15
  +++ WebDAVSource.java	15 Jan 2004 13:26:39 -0000	1.16
  @@ -185,6 +185,7 @@
           try {
               source = new WebDAVSource(location, principal, password, protocol, false);
           }  catch (HttpException he) {
  +            he.printStackTrace();
               try {
                   source = new WebDAVSource(location, principal, password, protocol, true);
               } catch (HttpException finalHe) {
  @@ -242,7 +243,7 @@
                   BufferedInputStream bi = null;
                   bi = new BufferedInputStream(this.resource.getMethodData());
                   if (!this.resource.exists()) {
  -                    throw new HttpException(this.systemId + "does not exist");
  +                    throw new HttpException(this.systemId + " does not exist");
                   }
                   return bi;
               }
  @@ -425,7 +426,7 @@
       public void setSourceCredential(SourceCredential sourcecredential)
           throws SourceException {
           this.sourcecredential = sourcecredential;
  -
  +        if (sourcecredential == null) return;
           try {
               HttpURL httpURL = new HttpURL(this.systemId);
               httpURL.setUserInfo(
  @@ -476,6 +477,11 @@
               try {
                   this.resource.putMethod(toByteArray());
               } catch (HttpException he) {
  +                final String message =
  +                    "Unable to close output stream. Server responded " +
  +                    he.getReasonCode() + " (" + he.getReason() + ") - " 
  +                    + he.getMessage();
  +                getLogger().debug(message);
                   throw new IOException(he.getMessage());
               }
           }
  @@ -613,35 +619,15 @@
        * @see org.apache.excalibur.source.TraversableSource#getChild(java.lang.String)
        */
       public Source getChild(String childName) throws SourceException {    	
  -        Source child = null;
  -        try {
  -            WebdavResource[] resources = this.resource.listWebdavResources();
  -            for (int i = 0; i < resources.length; i++) {
  -                if (childName.equals(resources[i].getDisplayName())) {
  -                	String childLocation = this.location + "/" + childName;
  -					WebDAVSource source = WebDAVSource.newWebDAVSource(
  -                        childLocation, 
  -                        this.principal, 
  -                        this.password, 
  -                        this.protocol, 
  -                        this.getLogger());
  -					source.setSourceCredential(this.getSourceCredential());
  -					return source;
  -                }
  -            }
  -        } catch (HttpException e) {
  -            if (getLogger().isDebugEnabled()) {
  -                final String message =
  -                    "Unable to get WebDAV children. Server responded " +
  -                    e.getReasonCode() + " (" + e.getReason() + ") - " 
  -                    + e.getMessage();
  -                getLogger().debug(message);
  -            }
  -            throw new SourceException("Failed to get WebDAV collection child.",e);
  -        } catch (IOException e) {
  -            throw new SourceException("Failed to get WebDAV collection child.",e);
  -        }
  -        return child;
  +    	String childLocation = this.location + "/" + childName;
  +    	WebDAVSource source = WebDAVSource.newWebDAVSource(
  +            childLocation, 
  +            this.principal, 
  +            this.password, 
  +            this.protocol, 
  +            this.getLogger());
  +    	source.setSourceCredential(this.getSourceCredential());
  +    	return source;
       }
   
       /**
  @@ -852,6 +838,13 @@
                      new PropertyName(sourceproperty.getNamespace(),sourceproperty.getName()),
                      prop, true);
   
  +        } catch(HttpException e) {
  +            final String message =
  +                "Unable to set property. Server responded " +
  +                e.getReasonCode() + " (" + e.getReason() + ") - " 
  +                + e.getMessage();
  +            getLogger().debug(message);
  +            throw new SourceException("Could not set property ", e);
           } catch (Exception e) {
               throw new SourceException("Could not set property ", e);
           }