Hello Stefan,
I'm grateful for your contribution so far
When I tried the code below I still get an unsatisfactory result.
Which is; when you run the method get Versions alone, that pools a list of the
previous revisions(including the current), what I get is a list containing only the
number of the current revision for that resource uri.
For instance I had revisions list of 1.0,1.1,...1.13 in my version_history table for a
particular resource
On pooling out the list of revisions that exist for this resource with the
content.retrieve(token, uri), I get a list containing only 1.13
I hope you understand the point I am trying make.
I figure there is a problem with the slide api, 2.0
I need your comment.
Or are there other ways of gooing about listing the history number for a resource?
I will be glad to hear from u today.
Thank you in advance.
Gbenga
Stefan Fromm <[EMAIL PROTECTED]> wrote:
Didn't work 2nd time. So here is the code as text:
import java.io.ByteArrayInputStream;
import java.util.Date;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.slide.authenticate.CredentialsToken;
import org.apache.slide.authenticate.SecurityToken;
import org.apache.slide.common.Domain;
import org.apache.slide.common.NamespaceAccessToken;
import org.apache.slide.common.SlideToken;
import org.apache.slide.common.SlideTokenImpl;
import org.apache.slide.content.Content;
import org.apache.slide.content.NodeProperty;
import org.apache.slide.content.NodeRevisionContent;
import org.apache.slide.content.NodeRevisionDescriptor;
import org.apache.slide.content.NodeRevisionDescriptors;
import org.apache.slide.content.NodeRevisionNumber;
import org.apache.slide.security.Security;
import org.apache.slide.structure.ObjectNotFoundException;
import org.apache.slide.structure.Structure;
import org.apache.slide.structure.SubjectNode;
public class SlideVersionsTest {
private NamespaceAccessToken namespace;
private SlideToken token;
private Structure structure;
private Content content;
private Security security;
private static final String AUTHORS_XML =
"" +
"" +
"Stefan" +
"Fromm" +
"" +
"";
public SlideVersionsTest(String slideuser) {
namespace = Domain.accessNamespace(new SecurityToken(""),
Domain.getDefaultNamespace());
token = new SlideTokenImpl(new CredentialsToken(slideuser));
token.setForceStoreEnlistment(true);
structure = namespace.getStructureHelper();
content = namespace.getContentHelper();
security = namespace.getSecurityHelper();
}
private String computeEtag(String uri, NodeRevisionDescriptor nrd)
throws Exception {
String result =
System.currentTimeMillis()
+ "_"
+ uri.hashCode()
+ "_"
+ nrd.getLastModified()
+ "_"
+ nrd.getContentLength();
result = new String(DigestUtils.md5Hex(result));
return result;
}
public void put(String uri, String data) throws Exception {
try {
namespace.begin();
try {
byte[] dataBytes = data.getBytes();
ByteArrayInputStream fis = new ByteArrayInputStream(dataBytes);
try
{
NodeRevisionNumber lastRevision = null;
try {
structure.retrieve(token, uri);
lastRevision = content.retrieve(token, uri).getLatestRevision();
System.out.println("Found resource with latest revision number " + (lastRevision ==
null?"none":lastRevision.toString()));
}
catch (ObjectNotFoundException e) {
SubjectNode subject = new SubjectNode();
// create object
structure.create(token, subject, uri);
}
if ( lastRevision != null )
lastRevision = new NodeRevisionNumber(lastRevision, false);
else
lastRevision = new NodeRevisionNumber();
// create node revision descriptor
NodeRevisionDescriptor revisionDescriptor = new NodeRevisionDescriptor(lastRevision,
NodeRevisionDescriptors.MAIN_BRANCH, new Vector(), new Hashtable());
revisionDescriptor.setResourceType("");
revisionDescriptor.setSource("");
revisionDescriptor.setContentLanguage("en");
revisionDescriptor.setLastModified(new Date());
revisionDescriptor.setETag(computeEtag(uri, revisionDescriptor));
revisionDescriptor.setCreationDate(new Date());
// Owner
String creator = ((SubjectNode)security.getPrincipal(token)).getPath().lastSegment();
revisionDescriptor.setCreationUser(creator);
revisionDescriptor.setOwner(creator);
String contentType = "text/plain";
revisionDescriptor.setContentType(contentType);
// properties
NodeProperty newProperty = new NodeProperty("authors", AUTHORS_XML, "stefan.fromm:");
revisionDescriptor.setProperty(newProperty);
// create content
NodeRevisionContent revisionContent = new NodeRevisionContent();
revisionContent.setContent(fis);
// important to create NodeRevisionDescriptors separately to be able to tell it to use
versioning
if ( lastRevision.toString().equals("1.0") )
content.create(token, uri, true);
content.create(token, uri, revisionDescriptor, revisionContent);
}
finally
{
fis.close();
}
namespace.commit();
}
catch (Exception e ) {
namespace.rollback();
throw e;
}
}
catch (OutOfMemoryError e)
{
throw new RuntimeException(e);
}
}
public NodeRevisionDescriptors getVersions(String uri) throws Exception {
namespace.begin();
try {
return content.retrieve(token, uri);
}
finally {
namespace.rollback();
}
}
public static void main(String[] args) throws Exception {
SlideVersionsTest test = new SlideVersionsTest("root");
test.put("/files/test.txt", "Content 1");
test.put("/files/test.txt", "Content 2");
test.put("/files/test.txt", "Content 3");
NodeRevisionDescriptors revisions = test.getVersions("/files/test.txt");
for ( Enumeration e = revisions.enumerateRevisionNumbers(); e.hasMoreElements(); ) {
NodeRevisionNumber number = (NodeRevisionNumber)e.nextElement();
System.out.println("number = " + number.toString());
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!