cziegeler 2002/06/12 03:14:53 Modified: lib jars.xml src/java/org/apache/cocoon/components/source/impl AvalonToCocoonSource.java CocoonToAvalonSource.java SitemapSource.java src/scratchpad/src/org/apache/cocoon/components/repository/impl SlideSource.java src/scratchpad/src/org/apache/cocoon/components/source SlideSource.java repository.xconf Added: lib/core avalon-excalibur-20020612.jar Removed: lib/core avalon-excalibur-20020603.jar Log: Switched to latest excalibur and fixed error in slide source configuration Revision Changes Path 1.12 +1 -1 xml-cocoon2/lib/jars.xml Index: jars.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/lib/jars.xml,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- jars.xml 5 Jun 2002 00:54:20 -0000 1.11 +++ jars.xml 12 Jun 2002 10:14:51 -0000 1.12 @@ -15,7 +15,7 @@ <description>Part of jakarta-avalon, it is a set of classes and patterns that support high level server development.</description> <used-by>Cocoon</used-by> - <lib>core/avalon-excalibur-20020603.jar</lib> + <lib>core/avalon-excalibur-20020612.jar</lib> <homepage>http://jakarta.apache.org/avalon/excalibur/</homepage> </file> <file> 1.2 +1215 -0 xml-cocoon2/lib/core/avalon-excalibur-20020612.jar <<Binary file>> 1.6 +3 -11 xml-cocoon2/src/java/org/apache/cocoon/components/source/impl/AvalonToCocoonSource.java Index: AvalonToCocoonSource.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/source/impl/AvalonToCocoonSource.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- AvalonToCocoonSource.java 4 Jun 2002 07:31:52 -0000 1.5 +++ AvalonToCocoonSource.java 12 Jun 2002 10:14:53 -0000 1.6 @@ -101,14 +101,7 @@ * is not possible to determine the date. */ public long getLastModified() { - final SourceValidity validity = this.source.getValidity(); - if (validity instanceof TimeStampValidity) { - return ((TimeStampValidity)validity).getTimeStamp(); - } - if (validity instanceof FileTimeStampValidity) { - return ((FileTimeStampValidity)validity).getTimeStamp(); - } - return 0; + return this.source.getLastModified(); } /** @@ -116,8 +109,7 @@ * is not possible to determine the length. */ public long getContentLength() { - // We have no possibility to get this! - return -1; + return this.source.getContentLength(); } /** 1.4 +52 -1 xml-cocoon2/src/java/org/apache/cocoon/components/source/impl/CocoonToAvalonSource.java Index: CocoonToAvalonSource.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/source/impl/CocoonToAvalonSource.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- CocoonToAvalonSource.java 4 Jun 2002 07:31:52 -0000 1.3 +++ CocoonToAvalonSource.java 12 Jun 2002 10:14:53 -0000 1.4 @@ -52,6 +52,7 @@ import java.io.IOException; import java.io.InputStream; +import java.util.Iterator; import org.apache.avalon.excalibur.pool.Recyclable; import org.apache.avalon.excalibur.xml.XMLizable; import org.apache.excalibur.source.*; @@ -157,4 +158,54 @@ public void recycle() { this.source.recycle(); } + + /** + * Return the content length of the content or -1 if the length is + * unknown + */ + public long getContentLength() + { + return this.source.getContentLength(); + } + + /** + * Get the last modification date of the source or 0 if it + * is not possible to determine the date. + */ + public long getLastModified() + { + return this.source.getLastModified(); + } + + /** + * 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. + */ + public String getParameter(String name) { + return null; + } + + /** + * 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. + */ + public long getParameterAsLong(String name) { + return 0; + } + + /** + * Get parameter names + * Using this it is possible to get custom information provided by the + * source implementation, like an expires date, HTTP headers etc. + */ + public Iterator getParameterNames() { + return java.util.Collections.EMPTY_LIST.iterator(); + } + + } + + + 1.13 +41 -1 xml-cocoon2/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java Index: SitemapSource.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- SitemapSource.java 4 Jun 2002 07:31:52 -0000 1.12 +++ SitemapSource.java 12 Jun 2002 10:14:53 -0000 1.13 @@ -88,6 +88,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.MalformedURLException; +import java.util.Iterator; import java.util.Map; /** @@ -213,6 +214,15 @@ } /** + * Get the last modification date. + * @return The last modification in milliseconds since January 1, 1970 GMT + * or 0 if it is unknown + */ + public long getLastModified() { + return 0; + } + + /** * Return an <code>InputStream</code> object to read from the source. */ public InputStream getInputStream() @@ -386,4 +396,34 @@ public void recycle() { reset(); } + + /** + * 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. + */ + public String getParameter(String name) { + return null; + } + + /** + * 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. + */ + public long getParameterAsLong(String name) { + return 0; + } + + /** + * Get parameter names + * Using this it is possible to get custom information provided by the + * source implementation, like an expires date, HTTP headers etc. + */ + public Iterator getParameterNames() { + return java.util.Collections.EMPTY_LIST.iterator(); + } + + } + 1.2 +247 -192 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/repository/impl/SlideSource.java Index: SlideSource.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/repository/impl/SlideSource.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SlideSource.java 11 Jun 2002 18:09:12 -0000 1.1 +++ SlideSource.java 12 Jun 2002 10:14:53 -0000 1.2 @@ -109,10 +109,11 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Date; +import java.util.Iterator; import java.util.Map; /** - * A sources from jakarta slide repositories. + * A sources from jakarta slide repositories. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephan Michels</a> * @version $Id$ @@ -131,45 +132,45 @@ /** Namespace access token. */ private NamespaceAccessToken nat; - + /** Structure helper. */ private Structure structure; - + /** Content helper. */ private Content content; - + /** Security helper. */ private Security security; - /** Lock helper. */ - private Lock lock; + /** Lock helper. */ + private Lock lock; - /** Macro helper. */ - private Macro macro; + /** Macro helper. */ + private Macro macro; private CredentialsToken credToken; - /** Slide token. */ - private SlideToken slideToken; + /** Slide token. */ + private SlideToken slideToken; - /** The URI of the source*/ - private String uri; + /** The URI of the source*/ + private String uri; - /** Revision number */ - private NodeRevisionNumber revisionNumber; + /** Revision number */ + private NodeRevisionNumber revisionNumber; private NodeRevisionDescriptors revisionDescriptors = null; private NodeRevisionDescriptor revisionDescriptor = null; //private String branch; - private SourceValidity validity; + private SourceValidity validity; - private SlideSourceOutputStream outputstream; + private SlideSourceOutputStream outputstream; private boolean initialized = false; - protected SlideSource(CredentialsToken credToken, NamespaceAccessToken nat, String uri) + protected SlideSource(CredentialsToken credToken, NamespaceAccessToken nat, String uri) throws SourceException { this.credToken = credToken; @@ -181,7 +182,7 @@ this.security = nat.getSecurityHelper(); this.lock = nat.getLockHelper(); this.macro = nat.getMacroHelper(); - + this.slideToken = new SlideTokenImpl(credToken); try { @@ -189,13 +190,13 @@ // Retrieve latest revision descriptor this.revisionDescriptor = content.retrieve(slideToken, revisionDescriptors); - + } catch (SlideException se) { throw new SourceException("Could determine the if the source is a collection", se); - } + } } - protected SlideSource(CredentialsToken credToken, NamespaceAccessToken nat, + protected SlideSource(CredentialsToken credToken, NamespaceAccessToken nat, String uri, String revision) throws SourceException { this.credToken = credToken; this.nat = nat; @@ -234,179 +235,233 @@ this.manager = manager; } - /** - * Return an <code>InputStream</code> object to read from the source. - * 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. - */ - public InputStream getInputStream() - throws IOException, SourceException { - try - { - ObjectNode object = structure.retrieve(this.slideToken, this.uri); + /** + * Return an <code>InputStream</code> object to read from the source. + * 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. + */ + public InputStream getInputStream() + throws IOException, SourceException { + try + { + ObjectNode object = structure.retrieve(this.slideToken, this.uri); - return content.retrieve(slideToken, revisionDescriptors, + return content.retrieve(slideToken, revisionDescriptors, revisionDescriptor).streamContent(); - } catch (SlideException se) { - throw new SourceException("Could not get source", se); - } + } catch (SlideException se) { + throw new SourceException("Could not get source", se); + } + } + + /** + * Return the unique identifer for this source + */ + public String getSystemId() { + return this.systemid; + } + + /** + * Get the Validity object. This can either wrap the last modification + * date or the expires information or... + * If it is currently not possible to calculate such an information + * <code>null</code> is returned. + */ + public SourceValidity getValidity() { + + try { + if (validity!=null) { + this.validity = new TimeStampValidity( + revisionDescriptor.getLastModifiedAsDate().getTime()); + } + } catch (Exception e) { + return null; + } + + return this.validity; + } + + /** + * Refresh the content of this object after the underlying data + * content has changed. + */ + public void discardValidity() { + this.validity = null; + } + + /** + * 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. + */ + public String getMimeType() { + + return revisionDescriptor.getContentType(); + } + + /** + * Does this source actually exist ? + * + * @return true if the resource exists. + */ + public boolean exists() { + + try { + structure.retrieve(this.slideToken, this.uri); + } catch (SlideException e) { + return false; + } + return true; + } + + /** + * Get an <code>InputStream</code> where raw bytes can be written to. + * The signification of these bytes is implementation-dependent and + * is not restricted to a serialized XML document. + * + * @return a stream to write to + */ + public OutputStream getOutputStream() throws IOException, SourceException { + + if (outputstream==null) + outputstream = new SlideSourceOutputStream(); + return outputstream; + } + + /** + * Can the data sent to an <code>OutputStream</code> returned by + * {@link #getOutputStream()} be cancelled ? + * + * @return true if the stream can be cancelled + */ + public boolean canCancel(OutputStream stream) { + + return outputstream.canCancel(); + } + + /** + * Cancel the data sent to an <code>OutputStream</code> returned by + * {@link #getOutputStream()}. + * <p> + * After cancel, the stream should no more be used. + */ + 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); + } + } + } + + /** + * A file outputStream that will rename the temp file to the destination file upon close() + * and discard the temp file upon cancel(). + */ + public class SlideSourceOutputStream extends ByteArrayOutputStream { + + private boolean isClosed = false; + + public void close() throws IOException { + super.close(); + + try { + NodeRevisionContent revisionContent = + new NodeRevisionContent(); + + byte[] bytes = toByteArray(); + revisionContent.setContent(bytes); + + revisionDescriptor.setContentLength(bytes.length); + + // Last modification date + revisionDescriptor.setLastModified(new Date()); + + //nat.begin(); + + if (revisionNumber==null) + content.create(slideToken, uri, revisionDescriptor, null); + content.store(slideToken, uri, revisionDescriptor, + revisionContent); + + //nat.commit(); + + } catch (Exception e) { + // FIXME: What should I do? + e.printStackTrace(); + } finally { + this.isClosed = true; + } + } + + public boolean canCancel() { + return !this.isClosed; + } + + public void cancel() throws Exception { + if (this.isClosed) { + throw new IllegalStateException("Cannot cancel : outputstrem is already closed"); + } + + this.isClosed = true; + super.close(); + } + } + /** + * Return the content length of the content or -1 if the length is + * unknown + */ + public long getContentLength() + { + return -1; + } + + /** + * Get the last modification date of the source or 0 if it + * is not possible to determine the date. + */ + public long getLastModified() + { + return 0; + } + + /** + * 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. + */ + public String getParameter(String name) { + return null; } - /** - * Return the unique identifer for this source - */ - public String getSystemId() { - return this.systemid; - } - - /** - * Get the Validity object. This can either wrap the last modification - * date or the expires information or... - * If it is currently not possible to calculate such an information - * <code>null</code> is returned. - */ - public SourceValidity getValidity() { - - try { - if (validity!=null) { - this.validity = new TimeStampValidity( - revisionDescriptor.getLastModifiedAsDate().getTime()); - } - } catch (Exception e) { - return null; - } - - return this.validity; - } - - /** - * Refresh the content of this object after the underlying data - * content has changed. - */ - public void discardValidity() { - this.validity = null; - } - - /** - * 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. - */ - public String getMimeType() { - - return revisionDescriptor.getContentType(); - } - - /** - * Does this source actually exist ? - * - * @return true if the resource exists. - */ - public boolean exists() { - - try { - structure.retrieve(this.slideToken, this.uri); - } catch (SlideException e) { - return false; - } - return true; - } - - /** - * Get an <code>InputStream</code> where raw bytes can be written to. - * The signification of these bytes is implementation-dependent and - * is not restricted to a serialized XML document. - * - * @return a stream to write to - */ - public OutputStream getOutputStream() throws IOException, SourceException { - - if (outputstream==null) - outputstream = new SlideSourceOutputStream(); - return outputstream; - } - - /** - * Can the data sent to an <code>OutputStream</code> returned by - * {@link #getOutputStream()} be cancelled ? - * - * @return true if the stream can be cancelled - */ - public boolean canCancel(OutputStream stream) { - - return outputstream.canCancel(); - } - - /** - * Cancel the data sent to an <code>OutputStream</code> returned by - * {@link #getOutputStream()}. - * <p> - * After cancel, the stream should no more be used. - */ - 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); - } - } - } - - /** - * A file outputStream that will rename the temp file to the destination file upon close() - * and discard the temp file upon cancel(). - */ - public class SlideSourceOutputStream extends ByteArrayOutputStream { - - private boolean isClosed = false; - - public void close() throws IOException { - super.close(); - - try { - NodeRevisionContent revisionContent = - new NodeRevisionContent(); - - byte[] bytes = toByteArray(); - revisionContent.setContent(bytes); - - revisionDescriptor.setContentLength(bytes.length); - - // Last modification date - revisionDescriptor.setLastModified(new Date()); - - //nat.begin(); - - if (revisionNumber==null) - content.create(slideToken, uri, revisionDescriptor, null); - content.store(slideToken, uri, revisionDescriptor, - revisionContent); - - //nat.commit(); - - } catch (Exception e) { - // FIXME: What should I do? - e.printStackTrace(); - } finally { - this.isClosed = true; - } - } - - public boolean canCancel() { - return !this.isClosed; - } - - public void cancel() throws Exception { - if (this.isClosed) { - throw new IllegalStateException("Cannot cancel : outputstrem is already closed"); - } - - this.isClosed = true; - super.close(); - } - } + /** + * 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. + */ + public long getParameterAsLong(String name) { + return 0; + } + + /** + * Get parameter names + * Using this it is possible to get custom information provided by the + * source implementation, like an expires date, HTTP headers etc. + */ + public Iterator getParameterNames() { + return emptyIterator; + } + + protected static EmptyIterator emptyIterator = new EmptyIterator(); + } + +class EmptyIterator implements Iterator { + public boolean hasNext() { return false; } + public Object next() { return null; } + public void remove() {} +} + 1.2 +382 -329 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/source/SlideSource.java Index: SlideSource.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/source/SlideSource.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SlideSource.java 22 May 2002 15:28:38 -0000 1.1 +++ SlideSource.java 12 Jun 2002 10:14:53 -0000 1.2 @@ -105,12 +105,13 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Date; +import java.util.Iterator; import java.util.Map; /** * A sources from jakarta slide domains. The sources wrappers - * to the stores of slide. It uses slide:// as pseudo-protocoll. It is also - * possible to get access to the store + * to the stores of slide. It uses slide:// as pseudo-protocoll. It is also + * possible to get access to the store * via webdav. * * Possible parameter are username and revision @@ -125,352 +126,404 @@ /** Namespace access token. */ private NamespaceAccessToken token; - + /** Structure helper. */ private Structure structure; - + /** Content helper. */ private Content content; - + /** Security helper. */ private Security security; - /** Lock helper. */ - private Lock lock; + /** Lock helper. */ + private Lock lock; - /** Macro helper. */ - private Macro macro; + /** Macro helper. */ + private Macro macro; - /** Slide token. */ - private SlideToken slideToken; + /** Slide token. */ + private SlideToken slideToken; - /** Request URI */ - private String requestUri; + /** Request URI */ + private String requestUri; - /** Revision number */ - private NodeRevisionNumber revisionNumber; + /** Revision number */ + private NodeRevisionNumber revisionNumber; - private SourceValidity validity; + private SourceValidity validity; - private SlideSourceOutputStream outputstream; + private SlideSourceOutputStream outputstream; - protected SlideSource(String location, Map parameters) { - this.systemid = location; + protected SlideSource(String location, Map parameters) { + this.systemid = location; - if (location.indexOf("://") >= 0) - location = location.substring(location.indexOf("://")+3); + if (location.indexOf("://") >= 0) + location = location.substring(location.indexOf("://")+3); - String namespace = location.substring(0, location.indexOf("/")); - //System.out.println("namespace = '"+namespace+"'"); - location = location.substring(location.indexOf("/")); - //System.out.println("location = '"+location+"'"); + String namespace = location.substring(0, location.indexOf("/")); + //System.out.println("namespace = '"+namespace+"'"); + location = location.substring(location.indexOf("/")); + //System.out.println("location = '"+location+"'"); - if ((parameters!=null) && (parameters.containsKey("revision"))) { - this.revisionNumber = new NodeRevisionNumber(parameters.get("revision").toString()); - //System.out.println("revision = '"+this.revisionNumber+"'"); - } else { + if ((parameters!=null) && (parameters.containsKey("revision"))) { + this.revisionNumber = new NodeRevisionNumber(parameters.get("revision").toString()); + //System.out.println("revision = '"+this.revisionNumber+"'"); + } else { this.revisionNumber = null; } - this.token = Domain.accessNamespace(new SecurityToken(new String()), - namespace); + this.token = Domain.accessNamespace(new SecurityToken(new String()), + namespace); + + this.structure = token.getStructureHelper(); + this.content = token.getContentHelper(); + this.security = token.getSecurityHelper(); + this.lock = token.getLockHelper(); + this.macro = token.getMacroHelper(); + + CredentialsToken credToken; + if ((parameters!=null) && (parameters.containsKey("username"))) + credToken = new CredentialsToken(parameters.get("username").toString()); + else + credToken = new CredentialsToken(new String("guest")); + + this.slideToken = new SlideTokenImpl(credToken); + + this.requestUri = location; + } + + /** + * Return an <code>InputStream</code> object to read from the source. + * 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. + */ + public InputStream getInputStream() + throws IOException, SourceException { + try { + ObjectNode object = structure.retrieve(this.slideToken, this.requestUri); + NodeRevisionDescriptors revisionDescriptors = + content.retrieve(slideToken, this.requestUri); + + if (revisionDescriptors.hasRevisions()) { + + NodeRevisionDescriptor revisionDescriptor; + if (this.revisionNumber!=null) + revisionDescriptor = + content.retrieve(this.slideToken, revisionDescriptors, this.revisionNumber); + else + // Retrieve latest revision descriptor + revisionDescriptor = + content.retrieve(this.slideToken, revisionDescriptors); + + if (revisionDescriptor != null) + return content.retrieve(slideToken, revisionDescriptors, + revisionDescriptor).streamContent(); + } + } catch (ServiceAccessException sae) { + throw new SourceException("Could not get source", sae); + } catch (AccessDeniedException ade) { + throw new SourceException("Could not get source", ade); + } catch (LinkedObjectNotFoundException lonfe) { + throw new SourceException("Could not get source", lonfe); + } catch (ObjectNotFoundException onfe) { + throw new SourceException("Could not get source", onfe); + } catch (RevisionDescriptorNotFoundException rdnfe) { + throw new SourceException("Could not get source", rdnfe); + } catch (RevisionContentNotFoundException rcnfe) { + throw new SourceException("Could not get source", rcnfe); + } catch (RevisionNotFoundException rnfe) { + throw new SourceException("Could not get source", rnfe); + } catch (ObjectLockedException ole) { + throw new SourceException("Could not get source", ole); + } + + return null; + } + + /** + * Return the unique identifer for this source + */ + public String getSystemId() { + return this.systemid; + } + + /** + * Get the Validity object. This can either wrap the last modification + * date or the expires information or... + * If it is currently not possible to calculate such an information + * <code>null</code> is returned. + */ + public SourceValidity getValidity() { + try { + if (validity!=null) { + ObjectNode object = structure.retrieve(this.slideToken, this.requestUri); + NodeRevisionDescriptors revisionDescriptors = + content.retrieve(slideToken, this.requestUri); + + if (revisionDescriptors.hasRevisions()) { + + NodeRevisionDescriptor revisionDescriptor; + if (this.revisionNumber!=null) + revisionDescriptor = + content.retrieve(this.slideToken, revisionDescriptors, this.revisionNumber); + else + // Retrieve latest revision descriptor + revisionDescriptor = + content.retrieve(this.slideToken, revisionDescriptors); + + if (revisionDescriptor != null) + this.validity = new TimeStampValidity( + revisionDescriptor.getLastModifiedAsDate().getTime()); + } + } + } catch (Exception e) { + return null; + } + + return this.validity; + } + + /** + * Refresh the content of this object after the underlying data + * content has changed. + */ + public void discardValidity() { + this.validity = null; + } + + /** + * 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. + */ + public String getMimeType() + { + try + { + ObjectNode object = structure.retrieve(this.slideToken, this.requestUri); + NodeRevisionDescriptors revisionDescriptors = + content.retrieve(slideToken, this.requestUri); + + if (revisionDescriptors.hasRevisions()) { + + NodeRevisionDescriptor revisionDescriptor; + if (this.revisionNumber!=null) + revisionDescriptor = + content.retrieve(this.slideToken, revisionDescriptors, this.revisionNumber); + else + // Retrieve latest revision descriptor + revisionDescriptor = + content.retrieve(this.slideToken, revisionDescriptors); + + if (revisionDescriptor != null) + revisionDescriptor.getContentType(); + } + } catch (Exception e) { + return null; + } + + return null; + } + + /** + * Does this source actually exist ? + * + * @return true if the resource exists. + */ + public boolean exists() + { + try { + structure.retrieve(this.slideToken, this.requestUri); + } catch (Exception e) { + return false; + } + return true; + } + + /** + * Get an <code>InputStream</code> where raw bytes can be written to. + * The signification of these bytes is implementation-dependent and + * is not restricted to a serialized XML document. + * + * @return a stream to write to + */ + public OutputStream getOutputStream() throws IOException, SourceException { + if (outputstream==null) + outputstream = new SlideSourceOutputStream(); + return outputstream; + } + + /** + * Can the data sent to an <code>OutputStream</code> returned by + * {@link #getOutputStream()} be cancelled ? + * + * @return true if the stream can be cancelled + */ + public boolean canCancel(OutputStream stream) { + return outputstream.canCancel(); + } + + /** + * Cancel the data sent to an <code>OutputStream</code> returned by + * {@link #getOutputStream()}. + * <p> + * After cancel, the stream should no more be used. + */ + 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); + } + } + } + + /** + * Tests whether a resource is a collection resource. + * + * @param revisionDescriptor revision descriptor of the resource + * + * @return true if the descriptor represents a collection, false otherwise + */ + public boolean isCollection(NodeRevisionDescriptor revisionDescriptor) { + + boolean result = false; + + if (revisionDescriptor == null) + return true; + + NodeProperty property = revisionDescriptor.getProperty("resourcetype"); + + if ((property != null) + && (property.getValue().equals("<collection/>"))) { + result = true; + } + + return result; + } + + /** + * A file outputStream that will rename the temp file to the destination file upon close() + * and discard the temp file upon cancel(). + */ + public class SlideSourceOutputStream extends ByteArrayOutputStream { + + private boolean isClosed = false; + + public void close() throws IOException { + super.close(); + + try { + NodeRevisionDescriptors revisionDescriptors = + content.retrieve(slideToken, requestUri); + + NodeRevisionDescriptor revisionDescriptor; + if (revisionNumber!=null) + revisionDescriptor = + content.retrieve(slideToken, revisionDescriptors, revisionNumber); + else + // Retrieve latest revision descriptor + revisionDescriptor = + content.retrieve(slideToken, revisionDescriptors); + + NodeRevisionContent revisionContent = + new NodeRevisionContent(); + + byte[] bytes = toByteArray(); + revisionContent.setContent(bytes); + + revisionDescriptor.setContentLength(bytes.length); + + // Last modification date + revisionDescriptor.setLastModified(new Date()); + + //token.begin(); + + if (revisionNumber==null) + content.create(slideToken, requestUri, revisionDescriptor, null); + content.store(slideToken, requestUri, revisionDescriptor, + revisionContent); + + //token.commit(); + + } catch (Exception e) { + // FIXME: What should I do? + e.printStackTrace(); + } finally { + this.isClosed = true; + } + } + + public boolean canCancel() { + return !this.isClosed; + } + + public void cancel() throws Exception { + if (this.isClosed) { + throw new IllegalStateException("Cannot cancel : outputstrem is already closed"); + } + + this.isClosed = true; + super.close(); + } + } + + /** + * Return the content length of the content or -1 if the length is + * unknown + */ + public long getContentLength() + { + return -1; + } + + /** + * Get the last modification date of the source or 0 if it + * is not possible to determine the date. + */ + public long getLastModified() + { + return 0; + } + + /** + * 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. + */ + public String getParameter(String name) { + return null; + } + + /** + * 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. + */ + public long getParameterAsLong(String name) { + return 0; + } + + /** + * Get parameter names + * Using this it is possible to get custom information provided by the + * source implementation, like an expires date, HTTP headers etc. + */ + public Iterator getParameterNames() { + return emptyIterator; + } + + protected static EmptyIterator emptyIterator = new EmptyIterator(); - this.structure = token.getStructureHelper(); - this.content = token.getContentHelper(); - this.security = token.getSecurityHelper(); - this.lock = token.getLockHelper(); - this.macro = token.getMacroHelper(); - - CredentialsToken credToken; - if ((parameters!=null) && (parameters.containsKey("username"))) - credToken = new CredentialsToken(parameters.get("username").toString()); - else - credToken = new CredentialsToken(new String("guest")); - - this.slideToken = new SlideTokenImpl(credToken); - - this.requestUri = location; - } - - /** - * Return an <code>InputStream</code> object to read from the source. - * 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. - */ - public InputStream getInputStream() - throws IOException, SourceException - { - try - { - ObjectNode object = structure.retrieve(this.slideToken, this.requestUri); - NodeRevisionDescriptors revisionDescriptors = - content.retrieve(slideToken, this.requestUri); - - if (revisionDescriptors.hasRevisions()) { - - NodeRevisionDescriptor revisionDescriptor; - if (this.revisionNumber!=null) - revisionDescriptor = - content.retrieve(this.slideToken, revisionDescriptors, this.revisionNumber); - else - // Retrieve latest revision descriptor - revisionDescriptor = - content.retrieve(this.slideToken, revisionDescriptors); - - if (revisionDescriptor != null) - return content.retrieve(slideToken, revisionDescriptors, - revisionDescriptor).streamContent(); - } - } catch (ServiceAccessException sae) { - throw new SourceException("Could not get source", sae); - } catch (AccessDeniedException ade) { - throw new SourceException("Could not get source", ade); - } catch (LinkedObjectNotFoundException lonfe) { - throw new SourceException("Could not get source", lonfe); - } catch (ObjectNotFoundException onfe) { - throw new SourceException("Could not get source", onfe); - } catch (RevisionDescriptorNotFoundException rdnfe) { - throw new SourceException("Could not get source", rdnfe); - } catch (RevisionContentNotFoundException rcnfe) { - throw new SourceException("Could not get source", rcnfe); - } catch (RevisionNotFoundException rnfe) { - throw new SourceException("Could not get source", rnfe); - } catch (ObjectLockedException ole) { - throw new SourceException("Could not get source", ole); - } - - return null; - } - - /** - * Return the unique identifer for this source - */ - public String getSystemId() { - return this.systemid; - } - - /** - * Get the Validity object. This can either wrap the last modification - * date or the expires information or... - * If it is currently not possible to calculate such an information - * <code>null</code> is returned. - */ - public SourceValidity getValidity() { - try { - if (validity!=null) { - ObjectNode object = structure.retrieve(this.slideToken, this.requestUri); - NodeRevisionDescriptors revisionDescriptors = - content.retrieve(slideToken, this.requestUri); - - if (revisionDescriptors.hasRevisions()) { - - NodeRevisionDescriptor revisionDescriptor; - if (this.revisionNumber!=null) - revisionDescriptor = - content.retrieve(this.slideToken, revisionDescriptors, this.revisionNumber); - else - // Retrieve latest revision descriptor - revisionDescriptor = - content.retrieve(this.slideToken, revisionDescriptors); - - if (revisionDescriptor != null) - this.validity = new TimeStampValidity( - revisionDescriptor.getLastModifiedAsDate().getTime()); - } - } - } catch (Exception e) { - return null; - } - - return this.validity; - } - - /** - * Refresh the content of this object after the underlying data - * content has changed. - */ - public void discardValidity() { - this.validity = null; - } - - /** - * 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. - */ - public String getMimeType() - { - try - { - ObjectNode object = structure.retrieve(this.slideToken, this.requestUri); - NodeRevisionDescriptors revisionDescriptors = - content.retrieve(slideToken, this.requestUri); - - if (revisionDescriptors.hasRevisions()) { - - NodeRevisionDescriptor revisionDescriptor; - if (this.revisionNumber!=null) - revisionDescriptor = - content.retrieve(this.slideToken, revisionDescriptors, this.revisionNumber); - else - // Retrieve latest revision descriptor - revisionDescriptor = - content.retrieve(this.slideToken, revisionDescriptors); - - if (revisionDescriptor != null) - revisionDescriptor.getContentType(); - } - } catch (Exception e) { - return null; - } - - return null; - } - - /** - * Does this source actually exist ? - * - * @return true if the resource exists. - */ - public boolean exists() - { - try { - structure.retrieve(this.slideToken, this.requestUri); - } catch (Exception e) { - return false; - } - return true; - } - - /** - * Get an <code>InputStream</code> where raw bytes can be written to. - * The signification of these bytes is implementation-dependent and - * is not restricted to a serialized XML document. - * - * @return a stream to write to - */ - public OutputStream getOutputStream() throws IOException, SourceException { - if (outputstream==null) - outputstream = new SlideSourceOutputStream(); - return outputstream; - } - - /** - * Can the data sent to an <code>OutputStream</code> returned by - * {@link #getOutputStream()} be cancelled ? - * - * @return true if the stream can be cancelled - */ - public boolean canCancel(OutputStream stream) { - return outputstream.canCancel(); - } - - /** - * Cancel the data sent to an <code>OutputStream</code> returned by - * {@link #getOutputStream()}. - * <p> - * After cancel, the stream should no more be used. - */ - 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); - } - } - } - - /** - * Tests whether a resource is a collection resource. - * - * @param revisionDescriptor revision descriptor of the resource - * - * @return true if the descriptor represents a collection, false otherwise - */ - public boolean isCollection - (NodeRevisionDescriptor revisionDescriptor) { - - boolean result = false; - - if (revisionDescriptor == null) - return true; - - NodeProperty property = revisionDescriptor.getProperty("resourcetype"); - - if ((property != null) - && (property.getValue().equals("<collection/>"))) { - result = true; - } - - return result; - } - - /** - * A file outputStream that will rename the temp file to the destination file upon close() - * and discard the temp file upon cancel(). - */ - public class SlideSourceOutputStream extends ByteArrayOutputStream { - - private boolean isClosed = false; - - public void close() throws IOException { - super.close(); - - try { - NodeRevisionDescriptors revisionDescriptors = - content.retrieve(slideToken, requestUri); - - NodeRevisionDescriptor revisionDescriptor; - if (revisionNumber!=null) - revisionDescriptor = - content.retrieve(slideToken, revisionDescriptors, revisionNumber); - else - // Retrieve latest revision descriptor - revisionDescriptor = - content.retrieve(slideToken, revisionDescriptors); - - NodeRevisionContent revisionContent = - new NodeRevisionContent(); - - byte[] bytes = toByteArray(); - revisionContent.setContent(bytes); - - revisionDescriptor.setContentLength(bytes.length); - - // Last modification date - revisionDescriptor.setLastModified(new Date()); - - //token.begin(); - - if (revisionNumber==null) - content.create(slideToken, requestUri, revisionDescriptor, null); - content.store(slideToken, requestUri, revisionDescriptor, - revisionContent); - - //token.commit(); - - } catch (Exception e) { - // FIXME: What should I do? - e.printStackTrace(); - } finally { - this.isClosed = true; - } - } - - public boolean canCancel() { - return !this.isClosed; - } - - public void cancel() throws Exception { - if (this.isClosed) { - throw new IllegalStateException("Cannot cancel : outputstrem is already closed"); - } - - this.isClosed = true; - super.close(); - } - } } + +class EmptyIterator implements Iterator { + public boolean hasNext() { return false; } + public Object next() { return null; } + public void remove() {} +} + 1.2 +1 -1 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/source/repository.xconf Index: repository.xconf =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/source/repository.xconf,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- repository.xconf 11 Jun 2002 18:09:12 -0000 1.1 +++ repository.xconf 12 Jun 2002 10:14:53 -0000 1.2 @@ -3,6 +3,6 @@ <xconf xpath="/cocoon/source-factories" unless="component-instance[@name='repository']"> <!-- repository pseudo protocol --> - <component-instance name="repository" class="org.apache.cocoon.components.eource.RepositorySourceFactory"/> + <component-instance name="repository" class="org.apache.cocoon.components.source.RepositorySourceFactory"/> </xconf>
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]