Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.openl.rules.repository.jcr;
  
  import java.util.List;
  
  import javax.jcr.Node;
  
Implementation for JCR Folder.

Author(s):
Aleh Bykhavets
 
 public class JcrFolder extends JcrEntity implements RFolder {

    
Creates new folder.

Parameters:
parentNode parent node (files or other folder)
nodeName name of new node
Returns:
newly created folder
Throws:
javax.jcr.RepositoryException if fails
 
     protected static JcrFolder createFolder(Node parentNodeString nodeNamethrows RepositoryException {
         Node n = NodeUtil.createNode(parentNodenodeName.true);
         parentNode.save();
         n.save();
 
         return new JcrFolder(n);
     }
 
     public JcrFolder(Node nodethrows RepositoryException {
         super(node);
 
         NodeUtil.checkNodeType(node.);
     }

    
 
     public RFile createFile(String namethrows RRepositoryException {
         try {
             return JcrFile.createFile(node(), name);
         } catch (RepositoryException e) {
             throw new RRepositoryException("Failed to Create File."e);
         }
     }

    
 
     public RFolder createFolder(String namethrows RRepositoryException {
         try {
             return JcrFolder.createFolder(node(), name);
         } catch (RepositoryException e) {
             throw new RRepositoryException("Failed to Create Sub Folder."e);
         }
     }

    
 
     public List<RFilegetFiles() throws RRepositoryException {
         List<RFileresult = new LinkedList<RFile>();
         listNodes(resulttrue);
         return result;
     }

    
 
     public List<RFoldergetFolders() throws RRepositoryException {
         List<RFolderresult = new LinkedList<RFolder>();
         listNodes(resultfalse);
         return result;
     }
 
     // ------ private methods ------
 
    
Lists nodes.

Parameters:
list2add list to which nodes should be added
isFiles whether return only files or only folders
Throws:
org.openl.rules.repository.exceptions.RRepositoryException if failed
 
     private void listNodes(List list2addboolean isFilesthrows RRepositoryException {
         try {
             NodeIterator ni = node().getNodes();
             while (ni.hasNext()) {
                 Node n = ni.nextNode();
 
                 // TODO: use search? But looking through direct child nodes
                 // seems faster
                 if (n.isNodeType(.)) {
                     if (!isFiles) {
                         list2add.add(new JcrFolder(n));
                     }
                 } else {
                     if (isFiles) {
                         list2add.add(new JcrFile(n));
                    }
                }
            }
        } catch (RepositoryException e) {
            throw new RRepositoryException("Failed to list nodes."e);
        }
    }
New to GrepCode? Check out our FAQ X