luetzkendorf 2005/01/10 10:21:05
Added: src/webdav/server/org/apache/slide/webdav/util/properties
ConfigurablePropertyComputer.java
InheritedProperty.java
src/webdav/server/org/apache/slide/webdav/util/resourcekind
ResourceKindConfigurator.java
Log:
added
Revision Changes Path
1.1
jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/properties/ConfigurablePropertyComputer.java
Index: ConfigurablePropertyComputer.java
===================================================================
// vi: set ts=3 sw=3:
package org.apache.slide.webdav.util.properties;
import org.apache.slide.common.PropertyName;
import org.apache.slide.util.conf.Configurable;
/**
* @author Stefan L�tzkendorf
*/
public interface ConfigurablePropertyComputer extends PropertyComputer,
Configurable
{
public void setPropertyName(PropertyName propertyName);
}
1.1
jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/properties/InheritedProperty.java
Index: InheritedProperty.java
===================================================================
// vi: set ts=3 sw=3:
package org.apache.slide.webdav.util.properties;
import org.apache.slide.common.NamespaceAccessToken;
import org.apache.slide.common.PropertyName;
import org.apache.slide.common.SlideException;
import org.apache.slide.common.SlideToken;
import org.apache.slide.content.Content;
import org.apache.slide.content.NodeProperty;
import org.apache.slide.content.NodeRevisionDescriptor;
import org.apache.slide.content.NodeRevisionDescriptors;
import org.apache.slide.structure.ObjectNode;
import org.apache.slide.structure.Structure;
import org.apache.slide.util.conf.Configuration;
import org.apache.slide.util.conf.ConfigurationException;
import org.apache.slide.webdav.util.WebdavContext;
import org.apache.slide.webdav.util.resourcekind.ResourceKind;
/**
* Property computer for properties that shall be inherited by parent or
* ancestor resources.
*
* <p>Sample declaration in Domain.xml.
* <pre>
* <event classname="org.apache.slide.event.DomainEvent" enable="true"/>
* <listener
classname="org.apache.slide.webdav.util.resourcekind.ResourceKindConfigurator">
* <configuration>
* <resource-kind name="DeltavCompliant">
* <live-properties>
* <live-property name="myProperty"
namespace="http://my.company.com/slide"
*
computer="org.apache.slide.webdav.util.properties.InheritedProperty">
* <computer-configuration>
* <default-value>a Value to use if no value could be
inherited</default-value>
* </computer-configuration>
* </live-property>
* </live-properties>
* </resource-kind>
* </configuration>
* </listener>
* </pre>
*
* <p><em>Note:</em> This is a sample of a property that is <em>computed</em>
* but not <em>protected</em>.
*/
public class InheritedProperty extends AbstractComputedProperty implements
ConfigurablePropertyComputer
{
private PropertyName propertyName;
private String defaultValue = "";
public void configure(Configuration configuration)
throws ConfigurationException
{
try {
Configuration c = configuration.getConfiguration("default-value");
this.defaultValue = c.getValue("");
} catch (ConfigurationException e) {
// ignore; no default-value given; is ok too
}
}
public PropertyName getPropertyName()
{
return this.propertyName;
}
public void setPropertyName(PropertyName propertyName)
{
this.propertyName = propertyName;
}
public Object computeValue(NamespaceAccessToken nsaToken,
NodeRevisionDescriptors revisionDescriptors,
NodeRevisionDescriptor revisionDescriptor,
ResourceKind resourceKind, WebdavContext context)
throws SlideException
{
NodeProperty property =
revisionDescriptor.getProperty(this.propertyName);
if (property == null) {
Structure structure = nsaToken.getStructureHelper();
Content content = nsaToken.getContentHelper();
SlideToken slideToken = context.getSlideToken();
String uri = revisionDescriptors.getUri();
ObjectNode node = structure.retrieve(slideToken, uri);
while (property == null) {
node = structure.getParent(slideToken, node);
if (node == null) {
return this.defaultValue;
}
revisionDescriptors = content.retrieve(slideToken,
node.getUri());
revisionDescriptor = content.retrieve(slideToken,
revisionDescriptors);
property = revisionDescriptor.getProperty(this.propertyName);
}
}
return property.getValue();
}
}
1.1
jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/resourcekind/ResourceKindConfigurator.java
Index: ResourceKindConfigurator.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/resourcekind/ResourceKindConfigurator.java,v
1.1 2005/01/10 18:21:05 luetzkendorf Exp $
* $Revision: 1.1 $
* $Date: 2005/01/10 18:21:05 $
*
* ====================================================================
*
* Copyright 1999-2002 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.slide.webdav.util.resourcekind;
import java.util.Enumeration;
import org.apache.slide.event.DomainEvent;
import org.apache.slide.event.DomainListener;
import org.apache.slide.util.conf.Configurable;
import org.apache.slide.util.conf.Configuration;
import org.apache.slide.util.conf.ConfigurationException;
/**
* Eventlistener that allows configuration of resource kind capabilities
* inside <code>Domain.xml</code>.
*
* <p>Sample:
* <pre>
* <event classname="org.apache.slide.event.DomainEvent" enable="true"/>
* <listener
classname="org.apache.slide.webdav.util.resourcekind.ResourceKindConfigurator">
* <configuration>
* <resource-kind name="DeltavCompliant">
* <live-properties>
* <live-property name="myProperty"
namespace="http://my.company.com/slide"
*
computer="org.apache.slide.webdav.util.properties.InheritedProperty">
* <computer-configuration>
* <default-value>a Value to use if no value could be
inherited</default-value>
* </computer-configuration>
* </live-property>
* </live-properties>
* </resource-kind>
* <resource-kind name="DeltavCompliantCollection">
* <live-properties>
* <live-property name="myCollectionProperty"
namespace="http://my.company.com/slide"
*
computer="org.apache.slide.webdav.util.properties.InheritedProperty">
* </live-property>
* </live-properties>
* </resource-kind>
* </configuration>
* </listener>
* </pre>
*/
public class ResourceKindConfigurator implements DomainListener, Configurable
{
private Configuration config = null;
public void configure(Configuration configuration)
throws ConfigurationException
{
this.config = configuration;
}
public void initialized(DomainEvent event)
{
if (config != null) {
Enumeration e = config.getConfigurations("resource-kind");
for (; e.hasMoreElements();) {
ResourceKindManager.initResourceKind(
(Configuration)e.nextElement());
}
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]