gcasper 2003/10/22 14:11:19
Modified: . gump.xml blocks.properties
Added: src/blocks/repository/java/org/apache/cocoon/generation
TraversableSourceDescriptionGenerator.java
Removed: src/blocks/scratchpad/java/org/apache/cocoon/generation
TraversableSourceDescriptionGenerator.java
Log:
Moved TraversableSourceDescriptionGenerator from scratchpad block
to repository block
Revision Changes Path
1.1
cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/generation/TraversableSourceDescriptionGenerator.java
Index: TraversableSourceDescriptionGenerator.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2003 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 java.io.IOException;
import java.util.Enumeration;
import java.util.Map;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.components.source.InspectableSource;
import org.apache.cocoon.components.source.LockableSource;
import org.apache.cocoon.components.source.RestrictableSource;
import org.apache.cocoon.components.source.SourceInspector;
import org.apache.cocoon.components.source.VersionableSource;
import org.apache.cocoon.components.source.helpers.GroupSourcePermission;
import org.apache.cocoon.components.source.helpers.PrincipalSourcePermission;
import org.apache.cocoon.components.source.helpers.SourceLock;
import org.apache.cocoon.components.source.helpers.SourcePermission;
import org.apache.cocoon.components.source.helpers.SourceProperty;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceException;
import org.apache.excalibur.source.TraversableSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
/**
*
* This Generator augments the output of the TraversableGenerator.
* <p>
* It adds:
* <ul>
* <li>version information if the Source implements VersionableSource.</li>
* <li>locking information if the Source implements Lockablesource.</li>
* <li>permission information if the Source implements
RestrictableSource.</li>
* <li>and describes its SourceProperties if the Source implements
InspectableSource.</li>
* </ul>
* </p>
* <p>
* Sitemap parameters that can be specified to control processing are:
* <ul>
* <li><code>version</code> (<code>true</code>)
* whether to generate versioning information.</li>
* <li><code>locking</code> (<code>true</code>)
* whether to generate locking information.</li>
* <li><code>permission</code> (<code>true</code>)
* whether to generate permission information.</li>
* <li><code>properties</code> (<code>true</code>)
* whether to generate source property information.</li>
* </p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephan Michels</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Unico Hommes</a>
*/
public class TraversableSourceDescriptionGenerator
extends TraversableGenerator {
protected static final String MIME_TYPE_ATTR_NAME = "mimeType";
private static final String REVISION_ATTR_NAME = "revision";
private static final String REVISIONBRANCH_ATTR_NAME = "branch";
private static final String PROPERTIES_NODE_NAME = "properties";
private static final String PROPERTIES_NODE_QNAME = PREFIX + ":" +
PROPERTIES_NODE_NAME;
private static final String PROPERTY_TYPE_ATTR_NAME = "type";
private static final String PERMISSIONS_NODE_NAME = "permissions";
private static final String PERMISSIONS_NODE_QNAME = PREFIX + ":" +
PERMISSIONS_NODE_NAME;
private static final String PERMISSION_NODE_NAME = "permission";
private static final String PERMISSION_NODE_QNAME = PREFIX + ":" +
PERMISSION_NODE_NAME;
private static final String LOCKS_NODE_NAME = "locks";
private static final String LOCKS_NODE_QNAME = PREFIX + ":" +
LOCKS_NODE_NAME;
private static final String LOCK_NODE_NAME = "lock";
private static final String LOCK_NODE_QNAME = PREFIX + ":" +
LOCK_NODE_NAME;
private static final String PRINCIPAL_ATTR_NAME = "principal";
private static final String GROUP_ATTR_NAME = "group";
private static final String PRIVILEGE_ATTR_NAME = "privilege";
private static final String INHERITABLE_ATTR_NAME = "inheritable";
private static final String NEGATIVE_ATTR_NAME = "negative";
private static final String TYPE_ATTR_NAME = "type";
private static final String EXPIRATION_ATTR_NAME = "expiration";
private static final String EXCLUSIVE_ATTR_NAME = "exclusive";
/** Include properties into the description */
private boolean properties = true;
/** Include permissions into the description */
private boolean permissions = true;
/** Include locks into the description */
private boolean locks = true;
/** Include version into the description */
private boolean version = true;
/**
* Set the <code>SourceResolver</code>, objectModel <code>Map</code>,
* the source and sitemap <code>Parameters</code> used to process the
request.
*
* @param resolver Source Resolver
* @param objectModel Object model.
* @param location Location of the source.
* @param parameters Parameters for the generator.
*/
public void setup(SourceResolver resolver, Map objectModel,
String location,
Parameters parameters)
throws ProcessingException, SAXException, IOException {
super.setup(resolver, objectModel, location, parameters);
this.properties = parameters.getParameterAsBoolean("properties",
true);
this.permissions = parameters.getParameterAsBoolean("permissions",
true);
this.locks = parameters.getParameterAsBoolean("locks", true);
this.version = parameters.getParameterAsBoolean("version", true);
}
/**
* Augments source nodes with additional information.
*
* @param source the Source to describe.
*/
protected void addContent(TraversableSource source)
throws SAXException, ProcessingException {
super.addContent(source);
try {
pushSourceDescription(source);
} catch (SourceException e) {
throw new ProcessingException(e);
}
}
/**
* Push a XML description of specified source.
*
* @param source the Source to describe.
*/
private void pushSourceDescription(Source source)
throws SAXException, SourceException {
if (source == null) {
return;
}
try {
if (this.properties) {
pushComputedSourceProperties(source);
if ((source instanceof InspectableSource)) {
pushLiveSourceProperties((InspectableSource) source);
}
}
if (this.permissions) {
try {
if (source instanceof RestrictableSource) {
pushSourcePermissions((RestrictableSource) source);
}
} catch (SourceException se) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Could not retrieve source
permissions", se);
}
}
}
if (this.locks && (source instanceof LockableSource)) {
pushSourceLocks((LockableSource) source);
}
} catch (SAXException saxe) {
throw saxe;
}
}
/**
* Push a XML description about all properties, which
* the source owns.
*
* @param source the Source to describe.
*/
private void pushLiveSourceProperties(InspectableSource source)
throws SAXException, SourceException {
SourceProperty[] properties = source.getSourceProperties();
if (properties != null && properties.length > 0) {
SourceProperty property;
AttributesImpl attributes = new AttributesImpl();
attributes.addAttribute("", PROPERTY_TYPE_ATTR_NAME,
PROPERTY_TYPE_ATTR_NAME, "CDATA", "live");
this.contentHandler.startElement(URI, PROPERTIES_NODE_NAME,
PROPERTIES_NODE_QNAME,
attributes);
for (int i = 0; i < properties.length; i++) {
property = properties[i];
this.contentHandler.startPrefixMapping("",
property.getNamespace());
property.toSAX(this.contentHandler);
this.contentHandler.endPrefixMapping("");
}
this.contentHandler.endElement(URI, PROPERTIES_NODE_NAME,
PROPERTIES_NODE_QNAME);
}
}
/**
* Push a XML description about all properties, which
* were computed by source inspectors.
*
* @param source the Source to describe.
*/
private void pushComputedSourceProperties(Source source)
throws SAXException, SourceException {
AttributesImpl attributes = new AttributesImpl();
attributes.addAttribute("", PROPERTY_TYPE_ATTR_NAME,
PROPERTY_TYPE_ATTR_NAME, "CDATA", "computed");
this.contentHandler.startElement(URI, PROPERTIES_NODE_NAME,
PROPERTIES_NODE_QNAME, attributes);
SourceInspector inspector = null;
try {
inspector = (SourceInspector)
this.manager.lookup(SourceInspector.ROLE);
SourceProperty[] properties =
inspector.getSourceProperties(source);
for (int i = 0; i < properties.length; i++) {
this.contentHandler.startPrefixMapping("",
properties[i].getNamespace());
properties[i].toSAX(this.contentHandler);
this.contentHandler.endPrefixMapping("");
}
} catch (ServiceException ce) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Could not retrieve source inspector", ce);
}
} finally {
if (inspector!=null) {
this.manager.release(inspector);
}
}
this.contentHandler.endElement(URI, PROPERTIES_NODE_NAME,
PROPERTIES_NODE_QNAME);
}
/**
* Push a XML description of all permissions of a source.
*
* @param source the Source to describe.
*/
private void pushSourcePermissions(RestrictableSource source)
throws SAXException, SourceException {
SourcePermission[] permissions = source.getSourcePermissions();
if (permissions != null && permissions.length > 0) {
this.contentHandler.startElement(URI,
PERMISSIONS_NODE_NAME,
PERMISSIONS_NODE_QNAME,
new AttributesImpl());
for (int i = 0; i < permissions.length; i++) {
AttributesImpl attributes = new AttributesImpl();
if (permissions[i] instanceof PrincipalSourcePermission) {
attributes.addAttribute("", PRINCIPAL_ATTR_NAME,
PRINCIPAL_ATTR_NAME, "CDATA",
((PrincipalSourcePermission)
permissions[i]).getPrincipal());
} else if (permissions[i] instanceof GroupSourcePermission) {
attributes.addAttribute("", GROUP_ATTR_NAME,
GROUP_ATTR_NAME, "CDATA",
((GroupSourcePermission)
permissions[i]).getGroup());
}
attributes.addAttribute("", PRIVILEGE_ATTR_NAME,
PRIVILEGE_ATTR_NAME, "CDATA",
permissions[i].getPrivilege());
attributes.addAttribute("", INHERITABLE_ATTR_NAME,
INHERITABLE_ATTR_NAME, "CDATA",
String.valueOf(permissions[i].isInheritable()));
attributes.addAttribute("", NEGATIVE_ATTR_NAME,
NEGATIVE_ATTR_NAME, "CDATA",
String.valueOf(permissions[i].isNegative()));
this.contentHandler.startElement(URI,
PERMISSION_NODE_NAME,
PERMISSION_NODE_QNAME,
attributes);
this.contentHandler.endElement(URI,
PERMISSION_NODE_NAME,
PERMISSION_NODE_QNAME);
}
this.contentHandler.endElement(URI, PERMISSIONS_NODE_NAME,
PERMISSIONS_NODE_QNAME);
}
}
/**
* Push a XML description about all locks of a source.
*
* @param source the Source to describe.
*/
public void pushSourceLocks(LockableSource source)
throws SAXException, SourceException {
Enumeration locks = source.getSourceLocks();
SourceLock lock;
if (locks != null && locks.hasMoreElements()) {
this.contentHandler.startElement(URI, LOCKS_NODE_NAME,
LOCKS_NODE_QNAME,
new AttributesImpl());
while (locks.hasMoreElements()) {
lock = (SourceLock) locks.nextElement();
AttributesImpl attributes = new AttributesImpl();
attributes = new AttributesImpl();
attributes.addAttribute("", PRINCIPAL_ATTR_NAME,
PRINCIPAL_ATTR_NAME, "CDATA",
lock.getSubject());
attributes.addAttribute("", TYPE_ATTR_NAME, TYPE_ATTR_NAME,
"CDATA", lock.getType());
attributes.addAttribute("", EXPIRATION_ATTR_NAME,
EXPIRATION_ATTR_NAME, "CDATA",
lock.getExpiration().toString());
attributes.addAttribute("", INHERITABLE_ATTR_NAME,
INHERITABLE_ATTR_NAME, "CDATA",
String.valueOf(lock.isInheritable()));
attributes.addAttribute("", EXCLUSIVE_ATTR_NAME,
EXCLUSIVE_ATTR_NAME, "CDATA",
String.valueOf(lock.isExclusive()));
this.contentHandler.startElement(URI, LOCK_NODE_NAME,
LOCK_NODE_QNAME, attributes);
this.contentHandler.endElement(URI, LOCK_NODE_NAME,
LOCK_NODE_QNAME);
}
this.contentHandler.endElement(URI, LOCKS_NODE_NAME,
LOCKS_NODE_QNAME);
}
}
/**
* Augments node elements with additional attributes describing the
Source.
* The additional attributes are a <code>mimeType</code> attribute,
* and iff the Source is an instance of VersionableSource and the
generator
* is configured to output versioning information two attributes:
* <code>revision</code> and <code>branch</code>.
*
* @param source the Source to describe.
*/
protected void setNodeAttributes(TraversableSource source) throws
SAXException, ProcessingException {
super.setNodeAttributes(source);
if (!source.isCollection()) {
String mimeType = source.getMimeType();
if (mimeType != null) {
attributes.addAttribute("", MIME_TYPE_ATTR_NAME,
MIME_TYPE_ATTR_NAME,
"CDATA", source.getMimeType());
}
}
if (this.version && (source instanceof VersionableSource)) {
try {
VersionableSource versionablesource = (VersionableSource)
source;
if (versionablesource.isVersioned()) {
if ((versionablesource.getSourceRevision()!=null) &&
(versionablesource.getSourceRevision().length()>0)) {
attributes.addAttribute("",
REVISION_ATTR_NAME,
REVISION_ATTR_NAME, "CDATA",
versionablesource.getSourceRevision());
}
if ((versionablesource.getSourceRevisionBranch()!=null) &&
(versionablesource.getSourceRevisionBranch().length()>
0)) {
attributes.addAttribute("",
REVISIONBRANCH_ATTR_NAME,
REVISIONBRANCH_ATTR_NAME,
"CDATA",
versionablesource.getSourceRevisionBranch());
}
}
} catch (SourceException e) {
throw new ProcessingException(e);
}
}
}
}
1.94 +1 -2 cocoon-2.1/gump.xml
Index: gump.xml
===================================================================
RCS file: /home/cvs/cocoon-2.1/gump.xml,v
retrieving revision 1.93
retrieving revision 1.94
diff -u -r1.93 -r1.94
--- gump.xml 22 Oct 2003 19:28:08 -0000 1.93
+++ gump.xml 22 Oct 2003 21:11:19 -0000 1.94
@@ -109,7 +109,6 @@
<depend project="jakarta-servletapi-4"/>
<depend project="cocoon-block-velocity"/>
<depend project="cocoon-block-cron"/>
- <depend project="cocoon-block-repository"/>
<work nested="tools/anttasks"/>
<home nested="build/cocoon-@@DATE@@"/>
1.39 +1 -1 cocoon-2.1/blocks.properties
Index: blocks.properties
===================================================================
RCS file: /home/cvs/cocoon-2.1/blocks.properties,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- blocks.properties 22 Oct 2003 19:45:05 -0000 1.38
+++ blocks.properties 22 Oct 2003 21:11:19 -0000 1.39
@@ -81,7 +81,7 @@
#exclude.block.proxy=true
#exclude.block.qdox=true
-#dependency: scratchpad, webdav needs repository
+#dependency: slide, webdav needs repository
#exclude.block.repository=true
#exclude.block.scratchpad=true
#exclude.block.slide=true