jmetzner 02/04/14 15:30:09
Added: java/scratchpad/src/org/apache/xindice/webdav/datasource
AbstractDAVDataSource.java DAVCollection.java
DAVDataSource.java DAVObject.java
DAVObjectException.java
DAVObjectNotFoundException.java
DAVObjectOperationNotAllowedException.java
DAVResource.java DefaultDAVObject.java
java/scratchpad/src/org/apache/xindice/webdav/datasource/xmldb
XMLDBCollection.java XMLDBDataSource.java
XMLDBResource.java
Log:
Revision Changes Path
1.1
xml-xindice/java/scratchpad/src/org/apache/xindice/webdav/datasource/AbstractDAVDataSource.java
Index: AbstractDAVDataSource.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xindice" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999-2001, The dbXML
* Group, L.L.C., http://www.dbxmlgroup.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xindice.webdav.datasource;
import org.apache.avalon.framework.logger.AbstractLoggable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
/**
* Abstract class for Xindice WebDav DataSources in Avalon.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jan Metzner</a>
* @version $Id: AbstractDAVDataSource.java,v 1.1 2002/04/14 22:30:09
jmetzner Exp $
*/
public abstract class AbstractDAVDataSource
extends AbstractLoggable implements DAVDataSource {
/**
* The name of the role for convenience
*/
String ROLE = "org.apache.xindice.webdav.datasource.AbstractDAVDataSource";
// --------------------------------------------------------- Public Methods
/**
* Set the web root fro this class.
*
* @param webRoot starting URL for web interface.
*/
public abstract void setWebRoot(String webRoot);
/**
* Configure and set up DB connection. Here we set the connection
* information needed to create the Connection objects. It must
* be called only once.
*
* @param conf The Configuration object needed to describe the connection.
*
* @throws ConfigurationException
*/
public abstract void configure(final Configuration configuration)
throws ConfigurationException;
/**
* Gets a DAVObject from the database.
*
* @param relativePath the relative path to the Object beginning with '/'.
* @throws DAVObjectNotFoundException when there is no such Object in the
* database.
* @throws DAVObjectException when other errors occur.
* @return DAVResource or DAVCollection object for this query.
*/
public abstract DAVObject getDAVObject(String relativePath)
throws DAVObjectException;
/**
* returns a webdavcollection from the database.
*
* @param relativePath relative path to the collection beginning with '/'.
* @throws DAVObjectNotFoundException when there is no such Object in the
* database.
* @throws DAVObjectException when other errors occur.
* @return the queried collection.
*/
public DAVCollection getDAVCollection(String relativePath) throws
DAVObjectException {
try {
return (DAVCollection) getDAVObject(relativePath);
} catch(java.lang.ClassCastException cce) {
throw new DAVObjectException("object is no collection: "+relativePath);
}
}
/**
* returns a webdav resource from the database.
*
* @param relativePath relative path to the resource beginning with '/'.
* @throws DAVObjectNotFoundException when there is no such Object in the
* database.
* @throws DAVObjectException when other errors occur.
* @return the queried resource.
*/
public DAVResource getDAVResource(String relativePath) throws
DAVObjectException {
try {
return (DAVResource) getDAVObject(relativePath);
} catch(java.lang.ClassCastException cce) {
throw new DAVObjectException("object is no resource: "+relativePath);
}
}
/**
* copies a DAVObject.
*
* @param sourcePath path to the source object.
* @param destinationPath path to the destination object.
* @param overwrite if true an existing destination object will be
* overwritten.
* @throws DAVObjectOperationNotAllowedException when the new destination
* object cannot be created.
* @throws DAVObjectNotFoundException when there is no such Object in the
* database.
* @throws DAVObjectException when other errors occur.
*/
public abstract void copyDAVObject(String sourcePath, String
destinationPath,
boolean overwrite) throws DAVObjectException;
/**
* deletes an DAVObject.
*
* @param path path to the object.
* @throws DAVObjectOperationNotAllowedException when the object can't be
deleted.
* @throws DAVObjectNotFoundException when there is no such Object in the
* database.
* @throws DAVObjectException when other errors occur.
*/
public abstract void deleteDAVObject(String path) throws DAVObjectException
;
/**
* creates a webdav collection.
*
* @param path path to the new collection.
* @throws DAVObjectOperationNotAllowedException when the new object can't
be created.
* @throws DAVObjectNotFoundException when there is no such parent
collection in the
* database.
* @throws DAVObjectException when other errors occur.
*/
public abstract void createDAVCollection(String path) throws
DAVObjectException ;
/**
* creates a webdav resource.
*
* @param path path to the new resource.
* @throws DAVObjectOperationNotAllowedException when the new object can't
be created.
* @throws DAVObjectNotFoundException when there is no such parent
collection in the
* database.
* @throws DAVObjectException when other errors occur.
*/
public abstract void createDAVResource(String path) throws
DAVObjectException ;
}
1.1
xml-xindice/java/scratchpad/src/org/apache/xindice/webdav/datasource/DAVCollection.java
Index: DAVCollection.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xindice" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999-2001, The dbXML
* Group, L.L.C., http://www.dbxmlgroup.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xindice.webdav.datasource;
/**
* represents a DAV collection.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jan Metzner</a>
* @version $Id: DAVCollection.java,v 1.1 2002/04/14 22:30:09 jmetzner Exp $
*/
public interface DAVCollection extends DAVObject {
/**
* returns array with child objects.
*
* @throws DAVObjectException when accessing errors occur.
* @return child objects.
*/
public DAVObject[] getChilds();
/**
* returns a child object.
*
* @param name object name.
* @throws DAVObjectNotFoundException when there is no such Object in the
* database.
* @throws DAVObjectException when other errors occur.
* @return DAVResource or DAVCollection object for this query.
*/
public DAVObject getChildObject(String name)
throws DAVObjectException;
/**
* returns a child resource.
*
* @param name resource name.
* @throws DAVObjectNotFoundException when there is no such Object in the
* database.
* @throws DAVObjectException when other errors occur.
* @return DAVResource object for this query.
*/
public DAVResource getChildResource(String name)
throws DAVObjectException;
/**
* returns a child collection.
*
* @param name collection name.
* @throws DAVObjectNotFoundException when there is no such Object in the
* database.
* @throws DAVObjectException when other errors occur.
* @return DAVCollection object for this query.
*/
public DAVCollection getChildCollection(String name)
throws DAVObjectException;
/**
* creates a new resource in this collection.
*
* @param name new resource name.
* @param content new resource content.
* @throws DAVObjectOperationNotAllowedException when the new destination
* object cannot be created.
* @throws DAVObjectException when other errors occur.
* @return new created DAVResource object.
*/
public DAVResource createResource(String name, String content)
throws DAVObjectException;
/**
* creates a new child collection in this collection.
*
* @param name new collection name.
* @throws DAVObjectOperationNotAllowedException when the new destination
* object cannot be created.
* @throws DAVObjectException when other errors occur.
* @return new created DAVCollection object.
*/
public DAVCollection createCollection(String name)
throws DAVObjectException;
}
1.1
xml-xindice/java/scratchpad/src/org/apache/xindice/webdav/datasource/DAVDataSource.java
Index: DAVDataSource.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Apache Xindice" and "Apache Software Foundation" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
[EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.xindice.webdav.datasource;
import org.apache.avalon.framework.logger.AbstractLoggable;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
/**
* WebDav DataSources Compnent for Avalon.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jan Metzner</a>
* @version $Id: DAVDataSource.java,v 1.1 2002/04/14 22:30:09 jmetzner Exp $
*/
public interface DAVDataSource extends Component {
String ROLE = "org.apache.xindice.webdav.datasource.DAVDataSource";
/**
* Set the web root fro this class.
*
* @param webRoot starting URL for web interface.
*/
public void setWebRoot(String webRoot);
/**
* Configure and set up DB connection. Here we set the connection
* information needed to create the Connection objects. It must
* be called only once.
*
* @param conf The Configuration object needed to describe the connection.
*
* @throws ConfigurationException
*/
public void configure(final Configuration configuration)
throws ConfigurationException;
/**
* Gets a DAVObject from the database.
*
* @param relativePath the relative path to the Object beginning with '/'.
* @throws DAVObjectNotFoundException when there is no such Object in the
* database.
* @throws DAVObjectException when other errors occur.
* @return DAVResource or DAVCollection object for this query.
*/
public abstract DAVObject getDAVObject(String relativePath)
throws DAVObjectException;
/**
* returns a webdav collection from the database.
*
* @param relativePath relative path to the collection beginning with '/'.
* @throws DAVObjectNotFoundException when there is no such Object in the
* database.
* @throws DAVObjectException when other errors occur.
* @return the queried collection.
*/
public DAVCollection getDAVCollection(String relativePath)
throws DAVObjectException;
/**
* returns a webdav resource from the database.
*
* @param relativePath relative path to the resource beginning with '/'.
* @throws DAVObjectNotFoundException when there is no such Object in the
* database.
* @throws DAVObjectException when other errors occur.
* @return the queried resource.
*/
public DAVResource getDAVResource(String relativePath)
throws DAVObjectException;
/**
* copies a DAVObject.
*
* @param sourcePath path to the source object.
* @param destinationPath path to the destination object.
* @param overwrite if true an existing destination object will be
* overwritten.
* @throws DAVObjectOperationNotAllowedException when the new destination
* object cannot be created.
* @throws DAVObjectNotFoundException when there is no such Object in the
* database.
* @throws DAVObjectException when other errors occur.
*/
public abstract void copyDAVObject(String sourcePath, String
destinationPath,
boolean overwrite) throws DAVObjectException;
/**
* deletes an DAVObject.
*
* @param path path to the object.
* @throws DAVObjectOperationNotAllowedException when the object can't be
deleted.
* @throws DAVObjectNotFoundException when there is no such Object in the
* database.
* @throws DAVObjectException when other errors occur.
*/
public abstract void deleteDAVObject(String path) throws DAVObjectException;
/**
* creates a webdav collection.
*
* @param path path to the new collection.
* @throws DAVObjectOperationNotAllowedException when the new object can't
be created.
* @throws DAVObjectNotFoundException when there is no such parent
collection in the
* database.
* @throws DAVObjectException when other errors occur.
*/
public abstract void createDAVCollection(String path) throws
DAVObjectException;
/**
* creates a webdav resource.
*
* @param path path to the new resource.
* @throws DAVObjectOperationNotAllowedException when the new object can't
be created.
* @throws DAVObjectNotFoundException when there is no such parent
collection in the
* database.
* @throws DAVObjectException when other errors occur.
*/
public abstract void createDAVResource(String path) throws
DAVObjectException;
}
1.1
xml-xindice/java/scratchpad/src/org/apache/xindice/webdav/datasource/DAVObject.java
Index: DAVObject.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xindice" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999-2001, The dbXML
* Group, L.L.C., http://www.dbxmlgroup.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xindice.webdav.datasource;
import java.util.Hashtable;
import java.util.Date;
/**
* represents a webdav object.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jan Metzner</a>
* @version $Id: DAVObject.java,v 1.1 2002/04/14 22:30:09 jmetzner Exp $
*/
public interface DAVObject {
/**
* returns object name.
*
* @return name of this object.
*/
public String getName();
/**
* returns the web URL of this object.
*
* @return web URL of this object.
*/
public String getWebURL();
/**
* returns if this object is a collection.
*
* @return true if this object is a collection.
*/
public boolean isCollection();
/**
* returns the object properties.
*
* @return object properties.
*/
public Hashtable getProperties();
/**
* get object property by name.
*
* @param name property name.
* @return object property.
*/
public String getProperty(String name);
/**
* set object property.
* existing values are overwritten
*
* @param name property name.
* @param value property value.
*/
public void setProperty(String name, String value);
/**
* set creation date property.
*
* @param date creation date.
*/
public void setCreationDateProperty(Date date);
/**
* set modification date property.
*
* @param date modification date.
*/
public void setModificationDateProperty(Date date);
}
1.1
xml-xindice/java/scratchpad/src/org/apache/xindice/webdav/datasource/DAVObjectException.java
Index: DAVObjectException.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xindice" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999-2001, The dbXML
* Group, L.L.C., http://www.dbxmlgroup.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xindice.webdav.datasource;
/**
* default exception for davobjects
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jan Metzner</a>
* @version $Id: DAVObjectException.java,v 1.1 2002/04/14 22:30:09 jmetzner
Exp $
*/
public class DAVObjectException extends Exception {
public DAVObjectException() {
super();
}
public DAVObjectException(String s) {
super(s);
}
}
1.1
xml-xindice/java/scratchpad/src/org/apache/xindice/webdav/datasource/DAVObjectNotFoundException.java
Index: DAVObjectNotFoundException.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xindice" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999-2001, The dbXML
* Group, L.L.C., http://www.dbxmlgroup.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xindice.webdav.datasource;
/**
* dav exception for not found davobjects.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jan Metzner</a>
* @version $Id: DAVObjectNotFoundException.java,v 1.1 2002/04/14 22:30:09
jmetzner Exp $
*/
public class DAVObjectNotFoundException extends DAVObjectException {
public DAVObjectNotFoundException() {
super();
}
public DAVObjectNotFoundException(String s) {
super(s);
}
}
1.1
xml-xindice/java/scratchpad/src/org/apache/xindice/webdav/datasource/DAVObjectOperationNotAllowedException.java
Index: DAVObjectOperationNotAllowedException.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xindice" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999-2001, The dbXML
* Group, L.L.C., http://www.dbxmlgroup.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xindice.webdav.datasource;
/**
* dav exception for forbidden davobject operations.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jan Metzner</a>
* @version $Id: DAVObjectOperationNotAllowedException.java,v 1.1 2002/04/14
22:30:09 jmetzner Exp $
*/
public class DAVObjectOperationNotAllowedException extends DAVObjectException
{
public DAVObjectOperationNotAllowedException() {
super();
}
public DAVObjectOperationNotAllowedException(String s) {
super(s);
}
}
1.1
xml-xindice/java/scratchpad/src/org/apache/xindice/webdav/datasource/DAVResource.java
Index: DAVResource.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xindice" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999-2001, The dbXML
* Group, L.L.C., http://www.dbxmlgroup.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xindice.webdav.datasource;
/**
* represents a DAV resource.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jan Metzner</a>
* @version $Id: DAVResource.java,v 1.1 2002/04/14 22:30:09 jmetzner Exp $
*/
public interface DAVResource extends DAVObject {
/**
* gets the content from this resource.
*
* @return content.
*/
public String getContent();
/**
* sets the content from this resource.
*
* @param content new content.
*
* @return this resource.
*/
public DAVResource setContent(String content);
}
1.1
xml-xindice/java/scratchpad/src/org/apache/xindice/webdav/datasource/DefaultDAVObject.java
Index: DefaultDAVObject.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xindice" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999-2001, The dbXML
* Group, L.L.C., http://www.dbxmlgroup.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xindice.webdav.datasource;
import java.util.Hashtable;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import java.text.SimpleDateFormat;
/**
* represents a webdav object.
* usefull for DAV methods like propfind where only some
* object properties are needed.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jan Metzner</a>
* @version $Id: DefaultDAVObject.java,v 1.1 2002/04/14 22:30:09 jmetzner Exp
$
*/
public class DefaultDAVObject implements DAVObject {
// -------------------------------------------------------------- Constants
/**
* The set of SimpleDateFormat formats to use in modification date.
*/
protected static final SimpleDateFormat modificationDateFormat =
new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
/**
* Simple date format for the creation date ISO representation (partial).
*/
protected static final SimpleDateFormat creationDateFormat =
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
/**
* GMT timezone.
*/
protected final static TimeZone gmtZone = TimeZone.getTimeZone("GMT");
// ----------------------------------------------------- Static Initializer
/**
* set timezone for formats.
*/
static {
modificationDateFormat.setTimeZone(gmtZone);
creationDateFormat.setTimeZone(gmtZone);
}
// ----------------------------------------------------- Instance Variables
/** the objectname on the web side */
protected String name;
/** the web URL to this object */
protected String webURL;
/** if true, this object is a collection */
protected boolean isCollection;
/**
* object properties.
* default properties:
* creationDate, modificationDate, displayName, contentType, resourceType
* additional properties for resources:
* contentLanguage, contentLength
*/
protected Hashtable properties;
// ------------------------------------------------------------ Constructor
public DefaultDAVObject(String relativePath, String webRoot, boolean
isCollection) {
this.webURL = rewritePath(webRoot, relativePath, isCollection);
// set name
this.name = this.webURL;
if(this.name.endsWith("/")) {
this.name = this.name.substring(0, this.name.length()-1);
}
int split = this.name.lastIndexOf("/");
if(split < 0) {
split = 0;
}
this.name = this.name.substring(split+1, this.name.length());
this.isCollection = isCollection;
// set properties
properties = new Hashtable(7);
setCreationDateProperty(new Date());
setModificationDateProperty(new Date());
setProperty("displayName", this.name);
if(isCollection) {
setProperty("contentType", "httpd/unix-directory");
setProperty("resourceType", "<resourcetype><collection
/></resourcetype>");
} else {
setProperty("contentType", "application/x-unknown-content-type");
setProperty("resourceType", "<resourcetype />");
setProperty("contentLanguage", Locale.getDefault().toString());
setProperty("contentLength", "200");
}
}
// --------------------------------------------------------- public Methods
/**
* returns object name.
*
* @return name of this object.
*/
public String getName() {
return name;
}
/**
* returns the web URL of this object.
*
* @return web URL of this object.
*/
public String getWebURL() {
return webURL;
}
/**
* returns if this object is a collection.
*
* @return true if this object is a collection.
*/
public boolean isCollection() {
return isCollection;
}
/**
* returns the object properties.
*
* @return object properties.
*/
public Hashtable getProperties() {
return (Hashtable)properties.clone();
}
/**
* get object property by name.
*
* @param name property name.
* @return object property.
*/
public String getProperty(String name) {
return (String) properties.get(name);
}
/**
* set object property.
* existing values are overwritten
*
* @param name property name.
* @param value property value.
*/
public void setProperty(String name, String value) {
properties.put(name, value);
}
/**
* set creation date property.
*
* @param date creation date.
*/
public void setCreationDateProperty(Date date) {
setProperty("creationDate", getISOCreationDate(date));
}
/**
* set modification date property.
*
* @param date modification date.
*/
public void setModificationDateProperty(Date date) {
setProperty("modificationDate", getModificationDate(date));
}
// ------------------------------------------------------ protected Methods
/**
* Get creation date in ISO format.
*/
protected String getISOCreationDate(Date date) {
StringBuffer creationDateValue = new StringBuffer
(creationDateFormat.format(date));
return creationDateValue.toString();
}
/**
* Get modification date.
*/
protected String getModificationDate(Date date) {
StringBuffer modificationDateValue = new StringBuffer
(modificationDateFormat.format(date));
return modificationDateValue.toString();
}
/**
* Path rewriter.
* the rewritten Path will start with '/'
*
* @param path Path to be rewiten
*/
protected String rewritePath(String rootPath, String relativePath, boolean
isCollection) {
String rewrittenPath = rootPath;
if(!rewrittenPath.endsWith("/")) {
rewrittenPath += "/";
}
if(!relativePath.startsWith("/")) {
rewrittenPath += relativePath;
} else {
rewrittenPath += relativePath.substring(1);
}
//TODO impl rewrite
if( !isCollection && rewrittenPath.endsWith("/") ) {
return rewrittenPath.substring(0, rewrittenPath.length()-2);
} else if( isCollection && !rewrittenPath.endsWith("/") ) {
return rewrittenPath+"/";
} else {
return rewrittenPath;
}
}
}
1.1
xml-xindice/java/scratchpad/src/org/apache/xindice/webdav/datasource/xmldb/XMLDBCollection.java
Index: XMLDBCollection.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xindice" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999-2001, The dbXML
* Group, L.L.C., http://www.dbxmlgroup.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xindice.webdav.datasource.xmldb;
import java.util.ArrayList;
import org.xmldb.api.base.XMLDBException;
import org.xmldb.api.base.Collection;
import org.xmldb.api.modules.XMLResource;
import org.apache.xindice.client.xmldb.services.CollectionManager;
import org.apache.xindice.xml.dom.DOMParser;
import org.apache.xindice.webdav.datasource.*;
/**
* Xindice collection using the XML:DB api.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jan Metzner</a>
*/
public class XMLDBCollection extends DefaultDAVObject implements
DAVCollection {
// ----------------------------------------------------- Instance Variables
protected Collection col;
// ------------------------------------------------------------ Constructor
public XMLDBCollection(String relativePath, String webRoot, Collection col)
{
super(relativePath, webRoot, true);
setProperty("contentType", "httpd/unix-directory");
this.col = col;
}
// --------------------------------------------------------- public Methods
public DAVObject[] getChilds() {
String[] colList;
try {
colList = this.col.listChildCollections();
} catch (org.xmldb.api.base.XMLDBException xmldbe) {
colList = new String[0];
}
String[] resList;
try {
resList = this.col.listResources();
} catch (org.xmldb.api.base.XMLDBException e) {
resList = new String[0];
}
ArrayList childs = new ArrayList(colList.length + resList.length);
for(int i = 0; i < colList.length; i++) {
DAVObject childCol = new DefaultDAVObject(colList[i], this.getWebURL(),
true);
childs.add(childCol);
}
for(int i = 0; i < resList.length; i++) {
DefaultDAVObject childRes = new DefaultDAVObject(resList[i],
this.getWebURL(), false);
childRes.setProperty("contentType", "text/xml");
childs.add(childRes);
}
return (DAVObject[]) childs.toArray(new DefaultDAVObject[0]);
}
public DAVObject getChildObject(String name)
throws DAVObjectException {
try {
return getChildResource(name);
} catch (DAVObjectNotFoundException donfe) {
; // do nothing
}
try {
return getChildCollection(name);
} catch (DAVObjectNotFoundException donfe) {
; // do nothing
}
throw new DAVObjectNotFoundException("Object "+name+" not found!");
}
public DAVResource getChildResource(String name)
throws DAVObjectException {
try {
XMLResource childRes = (XMLResource) this.col.getResource(name);
if(childRes != null) {
return new XMLDBResource(name, this.getWebURL(), childRes);
}
} catch (org.xmldb.api.base.XMLDBException xmldbe) {
xmldbe.printStackTrace();
throw new DAVObjectException(xmldbe.getMessage());
}
throw new DAVObjectNotFoundException("Resource "+name+" not found!");
}
public DAVCollection getChildCollection(String name)
throws DAVObjectException {
try {
Collection childCol = this.col.getChildCollection(name);
if(childCol != null) {
return new XMLDBCollection(name, this.getWebURL(), childCol);
}
} catch (org.xmldb.api.base.XMLDBException xmldbe) {
xmldbe.printStackTrace();
throw new DAVObjectException(xmldbe.getMessage());
}
throw new DAVObjectNotFoundException("Collection "+name+" not found!");
}
public DAVResource createResource(String name, String content)
throws DAVObjectException {
XMLResource res = null;
try {
res = (XMLResource) this.col.createResource(name,
"XMLResource");
res.setContent(content);
col.storeResource(res);
} catch (XMLDBException xmldbe) {
xmldbe.printStackTrace();
throw new DAVObjectOperationNotAllowedException
(xmldbe.getMessage());
}
if(res != null) {
return new XMLDBResource(name, this.getWebURL(), res);
} else {
throw new DAVObjectException("Could not get create resource "+name);
}
}
public DAVCollection createCollection(String name)
throws DAVObjectException {
try {
CollectionManager service =
(CollectionManager) this.col.getService("CollectionManager", "1.0");
String newCollectionConfig =
"<collection compressed=\"true\" name=\"" + name + "\">" +
" <filer class=\"org.apache.xindice.core.filer.BTreeFiler\"
gzip=\"true\"/>" +
"</collection>";
service.createCollection(name,
DOMParser.toDocument(newCollectionConfig));
Collection newCol = this.col.getChildCollection(name);
if(newCol != null) {
return new XMLDBCollection(name, this.getWebURL(), newCol);
} else {
throw new DAVObjectNotFoundException("Could not get new created
collection "+name);
}
} catch (Exception e) {
e.printStackTrace();
throw new DAVObjectException("Could not get create collection "+name);
}
}
}
1.1
xml-xindice/java/scratchpad/src/org/apache/xindice/webdav/datasource/xmldb/XMLDBDataSource.java
Index: XMLDBDataSource.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xindice" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999-2001, The dbXML
* Group, L.L.C., http://www.dbxmlgroup.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xindice.webdav.datasource.xmldb;
import org.xmldb.api.DatabaseManager;
import org.xmldb.api.base.Database;
import org.xmldb.api.base.XMLDBException;
import org.xmldb.api.base.Collection;
import org.xmldb.api.modules.XMLResource;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.xindice.webdav.datasource.*;
/**
* Xindice webdav DataSources for Avalon using the XML:DB API.
*
* The Configuration is like this:
*
* <pre>
* <datasource name='xmldb'>
*
<driver><i>org.apache.xindice.client.xmldb.DatabaseImpl</i></driver>
* <dbroot><i>xmldb:xindice:///db</i></dbroot>
* </datasource>
* </pre>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jan Metzner</a>
* @version $Id: XMLDBDataSource.java,v 1.1 2002/04/14 22:30:09 jmetzner Exp
$
*/
public class XMLDBDataSource extends AbstractDAVDataSource implements
DAVDataSource {
static String ROLE = DAVDataSource.ROLE + "/XMLDBDataSource";
// ----------------------------------------------------- Instance Variables
/** xmldb database */
protected Database database;
/** database root without ending '/' */
protected String dbRoot;
/** web root */
protected String webRoot;
// -------------------------------------------------------- Public Methods
public void setWebRoot(String webRoot) {
if( webRoot.endsWith("/") && (webRoot.length() > 1) ) {
this.webRoot = webRoot.substring(1);
} else {
this.webRoot = webRoot;
}
}
public void configure(final Configuration configuration)
throws ConfigurationException {
if(database == null) {
final String driver =
configuration.getChild("xmldb").getChild("driver").getValue("org.apache.xindice.client.xmldb.DatabaseImpl");
this.dbRoot =
configuration.getChild("xmldb").getChild("dbroot").getValue("xmldb:xindice:///db");
// openorb home for tomcat
Configuration openOrbHome =
configuration.getChild("xmldb").getChild("openorbhome", false);
if(openOrbHome != null) {
System.setProperty("openorb.home", openOrbHome.getValue());
}
if(getLogger().isDebugEnabled()) {
getLogger().debug("DBRoot set to: " + dbRoot);
getLogger().debug("Loading driver: " + driver);
}
// connect to database
try {
database = (Database) Class.forName(driver).newInstance();
DatabaseManager.registerDatabase(database);
} catch (java.lang.ClassNotFoundException e) {
if(getLogger().isWarnEnabled()) {
getLogger().warn("Database driver not found: "+e.getMessage());
} else {
e.printStackTrace();
}
} catch (java.lang.IllegalAccessException e) {
if(getLogger().isWarnEnabled()) {
getLogger().warn("Database driver - access denied:
"+e.getMessage());
} else {
e.printStackTrace();
}
} catch (java.lang.InstantiationException e) {
if(getLogger().isWarnEnabled()) {
getLogger().warn("Database driver - Instantiation denied:
"+e.getMessage());
} else {
e.printStackTrace();
}
} catch (org.xmldb.api.base.XMLDBException e) {
if(getLogger().isWarnEnabled()) {
getLogger().warn("XMLDB - driver could not be registered:
"+e.getMessage());
} else {
e.printStackTrace();
}
}
}
}
public DAVObject getDAVObject(String relativePath) throws
DAVObjectException {
String dbPath = dbRoot;
if(!relativePath.startsWith("/")) {
dbPath += "/";
}
dbPath += relativePath;
try {
Collection col = DatabaseManager.getCollection(dbPath);
if(col != null) {
// create new XCollection object
if(getLogger().isDebugEnabled()) {
getLogger().debug("Got XML:DB Collection from request "+dbPath);
}
return new XMLDBCollection(relativePath, this.webRoot, col);
} else {
if(getLogger().isDebugEnabled()) {
getLogger().debug("Could not get XML:DB Collection "+dbPath+"
resource?");
}
// no collection - get resource
if(relativePath.endsWith("/")) {
relativePath = relativePath.substring(0, relativePath.length()-1);
}
int split = relativePath.lastIndexOf("/");
String resName = "";
String newPath = "";
if(split != -1) {
resName = relativePath.substring(split+1, relativePath.length());
newPath = relativePath.substring(0, split);
} else {
resName = relativePath;
newPath = relativePath;
}
dbPath = dbRoot+newPath;
col = DatabaseManager.getCollection(dbPath);
if(col != null) {
XMLResource res = (XMLResource) col.getResource(resName);
if(getLogger().isDebugEnabled()) {
getLogger().debug("Got XML:DB Resource "+resName+" from request
"+dbPath);
}
return new XMLDBResource(relativePath, this.webRoot, res);
} else {
if(getLogger().isWarnEnabled()) {
getLogger().warn("No object for path: "+relativePath);
}
throw new DAVObjectNotFoundException(relativePath);
}
}
} catch (org.xmldb.api.base.XMLDBException xmldbe) {
if(getLogger().isWarnEnabled()) {
getLogger().warn("Could not get any XML:DB Object from request
"+relativePath);
}
xmldbe.printStackTrace();
throw new DAVObjectNotFoundException(relativePath);
}
}
public void copyDAVObject(String sourcePath, String destinationPath,
boolean overwrite) throws DAVObjectException {}
public void deleteDAVObject(String path) throws DAVObjectException {}
public void createDAVCollection(String path) throws DAVObjectException {}
public void createDAVResource(String path) throws DAVObjectException {}
}
1.1
xml-xindice/java/scratchpad/src/org/apache/xindice/webdav/datasource/xmldb/XMLDBResource.java
Index: XMLDBResource.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xindice" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999-2001, The dbXML
* Group, L.L.C., http://www.dbxmlgroup.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xindice.webdav.datasource.xmldb;
import org.xmldb.api.modules.XMLResource;
import org.apache.xindice.webdav.datasource.*;
/**
* Xindice xml Resource using the XML:DB api.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jan Metzner</a>
*/
public class XMLDBResource extends DefaultDAVObject implements DAVResource {
// ----------------------------------------------------- Instance Variables
protected XMLResource res;
// ------------------------------------------------------------ Constructor
public XMLDBResource(String relativePath, String webRoot, XMLResource res) {
super(relativePath, webRoot, false);
setProperty("contentType", "text/xml");
this.res = res;
}
// --------------------------------------------------------- public Methods
/**
* gets the content from this resource.
*
* @return content.
*/
public String getContent() {
try {
return (String)res.getContent();
} catch (org.xmldb.api.base.XMLDBException xmldbe) {
return null;
}
}
/**
* sets the content from this resource.
*
* @param content new content.
*
* @return this resource.
*/
public DAVResource setContent(String content) {
try {
res.setContent(content);
} catch (org.xmldb.api.base.XMLDBException xmldbe) {
;
}
return this;
}
}