Hi, everyone.

I want to make the CMS application by using jakarta-slide 
low-level API. So, I started studying of jakarta-slide. 
I perused the document which related to jakarta-slide. 
And, I created the test program of my own way. 
(The code is described in this mail end)

However, it is a doubt whether the usage of jakarta-slide 
low-level API which I am recognizing is right. Is the usage
of my jakarta-slide API right? 

Please let me hear the opinion of everybody. 
Especially, please teach the following four Questions. 

Questions 1:
Is the code by which contents are added to repository right?
(Refer to addContents())

Questions 2:
When contents are added to repository, is setting Revision
indispensable?
(Refer to addContents())

Questions 3:
Is the code by which the folder is created right?
(Refer to makeFolder())

Questions 4:
Is the code by which the folder and the file (contents) are 
distinguished right?
(Refer to isDirectory())

thank you.

--------------------------------------------------------------------
import java.io.*;
import java.util.*;
import org.apache.slide.authenticate.*;
import org.apache.slide.common.*;
import org.apache.slide.content.*;
import org.apache.slide.lock.*;
import org.apache.slide.security.*;
import org.apache.slide.structure.*;

public class TrySlideApi {

    NamespaceAccessToken token;
    Structure structure;
    Security security;
    Lock lock;
    Content content;
    SlideToken slideToken;

    /**
     * Constructor.
     * @param namespace namespace name
     */
    public TrySlideApi(String namespace) throws Exception {
        token =
            Domain.accessNamespace(new SecurityToken(new String()), 
            namespace);
        structure = token.getStructureHelper();
        security  = token.getSecurityHelper();
        lock      = token.getLockHelper();
        content   = token.getContentHelper();
    }
    
    /**
     * initialize slideToken
     * @param userid Credentials stored in this token
     * @throws Exception
     */
    public void init(String userid) throws Exception{
        CredentialsToken credToken =
            new CredentialsToken(new String(userid));
        slideToken = new SlideTokenImpl(credToken);
    }
    
    /**
     * The FILE is added to the repository. 
     * @param file New File 
     * @param path 
     * location in the namespace where we the object should be created
     * @throws Exception
     */
    public void addContents(String file, String path)
    throws Exception{
        FileInputStream is = new FileInputStream(new File(file));
        addContents(is, path, "1"); 
    }

    /**
     * The FILE is added to the repository. 
     * @param is New input stream
     * @param path 
     * location in the namespace where we the object should be created
     * @throws Exception
     */
    public void addContents(InputStream is, String path)
    throws Exception {
        addContents(is, path, "1"); 
    }

    /**
     * The FILE is added to the repository. 
     * @param file New File
     * @param path 
     * location in the namespace where we the object should be created
     * @param revision value of revision
     * @throws Exception
     */
    public void addContents(String file, String path, String revision)
    throws Exception {
        FileInputStream is = new FileInputStream(new File(file));
        addContents(is, path, revision); 
    }

    /**
     * The FILE is added to the repository. 
     * @param is New input stream
     * @param path 
     * location in the namespace where we the object should be created
     * @param revision value of revision
     * @throws Exception
     */
    public void addContents(InputStream is, String path, String revision)
    throws Exception {
        try{
            token.begin();
            SubjectNode rootuser = 
                (SubjectNode)structure.retrieve(slideToken, 
                    "/users/root");
            structure.create(slideToken, rootuser, path);
            content.create(slideToken, path, true);
            // Revision
            NodeRevisionDescriptors revisionDescriptors =
                content.retrieve(slideToken, path);
            NodeRevisionDescriptor currentRevisionDescriptor = 
                new NodeRevisionDescriptor(-1);
            currentRevisionDescriptor.setProperty("revision", revision);
            NodeRevisionContent currentRevisionContent = 
                new NodeRevisionContent();
            currentRevisionContent.setContent(is);
            // Contenet create
            // ** When hsqldb is used, 
            //  ObjectNotFoundException is output by the Next Row. why? ** 
            content.create(slideToken, path,
                currentRevisionDescriptor, currentRevisionContent);
        } finally{
            token.commit();
            is.close();
        }
    }

    /**
     * create Folder
     * @param folder folder path
     * @throws SlideException
     */
    public void makeFolder(String folder) throws SlideException {
        structure.create(slideToken, new SubjectNode(), folder);
    }

    /**
     * Returns the children of a folder(node) 
     * @param folder folder path
     * @return Enumeration of ObjectNode objects
     * @throws SlideException
     */
    public Enumeration getChildrenList(String folder)    
    throws SlideException {
        return structure.getChildren(
            slideToken, structure.retrieve(slideToken, folder));
    }

    /**
     * The ObjectNode is a Folder or Content(file)?. 
     * @param objects object node
     * @return ture is folder. false is Content(file).
     */
    public boolean isDirectory(ObjectNode objects) {
        if (objects instanceof slideroles.basic.RootRoleImpl ||
            objects instanceof slideroles.basic.UserRoleImpl || 
            objects instanceof slideroles.basic.GuestRoleImpl ){
            return false;
        } else {
            return true;
        }
    }

    /**
     * A specific Content Data is taken out. 
     * @param path content path(file path)
     * @return NodeRevisionContent object of specific Content
     * @throws SlideException
     */
    public NodeRevisionContent getRevContentData(String path)
    throws SlideException {
        NodeRevisionDescriptors revDescriptors =
            content.retrieve(slideToken, path);
        NodeRevisionDescriptor revDescriptor =
            content.retrieve(slideToken, revDescriptors);
        NodeRevisionContent revContent =
            content.retrieve(slideToken, revDescriptors, revDescriptor);
        
        return revContent;
    }

    /**
     * @return Content object
     */
    public Content getContent() {
        return content;
    }

    /**
     * @return Lock object
     */
    public Lock getLock() {
        return lock;
    }

    /**
     * @return Security object
     */
    public Security getSecurity() {
        return security;
    }

    /**
     * @return SlideToken object
     */
    public SlideToken getSlideToken() {
        return slideToken;
    }

    /**
     * @return Structure object
     */
    public Structure getStructure() {
        return structure;
    }

    /**
     * @return NamespaceAccessToken object
     */
    public NamespaceAccessToken getToken() {
        return token;
    }

    /**
     * Contents of the Folder are printed. (debug Method)
     * @param out print stream
     * @param path folder path
     * @throws SlideException
     */
    public void printListTrace(PrintStream out, String path) 
    throws SlideException {
        Enumeration lists = this.getChildrenList(path);
        while (lists.hasMoreElements()) {
            ObjectNode list = (ObjectNode) lists.nextElement();
            String current_path = list.getUri();
            String status;
            if( isDirectory(list) ){
                out.println("Child : [Folder ] : " + current_path);
                printListTrace(out, current_path) ;
            }else{
                out.println("Child : [Content] : " + current_path);  
            }    
        }
    }
    
    public static void main(String[] args) {
        NamespaceAccessToken token;
        Structure structure;
        Security security;
        Lock lock;
        Content content;
        SlideToken slideToken;

        try {
            TrySlideApi rcms = new TrySlideApi("xml");
            rcms.init("root");
            token     = rcms.getToken();
            structure = rcms.getStructure();
            security  = rcms.getSecurity();
            lock      = rcms.getLock();
            content   = rcms.getContent();
            slideToken= rcms.getSlideToken();

            // test createing a folder ro the repositry.
            try {
                structure.retrieve(slideToken, "/files/folder2");
            } catch (Exception e) {
                // The alert message below is output(every one ROW).Is it correct?
                // 16 Jul 2003 20:35:58 - WARNING - WARNING: No active transaction
                // 16 Jul 2003 20:35:58 - WARNING - WARNING: No active transaction
                rcms.makeFolder("/files/folder2");
                rcms.makeFolder("/files/folder2/folder3");
                rcms.makeFolder("/files/folder2/folder3/folder4");
                rcms.makeFolder("/files/folder2/folder3/folder4/folder5");
                rcms.makeFolder("/users/remm.user");
                rcms.makeFolder("/users/dave.user");
                rcms.makeFolder("/actions/read.action");
            }
            // test adding a file to the repository
            rcms.addContents("C:\\temp\\test1.txt",
                "/files/folder2/folder3/test1.txt", "test1.txt");
            rcms.addContents("C:\\temp\\test2.xls",
                "/files/folder2/folder3/test2.xls", "test2.xls");
          
            // test reading a file from the repository
            NodeRevisionContent cnt1 = 
                rcms.getRevContentData("/files/folder2/folder3/test1.txt");
            NodeRevisionContent cnt2 = 
                rcms.getRevContentData("/files/folder2/folder3/test2.xls");
            System.out.println("content1: " + 
                String.valueOf(cnt1.getContent()));
            System.out.println("content2: " + 
                String.valueOf(cnt2.getContent()));

            // test printing a contents of the Folder.
            rcms.printListTrace(System.out, "/");

        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to