You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-user@jakarta.apache.org by Eelco Hillenius <ee...@topicus.nl> on 2003/03/01 00:32:47 UTC

newbe on usage of low-level (non webdav) client API

Hi all,

I am quite new to Slide and I am having a hard time finding out the best way
of using it. I have just started building a CMS application that uses Slide
for a content repository. The first question that arises is whether I should
use the WebDav API or the lower level API? I assume that, as my both code
and Slide will run in the same VM, it will be much better performance-wise
to use the lower level API. Is that right?

The second question is if, using the plain client API, the test class that
you can find below shows the correct usage of the API. I am just trying to
add, retrieve and remove a file (named test.xml). The test runs fine...(data
shows up in RDBMS) but I have got the feeling I am doing too much. And I do
not understand that if I want to get things working I have to do something
like: structureHelper.create(slideToken, rootuser, "/files/test.xml"); This
adds the SubjectNode rootuser. I would rather just add a file node or
something... But I probably just do not understand some of the concepts of
the Slide API. Maybe I have to implement my own types of ObjectNodes?

Could someone please help me on this? Cheers,

Eelco Hillenius


Here's the code:

import java.io.*;
import junit.framework.TestCase;
import org.apache.slide.structure.*;
import org.apache.slide.content.*;
import org.apache.slide.common.*;
import org.apache.slide.authenticate.*;

/**
* Testing storing of a file in the repository
*/
public class StoreTest extends TestCase {
    protected NamespaceAccessToken nsAccessToken;
    protected CredentialsToken credToken;
    protected SlideToken slideToken;
    protected Structure structureHelper;
    protected Content contentHelper;
    protected SubjectNode rootuser;

    public StoreTest(String name) {
        super(name);
    }

    protected void setUp() throws Exception {
        nsAccessToken = Domain.accessNamespace(new SecurityToken(new
String()), "mynamespace");
        credToken = new CredentialsToken(new String("root"));
        slideToken = new SlideTokenImpl(credToken);
        structureHelper = nsAccessToken.getStructureHelper();
        contentHelper = nsAccessToken.getContentHelper();
        rootuser = (SubjectNode)structureHelper.retrieve(slideToken,
"/users/root");
    }

    protected void tearDown() throws Exception {
        Domain.closeNamespace(nsAccessToken);
    }

    /**
     * test adding a file to the repository
     */
    public void testAddFile() {
        try {
            InputStream is = getClass().getResourceAsStream("test.xml");
            nsAccessToken.begin();
            structureHelper.create(slideToken, rootuser, "/files/test.xml");
            contentHelper.create(slideToken, "/files/test.xml", true);
            NodeRevisionDescriptors revisionDescriptors =
contentHelper.retrieve(slideToken, "/files/test.xml");
            NodeRevisionDescriptor revisionDescriptor = new
NodeRevisionDescriptor(-1);
            revisionDescriptor.setProperty("revision", "1");
            NodeRevisionContent nodeRevContent = new NodeRevisionContent();
            nodeRevContent.setContent(is);
            contentHelper.create(slideToken, "/files/test.xml",
revisionDescriptor, nodeRevContent);
            nsAccessToken.commit();
            is.close();
        } catch (Throwable e) {
            e.printStackTrace();
            try { nsAccessToken.rollback(); } catch(Exception _e) { }
        }
    }

    /**
     * test reading a file from the repository
     */
    public void testReadFile() {
        try {
            NodeRevisionDescriptors revisionDescriptors =
contentHelper.retrieve(slideToken, "/files/test.xml");
            NodeRevisionDescriptor revisionDescriptor =
contentHelper.retrieve(slideToken, revisionDescriptors);
            NodeRevisionContent revContent =
contentHelper.retrieve(slideToken, revisionDescriptors, revisionDescriptor);
            System.out.println("content: " +
String.valueOf(revContent.getContent()));
            System.out.println("rev: " +
revisionDescriptors.getLatestRevision());
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

    /**
     * test deleting a file from the repository
     */
    public void testDeleteFile() {
       try {
           nsAccessToken.begin();
           structureHelper.remove(slideToken, rootuser);
           nsAccessToken.commit();
        } catch (Throwable e) {
           e.printStackTrace();
           try { nsAccessToken.rollback(); } catch(Exception _e) { }
        }
    }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org