Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.openl.rules.repository.jcr;
  
  import java.util.Calendar;
  
  import javax.jcr.Node;
  
Implementation of JCR File.

Author(s):
Aleh Bykhavets
 
 public class JcrFileAPI extends JcrEntityAPI implements ResourceAPI {

    
Creates a new instance of file.

Parameters:
parentNode parent node (files or folder)
nodeName name of new node
Returns:
newly created instance
Throws:
javax.jcr.RepositoryException if fails
 
     protected static JcrFileAPI createFile(JcrFolderAPI parentString nodeNameArtefactPath path)
             throws RepositoryException {
         Node parentNode = parent.node();
         Node n = NodeUtil.createFileNode(parentNodenodeName);
 
         parentNode.save();
         n.save();
 
         return new JcrFileAPI(nparent.getTransactionManager(), pathfalse);
     }
 
     public JcrFileAPI(Node nodeRTransactionManager transactionManagerArtefactPath pathboolean oldVersionthrows RepositoryException {
         super(nodetransactionManagerpatholdVersion);
 
         // NodeUtil.checkNodeType(node, JcrNT.NT_FILE);
     }
 
     public JcrFileAPI(Node nodeRTransactionManager transactionManagerArtefactPath paththrows RepositoryException {
         this(nodetransactionManagerpathfalse);
     }

    
 
     public InputStream getContent() throws ProjectException {
         try {
             return NodeUtil.getFileNodeContent(node());
         } catch (RRepositoryException e) {
             throw new ProjectException(""e);
         }
     }
 
     @Override
     public JcrFileAPI getVersion(CommonVersion version) {
         try {
             Node frozen = NodeUtil.getNode4Version(node(), version);
             return new JcrFileAPI(frozengetTransactionManager(), getArtefactPath(), true);
         } catch (RepositoryException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
             return null;
         }
     }

    
 
     public String getResourceType() {
         // TODO Auto-generated method stub
         return null;
     }

    
 
     public long getSize() {
         return NodeUtil.getFileNodeSize(node());
     }

    
 
     public void setContent(InputStream inputStreamthrows ProjectException {
         try {
             Node n = node();
             NodeUtil.smartCheckout(nfalse);
 
             Node resNode = n.getNode(.);
 
             long lastModifiedTime = System.currentTimeMillis();
             Calendar lastModified = Calendar.getInstance();
             lastModified.setTimeInMillis(lastModifiedTime);
 
             resNode.setProperty(.inputStream);
             resNode.setProperty("jcr:lastModified"lastModified);
            n.save();
        } catch (Exception e) {
            throw new ProjectException(""e);
        }
    }
New to GrepCode? Check out our FAQ X