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 2003/11/21 12:48:14 UTC
cvs commit: cocoon-2.1/src/blocks/webdav/java/org/apache/cocoon/components/source/impl WebDAVSourceFactory.java WebDAVSource.java
unico 2003/11/21 03:48:14
Modified: src/blocks/webdav/java/org/apache/cocoon/components/source/impl
WebDAVSourceFactory.java WebDAVSource.java
Log:
improve logging
remove unsupported operation exceptions in order to make it work with TraversableSourceDescriptionGenerator
Revision Changes Path
1.6 +2 -2 cocoon-2.1/src/blocks/webdav/java/org/apache/cocoon/components/source/impl/WebDAVSourceFactory.java
Index: WebDAVSourceFactory.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/webdav/java/org/apache/cocoon/components/source/impl/WebDAVSourceFactory.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- WebDAVSourceFactory.java 24 Sep 2003 22:34:52 -0000 1.5
+++ WebDAVSourceFactory.java 21 Nov 2003 11:48:14 -0000 1.6
@@ -101,7 +101,7 @@
}
WebDAVSource source =
- WebDAVSource.newWebDAVSource(location, principal, password, protocol);
+ WebDAVSource.newWebDAVSource(location, principal, password, protocol,getLogger());
return source;
}
1.11 +75 -27 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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- WebDAVSource.java 29 Oct 2003 14:16:53 -0000 1.10
+++ WebDAVSource.java 21 Nov 2003 11:48:14 -0000 1.11
@@ -69,6 +69,8 @@
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
import org.apache.cocoon.components.source.RestrictableSource;
import org.apache.cocoon.components.source.helpers.SourceCredential;
import org.apache.cocoon.components.source.helpers.SourcePermission;
@@ -105,7 +107,7 @@
* @author <a href="mailto:d.madama@pro-netics.com">Daniele Madama</a>
* @version $Id$
*/
-public class WebDAVSource implements Source,
+public class WebDAVSource extends AbstractLogEnabled implements Source,
RestrictableSource, ModifiableTraversableSource, InspectableSource {
@@ -169,7 +171,8 @@
public static WebDAVSource newWebDAVSource(String location,
String principal,
String password,
- String protocol) throws SourceException {
+ String protocol,
+ Logger logger) throws SourceException {
// FIXME: wild hack needed for writing to a new resource.
// if a resource doesn't exist, an exception
// will be thrown, unless such resource isn't created with the
@@ -178,21 +181,25 @@
// properties of an exixting resource. So either we do this
// hack here or we fill properties on the fly when requested.
// This "solution" is scary, but the SWCL is pretty dumb.
+ WebDAVSource source;
try {
- return new WebDAVSource(location, principal, password, protocol, false);
+ source = new WebDAVSource(location, principal, password, protocol, false);
} catch (HttpException he) {
try {
- return new WebDAVSource(location, principal, password, protocol, true);
+ source = new WebDAVSource(location, principal, password, protocol, true);
} catch (HttpException finalHe) {
- finalHe.printStackTrace(System.err);
- throw new SourceException("Error creating the source: ", finalHe);
+ final String message = "Error creating the source.";
+ throw new SourceException(message, finalHe);
} catch (IOException e) {
- e.printStackTrace(System.err);
- throw new SourceException("Error creating the source: ", e);
+ final String message = "Error creating the source.";
+ throw new SourceException(message, e);
}
} catch (IOException e) {
- throw new SourceException("Error creating the source: ", e);
+ final String message = "Error creating the source.";
+ throw new SourceException(message, e);
}
+ source.enableLogging(logger);
+ return source;
}
/**
@@ -433,7 +440,7 @@
*/
public void setSourcePermission(SourcePermission sourcepermission)
throws SourceException {
- throw new SourceException("Operation not supported");
+ //FIXME
}
/**
@@ -442,7 +449,8 @@
* @return Array of SourcePermission
*/
public SourcePermission[] getSourcePermissions() throws SourceException {
- throw new SourceException("Operation not supported");
+ //FIXME
+ return null;
}
public class WebDAVSourceOutputStream extends ByteArrayOutputStream {
@@ -514,7 +522,11 @@
ContentHandler handler)
throws SAXException {
for (int i = 0; i < resources.length; i++) {
- System.out.println("RESOURCE: " + resources[i].getDisplayName());
+ if (getLogger().isDebugEnabled()) {
+ final String message =
+ "RESOURCE: " + resources[i].getDisplayName();
+ getLogger().debug(message);
+ }
if (resources[i].isCollection()) {
try {
WebdavResource[] childs =
@@ -537,13 +549,34 @@
COLLECTION_NAME,
PREFIX + ":" + COLLECTION_NAME);
} catch (HttpException e) {
- e.printStackTrace();
+ if (getLogger().isDebugEnabled()) {
+ final String message =
+ "Unable to get WebDAV children. Server responded " +
+ e.getReasonCode() + " (" + e.getReason() + ") - "
+ + e.getMessage();
+ getLogger().debug(message);
+ }
} catch (SAXException e) {
- e.printStackTrace();
+ if (getLogger().isDebugEnabled()) {
+ final String message =
+ "Unable to get WebDAV children: "
+ + e.getMessage();
+ getLogger().debug(message,e);
+ }
} catch (IOException e) {
- e.printStackTrace();
+ if (getLogger().isDebugEnabled()) {
+ final String message =
+ "Unable to get WebDAV children: "
+ + e.getMessage();
+ getLogger().debug(message,e);
+ }
} catch (Exception e) {
- e.printStackTrace();
+ if (getLogger().isDebugEnabled()) {
+ final String message =
+ "Unable to get WebDAV children: "
+ + e.getMessage();
+ getLogger().debug(message,e);
+ }
}
} else {
AttributesImpl attrs = new AttributesImpl();
@@ -578,17 +611,27 @@
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);
+ WebDAVSource source = WebDAVSource.newWebDAVSource(
+ childLocation,
+ this.principal,
+ this.password,
+ this.protocol,
+ this.getLogger());
source.setSourceCredential(this.getSourceCredential());
return source;
}
}
} catch (HttpException e) {
- e.printStackTrace();
- throw new SourceException(e.getMessage());
+ 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) {
- e.printStackTrace();
- throw new SourceException(e.getMessage());
+ throw new SourceException("Failed to get WebDAV collection child.",e);
}
return child;
}
@@ -607,11 +650,15 @@
children.add(src);
}
} catch (HttpException e) {
- // TODO: getLogger.debug()
- throw new SourceException(e.getMessage(), 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 children.", e);
} catch (IOException e) {
- // TODO: getLogger.debug()
- throw new SourceException(e.getMessage(), e);
+ throw new SourceException("Failed to get WebDAV collection children.", e);
}
return children;
}
@@ -635,7 +682,8 @@
myLocation,
this.principal,
this.password,
- this.protocol);
+ this.protocol,
+ this.getLogger());
wds.setSourceCredential(this.getSourceCredential());
return wds;
}