nicolaken 02/05/22 08:28:05 Added: src/scratchpad/src/org/apache/cocoon/generation SlideCollectionGenerator.java Log: [PATCH] SourceFactory for jakarta slide (Bug#: 9267 ) submitter by [EMAIL PROTECTED] (Stephan Michels) to use: build installscratchpadwar and then remove the comments for the webdav servlet and mapping in web.xml. Revision Changes Path 1.1 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/generation/SlideCollectionGenerator.java Index: SlideCollectionGenerator.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 Cocoon" 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.cocoon.generation; import org.apache.avalon.excalibur.pool.Recyclable; import org.apache.avalon.framework.activity.Disposable; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.component.Composable; 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.parameters.Parameters; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.environment.Source; import org.apache.cocoon.environment.SourceResolver; import org.apache.slide.authenticate.CredentialsToken; import org.apache.slide.authenticate.SecurityToken; import org.apache.slide.common.Domain; import org.apache.slide.common.NamespaceAccessToken; import org.apache.slide.common.ServiceAccessException; import org.apache.slide.common.SlideException; import org.apache.slide.common.SlideToken; import org.apache.slide.common.SlideTokenImpl; import org.apache.slide.content.Content; import org.apache.slide.content.NodeProperty; import org.apache.slide.content.NodeRevisionContent; import org.apache.slide.content.NodeRevisionDescriptor; import org.apache.slide.content.NodeRevisionDescriptors; import org.apache.slide.content.RevisionContentNotFoundException; import org.apache.slide.content.RevisionDescriptorNotFoundException; import org.apache.slide.content.RevisionNotFoundException; import org.apache.slide.content.NodeRevisionNumber; import org.apache.slide.lock.Lock; import org.apache.slide.lock.NodeLock; import org.apache.slide.lock.ObjectLockedException; import org.apache.slide.macro.Macro; import org.apache.slide.security.AccessDeniedException; import org.apache.slide.security.NodePermission; import org.apache.slide.security.Security; import org.apache.slide.structure.LinkedObjectNotFoundException; import org.apache.slide.structure.ObjectNode; import org.apache.slide.structure.ObjectNotFoundException; import org.apache.slide.structure.Structure; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; import java.io.IOException; import java.util.Enumeration; import java.util.Date; import java.util.Map; /** * Generates an XML directory listing from a jakarta slide node. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephan Michels</a> * @version CVS $Id: SlideCollectionGenerator.java,v 1.1 2002/05/22 15:28:05 nicolaken Exp $ */ public class SlideCollectionGenerator extends AbstractGenerator implements Recyclable, Disposable, Configurable/*, Cacheable*/{ /** The URI of the namespace of this generator. */ private static final String URI = "http://apache.org/cocoon/slidecollection/1.0"; /** The namespace prefix for this namespace. */ private static final String PREFIX = "col"; private static final String COLLECTION_NODE_NAME = "collection"; private static final String OBJECT_NODE_NAME = "object"; private static final String PERMISSION_NODE_NAME = "permission"; private static final String LOCK_NODE_NAME = "lock"; private static final String URI_ATTR_NAME = "uri"; private static final String CONTENTLENGTH_ATTR_NAME = "contentlength"; private static final String LASTMODIFIED_ATTR_NAME = "lastmodified"; private static final String SUBJECTURI_ATTR_NAME = "subjecturi"; private static final String ACTIONURI_ATTR_NAME = "actionuri"; private static final String INHERITABLE_ATTR_NAME = "inheritable"; private static final String NEGATIVE_ATTR_NAME = "negative"; private static final String TYPEURI_ATTR_NAME = "typeuri"; private static final String EXPIRATION_ATTR_NAME = "expiration"; private static final String EXCLUSIVE_ATTR_NAME = "exclusive"; /** Namespace access token. */ private NamespaceAccessToken token; /** Structure helper. */ private Structure structure; /** Content helper. */ private Content content; /** Security helper. */ private Security security; /** Lock helper. */ private Lock lock; /** Macro helper. */ private Macro macro; /** Slide token. */ private SlideToken slideToken; /** uri of the node */ private String uri; /** * Pass the Configuration to the Configurable class. This method must * always be called after the constructor and before any other method. * * @param conf the class configurations. * * @throws ConfigurationException Thrown when a Configurable component * cannot be configured properly, or if * a value cannot be retrieved properly. */ public void configure(Configuration conf) throws ConfigurationException { } public void setup(SourceResolver resolver, Map objectModel, String src, Parameters parameters) throws ProcessingException, SAXException, IOException { super.setup(resolver, objectModel, src, parameters); String namespace = src.substring(0, src.indexOf("/")); this.uri = src.substring(src.indexOf("/")); //System.out.println("namespace = '"+namespace+"'"); //System.out.println("uri = '"+this.uri+"'"); this.token = Domain.accessNamespace(new SecurityToken(new String()), namespace); if (this.token==null) throw new ProcessingException("Could not access namespace '"+namespace+"'"); this.structure = token.getStructureHelper(); this.content = token.getContentHelper(); this.security = token.getSecurityHelper(); this.lock = token.getLockHelper(); this.macro = token.getMacroHelper(); CredentialsToken credToken = new CredentialsToken(parameters.getParameter("username", "root")); //System.out.println("username = '"+credToken.getPublicCredentials()+"'"); this.slideToken = new SlideTokenImpl(credToken); } /** * Generate the unique key. * This key must be unique inside the space of this component. * * @return The generated key hashes the src */ /*public long generateKey() { return HashUtil.hash( ); }*/ /** * Generate the validity object. * * @return The generated validity object or <code>null</code> if the * component is currently not cacheable. */ /*public CacheValidity generateValidity() { return new SourceCacheValidity( ); }*/ /** * Generate XML data. */ public void generate() throws IOException, SAXException, ProcessingException { try { this.contentHandler.startDocument(); this.contentHandler.startPrefixMapping(PREFIX,URI); pushObjectNode(this.uri, 1); this.contentHandler.endPrefixMapping(PREFIX); this.contentHandler.endDocument(); } catch (SlideException se) { throw new ProcessingException("Could not get source", se); } } /** * Tests whether a resource is a collection resource. * * @param revisionDescriptor revision descriptor of the resource * * @return true if the descriptor represents a collection, false otherwise */ public boolean isCollection (NodeRevisionDescriptor revisionDescriptor) { boolean result = false; if (revisionDescriptor == null) return true; NodeProperty property = revisionDescriptor.getProperty("resourcetype"); if ((property != null) && (property.getValue().equals("<collection/>"))) { result = true; } return result; } private void pushObjectNode(String objecturi, int deep) throws SAXException, SlideException { ObjectNode object = structure.retrieve(this.slideToken, objecturi); NodeRevisionDescriptor currentDescriptor = null; NodeRevisionDescriptors revisionDescriptors = content.retrieve(slideToken, objecturi); AttributesImpl attributes = new AttributesImpl(); attributes.addAttribute("", URI_ATTR_NAME, URI_ATTR_NAME, "CDATA", object.getUri()); boolean collection = true; if (revisionDescriptors.hasRevisions()) { // Retrieve latest revision descriptor currentDescriptor = content.retrieve(slideToken, revisionDescriptors); collection = isCollection(currentDescriptor); if (!collection) attributes.addAttribute("", CONTENTLENGTH_ATTR_NAME, CONTENTLENGTH_ATTR_NAME, "CDATA", String.valueOf(currentDescriptor.getContentLength())); attributes.addAttribute("", LASTMODIFIED_ATTR_NAME, LASTMODIFIED_ATTR_NAME, "CDATA", currentDescriptor.getLastModified()); } if (collection) { this.contentHandler.startElement(URI, COLLECTION_NODE_NAME, PREFIX+':'+COLLECTION_NODE_NAME, attributes); pushPermissionList(object); pushLockList(object); if (deep>0) { Enumeration children = structure.getChildren(slideToken, object); ObjectNode child; while (children.hasMoreElements()) { child = (ObjectNode) children.nextElement(); pushObjectNode(child.getUri(), deep-1); } } this.contentHandler.endElement(URI, COLLECTION_NODE_NAME, PREFIX+':'+COLLECTION_NODE_NAME); } else { this.contentHandler.startElement(URI, OBJECT_NODE_NAME, PREFIX+':'+COLLECTION_NODE_NAME, attributes); pushPermissionList(object); pushLockList(object); this.contentHandler.endElement(URI, OBJECT_NODE_NAME, PREFIX+':'+COLLECTION_NODE_NAME); } } private void pushPermissionList(ObjectNode object) throws SAXException, SlideException { Enumeration permissionsList = this.security.enumeratePermissions(slideToken, object.getUri()); NodePermission currentPermission; while (permissionsList.hasMoreElements()) { currentPermission = (NodePermission) permissionsList.nextElement(); AttributesImpl attributes = new AttributesImpl(); attributes.addAttribute("", SUBJECTURI_ATTR_NAME, SUBJECTURI_ATTR_NAME, "CDATA", currentPermission.getSubjectUri()); attributes.addAttribute("", ACTIONURI_ATTR_NAME, ACTIONURI_ATTR_NAME, "CDATA", currentPermission.getActionUri()); attributes.addAttribute("", INHERITABLE_ATTR_NAME, INHERITABLE_ATTR_NAME, "CDATA", String.valueOf(currentPermission.isInheritable())); attributes.addAttribute("", NEGATIVE_ATTR_NAME, NEGATIVE_ATTR_NAME, "CDATA", String.valueOf(currentPermission.isNegative())); this.contentHandler.startElement(URI, PERMISSION_NODE_NAME, PREFIX+':'+PERMISSION_NODE_NAME, attributes); this.contentHandler.endElement(URI, PERMISSION_NODE_NAME, PREFIX+':'+PERMISSION_NODE_NAME); } } public void pushLockList(ObjectNode object) throws SAXException, SlideException { Enumeration locksList = this.lock.enumerateLocks(slideToken, object.getUri(), false); NodeLock currentLock; while (locksList.hasMoreElements()) { currentLock = (NodeLock) locksList.nextElement(); AttributesImpl attributes = new AttributesImpl(); attributes = new AttributesImpl(); attributes.addAttribute("", SUBJECTURI_ATTR_NAME, SUBJECTURI_ATTR_NAME, "CDATA", currentLock.getSubjectUri()); attributes.addAttribute("", TYPEURI_ATTR_NAME, TYPEURI_ATTR_NAME, "CDATA", currentLock.getTypeUri()); attributes.addAttribute("", EXPIRATION_ATTR_NAME, EXPIRATION_ATTR_NAME, "CDATA", currentLock.getExpirationDate().toString()); attributes.addAttribute("", INHERITABLE_ATTR_NAME, INHERITABLE_ATTR_NAME, "CDATA", String.valueOf(currentLock.isInheritable())); attributes.addAttribute("", EXCLUSIVE_ATTR_NAME, EXCLUSIVE_ATTR_NAME, "CDATA", String.valueOf(currentLock.isExclusive())); this.contentHandler.startElement(URI, LOCK_NODE_NAME, PREFIX+':'+LOCK_NODE_NAME, attributes); this.contentHandler.endElement(URI, LOCK_NODE_NAME, PREFIX+':'+LOCK_NODE_NAME); } } /** * Recycle resources * */ public void recycle() { super.recycle(); } public void dispose() { Domain.closeNamespace(token); } }
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]