Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.openl.rules.repository.jcr;
  
  
  import javax.jcr.Node;
 
 public class JcrProductionFile extends JcrProductionEntity implements RFile {
    
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 JcrProductionFile createFile(Node parentNodeString nodeNamethrows RepositoryException {
         Node n = NodeUtil.createProdFileNode(parentNodenodeName);
 
         parentNode.save();
         n.save();
 
         return new JcrProductionFile(n);
     }
 
     public JcrProductionFile(Node nthrows RepositoryException {
         super(n);
     }

    
Gets content of the file. It is highly apreciated to close stream right after it is no longer needed.

Returns:
content stream with content of file
Throws:
org.openl.rules.repository.exceptions.RRepositoryException if failed
 
     public InputStream getContent() throws RRepositoryException {
         return NodeUtil.getFileNodeContent(node());
     }

    
Returns content of specified version of the file. As production files are not versioned, version parameter is ignored.

Parameters:
version ignored
Returns:
content of specified version
Throws:
org.openl.rules.repository.exceptions.RRepositoryException if failed
 
     public InputStream getContent4Version(CommonVersion versionthrows RRepositoryException {
         return getContent();
     }

    
Gets mime type of the file.

Returns:
mime type
 
     public String getMimeType() {
         return null;
     }

    
Returns size of the file's content in bytes.

Returns:
size of content or -1 if cannot determine it.
 
     public long getSize() {
         return NodeUtil.getFileNodeSize(node());
     }

    
Reverts the file to specified version.

Parameters:
versionName name of version
Throws:
org.openl.rules.repository.exceptions.RRepositoryException if failed
 
     public void revertToVersion(String versionNamethrows RRepositoryException {
         throw new UnsupportedOperationException();
     }

    
Sets/Updates content of the file. At the end input stream will be closed.

Parameters:
inputStream stream with new content of the file
Throws:
org.openl.rules.repository.exceptions.RRepositoryException if failed
 
     public void setContent(InputStream inputStreamthrows RRepositoryException {
         try {
             Node n = node();
 
             Node resNode = n.getNode("jcr:content");
 
            long lastModifiedTime = System.currentTimeMillis();
            Calendar lastModified = Calendar.getInstance();
            lastModified.setTimeInMillis(lastModifiedTime);
            resNode.setProperty("jcr:data"inputStream);
            resNode.setProperty("jcr:lastModified"lastModified);
            n.save();
        } catch (RepositoryException e) {
            throw new RRepositoryException("Failed to set Content"e);
        }
    }
New to GrepCode? Check out our FAQ X