juergen     02/03/08 03:55:51

  Modified:    src/webdav/server/org/apache/slide/webdav/util
                        PropertyHelper.java
  Log:
  Added support for computed properties.
  (ralf)
  
  Revision  Changes    Path
  1.5       +388 -4    
jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PropertyHelper.java
  
  Index: PropertyHelper.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PropertyHelper.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PropertyHelper.java       1 Mar 2002 16:48:24 -0000       1.4
  +++ PropertyHelper.java       8 Mar 2002 11:55:51 -0000       1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PropertyHelper.java,v
 1.4 2002/03/01 16:48:24 pnever Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/03/01 16:48:24 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PropertyHelper.java,v
 1.5 2002/03/08 11:55:51 juergen Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/03/08 11:55:51 $
    *
    * ====================================================================
    *
  @@ -70,13 +70,27 @@
   import org.jdom.Element;
   import org.jdom.Attribute;
   import org.jdom.JDOMException;
  +import org.jdom.Namespace;
   
   import org.apache.slide.common.Domain;
   import org.apache.slide.common.SlideToken;
   import org.apache.slide.common.NamespaceAccessToken;
  +import org.apache.slide.common.ServiceAccessException;
  +
   import org.apache.slide.content.NodeProperty;
   import org.apache.slide.content.NodeRevisionDescriptor;
   import org.apache.slide.content.NodeRevisionDescriptors;
  +import org.apache.slide.content.NodeRevisionNumber;
  +import org.apache.slide.content.Content;
  +import org.apache.slide.content.RevisionDescriptorNotFoundException;
  +
  +import org.apache.slide.structure.LinkedObjectNotFoundException;
  +import org.apache.slide.structure.ObjectNotFoundException;
  +
  +import org.apache.slide.security.AccessDeniedException;
  +
  +import org.apache.slide.lock.ObjectLockedException;
  +
   import org.apache.slide.webdav.util.resourcekind.*;
   
   
  @@ -86,7 +100,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Peter Nevermann</a>
    */
   
  -public class PropertyHelper extends AbstractWebdavHelper {
  +public class PropertyHelper extends AbstractWebdavHelper implements DeltavConstants 
{
       
       /**
        * Factory method.
  @@ -354,5 +368,375 @@
           Document d = xmlBuilder.build( new StringReader(propValue) );
           return d.getRootElement();
       }
  +    
  +    /**
  +     * Returns the property of the resource described by
  +     * the resourcePath.
  +     *
  +     * @param    propertyName        the name of the property.
  +     * @param    resourcePath        the path that identifies the resource.
  +     *
  +     * @return   the property.
  +     *
  +     * @throws   ObjectLockedException
  +     * @throws   RevisionDescriptorNotFoundException
  +     * @throws   ServiceAccessException
  +     * @throws   LinkedObjectNotFoundException
  +     * @throws   AccessDeniedException
  +     * @throws   ObjectNotFoundException
  +     */
  +    public NodeProperty getProperty(String propertyName, String resourcePath) 
throws ObjectLockedException, RevisionDescriptorNotFoundException, 
ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, 
ObjectNotFoundException {
  +        
  +        UriHandler uriHandler = UriHandler.getUriHandler(nsaToken, resourcePath);
  +        String uri = null;
  +        NodeRevisionDescriptors revisionDescriptors = null;
  +        NodeRevisionDescriptor revisionDescriptor = null;
  +        Content contentHelper = nsaToken.getContentHelper();
  +        
  +        if (uriHandler.isVersionUri()) {
  +            uri = uriHandler.getAssociatedHistoryUri();
  +            NodeRevisionNumber revisionNumber = new 
NodeRevisionNumber(uriHandler.getVersionName());
  +            revisionDescriptors = contentHelper.retrieve(sToken, uri);
  +            revisionDescriptor = contentHelper.retrieve(sToken, 
revisionDescriptors, revisionNumber);
  +        }
  +        else if (uriHandler.isHistoryUri()) {
  +            uri = uriHandler.getAssociatedHistoryUri();
  +            NodeRevisionNumber revisionNumber = new NodeRevisionNumber("0.0");
  +            revisionDescriptors = contentHelper.retrieve(sToken, uri);
  +            revisionDescriptor = contentHelper.retrieve(sToken, 
revisionDescriptors, revisionNumber);
  +        }
  +        else {
  +            uri = resourcePath;
  +            revisionDescriptors = contentHelper.retrieve(sToken, uri);
  +            revisionDescriptor = contentHelper.retrieve(sToken, 
revisionDescriptors);
  +        }
  +        return getProperty(propertyName, revisionDescriptors, revisionDescriptor);
  +    }
  +    
  +    /**
  +     * Returns the property of the resource described by
  +     * the resourcePath.
  +     *
  +     * @param    propertyName         the name of the property.
  +     * @param    revisionDescriptors  the NodeRevisionDescriptors of the resource.
  +     * @param    revisionDescriptor   the NodeRevisionDescriptor of the resource.
  +     *
  +     * @return   the property.
  +     *
  +     * @throws   ObjectLockedException
  +     * @throws   RevisionDescriptorNotFoundException
  +     * @throws   ServiceAccessException
  +     * @throws   LinkedObjectNotFoundException
  +     * @throws   AccessDeniedException
  +     * @throws   ObjectNotFoundException
  +     */
  +    public NodeProperty getProperty(String propertyName, NodeRevisionDescriptors 
revisionDescriptors, NodeRevisionDescriptor revisionDescriptor) throws 
ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, 
LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException {
  +        
  +        NodeProperty property = null;
  +        ResourceKind resourceKind = 
AbstractResourceKind.determineResourceKind(revisionDescriptor);
  +        if (resourceKind.isSupportedLiveProperty(propertyName)) {
  +            if (AbstractResourceKind.isComputedProperty(propertyName)) {
  +                property = computeProperty(propertyName, revisionDescriptors, 
revisionDescriptor);
  +            }
  +        }
  +        
  +        return property;
  +    }
  +    
  +    /**
  +     * Returns the computed property of the resource.
  +     *
  +     * @param    propertyName         the name of the property.
  +     * @param    revisionDescriptors  the NodeRevisionDescriptors of the resource.
  +     * @param    revisionDescriptor   the NodeRevisionDescriptor of the resource.
  +     *
  +     * @return   the property.
  +     *
  +     * @throws   ObjectLockedException
  +     * @throws   RevisionDescriptorNotFoundException
  +     * @throws   ServiceAccessException
  +     * @throws   LinkedObjectNotFoundException
  +     * @throws   AccessDeniedException
  +     * @throws   ObjectNotFoundException
  +     */
  +    public NodeProperty computeProperty(String propertyName, 
NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor 
revisionDescriptor) throws ObjectLockedException, RevisionDescriptorNotFoundException, 
ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, 
ObjectNotFoundException {
  +        
  +        NodeProperty property = null;
  +        if (P_SUCCESSOR_SET.equals(propertyName)) {
  +            property = new NodeProperty(propertyName, 
computeSuccessorSet(revisionDescriptors, revisionDescriptor));
  +        }
  +        else if (P_VERSION_HISTORY.equals(propertyName)) {
  +            property = new NodeProperty(propertyName, 
computeVersionHistory(revisionDescriptors, revisionDescriptor));
  +        }
  +        else if (P_ROOT_VERSION.equals(propertyName)) {
  +            property = new NodeProperty(propertyName, 
computeRootVersion(revisionDescriptors, revisionDescriptor));
  +        }
  +        else if (P_SUPPORTED_METHOD_SET.equals(propertyName)) {
  +            property = new NodeProperty(propertyName, 
computeSupportedMethodSet(revisionDescriptors, revisionDescriptor));
  +        }
  +        else if (P_SUPPORTED_LIVE_PROPERTY_SET.equals(propertyName)) {
  +            property = new NodeProperty(propertyName, 
computeSupportedLivePropertySet(revisionDescriptors, revisionDescriptor));
  +        }
  +        else if (P_SUPPORTED_REPORT_SET.equals(propertyName)) {
  +            property = new NodeProperty(propertyName, 
computeSupportedReportSet(revisionDescriptors, revisionDescriptor));
  +        }
  +        
  +        return property;
  +    }
  +    
  +    /**
  +     * Returns an XMLValue containing the <code>&lt;href&gt;</code> elements
  +     * describing the successors of the resource.
  +     *
  +     * @param    revisionDescriptors  the NodeRevisionDescriptors of the resource.
  +     * @param    revisionDescriptor   the NodeRevisionDescriptor of the resource.
  +     *
  +     * @return   the successor list.
  +     *
  +     * @throws   ObjectLockedException
  +     * @throws   RevisionDescriptorNotFoundException
  +     * @throws   ServiceAccessException
  +     * @throws   LinkedObjectNotFoundException
  +     * @throws   AccessDeniedException
  +     * @throws   ObjectNotFoundException
  +     */
  +    public XMLValue computeSuccessorSet(NodeRevisionDescriptors 
revisionDescriptors, NodeRevisionDescriptor revisionDescriptor) throws 
ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, 
LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException {
  +        
  +        XMLValue xmlValue = new XMLValue();
  +        Element hrefElement = new Element(E_HREF, defNamespace);
  +        NodeRevisionDescriptor successorRevisionDescriptor = null;
  +        NodeRevisionNumber successorRevisionNumber = null;
  +        Enumeration successorEnum = 
revisionDescriptors.getSuccessors(revisionDescriptor.getRevisionNumber());
  +        
  +        if (successorEnum != null) {
  +            while (successorEnum.hasMoreElements()) {
  +                successorRevisionNumber = 
(NodeRevisionNumber)successorEnum.nextElement();
  +                hrefElement = (Element)hrefElement.clone();
  +                StringBuffer buffer = new 
StringBuffer(revisionDescriptors.getUri());
  +                if ( ! revisionDescriptors.getUri().endsWith("/") ) {
  +                    buffer.append("/");
  +                }
  +                buffer.append(successorRevisionNumber.toString());
  +                hrefElement.setText(buffer.toString());
  +                xmlValue.add(hrefElement);
  +            }
  +        }
  +        return xmlValue;
  +    }
  +    
  +    /**
  +     * Returns an XMLValue containing the <code>&lt;href&gt;</code> element
  +     * with the history URI of the resource. If the resource is neither a
  +     * VR, checked-in VCR or checked-out VCR, the returned XMLValue is empty.
  +     *
  +     * @param    revisionDescriptors  the NodeRevisionDescriptors of the resource.
  +     * @param    revisionDescriptor   the NodeRevisionDescriptor of the resource.
  +     *
  +     * @return   the version history <code>&lt;href&gt;</code>.
  +     *
  +     * @throws   ObjectLockedException
  +     * @throws   RevisionDescriptorNotFoundException
  +     * @throws   ServiceAccessException
  +     * @throws   LinkedObjectNotFoundException
  +     * @throws   AccessDeniedException
  +     * @throws   ObjectNotFoundException
  +     */
  +    public XMLValue computeVersionHistory(NodeRevisionDescriptors 
revisionDescriptors, NodeRevisionDescriptor revisionDescriptor) throws 
ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, 
LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException {
  +        
  +        XMLValue xmlValue = new XMLValue();
  +        ResourceKind resourceKind = 
AbstractResourceKind.determineResourceKind(revisionDescriptor);
  +        if (resourceKind instanceof Version) {
  +            Element element = new Element(E_HREF, defNamespace);
  +            element.setText(revisionDescriptors.getUri());
  +            xmlValue.add(element);
  +        }
  +        else if (resourceKind instanceof CheckedInVersionControlled) {
  +            Element element = new Element(E_HREF, defNamespace);
  +            String checkedInUri = 
revisionDescriptor.getProperty(P_CHECKED_IN).getValue().toString();
  +            UriHandler uriHandler = UriHandler.getUriHandler(nsaToken, 
checkedInUri);
  +            element.setText(uriHandler.getAssociatedHistoryUri());
  +            xmlValue.add(element);
  +        }
  +        else if (resourceKind instanceof CheckedOutVersionControlled) {
  +            Element element = new Element(E_HREF, defNamespace);
  +            String checkedInUri = 
revisionDescriptor.getProperty(P_CHECKED_OUT).getValue().toString();
  +            UriHandler uriHandler = UriHandler.getUriHandler(nsaToken, 
checkedInUri);
  +            element.setText(uriHandler.getAssociatedHistoryUri());
  +            xmlValue.add(element);
  +        }
  +        
  +        return xmlValue;
  +    }
  +    
  +    /**
  +     * Returns an XMLValue containing the <code>&lt;href&gt;</code> element
  +     * with the URI of the root version of the history.
  +     * If the resource is not a history, the returned XMLValue is empty.
  +     *
  +     * @param    revisionDescriptors  the NodeRevisionDescriptors of the resource.
  +     * @param    revisionDescriptor   the NodeRevisionDescriptor of the resource.
  +     *
  +     * @return   the root version URI.
  +     *
  +     * @throws   ObjectLockedException
  +     * @throws   RevisionDescriptorNotFoundException
  +     * @throws   ServiceAccessException
  +     * @throws   LinkedObjectNotFoundException
  +     * @throws   AccessDeniedException
  +     * @throws   ObjectNotFoundException
  +     */
  +    public XMLValue computeRootVersion(NodeRevisionDescriptors revisionDescriptors, 
NodeRevisionDescriptor revisionDescriptor) throws ObjectLockedException, 
RevisionDescriptorNotFoundException, ServiceAccessException, 
LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException {
  +        
  +        XMLValue xmlValue = new XMLValue();
  +        
  +        ResourceKind resourceKind = 
AbstractResourceKind.determineResourceKind(revisionDescriptor);
  +        if (resourceKind instanceof VersionHistory) {
  +            Element element = new Element(E_HREF, defNamespace);
  +            StringBuffer buffer = new StringBuffer(revisionDescriptors.getUri());
  +            if ( ! revisionDescriptors.getUri().endsWith("/") ) {
  +                buffer.append("/");
  +            }
  +            buffer.append(revisionDescriptors.getInitialRevision().toString());
  +            element.setText(buffer.toString());
  +            xmlValue.add(element);
  +        }
  +        
  +        return xmlValue;
  +    }
  +    
  +    /**
  +     * Returns an XMLValue containing the <code>&lt;supported-method&gt;</code>
  +     * elements with the name (attribute) of the supported methods.
  +     * <br></br>
  +     * <i>Note:</i>
  +     * <br></br>
  +     * <i>
  +     * Due to the specification this is <b>not</b> a computed property, but because
  +     * of implementation problems it is not stored.
  +     * </i>
  +     *
  +     * @param    revisionDescriptors  the NodeRevisionDescriptors of the resource.
  +     * @param    revisionDescriptor   the NodeRevisionDescriptor of the resource.
  +     *
  +     * @return   the supported methods.
  +     *
  +     * @throws   ObjectLockedException
  +     * @throws   RevisionDescriptorNotFoundException
  +     * @throws   ServiceAccessException
  +     * @throws   LinkedObjectNotFoundException
  +     * @throws   AccessDeniedException
  +     * @throws   ObjectNotFoundException
  +     */
  +    public XMLValue computeSupportedMethodSet(NodeRevisionDescriptors 
revisionDescriptors, NodeRevisionDescriptor revisionDescriptor) throws 
ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, 
LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException {
  +        
  +        XMLValue xmlValue = new XMLValue();
  +        
  +        ResourceKind resourceKind = 
AbstractResourceKind.determineResourceKind(revisionDescriptor);
  +        Set supportedMethodNames = resourceKind.getSupportedMethods();
  +        Iterator iterator = supportedMethodNames.iterator();
  +        Element supportedMethod = null;
  +        while (iterator.hasNext()) {
  +            supportedMethod = new Element(E_SUPPORTED_METHOD);
  +            supportedMethod.setAttribute(new Attribute(E_NAME, 
(String)iterator.next()));
  +            xmlValue.add(supportedMethod);
  +        }
  +        
  +        return xmlValue;
  +    }
  +    
  +    /**
  +     * Returns an XMLValue containing the 
<code>&lt;supported-live-property&gt;</code>
  +     * elements containing <code>&lt;prop&gt;</code> which are containing
  +     * elements with the name of the property.
  +     * <br></br>
  +     * <i>Note:</i>
  +     * <br></br>
  +     * <i>
  +     * Due to the specification this is <b>not</b> a computed property, but because
  +     * of implementation problems it is not stored.
  +     * </i>
  +     *
  +     * @param    revisionDescriptors  the NodeRevisionDescriptors of the resource.
  +     * @param    revisionDescriptor   the NodeRevisionDescriptor of the resource.
  +     *
  +     * @return   the supported live properties.
  +     *
  +     * @throws   ObjectLockedException
  +     * @throws   RevisionDescriptorNotFoundException
  +     * @throws   ServiceAccessException
  +     * @throws   LinkedObjectNotFoundException
  +     * @throws   AccessDeniedException
  +     * @throws   ObjectNotFoundException
  +     */
  +    public XMLValue computeSupportedLivePropertySet(NodeRevisionDescriptors 
revisionDescriptors, NodeRevisionDescriptor revisionDescriptor) throws 
ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, 
LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException {
  +        
  +        XMLValue xmlValue = new XMLValue();
  +        
  +        ResourceKind resourceKind = 
AbstractResourceKind.determineResourceKind(revisionDescriptor);
  +        Set supportedLivePropertyNames = resourceKind.getSupportedLiveProperties();
  +        Iterator iterator = supportedLivePropertyNames.iterator();
  +        Element supportedLivePropertyElement = null;
  +        Element propElement = null;
  +        Element propertyElement = null;
  +        while (iterator.hasNext()) {
  +            
  +            supportedLivePropertyElement = new Element(E_SUPPORTED_LIVE_PROPERTY);
  +            propElement = new Element(E_PROP);
  +            supportedLivePropertyElement.addContent(propElement);
  +            propertyElement = new Element((String)iterator.next());
  +            propElement.addContent(propertyElement);
  +            xmlValue.add(supportedLivePropertyElement);
  +        }
  +        
  +        return xmlValue;
  +    }
  +    
  +    /**
  +     * Returns an XMLValue containing the <code>&lt;supported-report&gt;</code>
  +     * elements containing <code>&lt;report&gt;</code> which are containing
  +     * elements with the name of the report.
  +     * <br></br>
  +     * <i>Note:</i>
  +     * <br></br>
  +     * <i>
  +     * Due to the specification this is <b>not</b> a computed property, but because
  +     * of implementation problems it is not stored.
  +     * </i>
  +     *
  +     * @param    revisionDescriptors  the NodeRevisionDescriptors of the resource.
  +     * @param    revisionDescriptor   the NodeRevisionDescriptor of the resource.
  +     *
  +     * @return   the supported reports.
  +     *
  +     * @throws   ObjectLockedException
  +     * @throws   RevisionDescriptorNotFoundException
  +     * @throws   ServiceAccessException
  +     * @throws   LinkedObjectNotFoundException
  +     * @throws   AccessDeniedException
  +     * @throws   ObjectNotFoundException
  +     */
  +    public XMLValue computeSupportedReportSet(NodeRevisionDescriptors 
revisionDescriptors, NodeRevisionDescriptor revisionDescriptor) throws 
ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, 
LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException {
  +        
  +        XMLValue xmlValue = new XMLValue();
  +        
  +        ResourceKind resourceKind = 
AbstractResourceKind.determineResourceKind(revisionDescriptor);
  +        Set supportedReportNames = resourceKind.getSupportedReports();
  +        Iterator iterator = supportedReportNames.iterator();
  +        Element supportedReportElement = null;
  +        Element reportElement = null;
  +        Element propertyElement = null;
  +        while (iterator.hasNext()) {
  +            
  +            supportedReportElement = new Element(E_SUPPORTED_REPORT);
  +            reportElement = new Element(E_REPORT);
  +            supportedReportElement.addContent(reportElement);
  +            propertyElement = new Element((String)iterator.next());
  +            reportElement.addContent(propertyElement);
  +            xmlValue.add(supportedReportElement);
  +        }
  +        
  +        return xmlValue;
  +    }
  +    
   }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to