You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by gc...@apache.org on 2004/03/27 16:21:47 UTC
cvs commit: cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/repository RepositoryManager.java Repository.java
gcasper 2004/03/27 07:21:47
Added: src/blocks/repository/java/org/apache/cocoon/components/repository/helpers
RepositoryTransactionHelper.java
RepositoryVersioningHelper.java PropertyName.java
Principal.java RepositoryPropertyHelper.java
CredentialsToken.java
src/blocks/repository/java/org/apache/cocoon/components/repository
RepositoryManager.java Repository.java
Log:
Added:
-a new repository interface
-a repository manager
-some helper classes
Revision Changes Path
1.1 cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/repository/helpers/RepositoryTransactionHelper.java
Index: RepositoryTransactionHelper.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cocoon.components.repository.helpers;
import org.apache.cocoon.ProcessingException;
/**
* A locking helper interface intended to be used by flowscripts or corresponding wrapper components.
*/
public interface RepositoryTransactionHelper {
/**
* beginning a transaction on the repository
*
* @return a boolean indicating success.
* @throws ProcessingException
*/
boolean beginTran() throws ProcessingException;
/**
* committing a transaction on the repository
*
* @return a boolean indicating success.
* @throws ProcessingException
*/
boolean commitTran() throws ProcessingException;
/**
* rolling back a transaction on the repository
*
* @return a boolean indicating success.
* @throws ProcessingException
*/
boolean rollbackTran() throws ProcessingException;
/**
* lock the resource
*
* @param uri the uri of the resource.
* @return a boolean indicating success.
* @throws ProcessingException
*/
boolean lock(String uri) throws ProcessingException;
/**
* lock the resource with explicit timeout in seconds
*
* @param uri the uri of the resource.
* @param timeout the lock timeout in seconds.
* @return a boolean indicating success.
* @throws ProcessingException
*/
boolean lock(String uri, int timeout) throws ProcessingException;
/**
* unlock resource
*
* @param uri the uri of the resource.
* @return a boolean indicating success.
* @throws ProcessingException
*/
boolean unlock(String uri) throws ProcessingException;
/**
* checking wether the repository supports transactions
*
* @return true if the repository supports transactions.
*/
boolean supportsTransactions();
/**
* checking wether the repository supports locking
*
* @return true if the repository supports locking.
*/
boolean supportsLocking();
}
1.1 cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/repository/helpers/RepositoryVersioningHelper.java
Index: RepositoryVersioningHelper.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cocoon.components.repository.helpers;
import java.util.List;
import org.apache.cocoon.ProcessingException;
/**
* A versioning helper interface intended to be used by flowscripts or corresponding wrapper components.
*/
public interface RepositoryVersioningHelper {
/**
* checkout a resource
*
* @param uri the uri of the resource.
* @return a boolean indicating success.
* @throws ProcessingException
*/
boolean checkout(String uri) throws ProcessingException;
/**
* checkin a resource
*
* @param uri the uri of the resource.
* @return a boolean indicating success.
* @throws ProcessingException
*/
boolean checkin(String uri) throws ProcessingException;
/**
* undo a previously done checkout
*
* @param uri the uri of the resource.
* @return a boolean indicating success.
* @throws ProcessingException
*/
boolean uncheckout(String uri) throws ProcessingException;
/**
* check if a resource is under version control
*
* @param uri the uri of the resource.
* @return a boolean indicating if the resource is under version control.
* @throws ProcessingException
*/
boolean isVersioned(String uri) throws ProcessingException;
/**
* set a resource under version control
*
* @param uri the uri of the resource.
* @param versioned if true the resource is set under version control.
* @return a boolean indicating success.
* @throws ProcessingException
*/
boolean setVersioned(String uri, boolean versioned) throws ProcessingException;
/**
* get the version history of a resource
*
* @param uri the uri of the resource.
* @return a list containing the versions.
* @throws ProcessingException
*/
List getVersions(String uri) throws ProcessingException;
}
1.1 cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/repository/helpers/PropertyName.java
Index: PropertyName.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cocoon.components.repository.helpers;
/**
* A PropertyName object intentifies a specific property.
*/
public class PropertyName {
private String name;
private String namespace;
/**
* creates a PropertyName
*
* @param name the name of the property.
* @param namespace the namespace of the property.
*/
public PropertyName(String name, String namespace) {
this.name = name;
this.namespace = namespace;
}
/**
* get the name of the property
*
* @return the name of the property.
*/
public String getName() {
return this.name;
}
/**
* get the namespace of the property
*
* @return the namespace of the property.
*/
public String getNamespace() {
return this.namespace;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return (this.namespace+":"+this.name).hashCode();
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
return (obj != null && (obj instanceof PropertyName)
&& this.name.equals(((PropertyName)obj).getName())
&& this.namespace.equals(((PropertyName)obj).getNamespace()));
}
}
1.1 cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/repository/helpers/Principal.java
Index: Principal.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cocoon.components.repository.helpers;
import java.util.Set;
/**
* A Principal class to be used with a repository implementation.
*/
public class Principal {
private String name;
private String group;
private Set roles;
/**
* creates a Principal
*
* @param name the name of the principal.
* @param group the group of the principal.
* @param roles a Set containing the roles of the principal
*/
public Principal(String name, String group, Set roles) {
this.name = name;
this.group = group;
this.roles = roles;
}
/**
* get the name of the principal
*
* @return the name of the principal.
*/
public String getName() {
return this.name;
}
/**
* get the group name of the principal
*
* @return the group name of the principal.
*/
public String getGroup() {
return this.group;
}
/**
* get the roles of the principal
*
* @return A Set containing the roles of the principal.
*/
public Set getRoles() {
return this.roles;
}
}
1.1 cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/repository/helpers/RepositoryPropertyHelper.java
Index: RepositoryPropertyHelper.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cocoon.components.repository.helpers;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.components.source.helpers.SourceProperty;
import org.w3c.dom.Node;
/**
* A property helper interface intended to be used
* by flowscripts or corresponding wrapper components.
*/
public interface RepositoryPropertyHelper {
/**
* get a single property
*
* @param uri the uri of the resource.
* @param name the name of the property.
* @param namespace the namespace of the property.
* @return the property.
* @throws ProcessingException
*/
SourceProperty getProperty(String uri, String name, String namespace) throws ProcessingException;
/**
* get multiple properties
*
* @param uri the uri of the resource.
* @param propNames a Set containing the property names.
* @return a Map containing the property values.
* @throws ProcessingException
*/
Map getProperties(String uri, Set propNames) throws ProcessingException;
/**
* get all properties
*
* @param uri the uri of the resource.
* @return a List containing the property values.
* @throws ProcessingException
*/
List getAllProperties(String uri) throws ProcessingException;
/**
* set a single property to a String value
*
* @param uri the uri of the resource.
* @param name the name of the property.
* @param namespace the namespace of the property.
* @param value the String value to set the property to.
* @return a boolean indicating success.
* @throws ProcessingException
*/
boolean setProperty(String uri, String name, String namespace, String value) throws ProcessingException;
/**
* set a single property to a W3C Node value
*
* @param uri the uri of the resource.
* @param name the name of the property.
* @param namespace the namespace of the property.
* @param value the DOM value to set the property to.
* @return a boolean indicating success.
* @throws ProcessingException
*/
boolean setProperty(String uri, String name, String namespace, Node value) throws ProcessingException;
/**
* set multiple properties
*
* @param uri the uri of the resource.
* @param poperties a Map containing the properties to set.
* @return a boolean indicating success.
* @throws ProcessingException
*/
boolean setProperties(String uri, Map properties) throws ProcessingException;
}
1.1 cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/repository/helpers/CredentialsToken.java
Index: CredentialsToken.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cocoon.components.repository.helpers;
/**
* A CredentialsToken class to be used with a repository implementation.
*/
public class CredentialsToken {
private Principal principal;
private String credentials;
/**
* creates a CredentialsToken
*
* @param name the principal belonging to the credentials token.
* @param credentials the credentials of the credentials token.
*/
public CredentialsToken(Principal principal, String credentials) {
this.principal = principal;
this.credentials = credentials;
}
/**
* get the principal belonging to the credentials token
*
* @return the principal.
*/
public Principal getPrincipal() {
return this.principal;
}
/**
* get the credentials belonging to the credentials token
*
* @return String
*/
public String getCredentials() {
return credentials;
}
}
1.1 cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/repository/RepositoryManager.java
Index: RepositoryManager.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cocoon.components.repository;
import java.util.HashMap;
import java.util.Map;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.components.LifecycleHelper;
import org.apache.cocoon.components.repository.helpers.CredentialsToken;
/**
* A factory component to create instances of repositories.
*/
public class RepositoryManager extends AbstractLogEnabled
implements Serviceable, Disposable, Configurable, Component, ThreadSafe {
/** The Avalon role name */
public static final String ROLE = RepositoryManager.class.getName();
/* The ServiceManager */
private ServiceManager manager;
/* A HashMap holding the repositories configurations */
private Map repos = new HashMap();
/* (non-Javadoc)
* @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
*/
public void service(ServiceManager manager) throws ServiceException {
this.manager = manager;
}
/* (non-Javadoc)
* @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
*/
public void configure(Configuration configuration) throws ConfigurationException {
if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("configuring repository manager");
}
Configuration[] children = configuration.getChildren();
for (int i = 0; i < children.length; i++) {
if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("found repository: " + children[i].getAttribute("class"));
}
this.repos.put(children[i].getAttribute("name"), children[i]);
}
}
/* (non-Javadoc)
* @see org.apache.avalon.framework.activity.Disposable#dispose()
*/
public void dispose() {
this.manager = null;
}
/**
* get instance of repository.
*
* @param hint identifies the repository implementation to load.
* @param credentials the user credentials the repository instance is initialized with.
* @return the repository instance.
*/
public Repository getRepository(String hint, CredentialsToken credentials) throws ProcessingException {
if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("get repository for: " + hint);
}
String className = null;
try {
Configuration repoConfiguration = (Configuration)this.repos.get(hint);
className = repoConfiguration.getAttribute("class");
Class repoClass = Class.forName(className);
if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("loading class" + className);
}
Repository repo = (Repository)repoClass.newInstance();
LifecycleHelper.setupComponent(repo,
this.getLogger(),
null,
this.manager,
null,
repoConfiguration,
true);
repo.setCredentials(credentials);
return repo;
} catch (ConfigurationException ce) {
throw new ProcessingException("Could not get configuration for " + hint, ce);
} catch (ClassNotFoundException cnfe) {
throw new ProcessingException("Could not load class " + className, cnfe);
} catch (InstantiationException ie) {
throw new ProcessingException("Could not instantiate class " + className, ie);
} catch (IllegalAccessException iae) {
throw new ProcessingException("Could not instantiate class " + className, iae);
} catch (Exception e) {
throw new ProcessingException("Could not setup component " + className, e);
}
}
}
1.1 cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/repository/Repository.java
Index: Repository.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cocoon.components.repository;
import java.io.InputStream;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.components.repository.helpers.CredentialsToken;
import org.apache.cocoon.components.repository.helpers.RepositoryTransactionHelper;
import org.apache.cocoon.components.repository.helpers.RepositoryPropertyHelper;
import org.apache.cocoon.components.repository.helpers.RepositoryVersioningHelper;
import org.apache.excalibur.source.Source;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
/**
* A repository interface intended to be used by flowscripts or corresponding wrapper components.
*/
public interface Repository {
/**
* get content as String
*
* @param uri the uri of the resource.
* @return the content as a String.
* @throws ProcessingException
*/
String getContentString(String uri) throws ProcessingException;
/**
* get content as Stream
*
* @param uri the uri of the resource.
* @return the content as a InputStream.
* @throws ProcessingException
*/
InputStream getContentStream(String uri) throws ProcessingException;
/**
* get content as DOM
*
* @param uri the uri of the resource.
* @return the content as a W3C Document object.
* @throws ProcessingException
*/
Document getContentDOM(String uri) throws ProcessingException;
/**
* save content
*
* @param uri the uri of the resource.
* @param content the to be saved content given as a String.
* @return a boolean indicating success.
* @throws ProcessingException
*/
boolean saveContent(String uri, String content) throws ProcessingException;
/**
* save content
*
* @param uri the uri of the resource.
* @param content the to be saved content given as a W3C Node object.
* @return a boolean indicating success.
* @throws ProcessingException
*/
boolean saveContent(String uri, Node node) throws ProcessingException;
/**
* save content
*
* @param uri the uri of the resource.
* @param content the to be saved content given as a Excalibur Source object.
* @return a boolean indicating success.
* @throws ProcessingException
*/
boolean saveContent(String uri, Source source) throws ProcessingException;
/**
* copy a resource
*
* @param uri the uri of the resource.
* @param dest the destination of the copy.
* @param recurse if true recursively creates parent collections if not existant
* @param overwrite whether to overwrite the destination if it exists.
* @return a boolean indicating success.
* @throws ProcessingException
*/
boolean copy(String uri, String dest, boolean recurse, boolean overwrite) throws ProcessingException;
/**
* move a resource
*
* @param uri the uri of the resource.
* @param dest the destination of the move.
* @param recurse if true recursively creates parent collections if not existant
* @param overwrite whether to overwrite the destination if it exists.
* @return a boolean indicating success.
* @throws ProcessingException
*/
boolean move(String uri, String dest, boolean recurse, boolean overwrite) throws ProcessingException;
/**
* remove resource
*
* @param uri the uri of the resource.
* @return a boolean indicating success.
* @throws ProcessingException
*/
boolean remove(String uri) throws ProcessingException;
/**
* checks wether resource exists
*
* @param uri the uri of the document.
* @return a boolean indicating existance of the resource.
* @throws ProcessingException
*/
public boolean exists(String uri) throws ProcessingException;
/**
* make collection
*
* @param uri the uri of the collection.
* @param recursive a boolean indicating wether
* the operation should fail if the parent
* collection does not exist or wether the
* complete path should be created.
* @return a boolean indicating success.
* @throws ProcessingException
*/
boolean makeCollection(String uri, boolean recursive) throws ProcessingException;
/**
* get a property helper
*
* @return the property helper.
* Returns null if the Repository does not support properties.
*/
RepositoryPropertyHelper getPropertyHelper();
/**
* get a transaction helper
*
* @return a transaction helper.
* Returns null if the Repository does neither support transactions nor locks.
*/
RepositoryTransactionHelper getTransactionHelper();
/**
* get a versioning helper
*
* @return a versioning helper.
* Returns null if the Repository does not support versioning.
*/
RepositoryVersioningHelper getVersioningHelper();
/**
* get the credentials used against the repository
*
* @return the credentials in use.
*/
CredentialsToken getCredentials();
/**
* set the credentials to be used against the repository
*
* @param credentials the credentials to use.
*/
void setCredentials(CredentialsToken credentials);
}