this is my code, @ DefaultRepositoryDAO.java

package org.blueoxygen.jackrabbit.dao;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Calendar;
import java.util.UUID;
import java.util.ArrayList;
import java.util.List;

import javax.activation.MimetypesFileTypeMap;
import javax.jcr.AccessDeniedException;
import javax.jcr.InvalidItemStateException;
import javax.jcr.ItemExistsException;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.PathNotFoundException;
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Value;
import javax.jcr.lock.LockException;
import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.nodetype.NoSuchNodeTypeException;
import javax.jcr.version.Version;
import javax.jcr.version.VersionException;
import javax.jcr.version.VersionHistory;
import javax.jcr.version.VersionIterator;

import org.apache.jackrabbit.value.StringValue;
import org.blueoxygen.jackrabbit.AttachedStream;
import org.springmodules.jcr.SessionFactory;

public class DefaultRepositoryDAO implements RepositoryDAO {
        private SessionFactory jcrSessionFactory;
        private Session jcrSession;
        
        public Session getJcrSession() {
                return jcrSession;
        }

        public void setJcrSession(Session jcrSession) {
                this.jcrSession = jcrSession;
        }

        public SessionFactory getJcrSessionFactory() {
                return jcrSessionFactory;
        }

        public void setJcrSessionFactory(SessionFactory jcrSessionFactory) {
                this.jcrSessionFactory = jcrSessionFactory;
        }

        /**
         * Initialize Jackrabbit Session from Session Factory
         * for spring init-method
         * akan dipanggil ketika aplikasi startup
         */
        public void init(){
                try {
                        jcrSession = jcrSessionFactory.getSession();
                } catch (RepositoryException e) {
                        e.printStackTrace();
                }
        }
        
        /**
         * Logout Jackrabbit Session
         * for spring destroy-method
         */
        public void dispose(){
                jcrSession.logout();
        }

        
        /**
     * Imports a File.
     *
     * @param parentnode Parent Repository Node
     * @param file File to be imported
     * @throws RepositoryException on repository errors, IOException on io
errors
     */
    public void importFile(Node parentnode, File file, String key) throws
RepositoryException, IOException {
        String mimeType = new MimetypesFileTypeMap().getContentType(file);
        if (mimeType==null) mimeType="application/octet-stream";

        Node fileNode = parentnode.addNode(key, "nt:file");
        
        Node resNode = fileNode.addNode("jcr:content", "nt:resource");
        resNode.addMixin("mix:versionable"); //set node mixin type
        resNode.setProperty("jcr:mimeType", mimeType);
        resNode.setProperty("jcr:encoding", "");
        resNode.setProperty("jcr:data", new FileInputStream(file));
        Calendar lastModified = Calendar.getInstance();
        lastModified.setTimeInMillis(file.lastModified());
        resNode.setProperty("jcr:lastModified", lastModified);
        
    }

    /**
     * Import a Folder.
     *
     * @param parentnode Parent Repository Node
     * @param directory Directory to be traversed
     * @throws RepositoryException on repository errors, IOException on io
errors
     */
    public void importFolder(Node parentnode, File directory) throws
RepositoryException, IOException  {
        File[] direntries = directory.listFiles();
        System.out.println(parentnode.getPath());
        for (int i=0; i<direntries.length; i++) {
            File direntry = direntries[i];
            if (direntry.isDirectory()) {
                Node childnode =
parentnode.addNode(direntry.getName(),"nt:folder");
                importFolder(childnode, direntry);
            } else {
                importFile(parentnode, direntry,
UUID.randomUUID().toString());
            }
        }
    }

    /**
     * Dumps the contents of the given node to standard output.
     *
     * @param node the node to be dumped
     * @throws RepositoryException on repository errors
     */
    public void dump(Node node) throws RepositoryException {
        System.out.println(node.getPath());

        PropertyIterator properties = node.getProperties();
        while (properties.hasNext()) {
            Property property = properties.nextProperty();
            System.out.print(property.getPath() + "=");
            if (property.getDefinition().isMultiple()) {
                Value[] values = property.getValues();
                for (int i = 0; i < values.length; i++) {
                    if (i > 0) {
                        System.out.println(",");
                    }
                    System.out.println(values[i].getString());
                }
            } else {
                if (property.getType()==PropertyType.BINARY) {
                    System.out.print("<binary>");
                }  else {
                    System.out.print(property.getString());
                }

            }
            System.out.println();
        }

        NodeIterator nodes = node.getNodes();
        while (nodes.hasNext()) {
            Node child = nodes.nextNode();
            dump(child);
        }
    }
        
        /**
         * Get Root Node from Repository
         */
    public Node getRootNode() throws RepositoryException {
                return jcrSession.getRootNode();
        }
        
    /**
     * Save Jackrabbit Session to Repository
     */
        public void save() 
        throws AccessDeniedException, ItemExistsException,
ConstraintViolationException, 
               InvalidItemStateException, VersionException, LockException, 
               NoSuchNodeTypeException, RepositoryException {
                jcrSession.save();
        }
        public void getVersionList(Node node) throws RepositoryException,
IOException{
                //List versionList = new ArrayList();
                
                Node resNode = node.getNode("jcr:content");
                
                VersionHistory versionHistory = resNode.getVersionHistory();
                VersionIterator versionIterator = 
versionHistory.getAllVersions();
                
                // for each version, output the node as it was versioned 
                
                while(versionIterator.hasNext())
                {
                        Version version = versionIterator.nextVersion();
                        NodeIterator nodeIterator = version.getNodes();
                        while(nodeIterator.hasNext())
                        {
                                Node versionedNode = nodeIterator.nextNode();
                                String fileName = version.getName();            
                
                        }
                }               
        }       
}

and i have ArticleForm.java , which collect all my variable, but, i want to
access String fileName for each version in my ArticleForm.java so, i can
show it in my table in .jsp

this is my ArticleForm.java
/*
 * Created on Jan 17, 2005
 */
package org.blueoxygen.komodo.actions;

import java.util.ArrayList;
import java.util.List;

import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;

import org.blueoxygen.jackrabbit.dao.RepositoryDAO;
import org.blueoxygen.jackrabbit.dao.RepositoryDAOAware;


import com.opensymphony.xwork.ActionSupport;

/**
 * @author harry
 * email :  [EMAIL PROTECTED]
 */
public class ArticleForm extends ActionSupport implements PersistenceAware
{
        protected PersistenceManager pm;
        protected LogInformation logInfo;
        
        protected Article article;
        
        private RepositoryDAO repoManager;
        private String fileName;
        public String execute() 
        {
                creators = pm.findAllSorted(Creator.class, "creatorName");
                artPublishers = pm.findAllSorted(ArtPublisher.class, 
"publisherName");
                contributors = pm.findAllSorted(Contributor.class, 
"contributorName");
                formats = pm.findAllSorted(Format.class, "formatMediaType");
                types = pm.findAllSorted(Type.class, "typeCategory");
                languages = pm.findAllSorted(Language.class, "langDescription");
                articleCategories = pm.findAllSorted(ArticleCategory.class, 
"name");            
                /*try {
                        //fileName = repoManager.getRootNode().getPath();
                        fileName = 
repoManager.getRootNode().getNode(article.getId()).getName();
                } catch (RepositoryException e) {
                        
                        e.printStackTrace();
                }*/
                return SUCCESS;
        }

        public String getFileName() {
                return fileName;
        }



        public void setFileName(String fileName) {
                this.fileName = fileName;
        }
}

help me please, i'm still newbie in java.. but so many things must i did..

-- 
View this message in context: 
http://www.nabble.com/versioning-file-and-show-it-in-table-tf4022881.html#a11426236
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Reply via email to