Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2009 eXo Platform SAS.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
   * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.exoplatform.services.jcr.webdav.resource;
 
 
 import java.net.URI;
 import java.util.Set;
 
 import javax.jcr.Node;
Created by The eXo Platform SARL .
Resource containing JCR's nt:file/jcr:content underneath. Identified by nt:file's URI jcr:content's jcr:data property contains file's payload

Author(s):
Gennady Azarenkov
Version:
$Id: FileResource.java 4722 2011-08-09 14:09:17Z dkuleshov $
 
 public class FileResource extends GenericResource
 {

   
logger.
 
    private static final Log LOG = ExoLogger.getLogger("exo.jcr.component.webdav.FileResource");

   
The list of properties which are skipped for nt:file.
 
    protected final static Set<StringFILE_SKIP = new HashSet<String>();
    static
    {
       // FILE_SKIP.add("jcr:primaryType");
       .add("jcr:mixinTypes");
       .add("jcr:created");
       .add("jcr:lockOwner");
       .add("jcr:lockIsDeep");
    };

   
The list of properties which are skipped for jcr:content.
 
    protected final static Set<StringCONTENT_SKIP = new HashSet<String>();
    static
    {
       .add("jcr:data");
       .add("jcr:lastModified");
       .add("jcr:mimeType");
       .add("jcr:uuid");
       .add("jcr:lockOwner");
       .add("jcr:lockIsDeep");
 
       .add("dc:date");
       .add("exo:internalUse");
    };

   
Node.
 
    protected final Node node;

   
Content Node (jcr:content).
 
    private Node contentNode;

   
Data Property (jcr:data).
   private Property contentData;

   

Parameters:
identifier resource identifier
node node
namespaceContext namespace context
Throws:
IllegalResourceTypeException IllegalResourceTypeException
javax.jcr.RepositoryException javax.jcr.RepositoryException
   public FileResource(final URI identifierNode nodefinal WebDavNamespaceContext namespaceContext)
   {
      this(identifiernodenamespaceContext);
   }

   

Parameters:
type resource type
identifier resource identifier
node node
namespaceContext namespace context
Throws:
IllegalResourceTypeException javax.jcr.RepositoryException
   protected FileResource(final int typefinal URI identifierNode nodefinal WebDavNamespaceContext namespaceContext)
   {
      super(typeidentifiernamespaceContext);
      this. = node;
   }

   
   public Set<HierarchicalPropertygetProperties(boolean namesOnlythrows PathNotFoundException,
   {
      Set<HierarchicalPropertyprops = super.getProperties(namesOnly);
      props.add(namesOnly ? new HierarchicalProperty() : getProperty());
      props.add(namesOnly ? new HierarchicalProperty() : getProperty());
      props.add(namesOnly ? new HierarchicalProperty() : getProperty());
      QName nodeTypeName = .createQName("jcr:nodeType");
      HierarchicalProperty noneTypeProp =
         new HierarchicalProperty(nodeTypeNamecontentNode().getPrimaryNodeType().getName());
      props.add(noneTypeProp);
      Set<QNamepresents = new HashSet<QName>();
      PropertyIterator jcrProps = .getProperties();
      while (jcrProps.hasNext())
      {
         Property property = jcrProps.nextProperty();
         if (!.contains(property.getName()))
         {
            QName name = .createQName(property.getName());
            presents.add(name);
            props.add((namesOnly) ? new HierarchicalProperty(name) : getProperty(name));
            if (name.getLocalPart().equals("isCheckedOut"))
            {
               QName qname = .createQName("D:checked-in");
               presents.add(qname);
               props.add(new HierarchicalProperty(qname));
            }
         }
      }
      jcrProps = contentNode().getProperties();
      HierarchicalProperty jcrContentProp =
      while (jcrProps.hasNext())
      {
         Property property = jcrProps.nextProperty();
         if (!.contains(property.getName()))
         {
            QName name = .createQName(property.getName());
            if (presents.contains(name))
            {
               continue;
            }
            jcrContentProp.addChild((namesOnly) ? new HierarchicalProperty(name) : getProperty(name));
         }
      }
      if (!jcrContentProp.getChildren().isEmpty())
      {
         props.add(jcrContentProp);
      }
      return props;
   }

   
   {
      if (name.equals())
      {
         return new HierarchicalProperty(name.getName());
      }
      else if (name.equals())
      {
         Calendar created = .getProperty("jcr:created").getDate();
         HierarchicalProperty creationDate = new HierarchicalProperty(namecreated);
         creationDate.setAttribute("b:dt""dateTime.tz");
         return creationDate;
      }
      else if (name.equals())
      {
         return new HierarchicalProperty(name"0");
      }
      else if (name.equals())
      {
         return new HierarchicalProperty(name, String.valueOf(dataProperty().getLength()));
      }
      else if (name.equals())
      {
         return new HierarchicalProperty(namecontentNode().getProperty("jcr:mimeType").getString());
      }
      else if (name.equals())
      {
         Calendar modified;
         try
         {
            modified = contentNode().getProperty("jcr:lastModified").getDate();
         }
         catch (PathNotFoundException e)
         {
            modified = .getProperty("jcr:created").getDate();
         }
         HierarchicalProperty lastModified = new HierarchicalProperty(namemodified);
         lastModified.setAttribute("b:dt""dateTime.rfc1123");
         return lastModified;
      }
      else if (name.equals())
      {
         return new HierarchicalProperty(name"0");
      }
      else if (name.equals())
      {
         return new HierarchicalProperty(name"0");
      }
      else if (name.equals())
      {
         return new HierarchicalProperty(name"0");
      }
      else if (name.equals())
      {
         return new HierarchicalProperty(name"0");
      }
      else if (name.equals())
      {
         return new HierarchicalProperty(name.getParent().getName());
      }
      else if (name.equals())
      {
         return new HierarchicalProperty(name);
      }
      else if (name.equals())
      {
         if (!.canAddMixin("mix:lockable"))
         {
            throw new PathNotFoundException();
         }
         return supportedLock();
      }
      else if (name.equals())
      {
         if (.isLocked())
         {
            String token = .getLock().getLockToken();
            String owner = .getLock().getLockOwner();
            return lockDiscovery(tokenowner"86400");
         }
         else
         {
            throw new PathNotFoundException();
         }
      }
      else if (name.equals())
      {
         return new HierarchicalProperty(name"0");
      }
      else if (name.equals())
      {
         return supportedMethodSet();
      }
      else if (name.equals(.))
      {
         return ACLProperties.getACL((NodeImpl));
      }
      else if (name.equals())
      {
         return ACLProperties.getOwner((NodeImpl));
      }
      else
      {
         try
         {
            Property property = .getProperty(WebDavNamespaceContext.createName(name));
            String propertyValue;
            if (property.getDefinition().isMultiple())
            {
               if (property.getValues().length == 0)
               {
                  throw new PathNotFoundException();
               }
               propertyValue = property.getValues()[0].getString();
            }
            else
            {
               propertyValue = property.getString();
            }
            return new HierarchicalProperty(namepropertyValue);
         }
         catch (PathNotFoundException e)
         {
            Property property = contentNode().getProperty(WebDavNamespaceContext.createName(name));
            String propertyValue;
            if (property.getDefinition().isMultiple())
            {
               if (property.getValues().length >= 1)
               {
                  propertyValue = property.getValues()[0].getString();
               }
               else
               {
                  // this means that we return empty value, because according to WebDAV spec:
                  // this is a property whose semantics and syntax are not enforced by the server
                  // the server only records the value of a dead property;
                  // the client is responsible for maintaining the consistency of the syntax and semantics of a dead property. 
                  propertyValue = "";
               }
            }
            else
            {
               propertyValue = property.getString();
            }
            return new HierarchicalProperty(namepropertyValue);
         }
      }
   }

   
   public boolean isCollection()
   {
      return false;
   }

   
Returns the content of node as text.

   {
      return dataProperty().getString();
   }

   
Returns the content of node as stream.

   {
      return dataProperty().getStream();
   }

   
if the content of node is text.

Returns:
true if the content of node is text false if not
   public boolean isTextContent()
   {
      try
      {
         return dataProperty().getType() != .;
      }
      catch (RepositoryException exc)
      {
         .error(exc.getMessage(), exc);
         return false;
      }
   }

   
Returns the content node.

Returns:
Node, the content node
Throws:
javax.jcr.RepositoryException javax.jcr.RepositoryException
   protected Node contentNode() throws RepositoryException
   {
      if ( == null)
      {
         return  = .getNode("jcr:content");
      }
      else
      {
         return ;
      }
   }

   
Returns the data property.

Returns:
Property, the content data property
Throws:
javax.jcr.RepositoryException javax.jcr.RepositoryException
   protected Property dataProperty() throws RepositoryException
   {
      if ( == null)
      {
         return  = contentNode().getProperty("jcr:data");
      }
      else
      {
         return ;
      }
   }
New to GrepCode? Check out our FAQ X