stephan 2003/01/29 02:55:18
Modified: src/java/org/apache/cocoon/components/source SourceUtil.java
WriteableSource.java
src/java/org/apache/cocoon/components/source/impl
FileSource.java
src/scratchpad/src/org/apache/cocoon/components/source/impl
SlideSource.java
Log:
Made changes as we discussed
http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=104210729224250&w=2
Moved the copy() and move() methods into the SourceUtil.
Revision Changes Path
1.13 +308 -162
xml-cocoon2/src/java/org/apache/cocoon/components/source/SourceUtil.java
Index: SourceUtil.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/source/SourceUtil.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- SourceUtil.java 14 Jan 2003 09:54:20 -0000 1.12
+++ SourceUtil.java 29 Jan 2003 10:55:16 -0000 1.13
@@ -9,7 +9,7 @@
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,
+ 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,
@@ -17,12 +17,12 @@
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
+ 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
+ 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]
@@ -33,7 +33,7 @@
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
+ 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
@@ -75,6 +75,7 @@
import org.xml.sax.helpers.DefaultHandler;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.Map;
@@ -83,44 +84,51 @@
* This class contains some utility methods for the source resolving.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Stephan Michels</a>
* @version $Id$
*/
public final class SourceUtil
{
/** Avoid instantiation */
- protected SourceUtil() {}
+ protected SourceUtil() {
+ }
/**
* Generates SAX events from the given source
* <b>NOTE</b> : if the implementation can produce lexical events, care
should be taken
* that <code>handler</code> can actually
* directly implement the LexicalHandler interface!
- * @param source the data
+ * @param source The data
+ * @param handler Content handler
+ * @param manager Component manager
+ *
+ * @throws IOException If a io exception occurs.
* @throws ProcessingException if no suitable converter is found
+ * @throws SAXException If a SAX exception occurs.
*/
- static public void toSAX( Source source,
- ContentHandler handler,
- ComponentManager manager )
- throws SAXException, IOException, ProcessingException {
- if ( source instanceof org.apache.excalibur.xml.sax.XMLizable ) {
- ((org.apache.excalibur.xml.sax.XMLizable)source).toSAX( handler
);
- } else if ( source instanceof org.apache.cocoon.xml.XMLizable ) {
- ((org.apache.cocoon.xml.XMLizable)source).toSAX( handler );
+ static public void toSAX(Source source, ContentHandler handler,
+ ComponentManager manager)
+ throws SAXException, IOException,
+ ProcessingException {
+ if (source instanceof org.apache.excalibur.xml.sax.XMLizable) {
+ ((org.apache.excalibur.xml.sax.XMLizable) source).toSAX(handler);
+ } else if (source instanceof org.apache.cocoon.xml.XMLizable) {
+ ((org.apache.cocoon.xml.XMLizable) source).toSAX(handler);
} else {
XMLizer xmlizer = null;
+
try {
- xmlizer = (XMLizer) manager.lookup( XMLizer.ROLE);
- xmlizer.toSAX( source.getInputStream(),
- source.getMimeType(),
- source.getSystemId(),
- handler );
+ xmlizer = (XMLizer) manager.lookup(XMLizer.ROLE);
+ xmlizer.toSAX(source.getInputStream(), source.getMimeType(),
+ source.getSystemId(), handler);
} catch (SourceException se) {
throw SourceUtil.handle(se);
} catch (ComponentException ce) {
- throw new ProcessingException("Exception during streaming
source.", ce);
+ throw new ProcessingException("Exception during streaming
source.",
+ ce);
} finally {
- manager.release( (Component)xmlizer );
+ manager.release((Component) xmlizer);
}
}
}
@@ -130,40 +138,56 @@
* <b>NOTE</b> : if the implementation can produce lexical events, care
should be taken
* that <code>handler</code> can actually
* directly implement the LexicalHandler interface!
- *
- * @param source the data
+ *
+ * @param source The data.
+ * @param handler Content handler.
+ * @param manager Component manager.
+ * @param typeParameters
+ * @param filterDocumentEvent
+ *
+ * @throws IOException If a io exception occurs.
* @throws ProcessingException if no suitable converter is found
+ * @throws SAXException If a SAX exception occurs.
*/
- static public void toSAX( Source source,
- ContentHandler handler,
- ComponentManager manager,
- Parameters typeParameters,
- boolean filterDocumentEvent)
- throws SAXException, IOException, ProcessingException {
-
-
+ static public void toSAX(Source source, ContentHandler handler,
+ ComponentManager manager,
+ Parameters typeParameters,
+ boolean filterDocumentEvent)
+ throws SAXException, IOException,
+ ProcessingException {
+
// Test for url rewriting
- if (typeParameters != null
- && typeParameters.getParameter(URLRewriter.PARAMETER_MODE, null)
!= null) {
+ if ((typeParameters!=null) &&
+ (typeParameters.getParameter(URLRewriter.PARAMETER_MODE, null)!=
+ null)) {
handler = new URLRewriter(typeParameters, handler);
}
if (filterDocumentEvent) {
IncludeXMLConsumer filter = new IncludeXMLConsumer(handler);
+
toSAX(source, filter, manager);
} else {
toSAX(source, handler, manager);
}
}
-
+
/**
* Generates a DOM from the given source
- * @param source the data
+ * @param source The data
+ * @param manager Component manager.
+ *
+ * @return Created DOM document.
+ *
+ * @throws IOException If a io exception occurs.
* @throws ProcessingException if no suitable converter is found
+ * @throws SAXException If a SAX exception occurs.
*/
- static public Document toDOM( Source source,
- ComponentManager manager )
- throws SAXException, IOException, ProcessingException {
+ static public Document toDOM(Source source,
+ ComponentManager manager)
+ throws SAXException, IOException,
+ ProcessingException {
DOMBuilder builder = new DOMBuilder();
+
toSAX(source, builder, manager);
return builder.getDocument();
}
@@ -172,32 +196,53 @@
* Make a ProcessingException from a SourceException
* If the exception is a SourceNotFoundException than a
* ResourceNotFoundException is thrown
+ *
+ * @param se Source exception
+ *
+ * @return Created processing exception.
*/
static public ProcessingException handle(SourceException se) {
- if (se instanceof SourceNotFoundException)
+ if (se instanceof SourceNotFoundException) {
return new ResourceNotFoundException("Resource not found.", se);
- return new ProcessingException("Exception during source resolving.",
se);
+ }
+ return new ProcessingException("Exception during source resolving.",
+ se);
}
/**
* Make a ProcessingException from a SourceException
* If the exception is a SourceNotFoundException than a
* ResourceNotFoundException is thrown
+ *
+ * @param message Additional exception message.
+ * @param se Source exception.
+ *
+ * @return Created processing exception.
*/
static public ProcessingException handle(String message,
SourceException se) {
- if (se instanceof SourceNotFoundException)
+ if (se instanceof SourceNotFoundException) {
return new ResourceNotFoundException(message, se);
+ }
return new ProcessingException(message, se);
}
/**
* Get an InputSource object
+ *
+ * @param source Source.
+ *
+ * @return Input stream of the source.
+ *
+ * @throws IOException If a io exception occurs.
+ * @throws ProcessingException If an exception occurs during
+ * processing.
*/
static public InputSource getInputSource(Source source)
- throws IOException, ProcessingException {
+ throws IOException, ProcessingException {
try {
final InputSource newObject = new
InputSource(source.getInputStream());
+
newObject.setSystemId(source.getSystemId());
return newObject;
} catch (SourceException se) {
@@ -207,136 +252,228 @@
/**
* Get a <code>Source</code> object
+ *
+ * @param uri Uri of the source.
+ * @param typeParameters
+ * @param resourceParameters Parameters of the source.
+ * @param resolver Resolver for the source.
+ *
+ * @return The resolved source.
+ *
+ * @throws IOException If a io exception occurs.
+ * @throws SAXException If a SAX exception occurs.
+ * @throws SourceException If the source an exception throws.
*/
- static public Source getSource(String uri,
- Parameters typeParameters,
- SourceParameters resourceParameters,
- SourceResolver resolver)
- throws IOException, SAXException, SourceException {
+ static public Source getSource(String uri, Parameters typeParameters,
+ SourceParameters resourceParameters,
+ SourceResolver resolver)
+ throws IOException, SAXException,
+ SourceException {
// first step: encode parameters which are already appended to the
url
int queryPos = uri.indexOf('?');
- if (queryPos != -1) {
+
+ if (queryPos!=-1) {
String queryString = uri.substring(queryPos+1);
SourceParameters queries = new SourceParameters(queryString);
+
if (queries.hasParameters()) {
StringBuffer buffer;
+
buffer = new StringBuffer(uri.substring(0, queryPos));
String current;
Iterator iter = queries.getParameterNames();
char separator = '?';
Iterator values;
- while (iter.hasNext() == true) {
- current = (String)iter.next();
+
+ while (iter.hasNext()==true) {
+ current = (String) iter.next();
values = queries.getParameterValues(current);
while (values.hasNext()) {
- buffer.append(separator)
- .append(current)
- .append('=')
-
.append(org.apache.excalibur.source.SourceUtil.encode((String)values.next()));
+
buffer.append(separator).append(current).append('=').append(org.apache.excalibur.source.SourceUtil.encode((String)
values.next()));
separator = '&';
}
}
uri = buffer.toString();
}
}
- boolean followRedirects = (typeParameters != null ?
-
typeParameters.getParameterAsBoolean("followRedirects", true)
- : true);
- String method = (typeParameters != null ?
typeParameters.getParameter("method", "GET")
- : "GET");
- if (method.equalsIgnoreCase("POST")
- && (resourceParameters == null ||
!resourceParameters.hasParameters() )) {
+ boolean followRedirects = ((typeParameters!=null)
+ ?
typeParameters.getParameterAsBoolean("followRedirects", true)
+ : true);
+ String method = ((typeParameters!=null)
+ ? typeParameters.getParameter("method", "GET")
+ : "GET");
+
+ if (method.equalsIgnoreCase("POST") &&
+ ((resourceParameters==null) ||
+ !resourceParameters.hasParameters())) {
method = "GET";
}
- if (uri.startsWith("cocoon:")
- && resourceParameters != null
- && resourceParameters.hasParameters()) {
-
+ if (uri.startsWith("cocoon:") && (resourceParameters!=null) &&
+ resourceParameters.hasParameters()) {
int pos = uri.indexOf(";jsessionid=");
- if (uri.startsWith("cocoon:") == false) {
- if (pos != -1) uri = uri.substring(0, pos);
- uri =
org.apache.excalibur.source.SourceUtil.appendParameters(uri,
resourceParameters);
+
+ if (uri.startsWith("cocoon:")==false) {
+ if (pos!=-1) {
+ uri = uri.substring(0, pos);
+ }
+ uri =
org.apache.excalibur.source.SourceUtil.appendParameters(uri,
+ resourceParameters);
} else {
StringBuffer buf;
- if (pos == -1) {
+
+ if (pos==-1) {
buf = new StringBuffer(uri);
} else {
buf = new StringBuffer(uri.substring(0, pos));
}
- buf.append((uri.indexOf('?') == -1 ? '?' : '&'));
+ buf.append(((uri.indexOf('?')==-1) ? '?' : '&'));
buf.append(resourceParameters.getEncodedQueryString());
uri = buf.toString();
}
}
Map resolverParameters = new java.util.HashMap();
+
resolverParameters.put(URLSource.HTTP_METHOD, method);
- resolverParameters.put(URLSource.REQUEST_PARAMETERS,
resourceParameters);
+ resolverParameters.put(URLSource.REQUEST_PARAMETERS,
+ resourceParameters);
return resolver.resolveURI(uri, null, resolverParameters);
}
+ /**
+ * Move the source to a specified destination.
+ *
+ * @param source Source of the source.
+ * @param destination Destination of the source.
+ *
+ * @throws SourceException If an exception occurs during
+ * the move.
+ */
+ static public void move(Source source,
+ Source destination) throws SourceException {
+ if (source instanceof WriteableSource) {
+ copy(source, destination);
+ ((WriteableSource) source).delete();
+ } else {
+ throw new SourceException("Source '"+source.getSystemId()+
+ "' is not writeable");
+ }
+ }
+
+ /**
+ * Copy the source to a specified destination.
+ *
+ * @param source Source of the source.
+ * @param destination Destination of the source.
+ *
+ * @throws SourceException If an exception occurs during
+ * the copy.
+ */
+ static public void copy(Source source,
+ Source destination) throws SourceException {
+ if ((source instanceof MoveableSource) &&
+ (source.getClass().equals(destination.getClass()))) {
+ ((MoveableSource) source).copy(destination);
+ } else {
+ if ( !(destination instanceof WriteableSource)) {
+ throw new SourceException("Source '"+
+ destination.getSystemId()+
+ "' is not writeable");
+ }
+
+ try {
+ OutputStream out = ((WriteableSource)
destination).getOutputStream();
+ InputStream in = source.getInputStream();
+
+ byte[] buffer = new byte[8192];
+ int length = -1;
+
+ while ((length = in.read(buffer))>-1) {
+ out.write(buffer, 0, length);
+ }
+ in.close();
+ out.flush();
+ out.close();
+ } catch (IOException ioe) {
+ throw new SourceException("Could not copy source '"+
+ source.getSystemId()+"' to '"+
+ destination.getSystemId()+"' :"+
+ ioe.getMessage(), ioe);
+ }
+ }
+ }
/**
* Write a DOM Fragment to a source
* If the source is a [EMAIL PROTECTED] WriteableSource} the interface
is used.
* If not, the source is invoked with an additional parameter named
* "content" containing the XML.
+ *
+ * @param location
+ * @param typeParameters
+ * @param parameters
+ * @param frag
+ * @param resolver
+ * @param serializerName
+ * @param manager
+ *
+ * @throws ProcessingException
*/
- public static void writeDOM(String location,
- Parameters typeParameters,
- SourceParameters parameters,
- DocumentFragment frag,
- SourceResolver resolver,
- String serializerName,
- ComponentManager manager)
- throws ProcessingException {
-
+ public static void writeDOM(String location, Parameters typeParameters,
+ SourceParameters parameters,
+ DocumentFragment frag,
+ SourceResolver resolver,
+ String serializerName,
+ ComponentManager manager)
+ throws ProcessingException {
+
Source source = null;
+
try {
- source = SourceUtil.getSource(location,
- typeParameters,
- parameters,
- resolver);
+ source = SourceUtil.getSource(location, typeParameters,
+ parameters, resolver);
if (source instanceof WriteableSource) {
- WriteableSource ws = (WriteableSource)source;
+ WriteableSource ws = (WriteableSource) source;
frag.normalize();
if (ws instanceof WriteableSAXSource) {
- ContentHandler contentHandler =
((WriteableSAXSource)ws).getContentHandler();
+ ContentHandler contentHandler = ((WriteableSAXSource)
ws).getContentHandler();
DOMStreamer streamer = new DOMStreamer(contentHandler);
+
streamer.stream(frag);
} else {
// Lookup the Serializer
- // FIXME (CZ) : Due to the CM hierarchy we don't get the
- // correct serializer selector...
-// ComponentSelector selector = null;
-// Serializer serializer = null;
-// OutputStream oStream = null;
-// try {
-// selector =
(ComponentSelector)manager.lookup(Serializer.ROLE + "Selector");
-// serializer =
(Serializer)selector.select(serializerName);
-// oStream = ws.getOutputStream();
-// serializer.setOutputStream(oStream);
-// DOMStreamer streamer = new DOMStreamer(serializer);
-// streamer.stream(frag);
-// } finally {
-// if (oStream != null) {
-// oStream.flush();
-// try {
-// oStream.close();
-// } finally {
-// if ( selector != null ) {
-// selector.release( serializer );
-// manager.release( selector );
-// }
-// }
-// }
-// }
- final String content = XMLUtils.serializeNode(frag,
-
XMLUtils.defaultSerializeToXMLFormat(false));
+ // FIXME (CZ) : Due to the CM hierarchy we don't get the
+ // correct serializer selector...
+ // ComponentSelector selector = null;
+ // Serializer serializer = null;
+ // OutputStream oStream = null;
+ // try {
+ // selector =
(ComponentSelector)manager.lookup(Serializer.ROLE + "Selector");
+ // serializer =
(Serializer)selector.select(serializerName);
+ // oStream = ws.getOutputStream();
+ // serializer.setOutputStream(oStream);
+ // DOMStreamer streamer = new DOMStreamer(serializer);
+ // streamer.stream(frag);
+ // } finally {
+ // if (oStream != null) {
+ // oStream.flush();
+ // try {
+ // oStream.close();
+ // } finally {
+ // if ( selector != null ) {
+ // selector.release( serializer );
+ // manager.release( selector );
+ // }
+ // }
+ // }
+ // }
+ final String content = XMLUtils.serializeNode(frag,
+
XMLUtils.defaultSerializeToXMLFormat(false));
OutputStream oStream = ws.getOutputStream();
+
oStream.write(content.getBytes());
oStream.flush();
oStream.close();
@@ -346,50 +483,49 @@
// Lookup the Serializer
// FIXME (CZ) : Due to the CM hierarchy we don't get the
// correct serializer selector...
-// ComponentSelector selector = null;
-// Serializer serializer = null;
-// ByteArrayOutputStream oStream = new
ByteArrayOutputStream();
-// try {
-// selector =
(ComponentSelector)manager.lookup(Serializer.ROLE + "Selector");
-// serializer =
(Serializer)selector.select(serializerName);
-// serializer.setOutputStream(oStream);
-// DOMStreamer streamer = new DOMStreamer(serializer);
-// streamer.stream(frag);
-// } finally {
-// if (oStream != null) {
-// oStream.flush();
-// try {
-// oStream.close();
-// } finally {
-// if ( selector != null ) {
-// selector.release( serializer );
-// manager.release( selector );
-// }
-// }
-// }
-// }
-// final String content = oStream.toString();
- final String content = XMLUtils.serializeNode(frag,
-
XMLUtils.defaultSerializeToXMLFormat(false));
+ // ComponentSelector selector = null;
+ // Serializer serializer = null;
+ // ByteArrayOutputStream oStream = new
ByteArrayOutputStream();
+ // try {
+ // selector =
(ComponentSelector)manager.lookup(Serializer.ROLE + "Selector");
+ // serializer = (Serializer)selector.select(serializerName);
+ // serializer.setOutputStream(oStream);
+ // DOMStreamer streamer = new DOMStreamer(serializer);
+ // streamer.stream(frag);
+ // } finally {
+ // if (oStream != null) {
+ // oStream.flush();
+ // try {
+ // oStream.close();
+ // } finally {
+ // if ( selector != null ) {
+ // selector.release( serializer );
+ // manager.release( selector );
+ // }
+ // }
+ // }
+ // }
+ // final String content = oStream.toString();
+ final String content = XMLUtils.serializeNode(frag,
+
XMLUtils.defaultSerializeToXMLFormat(false));
+
resolver.release(source);
- if (parameters == null) {
+ if (parameters==null) {
parameters = new SourceParameters();
} else {
- parameters = (SourceParameters)parameters.clone();
+ parameters = (SourceParameters) parameters.clone();
}
parameters.setSingleParameterValue("content", content);
- source = SourceUtil.getSource(location,
- typeParameters,
- parameters,
- resolver);
+ source = SourceUtil.getSource(location, typeParameters,
+ parameters, resolver);
SourceUtil.toSAX(source, new DefaultHandler(), manager);
}
} catch (IOException ce) {
throw new ProcessingException(ce);
} catch (SAXException ce) {
throw new ProcessingException(ce);
-// } catch (ComponentException ce) {
-// throw new ProcessingException("Exception during lookup of
component.", ce);
+ // } catch (ComponentException ce) {
+ // throw new ProcessingException("Exception during lookup of
component.", ce);
} catch (SourceException se) {
throw SourceUtil.handle(se);
} finally {
@@ -399,26 +535,36 @@
/**
* Read a DOM Fragment from a source
+ *
+ * @param location
+ * @param typeParameters
+ * @param parameters
+ * @param resolver
+ * @param manager
+ *
+ * @return
+ *
+ * @throws ProcessingException
*/
- public static DocumentFragment readDOM(String location,
- Parameters typeParameters,
- SourceParameters parameters,
- SourceResolver resolver,
- ComponentManager manager)
- throws ProcessingException {
-
+ public static DocumentFragment readDOM(String location,
+ Parameters typeParameters,
+ SourceParameters parameters,
+ SourceResolver resolver,
+ ComponentManager manager)
+ throws ProcessingException {
+
Source source = null;
+
try {
- source = SourceUtil.getSource(location,
- typeParameters,
- parameters,
- resolver);
+ source = SourceUtil.getSource(location, typeParameters,
+ parameters, resolver);
Document doc = SourceUtil.toDOM(source, manager);
DocumentFragment fragment = doc.createDocumentFragment();
+
fragment.appendChild(doc.getDocumentElement());
-
+
return fragment;
-
+
} catch (IOException ce) {
throw new ProcessingException(ce);
} catch (SAXException ce) {
1.5 +1 -16
xml-cocoon2/src/java/org/apache/cocoon/components/source/WriteableSource.java
Index: WriteableSource.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/source/WriteableSource.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- WriteableSource.java 19 Aug 2002 07:57:21 -0000 1.4
+++ WriteableSource.java 29 Jan 2003 10:55:16 -0000 1.5
@@ -112,21 +112,6 @@
void cancel(OutputStream stream) throws SourceException;
/**
- * Move the source to source.getSystemId(), including all properties
- * deletes this source.
- *
- * @param source Destination of the source.
- */
- void move(WriteableSource source) throws SourceException;
-
- /**
- * Copy the source to source.getSystemId(), including all properties.
- *
- * @param source Destination of the source.
- */
- void copy(WriteableSource source) throws SourceException;
-
- /**
* Delete the source.
*/
void delete() throws SourceException;
1.9 +2 -37
xml-cocoon2/src/java/org/apache/cocoon/components/source/impl/FileSource.java
Index: FileSource.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/source/impl/FileSource.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- FileSource.java 5 Dec 2002 10:17:29 -0000 1.8
+++ FileSource.java 29 Jan 2003 10:55:17 -0000 1.9
@@ -252,45 +252,10 @@
}
/**
- * Move the source to source.getSystemId(), including all properties
- * deletes this source.
- *
- * @param source Destination of the source.
- */
- public void move(WriteableSource source) throws SourceException {
- this.copy(source);
- this.delete();
- }
-
- /**
- * Copy the source to source.getSystemId(), including all properties.
- *
- * @param source Destination of the source.
- */
- public void copy(WriteableSource source) throws SourceException {
- try {
- OutputStream out = source.getOutputStream();
- InputStream in = getInputStream();
-
- byte[] buffer = new byte[8192];
- int length = -1;
-
- while ((length = in.read(buffer)) > -1) {
- out.write(buffer, 0, length);
- }
- in.close();
- out.flush();
- out.close();
- } catch (IOException ioe) {
- throw new SourceException("Could not copy source :
"+ioe.getMessage(), ioe);
- }
- }
-
- /**
* Delete the source.
*/
public void delete() throws SourceException {
if (!this.file.delete())
- throw new SourceException("Could not delete source.");
+ throw new SourceException("Could not delete source
'"+this.file.getPath()+"'");
}
}
1.28 +811 -454
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/source/impl/SlideSource.java
Index: SlideSource.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/source/impl/SlideSource.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- SlideSource.java 9 Jan 2003 18:43:29 -0000 1.27
+++ SlideSource.java 29 Jan 2003 10:55:17 -0000 1.28
@@ -1,57 +1,53 @@
/*
- * The Apache Software License, Version 1.1
- *
- *
- * Copyright (c) 2001 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, 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 (INCLUDING, 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. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- */
+
+ ============================================================================
+ 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.components.source.impl;
@@ -80,7 +76,9 @@
import org.apache.cocoon.components.source.InspectableSource;
import org.apache.cocoon.components.source.LockableSource;
import org.apache.cocoon.components.source.ModifiableTraversableSource;
+import org.apache.cocoon.components.source.MoveableSource;
import org.apache.cocoon.components.source.RestrictableSource;
+import org.apache.cocoon.components.source.SourceUtil;
import org.apache.cocoon.components.source.VersionableSource;
import org.apache.cocoon.components.source.WriteableSource;
import org.apache.cocoon.components.source.helpers.GroupSourcePermission;
@@ -125,13 +123,15 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Stephan Michels</a>
* @version $Id$
*/
-public class SlideSource extends AbstractLogEnabled implements
- Composable, Contextualizable, Source, WriteableSource,
ModifiableTraversableSource,
- RestrictableSource, LockableSource, InspectableSource,
VersionableSource {
+public class SlideSource extends AbstractLogEnabled
+ implements Composable, Contextualizable, Source, WriteableSource,
+ ModifiableTraversableSource, MoveableSource, RestrictableSource,
+ LockableSource, InspectableSource, VersionableSource
+{
/** Component manager */
private ComponentManager manager;
-
+
/** Component context */
private Context context;
@@ -164,8 +164,8 @@
/** Slide token. */
private SlideToken slideToken;
- /** Pseudo protocol */
- private String protocol = "slide";
+ /** Pseudo scheme */
+ private String scheme = "slide";
/** The URI of the source*/
private String uri;
@@ -176,9 +176,10 @@
private NodeRevisionDescriptors revisionDescriptors = null;
private NodeRevisionDescriptor revisionDescriptor = null;
- //private String branch;
+ // private String branch;
- private SourceCredential sourcecredential = new
SourceCredential("guest", "guest");
+ private SourceCredential sourcecredential = new SourceCredential("guest",
+ "guest");
private String sourcerevision = null;
private String sourcerevisionbranch = null;
private SourceValidity validity = null;
@@ -187,23 +188,37 @@
private boolean initialized = false;
- public SlideSource(NamespaceAccessToken nat, String protocol, String
uri, SourceCredential sourcecredential,
- String sourcerevision, String sourcerevisionbranch)
- throws SourceException {
+ /**
+ * Create a slide source.
+ *
+ * @param nat Namespace access token
+ * @param scheme Scheme of the source
+ * @param uri URI of the source.
+ * @param sourcecredential Credential, which should be used.
+ * @param sourcerevision Revision, which should be used.
+ * @param sourcerevisionbranch Branch, which should be used.
+ *
+ * @throws SourceException If Exception occurs during the initialization.
+ */
+ public SlideSource(NamespaceAccessToken nat, String scheme, String uri,
+ SourceCredential sourcecredential,
+ String sourcerevision,
+ String sourcerevisionbranch) throws SourceException {
this.sourcecredential = sourcecredential;
this.credToken = new
CredentialsToken(this.sourcecredential.getPrincipal());
this.nat = nat;
this.config = this.nat.getNamespaceConfig();
- this.protocol = protocol;
+ this.scheme = scheme;
this.uri = uri;
- if ((this.uri==null) || (this.uri.length()==0))
+ if ((this.uri==null) || (this.uri.length()==0)) {
this.uri = "/";
- else if (!this.uri.startsWith("/"))
+ } else if ( !this.uri.startsWith("/")) {
this.uri = "/"+this.uri;
-
- this.systemid = protocol+":/"+uri; // FIXME dirty hack
+ }
+
+ this.systemid = scheme+":/"+uri; // FIXME dirty hack
this.sourcerevision = sourcerevision;
this.sourcerevisionbranch = sourcerevisionbranch;
@@ -222,15 +237,15 @@
*
* @param manager The ComponentManager which this Composable uses
*
- * @throws ComponentException
+ * @throws ComponentException If a exception occurs.
*/
public void compose(ComponentManager manager) throws ComponentException {
this.manager = manager;
try {
- initialize();// FIXME SourceResolver doesn't handle Initializable
+ initialize(); // FIXME SourceResolver doesn't handle
Initializable
} catch (Exception e) {
- throw new
ComponentException("org.apache.excalibur.source.Source",
+ throw new
ComponentException("org.apache.excalibur.source.Source",
"Could not initialize component",
e);
}
}
@@ -240,10 +255,9 @@
* This method is called after the LogEnabled.enableLogging() (if
present)
* method and before any other method.
*
- * @param context the context
- * @throws ContextException if context is invalid
+ * @param context The context.
*/
- public void contextualize(Context context) {
+ public void contextualize(Context context) {
this.context = context;
}
@@ -255,12 +269,15 @@
* @throws Exception if an error occurs
*/
public void initialize() throws Exception {
-
+
try {
- this.revisionDescriptors = content.retrieve(this.slideToken,
this.config.getFilesPath()+this.uri);
+ this.revisionDescriptors = content.retrieve(this.slideToken,
+
this.config.getFilesPath()+
+ this.uri);
// Retrieve latest revision descriptor
- this.revisionDescriptor = content.retrieve(slideToken,
revisionDescriptors);
+ this.revisionDescriptor = content.retrieve(slideToken,
+ revisionDescriptors);
this.sourcerevision =
this.revisionDescriptor.getRevisionNumber().toString();
this.sourcerevisionbranch =
this.revisionDescriptor.getBranchName();
@@ -282,14 +299,20 @@
* This is the data at the point of invocation of this method,
* so if this is Modifiable, you might get different content
* from two different invocations.
+ *
+ * @return Input stream for the source.
+ *
+ * @throws IOException If an IO excepetion occurs.
+ * @throws SourceException If an exception occurs.
*/
- public InputStream getInputStream()
- throws IOException, SourceException {
+ public InputStream getInputStream() throws IOException, SourceException {
try {
- ObjectNode object = structure.retrieve(this.slideToken,
this.config.getFilesPath()+this.uri);
+ ObjectNode object = structure.retrieve(this.slideToken,
+
this.config.getFilesPath()+
+ this.uri);
return content.retrieve(slideToken, this.revisionDescriptors,
- this.revisionDescriptor).streamContent();
+ this.revisionDescriptor).streamContent();
} catch (SlideException se) {
throw new SourceException("Could not get source", se);
}
@@ -297,6 +320,8 @@
/**
* Return the unique identifer for this source
+ *
+ * @return System identifier for the source.
*/
public String getSystemId() {
return this.systemid;
@@ -307,13 +332,14 @@
* date or the expires information or...
* If it is currently not possible to calculate such an information
* <code>null</code> is returned.
+ *
+ * @return Validity for the source.
*/
public SourceValidity getValidity() {
-
+
try {
if ((this.validity==null) && (this.revisionDescriptor!=null)) {
- this.validity = new TimeStampValidity(
-
this.revisionDescriptor.getLastModifiedAsDate().getTime());
+ this.validity = new
TimeStampValidity(this.revisionDescriptor.getLastModifiedAsDate().getTime());
}
} catch (Exception e) {
getLogger().debug("Could not create SourceValidity", e);
@@ -336,10 +362,13 @@
* The mime-type of the content described by this object.
* If the source is not able to determine the mime-type by itself
* this can be null.
+ *
+ * @return Mime type of the source.
*/
public String getMimeType() {
- if (this.revisionDescriptor!=null)
+ if (this.revisionDescriptor!=null) {
return this.revisionDescriptor.getContentType();
+ }
return null;
}
@@ -350,7 +379,8 @@
*/
public boolean exists() {
try {
- structure.retrieve(this.slideToken,
this.config.getFilesPath()+this.uri);
+ structure.retrieve(this.slideToken,
+ this.config.getFilesPath()+this.uri);
} catch (SlideException e) {
return false;
}
@@ -363,8 +393,12 @@
* is not restricted to a serialized XML document.
*
* @return a stream to write to
+ *
+ * @throws IOException
+ * @throws SourceException
*/
- public OutputStream getOutputStream() throws IOException,
SourceException {
+ public OutputStream getOutputStream()
+ throws IOException, SourceException {
if (outputstream==null) {
outputstream = new SlideSourceOutputStream();
outputstream.enableLogging(getLogger());
@@ -376,6 +410,7 @@
* Can the data sent to an <code>OutputStream</code> returned by
* [EMAIL PROTECTED] #getOutputStream()} be cancelled ?
*
+ * @param stream The ouput stream, which should be cancelled.
* @return true if the stream can be cancelled
*/
public boolean canCancel(OutputStream stream) {
@@ -387,13 +422,18 @@
* [EMAIL PROTECTED] #getOutputStream()}.
* <p>
* After cancel, the stream should no more be used.
+ *
+ * @param stream The ouput stream, which should be cancelled.
+ *
+ * @throws SourceException If the ouput stream can't be cancelled.
*/
public void cancel(OutputStream stream) throws SourceException {
if (outputstream==stream) {
try {
outputstream.cancel();
} catch (Exception e) {
- throw new SourceException("Could not cancel output stream",
e);
+ throw new SourceException("Could not cancel output stream",
+ e);
}
}
}
@@ -401,7 +441,9 @@
/**
* A helper can the getOutputStream() method
*/
- public class SlideSourceOutputStream extends ByteArrayOutputStream
implements LogEnabled {
+ public class SlideSourceOutputStream extends ByteArrayOutputStream
+ implements LogEnabled
+ {
private boolean isClosed = false;
private Logger logger = null;
@@ -414,13 +456,18 @@
this.logger = logger;
}
+ /**
+ *
+ *
+ * @throws IOException
+ */
public void close() throws IOException {
super.close();
byte[] bytes = new byte[0]; // must be initialized
+
try {
- NodeRevisionContent revisionContent =
- new NodeRevisionContent();
+ NodeRevisionContent revisionContent = new
NodeRevisionContent();
bytes = toByteArray();
revisionContent.setContent(bytes);
@@ -430,8 +477,10 @@
String resourceName = config.getFilesPath()+uri;
int lastSlash = resourceName.lastIndexOf('/');
- if (lastSlash != -1)
- resourceName = resourceName.substring(lastSlash + 1);
+
+ if (lastSlash!=-1) {
+ resourceName = resourceName.substring(lastSlash+1);
+ }
revisionDescriptor.setName(resourceName);
}
@@ -442,15 +491,18 @@
nat.begin();
- if (revisionNumber==null)
- content.create(slideToken, config.getFilesPath()+uri,
revisionDescriptor, null);
- content.store(slideToken, config.getFilesPath()+uri,
revisionDescriptor,
- revisionContent);
+ if (revisionNumber==null) {
+ content.create(slideToken, config.getFilesPath()+uri,
+ revisionDescriptor, null);
+ }
+ content.store(slideToken, config.getFilesPath()+uri,
+ revisionDescriptor, revisionContent);
- try {
+ try {
nat.commit();
} catch (Exception cme) {
- this.logger.warn("Could not commit the transaction.",
cme);
+ this.logger.warn("Could not commit the transaction.",
+ cme);
}
} catch (ObjectNotFoundException e) {
@@ -459,17 +511,17 @@
SubjectNode subject = new SubjectNode();
try {
- // Creating an object
- structure.create(slideToken, subject,
config.getFilesPath()+uri);
+ // Creating an object
+ structure.create(slideToken, subject,
+ config.getFilesPath()+uri);
} catch (SlideException se) {
throw new CascadingIOException(se);
}
- NodeRevisionDescriptor revisionDescriptor =
- new NodeRevisionDescriptor(bytes.length);
+ NodeRevisionDescriptor revisionDescriptor = new
NodeRevisionDescriptor(bytes.length);
// Resource type
- revisionDescriptor.setResourceType("");
+ revisionDescriptor.setResourceType("");
// Source
revisionDescriptor.setSource("");
@@ -482,13 +534,13 @@
// Get content type
String contentType = null;
+
try {
- contentType = ((org.apache.cocoon.environment.Context)
-
context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT)).getMimeType(uri);
+ contentType = ((org.apache.cocoon.environment.Context)
context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT)).getMimeType(uri);
} catch (ContextException ce) {
this.logger.warn("Could not get context to determine the
mime type.");
}
- if (contentType == null) {
+ if (contentType==null) {
contentType = "application/octet-stream";
}
revisionDescriptor.setContentType(contentType);
@@ -497,29 +549,30 @@
revisionDescriptor.setLastModified(new Date());
// Owner
- revisionDescriptor.setOwner(
- slideToken.getCredentialsToken().getPublicCredentials());
+
revisionDescriptor.setOwner(slideToken.getCredentialsToken().getPublicCredentials());
// Creating revisionDescriptor associated with the object
- NodeRevisionContent revisionContent =
- new NodeRevisionContent();
+ NodeRevisionContent revisionContent = new
NodeRevisionContent();
+
revisionContent.setContent(bytes);
try {
- content.create(slideToken, config.getFilesPath()+uri,
revisionDescriptor,
- revisionContent);
+ content.create(slideToken, config.getFilesPath()+uri,
+ revisionDescriptor, revisionContent);
try {
nat.commit();
} catch (Exception cme) {
- this.logger.warn("Could not commit the
transaction.", cme);
+ this.logger.warn("Could not commit the transaction.",
+ cme);
}
} catch (SlideException se) {
try {
nat.rollback();
} catch (Exception rbe) {
- this.logger.warn("Could not rollback the
transaction.", rbe);
+ this.logger.warn("Could not rollback the
transaction.",
+ rbe);
}
this.logger.error("Could not create source", se);
@@ -530,21 +583,36 @@
this.logger.error("Could not create source", e);
throw new CascadingIOException(e.getMessage(), e);
} finally {
-
+
try {
nat.rollback();
} catch (Exception rbe) {
- this.logger.warn("Could not rollback the transaction.",
rbe);
+ this.logger.warn("Could not rollback the transaction.",
+ rbe);
}
this.isClosed = true;
}
}
+ /**
+ * Can the data sent to an <code>OutputStream</code> returned by
+ * [EMAIL PROTECTED] #getOutputStream()} be cancelled ?
+ *
+ * @return true if the stream can be cancelled
+ */
public boolean canCancel() {
return !this.isClosed;
}
+ /**
+ * Cancel the data sent to an <code>OutputStream</code> returned by
+ * [EMAIL PROTECTED] #getOutputStream()}.
+ * <p>
+ * After cancel, the stream should no more be used.
+ *
+ * @throws SourceException If the ouput stream can't be cancelled.
+ */
public void cancel() throws Exception {
if (this.isClosed) {
throw new IllegalStateException("Cannot cancel : outputstrem
is already closed");
@@ -556,79 +624,60 @@
}
/**
- * Move the source to source.getSystemId(), including all properties
- * deletes this source.
+ * Move the current source to a specified destination.
+ *
+ * @param destination Destination of the source.
*
- * @param source Destination of the source.
+ * @throws SourceException If an exception occurs during
+ * the move.
*/
- public void move(WriteableSource source) throws SourceException {
+ public void move(Source source) throws SourceException {
if (source instanceof SlideSource) {
try {
- this.macro.move(slideToken,
this.config.getFilesPath()+this.uri,
-
this.config.getFilesPath()+((SlideSource)source).uri);
- } catch (SlideException se) {
+ this.macro.move(slideToken,
+ this.config.getFilesPath()+this.uri,
+ this.config.getFilesPath()+
+ ((SlideSource) source).uri);
+ } catch (SlideException se) {
throw new SourceException("Could not move source.", se);
}
} else {
- try {
- OutputStream out = source.getOutputStream();
- InputStream in = getInputStream();
-
- byte[] buffer = new byte[8192];
- int length = -1;
-
- while ((length = in.read(buffer)) > -1) {
- out.write(buffer, 0, length);
- }
- in.close();
- out.flush();
- out.close();
- } catch (IOException ioe) {
- throw new SourceException("Could not copy source :
"+ioe.getMessage());
- }
- this.delete();
+ SourceUtil.move(this, source);
}
}
/**
- * Copy the source to source.getSystemId(), including all properties.
+ * Copy the current source to a specified destination.
*
- * @param source Destination of the source.
+ * @param destination Destination of the source.
+ *
+ * @throws SourceException If an exception occurs during
+ * the copy.
*/
- public void copy(WriteableSource source) throws SourceException {
+ public void copy(Source source) throws SourceException {
if (source instanceof SlideSource) {
try {
- this.macro.copy(slideToken,
this.config.getFilesPath()+this.uri,
-
this.config.getFilesPath()+((SlideSource)source).uri);
+ this.macro.copy(slideToken,
+ this.config.getFilesPath()+this.uri,
+ this.config.getFilesPath()+
+ ((SlideSource) source).uri);
} catch (SlideException se) {
throw new SourceException("Could not move source.", se);
}
} else {
- try {
- OutputStream out = source.getOutputStream();
- InputStream in = getInputStream();
-
- byte[] buffer = new byte[8192];
- int length = -1;
-
- while ((length = in.read(buffer)) > -1) {
- out.write(buffer, 0, length);
- }
- in.close();
- out.flush();
- out.close();
- } catch (IOException ioe) {
- throw new SourceException("Could not copy source :
"+ioe.getMessage());
- }
+ SourceUtil.copy(this, source);
}
}
/**
* Delete the source.
+ *
+ * @throws SourceException If the source could not be deleted.
*/
public void delete() throws SourceException {
try {
- this.macro.delete(slideToken,
this.config.getFilesPath()+this.uri);
+ this.macro.delete(slideToken,
+ this.config.getFilesPath()+this.uri);
} catch (SlideException se) {
throw new SourceException("Could not delete source.", se);
}
@@ -636,12 +685,14 @@
/**
* Return the content length of the content or -1 if the length is
- * unknown
+ * unknown.
+ *
+ * @return Content length of the source.
*/
- public long getContentLength()
- {
- if (revisionDescriptor!=null)
+ public long getContentLength() {
+ if (revisionDescriptor!=null) {
return revisionDescriptor.getContentLength();
+ }
return -1;
}
@@ -649,11 +700,13 @@
/**
* Get the last modification date of the source or 0 if it
* is not possible to determine the date.
+ *
+ * @return Last modified date of the source.
*/
- public long getLastModified()
- {
- if (revisionDescriptor!=null)
+ public long getLastModified() {
+ if (revisionDescriptor!=null) {
return revisionDescriptor.getLastModifiedAsDate().getTime();
+ }
return 0;
}
@@ -661,6 +714,10 @@
* Get the value of a parameter.
* Using this it is possible to get custom information provided by the
* source implementation, like an expires date, HTTP headers etc.
+ *
+ * @param name Name of the parameter.
+ *
+ * @return Value of the parameter.
*/
public String getParameter(String name) {
return null;
@@ -670,6 +727,10 @@
* Get the value of a parameter.
* Using this it is possible to get custom information provided by the
* source implementation, like an expires date, HTTP headers etc.
+ *
+ * @param name Name of the parameter.
+ *
+ * @return Value of the parameter a long.
*/
public long getParameterAsLong(String name) {
return 0;
@@ -679,33 +740,47 @@
* Get parameter names
* Using this it is possible to get custom information provided by the
* source implementation, like an expires date, HTTP headers etc.
+ *
+ * @return
*/
public Iterator getParameterNames() {
return new EmptyIterator();
}
- class EmptyIterator implements Iterator {
- public boolean hasNext() { return false; }
- public Object next() { return null; }
- public void remove() {}
+ class EmptyIterator implements Iterator
+ {
+
+ public boolean hasNext() {
+ return false;
+ }
+
+ public Object next() {
+ return null;
+ }
+
+ public void remove() {
+ }
}
/**
* Tests whether a resource is a collection resource.
*
* @return true if the descriptor represents a collection, false
otherwise
+ *
+ * @throws SourceException If an exception occurs.
*/
public boolean isSourceCollection() throws SourceException {
boolean result = false;
- if (revisionDescriptor == null)
+ if (revisionDescriptor==null) {
return true;
+ }
NodeProperty property =
revisionDescriptor.getProperty("resourcetype");
- if ((property != null)
- && (property.getValue().equals("<collection/>"))) {
+ if ((property!=null) &&
+ (property.getValue().equals("<collection/>"))) {
result = true;
}
@@ -714,37 +789,51 @@
/**
* Returns the count of child sources.
+ *
+ * @return Count of child sources.
+ *
+ * @throws SourceException If an exception occurs.
*/
public int getChildSourceCount() throws SourceException {
try {
- int i=0;
- for(Enumeration children=structure.retrieve(this.slideToken,
- this.config.getFilesPath()+this.uri).enumerateChildren();
children.hasMoreElements();)
- if
(((String)children.nextElement()).startsWith(this.config.getFilesPath()))
+ int i = 0;
+
+ for (Enumeration children = structure.retrieve(this.slideToken,
+ this.config.getFilesPath()+this.uri).enumerateChildren();
+ children.hasMoreElements(); )
+ if (((String)
children.nextElement()).startsWith(this.config.getFilesPath())) {
i++;
+ }
return i;
} catch (SlideException se) {
throw new SourceException("Could not get children", se);
}
}
-
+
/**
* Return the system id of a child source.
*
* @param index Index of the child
+ *
+ * @return System identifier of the child source.
+ *
+ * @throws SourceException If an exception occurs.
*/
public String getChildSource(int index) throws SourceException {
try {
- int i=0;
+ int i = 0;
String child;
- for(Enumeration children=structure.retrieve(this.slideToken,
- this.config.getFilesPath()+this.uri).enumerateChildren();
children.hasMoreElements();) {
-
- child = (String)children.nextElement();
+
+ for (Enumeration children = structure.retrieve(this.slideToken,
+ this.config.getFilesPath()+this.uri).enumerateChildren();
+ children.hasMoreElements(); ) {
+ child = (String) children.nextElement();
if (child.startsWith(this.config.getFilesPath())) {
- if (i==index)
- return
protocol+":/"+child.substring(this.config.getFilesPath().length());
+ if (i==index) {
+ return scheme+":/"+
+
child.substring(this.config.getFilesPath().length());
+ }
i++;
}
@@ -757,26 +846,34 @@
/**
* Return the system if of the parent source. The method should return
- * null if the source hasn't a parent.
+ * null if the source hasn't a parent.
+ *
+ * @return System identifier of the parent source.
*/
public String getParentSource() {
- if ((this.uri==null) || (this.uri.length()<=1))
+ if ((this.uri==null) || (this.uri.length()<=1)) {
return null;
+ }
- if (this.uri.endsWith("/"))
- return protocol+":/"+this.uri.substring(0,
- this.uri.substring(0,this.uri.length()-1).lastIndexOf("/"));
+ if (this.uri.endsWith("/")) {
+ return scheme+":/"+
+ this.uri.substring(0, this.uri.substring(0,
+ this.uri.length()-1).lastIndexOf("/"));
+ }
- return protocol+":/"+this.uri.substring(0,
this.uri.lastIndexOf("/"));
+ return scheme+":/"+this.uri.substring(0, this.uri.lastIndexOf("/"));
}
/**
* Create a collection of sources.
*
- * @param collectionname Name of the collectiom, which
+ * @param collectionname Name of the collectiom, which
* should be created.
+ *
+ * @throws SourceException if an exception occurs.
*/
- public void createCollection(String collectionname) throws
SourceException {
+ public void createCollection(String collectionname)
+ throws SourceException {
SubjectNode collection = new SubjectNode();
NodeRevisionDescriptor revisionDescriptor = new
NodeRevisionDescriptor(0);
@@ -797,33 +894,46 @@
revisionDescriptor.setSource("");
// Owner
- revisionDescriptor.setOwner(
- slideToken.getCredentialsToken().getPublicCredentials());
+
revisionDescriptor.setOwner(slideToken.getCredentialsToken().getPublicCredentials());
try {
- structure.create(slideToken, collection,
this.config.getFilesPath()+this.uri+"/"+collectionname);
- content.create(slideToken,
this.config.getFilesPath()+this.uri+"/"+collectionname,
- revisionDescriptor, null);
+ structure.create(slideToken, collection,
+ this.config.getFilesPath()+this.uri+"/"+
+ collectionname);
+ content.create(slideToken,
+ this.config.getFilesPath()+this.uri+"/"+
+ collectionname, revisionDescriptor, null);
} catch (SlideException se) {
throw new SourceException("Could not create collection.", se);
}
- }
+ }
- /**
+ /**
* Get the current credential for the source
+ *
+ * @return Return the current used credential;
+ *
+ * @throws SourceException If an exception occurs.
*/
public SourceCredential getSourceCredential() throws SourceException {
return this.sourcecredential;
}
- /**
+ /**
* Set the credential for the source
+ *
+ * @param sourcecredential The credential, which should be used.
+ *
+ * @throws SourceException If an exception occurs.
*/
- public void setSourceCredential(SourceCredential sourcecredential)
throws SourceException {
- if ((sourcecredential==null) ||
- (sourcecredential.getPrincipal()==null) ||
(sourcecredential.getPrincipal().length()<=0))
+ public void setSourceCredential(SourceCredential sourcecredential)
+ throws SourceException {
+ if ((sourcecredential==null) ||
+ (sourcecredential.getPrincipal()==null) ||
+ (sourcecredential.getPrincipal().length()<=0)) {
return;
+ }
this.sourcecredential = sourcecredential;
this.credToken = new
CredentialsToken(this.sourcecredential.getPrincipal());
@@ -837,115 +947,193 @@
*
* @throws SourceException If an exception occurs during this operation
**/
- public void addSourcePermission(SourcePermission sourcepermission)
throws SourceException {
+ public void addSourcePermission(SourcePermission sourcepermission)
+ throws SourceException {
NamespaceConfig config = this.nat.getNamespaceConfig();
String subject = null;
+
if (sourcepermission instanceof PrincipalSourcePermission) {
- subject =
config.getUsersPath()+"/"+((PrincipalSourcePermission)sourcepermission).getPrincipal();
+ subject = config.getUsersPath()+"/"+
+ ((PrincipalSourcePermission)
sourcepermission).getPrincipal();
// Test if principal exists
try {
- ObjectNode objectnode = structure.retrieve(this.slideToken,
subject);
- if (!(objectnode instanceof SubjectNode))
+ ObjectNode objectnode = structure.retrieve(this.slideToken,
+ subject);
+
+ if ( !(objectnode instanceof SubjectNode)) {
throw new SourceException("Principal '"+
-
((PrincipalSourcePermission)sourcepermission).getPrincipal()+"' doesn't
exists");
+ ((PrincipalSourcePermission)
sourcepermission).getPrincipal()+
+ "' doesn't exists");
+ }
} catch (SlideException se) {
throw new SourceException("Could not retrieve object for
principal '"+
-
((PrincipalSourcePermission)sourcepermission).getPrincipal()+"'", se);
+ ((PrincipalSourcePermission)
sourcepermission).getPrincipal()+
+ "'", se);
}
} else if (sourcepermission instanceof GroupSourcePermission) {
- subject =
config.getUsersPath()+"/"+((GroupSourcePermission)sourcepermission).getGroup();
+ subject = config.getUsersPath()+"/"+
+ ((GroupSourcePermission) sourcepermission).getGroup();
// Test if group exists
try {
- ObjectNode objectnode = structure.retrieve(this.slideToken,
subject);
- if (!(objectnode instanceof GroupNode))
+ ObjectNode objectnode = structure.retrieve(this.slideToken,
+ subject);
+
+ if ( !(objectnode instanceof GroupNode)) {
throw new SourceException("Group '"+
-
((GroupSourcePermission)sourcepermission).getGroup()+"' doesn't exists");
+ ((GroupSourcePermission)
sourcepermission).getGroup()+
+ "' doesn't exists");
+ }
} catch (SlideException se) {
throw new SourceException("Could not retrieve object for
group '"+
-
((GroupSourcePermission)sourcepermission).getGroup()+"'", se);
+ ((GroupSourcePermission)
sourcepermission).getGroup()+
+ "'", se);
}
subject = "+"+subject; // Additional '+' to expand the group
- } else
+ } else {
throw new SourceException("Does't support category of
permission");
+ }
boolean negative = sourcepermission.isNegative();
boolean inheritable = sourcepermission.isInheritable();
if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_ALL)) {
addPermission(subject, "/", negative, inheritable);
- } else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_READ)) {
- addPermission(subject, config.getReadObjectAction().getUri(),
negative, inheritable);
- addPermission(subject, config.getReadLocksAction().getUri(),
negative, inheritable);
- addPermission(subject,
config.getReadRevisionMetadataAction().getUri(), negative, inheritable);
- addPermission(subject,
config.getReadRevisionContentAction().getUri(), negative, inheritable);
+ } else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_READ)) {
+ addPermission(subject, config.getReadObjectAction().getUri(),
+ negative, inheritable);
+ addPermission(subject, config.getReadLocksAction().getUri(),
+ negative, inheritable);
+ addPermission(subject,
+ config.getReadRevisionMetadataAction().getUri(),
+ negative, inheritable);
+ addPermission(subject,
+ config.getReadRevisionContentAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_READ_SOURCE))
{
- addPermission(subject, config.getReadObjectAction().getUri(),
negative, inheritable);
+ addPermission(subject, config.getReadObjectAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_READ_LOCKS))
{
- addPermission(subject, config.getReadLocksAction().getUri(),
negative, inheritable);
+ addPermission(subject, config.getReadLocksAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_READ_PROPERTY))
{
- addPermission(subject,
config.getReadRevisionMetadataAction().getUri(), negative, inheritable);
+ addPermission(subject,
+ config.getReadRevisionMetadataAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_READ_CONTENT))
{
- addPermission(subject,
config.getReadRevisionContentAction().getUri(), negative, inheritable);
+ addPermission(subject,
+ config.getReadRevisionContentAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_WRITE)) {
- addPermission(subject, config.getCreateObjectAction().getUri(),
negative, inheritable);
- addPermission(subject, config.getRemoveObjectAction().getUri(),
negative, inheritable);
- addPermission(subject, config.getLockObjectAction().getUri(),
negative, inheritable);
- addPermission(subject,
config.getCreateRevisionMetadataAction().getUri(), negative, inheritable);
- addPermission(subject,
config.getModifyRevisionMetadataAction().getUri(), negative, inheritable);
- addPermission(subject,
config.getRemoveRevisionMetadataAction().getUri(), negative, inheritable);
- addPermission(subject,
config.getCreateRevisionContentAction().getUri(), negative, inheritable);
- addPermission(subject,
config.getModifyRevisionContentAction().getUri(), negative, inheritable);
- addPermission(subject,
config.getRemoveRevisionContentAction().getUri(), negative, inheritable);
+ addPermission(subject, config.getCreateObjectAction().getUri(),
+ negative, inheritable);
+ addPermission(subject, config.getRemoveObjectAction().getUri(),
+ negative, inheritable);
+ addPermission(subject, config.getLockObjectAction().getUri(),
+ negative, inheritable);
+ addPermission(subject,
+ config.getCreateRevisionMetadataAction().getUri(),
+ negative, inheritable);
+ addPermission(subject,
+ config.getModifyRevisionMetadataAction().getUri(),
+ negative, inheritable);
+ addPermission(subject,
+ config.getRemoveRevisionMetadataAction().getUri(),
+ negative, inheritable);
+ addPermission(subject,
+ config.getCreateRevisionContentAction().getUri(),
+ negative, inheritable);
+ addPermission(subject,
+ config.getModifyRevisionContentAction().getUri(),
+ negative, inheritable);
+ addPermission(subject,
+ config.getRemoveRevisionContentAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_CREATE_SOURCE))
{
- addPermission(subject, config.getCreateObjectAction().getUri(),
negative, inheritable);
+ addPermission(subject, config.getCreateObjectAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_REMOVE_SOURCE))
{
- addPermission(subject, config.getRemoveObjectAction().getUri(),
negative, inheritable);
+ addPermission(subject, config.getRemoveObjectAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_LOCK_SOURCE))
{
- addPermission(subject, config.getLockObjectAction().getUri(),
negative, inheritable);
+ addPermission(subject, config.getLockObjectAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_CREATE_PROPERTY))
{
- addPermission(subject,
config.getCreateRevisionMetadataAction().getUri(), negative, inheritable);
+ addPermission(subject,
+ config.getCreateRevisionMetadataAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_MODIFY_PROPERTY))
{
- addPermission(subject,
config.getModifyRevisionMetadataAction().getUri(), negative, inheritable);
+ addPermission(subject,
+ config.getModifyRevisionMetadataAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_REMOVE_PROPERTY))
{
- addPermission(subject,
config.getRemoveRevisionMetadataAction().getUri(), negative, inheritable);
+ addPermission(subject,
+ config.getRemoveRevisionMetadataAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_CREATE_CONTENT))
{
- addPermission(subject,
config.getCreateRevisionContentAction().getUri(), negative, inheritable);
+ addPermission(subject,
+ config.getCreateRevisionContentAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_MODIFY_CONTENT))
{
- addPermission(subject,
config.getModifyRevisionContentAction().getUri(), negative, inheritable);
+ addPermission(subject,
+ config.getModifyRevisionContentAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_REMOVE_CONTENT))
{
- addPermission(subject,
config.getRemoveRevisionContentAction().getUri(), negative, inheritable);
+ addPermission(subject,
+ config.getRemoveRevisionContentAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_READ_ACL)) {
- addPermission(subject,
config.getReadPermissionsAction().getUri(), negative, inheritable);
+ addPermission(subject,
+ config.getReadPermissionsAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_WRITE_ACL)) {
- addPermission(subject,
config.getGrantPermissionAction().getUri(), negative, inheritable);
- addPermission(subject,
config.getRevokePermissionAction().getUri(), negative, inheritable);
+ addPermission(subject,
+ config.getGrantPermissionAction().getUri(),
+ negative, inheritable);
+ addPermission(subject,
+ config.getRevokePermissionAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_GRANT_PERMISSION))
{
- addPermission(subject,
config.getGrantPermissionAction().getUri(), negative, inheritable);
+ addPermission(subject,
+ config.getGrantPermissionAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_REVOKE_PERMISSION))
{
- addPermission (subject,
config.getRevokePermissionAction().getUri(), negative, inheritable);
+ addPermission(subject,
+ config.getRevokePermissionAction().getUri(),
+ negative, inheritable);
}
}
/**
* Add permission to the list of permissions.
+ *
+ * @param subject Subject of the permission.
+ * @param action Action for the subject.
+ * @param negative If the permission, should be allowed or denied.
+ * @param inheritable If the permission is inheritable.
+ *
+ * @throws SourceException If an exception occurs.
*/
private void addPermission(String subject, String action,
- boolean negative, boolean inheritable) throws
SourceException {
+ boolean negative,
+ boolean inheritable) throws SourceException {
try {
- NodePermission permission = new NodePermission
- (this.config.getFilesPath()+this.uri, subject, action,
inheritable, negative);
+ NodePermission permission = new
NodePermission(this.config.getFilesPath()+
+ this.uri, subject, action,
+ inheritable, negative);
+
this.security.grantPermission(this.slideToken, permission);
// Last modification date
revisionDescriptor.setLastModified(new Date());
- content.store(slideToken, this.config.getFilesPath()+this.uri,
revisionDescriptor, null);
+ content.store(slideToken, this.config.getFilesPath()+this.uri,
+ revisionDescriptor, null);
} catch (SlideException se) {
throw new SourceException("Couldn't grant permission", se);
@@ -959,42 +1147,57 @@
*
* @throws SourceException If an exception occurs during this operation
**/
- public void removeSourcePermission(SourcePermission sourcepermission)
throws SourceException {
+ public void removeSourcePermission(SourcePermission sourcepermission)
+ throws SourceException {
NamespaceConfig config = this.nat.getNamespaceConfig();
String subject = null;
+
if (sourcepermission instanceof PrincipalSourcePermission) {
- subject =
config.getUsersPath()+"/"+((PrincipalSourcePermission)sourcepermission).getPrincipal();
+ subject = config.getUsersPath()+"/"+
+ ((PrincipalSourcePermission)
sourcepermission).getPrincipal();
// Test if principal exists
try {
- ObjectNode objectnode = structure.retrieve(this.slideToken,
subject);
- if (!(objectnode instanceof SubjectNode))
+ ObjectNode objectnode = structure.retrieve(this.slideToken,
+ subject);
+
+ if ( !(objectnode instanceof SubjectNode)) {
throw new SourceException("Principal '"+
-
((PrincipalSourcePermission)sourcepermission).getPrincipal()+"' doesn't
exists");
+ ((PrincipalSourcePermission)
sourcepermission).getPrincipal()+
+ "' doesn't exists");
+ }
} catch (SlideException se) {
throw new SourceException("Could not retrieve object for
principal '"+
-
((PrincipalSourcePermission)sourcepermission).getPrincipal()+"'", se);
+ ((PrincipalSourcePermission)
sourcepermission).getPrincipal()+
+ "'", se);
}
} else if (sourcepermission instanceof GroupSourcePermission) {
- subject =
config.getUsersPath()+"/"+((GroupSourcePermission)sourcepermission).getGroup();
+ subject = config.getUsersPath()+"/"+
+ ((GroupSourcePermission) sourcepermission).getGroup();
// Test if group exists
try {
- ObjectNode objectnode = structure.retrieve(this.slideToken,
subject);
- if (!(objectnode instanceof GroupNode))
+ ObjectNode objectnode = structure.retrieve(this.slideToken,
+ subject);
+
+ if ( !(objectnode instanceof GroupNode)) {
throw new SourceException("Group '"+
-
((GroupSourcePermission)sourcepermission).getGroup()+"' doesn't exists");
+ ((GroupSourcePermission)
sourcepermission).getGroup()+
+ "' doesn't exists");
+ }
} catch (SlideException se) {
throw new SourceException("Could not retrieve object for
group '"+
-
((GroupSourcePermission)sourcepermission).getGroup()+"'", se);
+ ((GroupSourcePermission)
sourcepermission).getGroup()+
+ "'", se);
}
subject = "+"+subject; // Additional '+' to expand the group
- } else
+ } else {
throw new SourceException("Does't support category of
permission");
+ }
boolean negative = sourcepermission.isNegative();
boolean inheritable = sourcepermission.isInheritable();
@@ -1002,72 +1205,140 @@
if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_ALL)) {
removePermission(subject, "/", negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_READ)) {
- removePermission(subject, config.getReadObjectAction().getUri(),
negative, inheritable);
- removePermission(subject, config.getReadLocksAction().getUri(),
negative, inheritable);
- removePermission(subject,
config.getReadRevisionMetadataAction().getUri(), negative, inheritable);
- removePermission(subject,
config.getReadRevisionContentAction().getUri(), negative, inheritable);
+ removePermission(subject, config.getReadObjectAction().getUri(),
+ negative, inheritable);
+ removePermission(subject, config.getReadLocksAction().getUri(),
+ negative, inheritable);
+ removePermission(subject,
+ config.getReadRevisionMetadataAction().getUri(),
+ negative, inheritable);
+ removePermission(subject,
+ config.getReadRevisionContentAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_READ_SOURCE))
{
- removePermission(subject, config.getReadObjectAction().getUri(),
negative, inheritable);
+ removePermission(subject, config.getReadObjectAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_READ_LOCKS))
{
- removePermission(subject, config.getReadLocksAction().getUri(),
negative, inheritable);
+ removePermission(subject, config.getReadLocksAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_READ_PROPERTY))
{
- removePermission(subject,
config.getReadRevisionMetadataAction().getUri(), negative, inheritable);
+ removePermission(subject,
+ config.getReadRevisionMetadataAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_READ_CONTENT))
{
- removePermission(subject,
config.getReadRevisionContentAction().getUri(), negative, inheritable);
+ removePermission(subject,
+ config.getReadRevisionContentAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_WRITE)) {
- removePermission(subject,
config.getCreateObjectAction().getUri(), negative, inheritable);
- removePermission(subject,
config.getRemoveObjectAction().getUri(), negative, inheritable);
- removePermission(subject, config.getLockObjectAction().getUri(),
negative, inheritable);
- removePermission(subject,
config.getCreateRevisionMetadataAction().getUri(), negative, inheritable);
- removePermission(subject,
config.getModifyRevisionMetadataAction().getUri(), negative, inheritable);
- removePermission(subject,
config.getRemoveRevisionMetadataAction().getUri(), negative, inheritable);
- removePermission(subject,
config.getCreateRevisionContentAction().getUri(), negative, inheritable);
- removePermission(subject,
config.getModifyRevisionContentAction().getUri(), negative, inheritable);
- removePermission(subject,
config.getRemoveRevisionContentAction().getUri(), negative, inheritable);
+ removePermission(subject,
+ config.getCreateObjectAction().getUri(),
+ negative, inheritable);
+ removePermission(subject,
+ config.getRemoveObjectAction().getUri(),
+ negative, inheritable);
+ removePermission(subject, config.getLockObjectAction().getUri(),
+ negative, inheritable);
+ removePermission(subject,
+
config.getCreateRevisionMetadataAction().getUri(),
+ negative, inheritable);
+ removePermission(subject,
+
config.getModifyRevisionMetadataAction().getUri(),
+ negative, inheritable);
+ removePermission(subject,
+
config.getRemoveRevisionMetadataAction().getUri(),
+ negative, inheritable);
+ removePermission(subject,
+
config.getCreateRevisionContentAction().getUri(),
+ negative, inheritable);
+ removePermission(subject,
+
config.getModifyRevisionContentAction().getUri(),
+ negative, inheritable);
+ removePermission(subject,
+
config.getRemoveRevisionContentAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_CREATE_SOURCE))
{
- removePermission(subject,
config.getCreateObjectAction().getUri(), negative, inheritable);
+ removePermission(subject,
+ config.getCreateObjectAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_REMOVE_SOURCE))
{
- removePermission(subject,
config.getRemoveObjectAction().getUri(), negative, inheritable);
+ removePermission(subject,
+ config.getRemoveObjectAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_LOCK_SOURCE))
{
- removePermission(subject, config.getLockObjectAction().getUri(),
negative, inheritable);
+ removePermission(subject, config.getLockObjectAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_CREATE_PROPERTY))
{
- removePermission(subject,
config.getCreateRevisionMetadataAction().getUri(), negative, inheritable);
+ removePermission(subject,
+
config.getCreateRevisionMetadataAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_MODIFY_PROPERTY))
{
- removePermission(subject,
config.getModifyRevisionMetadataAction().getUri(), negative, inheritable);
+ removePermission(subject,
+
config.getModifyRevisionMetadataAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_REMOVE_PROPERTY))
{
- removePermission(subject,
config.getRemoveRevisionMetadataAction().getUri(), negative, inheritable);
+ removePermission(subject,
+
config.getRemoveRevisionMetadataAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_CREATE_CONTENT))
{
- removePermission(subject,
config.getCreateRevisionContentAction().getUri(), negative, inheritable);
+ removePermission(subject,
+
config.getCreateRevisionContentAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_MODIFY_CONTENT))
{
- removePermission(subject,
config.getModifyRevisionContentAction().getUri(), negative, inheritable);
+ removePermission(subject,
+
config.getModifyRevisionContentAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_REMOVE_CONTENT))
{
- removePermission(subject,
config.getRemoveRevisionContentAction().getUri(), negative, inheritable);
+ removePermission(subject,
+
config.getRemoveRevisionContentAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_READ_ACL)) {
- removePermission(subject,
config.getReadPermissionsAction().getUri(), negative, inheritable);
+ removePermission(subject,
+ config.getReadPermissionsAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_WRITE_ACL)) {
- removePermission(subject,
config.getGrantPermissionAction().getUri(), negative, inheritable);
- removePermission(subject,
config.getRevokePermissionAction().getUri(), negative, inheritable);
+ removePermission(subject,
+ config.getGrantPermissionAction().getUri(),
+ negative, inheritable);
+ removePermission(subject,
+ config.getRevokePermissionAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_GRANT_PERMISSION))
{
- removePermission(subject,
config.getGrantPermissionAction().getUri(), negative, inheritable);
+ removePermission(subject,
+ config.getGrantPermissionAction().getUri(),
+ negative, inheritable);
} else if
(sourcepermission.getPrivilege().equals(SourcePermission.PRIVILEGE_REVOKE_PERMISSION))
{
- removePermission (subject,
config.getRevokePermissionAction().getUri(), negative, inheritable);
+ removePermission(subject,
+ config.getRevokePermissionAction().getUri(),
+ negative, inheritable);
}
}
/**
* Remove a permission from the list of permissions.
+ *
+ * @param subject Subject of the permission.
+ * @param action Action for the subject.
+ * @param negative If the permission, should be allowed or denied.
+ * @param inheritable If the permission is inheritable.
+ *
+ * @throws SourceException If an exception occurs.
*/
private void removePermission(String subject, String action,
- boolean negative, boolean inheritable)
throws SourceException {
+ boolean negative,
+ boolean inheritable)
+ throws SourceException {
try {
- NodePermission permission = new NodePermission
- (this.config.getFilesPath()+this.uri, subject, action,
inheritable, negative);
+ NodePermission permission = new
NodePermission(this.config.getFilesPath()+
+ this.uri, subject, action,
+ inheritable, negative);
+
this.security.revokePermission(this.slideToken, permission);
// Last modification date
revisionDescriptor.setLastModified(new Date());
- content.store(slideToken, this.config.getFilesPath()+this.uri,
revisionDescriptor, null);
+ content.store(slideToken, this.config.getFilesPath()+this.uri,
+ revisionDescriptor, null);
} catch (SlideException se) {
throw new SourceException("Couldn't grant permission", se);
@@ -1079,69 +1350,66 @@
* Based on the implementation of
org.apache.slide.webdav.util.PropertyHelper .
*
* @return Array of SourcePermission
+ *
+ * @throws SourceException If an exception occurs.
**/
public SourcePermission[] getSourcePermissions() throws SourceException {
try {
NamespaceConfig config = this.nat.getNamespaceConfig();
- ObjectNode current = structure.retrieve(this.slideToken,
this.config.getFilesPath()+this.uri);
+ ObjectNode current = structure.retrieve(this.slideToken,
+
this.config.getFilesPath()+
+ this.uri);
- security.checkCredentials(this.slideToken, current,
config.getReadPermissionsAction());
+ security.checkCredentials(this.slideToken, current,
+ config.getReadPermissionsAction());
String userspath = config.getUsersPath();
// read
String readObjectUri = config.getReadObjectAction().getUri();
- String readRevisionMetadataUri =
- config.getReadRevisionMetadataAction().getUri();
- String readRevisionContentUri =
- config.getReadRevisionContentAction().getUri();
+ String readRevisionMetadataUri =
config.getReadRevisionMetadataAction().getUri();
+ String readRevisionContentUri =
config.getReadRevisionContentAction().getUri();
// write
String createObjectUri = config.getCreateObjectAction().getUri();
String removeObjectUri = config.getRemoveObjectAction().getUri();
String lockObjectUri = config.getLockObjectAction().getUri();
String readLocksUri = config.getReadLocksAction().getUri();
- String createRevisionMetadataUri =
- config.getCreateRevisionMetadataAction().getUri();
- String modifyRevisionMetadataUri =
- config.getModifyRevisionMetadataAction().getUri();
- String removeRevisionMetadataUri =
- config.getRemoveRevisionMetadataAction().getUri();
- String createRevisionContentUri =
- config.getCreateRevisionContentAction().getUri();
- String modifyRevisionContentUri =
- config.getModifyRevisionContentAction().getUri();
- String removeRevisionContentUri =
- config.getRemoveRevisionContentAction().getUri();
+ String createRevisionMetadataUri =
config.getCreateRevisionMetadataAction().getUri();
+ String modifyRevisionMetadataUri =
config.getModifyRevisionMetadataAction().getUri();
+ String removeRevisionMetadataUri =
config.getRemoveRevisionMetadataAction().getUri();
+ String createRevisionContentUri =
config.getCreateRevisionContentAction().getUri();
+ String modifyRevisionContentUri =
config.getModifyRevisionContentAction().getUri();
+ String removeRevisionContentUri =
config.getRemoveRevisionContentAction().getUri();
// read-acl
String readPermissionsUri =
config.getReadPermissionsAction().getUri();
// write-acl
String grantPermissionUri =
config.getGrantPermissionAction().getUri();
- String revokePermissionUri =
- config.getRevokePermissionAction().getUri();
+ String revokePermissionUri =
config.getRevokePermissionAction().getUri();
boolean inheritedPermissions = false;
Vector permissions = new Vector();
ArrayList sourcepermissions = new ArrayList();
- while (current != null) {
-
+ while (current!=null) {
try {
// put all permissions in a list
permissions.clear();
- Enumeration aclList =
security.enumeratePermissions(this.slideToken, current);
+ Enumeration aclList =
security.enumeratePermissions(this.slideToken,
+ current);
+
while (aclList.hasMoreElements()) {
-
NodePermission permission = (NodePermission)
aclList.nextElement();
-
+
// if we are processing inheritedPermissions (from
parent and up)
// then the permission should be inheritable
- if (inheritedPermissions &&
!permission.isInheritable()) {
+ if (inheritedPermissions &&
+ !permission.isInheritable()) {
// continue with next permission
continue;
}
@@ -1150,118 +1418,120 @@
// start combining and writing the permissions
while (permissions.size()>0) {
-
NodePermission permission = (NodePermission)
permissions.get(0);
+
permissions.remove(0);
String principal = permission.getSubjectUri();
boolean negative = permission.isNegative();
- String action = permission.getActionUri();
+ String action = permission.getActionUri();
// read
- boolean isReadObject =
readObjectUri.startsWith(action);
- boolean isReadLocks =
readLocksUri.startsWith(action);
+ boolean isReadObject =
readObjectUri.startsWith(action);
+ boolean isReadLocks =
readLocksUri.startsWith(action);
boolean isReadRevisionMetadata =
readRevisionMetadataUri.startsWith(action);
- boolean isReadRevisionContent =
readRevisionContentUri.startsWith(action);
+ boolean isReadRevisionContent =
readRevisionContentUri.startsWith(action);
// write
- boolean isCreateObject =
createObjectUri.startsWith(action);
- boolean isRemoveObject =
removeObjectUri.startsWith(action);
- boolean isLockObject =
lockObjectUri.startsWith(action);
+ boolean isCreateObject =
createObjectUri.startsWith(action);
+ boolean isRemoveObject =
removeObjectUri.startsWith(action);
+ boolean isLockObject =
lockObjectUri.startsWith(action);
boolean isCreateRevisionMetadata =
createRevisionMetadataUri.startsWith(action);
boolean isModifyRevisionMetadata =
modifyRevisionMetadataUri.startsWith(action);
boolean isRemoveRevisionMetadata =
removeRevisionMetadataUri.startsWith(action);
- boolean isCreateRevisionContent =
createRevisionContentUri.startsWith(action);
- boolean isModifyRevisionContent =
modifyRevisionContentUri.startsWith(action);
- boolean isRemoveRevisionContent =
removeRevisionContentUri.startsWith(action);
+ boolean isCreateRevisionContent =
createRevisionContentUri.startsWith(action);
+ boolean isModifyRevisionContent =
modifyRevisionContentUri.startsWith(action);
+ boolean isRemoveRevisionContent =
removeRevisionContentUri.startsWith(action);
- //read-acl
+ // read-acl
boolean isReadPermissions =
readPermissionsUri.startsWith(action);
// write-acl
- boolean isGrantPermission =
grantPermissionUri.startsWith(action);
+ boolean isGrantPermission =
grantPermissionUri.startsWith(action);
boolean isRevokePermission =
revokePermissionUri.startsWith(action);
// check the other permissions to combine them
// (if they are for the same principal/negative)
- for (int i=0; i<permissions.size() ; i++) {
+ for (int i = 0; i<permissions.size(); i++) {
NodePermission otherPermission =
(NodePermission) permissions.get(i);
+
if
(principal.equals(otherPermission.getSubjectUri()) &&
(negative==otherPermission.isNegative())) {
-
permissions.remove(i);
i--; // because we removed the current one
- action = otherPermission.getActionUri();
+ action = otherPermission.getActionUri();
// read
- isReadObject |=
readObjectUri.startsWith(action);
- isReadLocks |=
readLocksUri.startsWith(action);
+ isReadObject |=
readObjectUri.startsWith(action);
+ isReadLocks |=
readLocksUri.startsWith(action);
isReadRevisionMetadata |=
readRevisionMetadataUri.startsWith(action);
- isReadRevisionContent |=
readRevisionContentUri.startsWith(action);
+ isReadRevisionContent |=
readRevisionContentUri.startsWith(action);
// write
- isCreateObject |=
createObjectUri.startsWith(action);
- isRemoveObject |=
removeObjectUri.startsWith(action);
- isLockObject |=
lockObjectUri.startsWith(action);
+ isCreateObject |=
createObjectUri.startsWith(action);
+ isRemoveObject |=
removeObjectUri.startsWith(action);
+ isLockObject |=
lockObjectUri.startsWith(action);
isCreateRevisionMetadata |=
createRevisionMetadataUri.startsWith(action);
isModifyRevisionMetadata |=
modifyRevisionMetadataUri.startsWith(action);
isRemoveRevisionMetadata |=
removeRevisionMetadataUri.startsWith(action);
- isCreateRevisionContent |=
createRevisionContentUri.startsWith(action);
- isModifyRevisionContent |=
modifyRevisionContentUri.startsWith(action);
- isRemoveRevisionContent |=
removeRevisionContentUri.startsWith(action);
+ isCreateRevisionContent |=
createRevisionContentUri.startsWith(action);
+ isModifyRevisionContent |=
modifyRevisionContentUri.startsWith(action);
+ isRemoveRevisionContent |=
removeRevisionContentUri.startsWith(action);
- //read-acl
+ // read-acl
isReadPermissions |=
readPermissionsUri.startsWith(action);
// write-acl
- isGrantPermission |=
grantPermissionUri.startsWith(action);
+ isGrantPermission |=
grantPermissionUri.startsWith(action);
isRevokePermission |=
revokePermissionUri.startsWith(action);
}
}
// WebDAV privileges
boolean isRead = isReadObject && isReadLocks &&
- isReadRevisionMetadata && isReadRevisionContent;
+ isReadRevisionMetadata &&
+ isReadRevisionContent;
- boolean isWrite = isCreateObject && isRemoveObject
&& isLockObject &&
- isCreateRevisionMetadata &&
isModifyRevisionMetadata &&
- isRemoveRevisionMetadata &&
- isCreateRevisionContent &&
isModifyRevisionContent &&
- isRemoveRevisionContent;
+ boolean isWrite = isCreateObject && isRemoveObject &&
+ isLockObject &&
+ isCreateRevisionMetadata &&
+ isModifyRevisionMetadata &&
+ isRemoveRevisionMetadata &&
+ isCreateRevisionContent &&
+ isModifyRevisionContent &&
+ isRemoveRevisionContent;
boolean isReadAcl = isReadPermissions;
-
- boolean isWriteAcl = isGrantPermission &&
isRevokePermission;
- boolean isAll = isRead && isWrite && isReadAcl &&
isWriteAcl;
+ boolean isWriteAcl = isGrantPermission &&
+ isRevokePermission;
+
+ boolean isAll = isRead && isWrite && isReadAcl &&
+ isWriteAcl;
SourcePermission sourcepermission = null;
- if (principal.equals("~"))
- sourcepermission =
- new
PrincipalSourcePermission(PrincipalSourcePermission.PRINCIPAL_SELF, null,
-
inheritedPermissions, negative);
- else if (principal.equals("nobody"))
- sourcepermission =
- new
PrincipalSourcePermission(PrincipalSourcePermission.PRINCIPAL_GUEST, null,
-
inheritedPermissions, negative);
- else if (principal.equals(userspath))
- sourcepermission =
- new
PrincipalSourcePermission(PrincipalSourcePermission.PRINCIPAL_ALL, null,
-
inheritedPermissions, negative);
- else if (principal.startsWith(userspath+"/"))
- sourcepermission =
- new
PrincipalSourcePermission(principal.substring(userspath.length()+1), null,
-
inheritedPermissions, negative);
- else if (principal.startsWith("+"+userspath+"/"))
- sourcepermission =
- new
GroupSourcePermission(principal.substring(userspath.length()+2), null,
-
inheritedPermissions, negative);
- else
- sourcepermission = new
PrincipalSourcePermission(principal, null,
-
inheritedPermissions, negative);
+ if (principal.equals("~")) {
+ sourcepermission = new
PrincipalSourcePermission(PrincipalSourcePermission.PRINCIPAL_SELF,
+ null, inheritedPermissions, negative);
+ } else if (principal.equals("nobody")) {
+ sourcepermission = new
PrincipalSourcePermission(PrincipalSourcePermission.PRINCIPAL_GUEST,
+ null, inheritedPermissions, negative);
+ } else if (principal.equals(userspath)) {
+ sourcepermission = new
PrincipalSourcePermission(PrincipalSourcePermission.PRINCIPAL_ALL,
+ null, inheritedPermissions, negative);
+ } else if (principal.startsWith(userspath+"/")) {
+ sourcepermission = new
PrincipalSourcePermission(principal.substring(userspath.length()+
+ 1), null, inheritedPermissions, negative);
+ } else if (principal.startsWith("+"+userspath+"/")) {
+ sourcepermission = new
GroupSourcePermission(principal.substring(userspath.length()+
+ 2), null, inheritedPermissions, negative);
+ } else {
+ sourcepermission = new
PrincipalSourcePermission(principal,
+ null, inheritedPermissions, negative);
+ }
if (isAll) {
sourcepermission.setPrivilege(SourcePermission.PRIVILEGE_ALL);
@@ -1269,36 +1539,49 @@
if (isRead) {
sourcepermission.setPrivilege(SourcePermission.PRIVILEGE_READ);
} else {
- if (isReadObject)
+ if (isReadObject) {
sourcepermission.setPrivilege(SourcePermission.PRIVILEGE_READ_SOURCE);
- if (isReadLocks)
+ }
+ if (isReadLocks) {
sourcepermission.setPrivilege(SourcePermission.PRIVILEGE_READ_LOCKS);
- if (isReadRevisionMetadata)
+ }
+ if (isReadRevisionMetadata) {
sourcepermission.setPrivilege(SourcePermission.PRIVILEGE_READ_PROPERTY);
- if (isReadRevisionContent)
+ }
+ if (isReadRevisionContent) {
sourcepermission.setPrivilege(SourcePermission.PRIVILEGE_READ_CONTENT);
+ }
}
if (isWrite) {
sourcepermission.setPrivilege(SourcePermission.PRIVILEGE_WRITE);
} else {
- if (isCreateObject)
+ if (isCreateObject) {
sourcepermission.setPrivilege(SourcePermission.PRIVILEGE_CREATE_SOURCE);
- if (isRemoveObject)
+ }
+ if (isRemoveObject) {
sourcepermission.setPrivilege(SourcePermission.PRIVILEGE_REMOVE_SOURCE);
- if (isLockObject)
+ }
+ if (isLockObject) {
sourcepermission.setPrivilege(SourcePermission.PRIVILEGE_LOCK_SOURCE);
- if (isCreateRevisionMetadata)
+ }
+ if (isCreateRevisionMetadata) {
sourcepermission.setPrivilege(SourcePermission.PRIVILEGE_CREATE_PROPERTY);
- if (isModifyRevisionMetadata)
+ }
+ if (isModifyRevisionMetadata) {
sourcepermission.setPrivilege(SourcePermission.PRIVILEGE_MODIFY_PROPERTY);
- if (isRemoveRevisionMetadata)
+ }
+ if (isRemoveRevisionMetadata) {
sourcepermission.setPrivilege(SourcePermission.PRIVILEGE_REMOVE_PROPERTY);
- if (isCreateRevisionContent)
+ }
+ if (isCreateRevisionContent) {
sourcepermission.setPrivilege(SourcePermission.PRIVILEGE_CREATE_CONTENT);
- if (isModifyRevisionContent)
+ }
+ if (isModifyRevisionContent) {
sourcepermission.setPrivilege(SourcePermission.PRIVILEGE_MODIFY_CONTENT);
- if (isRemoveRevisionContent)
+ }
+ if (isRemoveRevisionContent) {
sourcepermission.setPrivilege(SourcePermission.PRIVILEGE_REMOVE_CONTENT);
+ }
}
if (isReadAcl) {
sourcepermission.setPrivilege(SourcePermission.PRIVILEGE_READ_ACL);
@@ -1306,33 +1589,38 @@
if (isWriteAcl) {
sourcepermission.setPrivilege(SourcePermission.PRIVILEGE_WRITE_ACL);
} else {
- if (isGrantPermission)
+ if (isGrantPermission) {
sourcepermission.setPrivilege(SourcePermission.PRIVILEGE_GRANT_PERMISSION);
- if (isRevokePermission)
+ }
+ if (isRevokePermission) {
sourcepermission.setPrivilege(SourcePermission.PRIVILEGE_REVOKE_PERMISSION);
+ }
}
}
sourcepermissions.add(sourcepermission);
}
} catch (SlideException se) {
- throw new SourceException("Exception eccurs while
retrieveing source permission", se);
+ throw new SourceException("Exception eccurs while
retrieveing source permission",
+ se);
}
inheritedPermissions = true;
-
+
try {
current = structure.getParent(this.slideToken, current);
} catch (SlideException e) {
break;
}
- }
+ }
SourcePermission[] sourcepermissionArray = new
SourcePermission[sourcepermissions.size()];
- return (SourcePermission[])
sourcepermissions.toArray((Object[])sourcepermissionArray);
+
+ return (SourcePermission[]) sourcepermissions.toArray((Object[])
sourcepermissionArray);
} catch (SlideException se) {
- throw new SourceException("Exception eccurs while retrieveing
source permission", se);
+ throw new SourceException("Exception eccurs while retrieveing
source permission",
+ se);
}
}
@@ -1346,20 +1634,23 @@
public void addSourceLocks(SourceLock sourcelock) throws SourceException
{
throw new SourceException("Operation not yet supported");
}
-
+
/**
* Returns a enumeration of the existing locks
*
* @return Enumeration of SourceLock
+ *
+ * @throws SourceException If an exception occurs.
*/
public Enumeration getSourceLocks() throws SourceException {
try {
Vector sourcelocks = new Vector();
NodeLock lock;
- for(Enumeration locks =
this.lock.enumerateLocks(this.slideToken, this.config.getFilesPath()+this.uri,
false);
- locks.hasMoreElements();) {
+ for (Enumeration locks =
this.lock.enumerateLocks(this.slideToken,
+ this.config.getFilesPath()+this.uri, false);
+ locks.hasMoreElements(); ) {
lock = (NodeLock) locks.nextElement();
sourcelocks.addElement(new SourceLock(lock.getSubjectUri(),
@@ -1382,15 +1673,18 @@
*
* @throws SourceException If an exception occurs during this operation
*/
- public void setSourceProperty(SourceProperty sourceproperty) throws
SourceException {
+ public void setSourceProperty(SourceProperty sourceproperty)
+ throws SourceException {
try {
- revisionDescriptor.setProperty(sourceproperty.getName(),
sourceproperty.getNamespace(),
+ revisionDescriptor.setProperty(sourceproperty.getName(),
+ sourceproperty.getNamespace(),
sourceproperty.getValueAsString());
// Last modification date
revisionDescriptor.setLastModified(new Date());
- content.store(slideToken, this.config.getFilesPath()+this.uri,
revisionDescriptor, null);
+ content.store(slideToken, this.config.getFilesPath()+this.uri,
+ revisionDescriptor, null);
} catch (SlideException se) {
throw new SourceException("Could not set property", se);
}
@@ -1401,130 +1695,193 @@
*
* @param namespace Namespace of the property
* @param name Name of the property
+ *
+ * @return Property of the source.
+ *
+ * @throws SourceException If an exception occurs.
*/
- public SourceProperty getSourceProperty(String namespace, String name)
throws SourceException {
+ public SourceProperty getSourceProperty(String namespace,
+ String name)
+ throws SourceException {
- if (revisionDescriptor==null)
+ if (revisionDescriptor==null) {
return null;
+ }
return new SourceProperty(namespace, name,
- revisionDescriptor.getProperty(name,
namespace).getValue().toString());
+ revisionDescriptor.getProperty(name,
+ namespace).getValue().toString());
}
/**
* Returns a enumeration of the properties
*
* @return Enumeration of SourceProperty
+ *
+ * @throws SourceException If an exception occurs.
*/
public SourceProperty[] getSourceProperties() throws SourceException {
- if (revisionDescriptor==null)
+ if (revisionDescriptor==null) {
return new SourceProperty[0];
+ }
Vector sourceproperties = new Vector();
NodeProperty property;
- for(Enumeration e = revisionDescriptor.enumerateProperties();
e.hasMoreElements();) {
- property = (NodeProperty)e.nextElement();
- sourceproperties.addElement(new
SourceProperty(property.getNamespace(), property.getName(),
-
property.getValue().toString()));
+
+ for (Enumeration e = revisionDescriptor.enumerateProperties();
+ e.hasMoreElements(); ) {
+ property = (NodeProperty) e.nextElement();
+ sourceproperties.addElement(new
SourceProperty(property.getNamespace(),
+ property.getName(), property.getValue().toString()));
}
SourceProperty[] sourcepropertiesArray = new
SourceProperty[sourceproperties.size()];
- for(int i=0; i<sourceproperties.size(); i++)
- sourcepropertiesArray[i] =
(SourceProperty)sourceproperties.elementAt(i);
+
+ for (int i = 0; i<sourceproperties.size(); i++)
+ sourcepropertiesArray[i] = (SourceProperty)
sourceproperties.elementAt(i);
return sourcepropertiesArray;
}
-
- public void removeSourceProperty(String namespace, String name) throws
SourceException {
+
+ /**
+ * Remove a specified source property.
+ *
+ * @param namespace Namespace of the property.
+ * @param name Name of the property.
+ *
+ * @throws SourceException If an exception occurs.
+ */
+ public void removeSourceProperty(String namespace,
+ String name) throws SourceException {
try {
- if ((revisionDescriptor!=null) && (!namespace.equals("DAV:"))) {
- revisionDescriptor.removeProperty(name,namespace);
+ if ((revisionDescriptor!=null) && ( !namespace.equals("DAV:"))) {
+ revisionDescriptor.removeProperty(name, namespace);
// Last modification date
revisionDescriptor.setLastModified(new Date());
- content.store(slideToken,
this.config.getFilesPath()+this.uri, revisionDescriptor, null);
+ content.store(slideToken,
+ this.config.getFilesPath()+this.uri,
+ revisionDescriptor, null);
}
} catch (SlideException se) {
throw new SourceException("Could not remove property", se);
}
}
- /**
+ /**
* If this source versioned
+ *
+ * @return True if the current source is versioned.
+ *
+ * @throws SourceException If an exception occurs.
*/
public boolean isVersioned() throws SourceException {
try {
- this.revisionDescriptors = content.retrieve(this.slideToken,
this.config.getFilesPath()+this.uri);
+ this.revisionDescriptors = content.retrieve(this.slideToken,
+
this.config.getFilesPath()+
+ this.uri);
return this.revisionDescriptors.hasRevisions();
} catch (SlideException se) {
- throw new SourceException("Could not retrieve revision
descriptor", se);
+ throw new SourceException("Could not retrieve revision
descriptor",
+ se);
}
}
- /**
+ /**
* Get the current revision of the source
+ *
+ * @return The current revision of the source
+ *
+ * @throws SourceException If an exception occurs.
*/
public String getSourceRevision() throws SourceException {
return this.sourcerevision;
}
- /**
+ /**
* Sets the wanted revision of the source
+ *
+ * @param sourcerevision The revision, which should be used.
+ *
+ * @throws SourceException If an exception occurs.
*/
- public void setSourceRevision(String sourcerevision) throws
SourceException {
+ public void setSourceRevision(String sourcerevision)
+ throws SourceException {
this.sourcerevision = sourcerevision;
try {
- this.revisionDescriptors = content.retrieve(this.slideToken,
this.config.getFilesPath()+this.uri);
+ this.revisionDescriptors = content.retrieve(this.slideToken,
+
this.config.getFilesPath()+
+ this.uri);
// Retrieve revision descriptor by the revision
- this.revisionDescriptor = content.retrieve(slideToken,
revisionDescriptors,
- new
NodeRevisionNumber(this.sourcerevision));
+ this.revisionDescriptor = content.retrieve(slideToken,
+ revisionDescriptors,
+ new
NodeRevisionNumber(this.sourcerevision));
} catch (SlideException se) {
- throw new SourceException("Could not retrieve revision
descriptor", se);
+ throw new SourceException("Could not retrieve revision
descriptor",
+ se);
}
}
- /**
+ /**
* Get the current branch of the revision from the source
+ *
+ * @return The branch of the revision
+ *
+ * @throws SourceException If an exception occurs.
*/
public String getSourceRevisionBranch() throws SourceException {
return this.sourcerevisionbranch;
}
- /**
+ /**
* Sets the wanted branch of the revision from the source
+ *
+ * @param sourcerevisionbranch The branch, which should be used.
+ *
+ * @throws SourceException If an exception occurs.
*/
- public void setSourceRevisionBranch(String sourcerevisionbranch) throws
SourceException {
- this.sourcerevisionbranch = sourcerevisionbranch;
+ public void setSourceRevisionBranch(String sourcerevisionbranch)
+ throws SourceException {
+ this.sourcerevisionbranch = sourcerevisionbranch;
// FIXME Retrieve the the revsion descriptor with current branch
}
- /**
+ /**
* Get the latest revision
+ *
+ * @return Last revision of the source.
+ *
+ * @throws SourceException If an exception occurs.
*/
public String getLatestSourceRevision() throws SourceException {
try {
- this.revisionDescriptors = content.retrieve(this.slideToken,
this.config.getFilesPath()+this.uri);
+ this.revisionDescriptors = content.retrieve(this.slideToken,
+
this.config.getFilesPath()+
+ this.uri);
return this.revisionDescriptors.getLatestRevision().toString();
} catch (SlideException se) {
- throw new SourceException("Could not retrieve revision
descriptor", se);
+ throw new SourceException("Could not retrieve revision
descriptor",
+ se);
}
}
- /**
- * @see org.apache.excalibur.source.Source#getProtocol()
- */
- public String getProtocol() {
- return this.protocol;
- }
+ /**
+ * @see org.apache.excalibur.source.Source#getProtocol()
+ *
+ * @return Scheme of the source.
+ */
+ public String getProtocol() {
+ return this.scheme;
+ }
}
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]