Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.openl.rules.repository.jcr;
  
  
  import javax.jcr.Node;
 import java.util.List;
 
 public class JcrProductionFolder extends JcrProductionEntity 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 JcrProductionFolder createFolder(Node parentNodeString nodeNamethrows RepositoryException {
         Node n = NodeUtil.createNode(parentNodenodeName.false);
         parentNode.save();
         n.save();
 
         return new JcrProductionFolder(n);
     }
 
     public JcrProductionFolder(Node nodethrows RepositoryException {
         super(node);
     }

    
Creates file to the folder.

Parameters:
name name of new file
Returns:
newly created file
Throws:
org.openl.rules.repository.exceptions.RRepositoryException if failed
 
     public RFile createFile(String namethrows RRepositoryException {
         try {
             return JcrProductionFile.createFile(node(), name);
         } catch (RepositoryException e) {
             throw new RRepositoryException("failed to create file"e);
         }
     }

    
Creates sub folder to the folder.

Parameters:
name name of new folder
Returns:
newly created folder
Throws:
org.openl.rules.repository.exceptions.RRepositoryException if failed
 
     public RFolder createFolder(String namethrows RRepositoryException {
         try {
             return createFolder(node(), name);
         } catch (RepositoryException e) {
             throw new RRepositoryException("failed to create subfolder"e);
         }
     }

    
Gets list of files from the folder.

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

    
Gets list of sub folders. It returns direct descendants only.

Returns:
list of sub folders.
 
     public List<RFoldergetFolders() throws RRepositoryException {
         List<RFolderresult = new LinkedList<RFolder>();
         listNodes(resultfalse);
         return result;
 
     }

    
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 JcrProductionFolder(n));
                    }
                } else {
                    if (isFiles) {
                        list2add.add(new JcrProductionFile(n));
                    }
                }
            }
        } catch (RepositoryException e) {
            throw new RRepositoryException("failed to list nodes"e);
        }
    }
New to GrepCode? Check out our FAQ X