Package org.exoplatform.common.util

Examples of org.exoplatform.common.util.HierarchicalProperty


         InputStream istream;

         if (ResourceUtil.isFile(node))
         {

            HierarchicalProperty lastModifiedProperty;
           
            if (version != null)
            {
               VersionedResource versionedFile = new VersionedFileResource(uri, node, nsContext);
               resource = versionedFile.getVersionHistory().getVersion(version);
              
               lastModifiedProperty = resource.getProperty(FileResource.GETLASTMODIFIED);
               istream = ((VersionResource)resource).getContentAsStream();
            }
            else
            {
               resource = new FileResource(uri, node, nsContext);
              
               lastModifiedProperty = resource.getProperty(FileResource.GETLASTMODIFIED);
               istream = ((FileResource)resource).getContentAsStream();
            }

            // check before any other reads
            if (ifModifiedSince != null)
            {
               DateFormat dateFormat = new SimpleDateFormat(WebDavConst.DateFormat.MODIFICATION, Locale.US);
               Date lastModifiedDate = dateFormat.parse(lastModifiedProperty.getValue());
              
               dateFormat = new SimpleDateFormat(WebDavConst.DateFormat.IF_MODIFIED_SINCE_PATTERN, Locale.US);
               Date ifModifiedSinceDate = dateFormat.parse(ifModifiedSince);
              
               if(ifModifiedSinceDate.getTime() >= lastModifiedDate.getTime()){
                  return Response.notModified().entity("Not Modified").build();
               }
            }

            HierarchicalProperty contentLengthProperty = resource.getProperty(FileResource.GETCONTENTLENGTH);
            long contentLength = new Long(contentLengthProperty.getValue());

            // content length is not present
            if (contentLength == 0)
            {
               return Response.ok().header(ExtHttpHeaders.ACCEPT_RANGES, "bytes").entity(istream).build();
            }

            HierarchicalProperty mimeTypeProperty = resource.getProperty(FileResource.GETCONTENTTYPE);
            String contentType = mimeTypeProperty.getValue();

            // no ranges request
            if (ranges.size() == 0)
            {
               return Response.ok().header(HttpHeaders.CONTENT_LENGTH, Long.toString(contentLength)).header(
View Full Code Here


   public Set<HierarchicalProperty> getProperties(boolean namesOnly) throws PathNotFoundException,
      AccessDeniedException, RepositoryException
   {
      Set<HierarchicalProperty> props = super.getProperties(namesOnly);

      props.add(namesOnly ? new HierarchicalProperty(GETLASTMODIFIED) : getProperty(GETLASTMODIFIED));
      props.add(namesOnly ? new HierarchicalProperty(GETCONTENTLENGTH) : getProperty(GETCONTENTLENGTH));
      props.add(namesOnly ? new HierarchicalProperty(GETCONTENTTYPE) : getProperty(GETCONTENTTYPE));

      QName nodeTypeName = namespaceContext.createQName("jcr:nodeType");
      HierarchicalProperty noneTypeProp =
         new HierarchicalProperty(nodeTypeName, contentNode().getPrimaryNodeType().getName());
      props.add(noneTypeProp);

      Set<QName> presents = new HashSet<QName>();

      PropertyIterator jcrProps = node.getProperties();
      while (jcrProps.hasNext())
      {
         Property property = jcrProps.nextProperty();
         if (!FILE_SKIP.contains(property.getName()))
         {
            QName name = namespaceContext.createQName(property.getName());
            presents.add(name);
            props.add((namesOnly) ? new HierarchicalProperty(name) : getProperty(name));
            if (name.getLocalPart().equals("isCheckedOut"))
            {
               QName qname = namespaceContext.createQName("D:checked-in");
               presents.add(qname);
               props.add(new HierarchicalProperty(qname));
            }
         }
      }

      jcrProps = contentNode().getProperties();
      HierarchicalProperty jcrContentProp =
         new HierarchicalProperty(namespaceContext.createQName(WebDavConst.NodeTypes.JCR_CONTENT));

      while (jcrProps.hasNext())
      {
         Property property = jcrProps.nextProperty();
         if (!CONTENT_SKIP.contains(property.getName()))
         {
            QName name = namespaceContext.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;
   }
View Full Code Here

   public HierarchicalProperty getProperty(QName name) throws PathNotFoundException, AccessDeniedException,
      RepositoryException
   {
      if (name.equals(DISPLAYNAME))
      {
         return new HierarchicalProperty(name, node.getName());
      }
      else if (name.equals(CREATIONDATE))
      {
         Calendar created = node.getProperty("jcr:created").getDate();

         HierarchicalProperty creationDate = new HierarchicalProperty(name, created, CREATION_PATTERN);
         creationDate.setAttribute("b:dt", "dateTime.tz");
         return creationDate;
      }
      else if (name.equals(CHILDCOUNT))
      {
         return new HierarchicalProperty(name, "0");
      }
      else if (name.equals(GETCONTENTLENGTH))
      {
         return new HierarchicalProperty(name, String.valueOf(dataProperty().getLength()));
      }
      else if (name.equals(GETCONTENTTYPE))
      {
         return new HierarchicalProperty(name, contentNode().getProperty("jcr:mimeType").getString());
      }
      else if (name.equals(GETLASTMODIFIED))
      {
         Calendar modified;
         try
         {
            modified = contentNode().getProperty("jcr:lastModified").getDate();
         }
         catch (PathNotFoundException e)
         {
            modified = node.getProperty("jcr:created").getDate();
         }
         HierarchicalProperty lastModified = new HierarchicalProperty(name, modified, MODIFICATION_PATTERN);
         lastModified.setAttribute("b:dt", "dateTime.rfc1123");
         return lastModified;
      }
      else if (name.equals(HASCHILDREN))
      {
         return new HierarchicalProperty(name, "0");
      }
      else if (name.equals(ISCOLLECTION))
      {
         return new HierarchicalProperty(name, "0");
      }
      else if (name.equals(ISFOLDER))
      {
         return new HierarchicalProperty(name, "0");
      }
      else if (name.equals(ISROOT))
      {
         return new HierarchicalProperty(name, "0");
      }
      else if (name.equals(PARENTNAME))
      {
         return new HierarchicalProperty(name, node.getParent().getName());
      }
      else if (name.equals(RESOURCETYPE))
      {
         return new HierarchicalProperty(name);
      }
      else if (name.equals(SUPPORTEDLOCK))
      {
         if (!node.canAddMixin("mix:lockable"))
         {
            throw new PathNotFoundException();
         }
         return supportedLock();
      }
      else if (name.equals(LOCKDISCOVERY))
      {
         if (node.isLocked())
         {
            String token = node.getLock().getLockToken();
            String owner = node.getLock().getLockOwner();
            return lockDiscovery(token, owner, "86400");
         }
         else
         {
            throw new PathNotFoundException();
         }
      }
      else if (name.equals(ISVERSIONED))
      {
         return new HierarchicalProperty(name, "0");
      }
      else if (name.equals(SUPPORTEDMETHODSET))
      {
         return supportedMethodSet();
      }
      else
      {
         try
         {
            Property property = node.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(name, propertyValue);
         }
         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(name, propertyValue);
         }
      }
   }
View Full Code Here

         {
            QName name = namespaceContext.createQName(property.getName());

            try
            {
               props.add((namesOnly) ? new HierarchicalProperty(name) : getProperty(name));
            }
            catch (Exception exc)
            {
               if (LOG.isDebugEnabled())
                  LOG.error(exc.getMessage(), exc);
View Full Code Here

   public HierarchicalProperty getProperty(QName name) throws PathNotFoundException, AccessDeniedException,
      RepositoryException
   {
      if (name.equals(DISPLAYNAME))
      {
         return new HierarchicalProperty(name, node.getName());

      }
      else if (name.equals(CHILDCOUNT))
      {
         return new HierarchicalProperty(name, "" + node.getNodes().getSize());

      }
      else if (name.equals(CREATIONDATE))
      {
         if (node.isNodeType("nt:hierarchyNode"))
         {
            Calendar created = node.getProperty("jcr:created").getDate();
            HierarchicalProperty creationDate = new HierarchicalProperty(name, created, CREATION_PATTERN);
            creationDate.setAttribute("b:dt", "dateTime.tz");
            return creationDate;

         }
         else
         {
            throw new PathNotFoundException("Property not found " + CREATIONDATE);
         }

      }
      else if (name.equals(HASCHILDREN))
      {
         if (node.getNodes().getSize() > 0)
         {
            return new HierarchicalProperty(name, "1");
         }
         else
         {
            return new HierarchicalProperty(name, "0");
         }

      }
      else if (name.equals(ISCOLLECTION))
      {
         return new HierarchicalProperty(name, "1");

      }
      else if (name.equals(ISFOLDER))
      {
         return new HierarchicalProperty(name, "1");

      }
      else if (name.equals(ISROOT))
      {
         return new HierarchicalProperty(name, (node.getDepth() == 0) ? "1" : "0");

      }
      else if (name.equals(PARENTNAME))
      {
         if (node.getDepth() == 0)
         {
            throw new PathNotFoundException();
         }
         return new HierarchicalProperty(name, node.getParent().getName());

      }
      else if (name.equals(RESOURCETYPE))
      {
         HierarchicalProperty collectionProp = new HierarchicalProperty(new QName("DAV:", "collection"));
         HierarchicalProperty resourceType = new HierarchicalProperty(name);
         resourceType.addChild(collectionProp);
         return resourceType;

      }
      else if (name.equals(SUPPORTEDLOCK))
      {
         if (!node.canAddMixin("mix:lockable"))
         {
            throw new PathNotFoundException();
         }
         return supportedLock();

      }
      else if (name.equals(LOCKDISCOVERY))
      {
         if (node.isLocked())
         {
            String token = node.getLock().getLockToken();
            String owner = node.getLock().getLockOwner();

            return lockDiscovery(token, owner, "86400");
         }
         throw new PathNotFoundException();

      }
      else if (name.equals(ISVERSIONED))
      {
         return new HierarchicalProperty(name, "0");

      }
      else if (name.equals(SUPPORTEDMETHODSET))
      {
         return supportedMethodSet();

      }
      else if (name.equals(ORDERING_TYPE))
      {
         if (node.getPrimaryNodeType().hasOrderableChildNodes())
         {
            HierarchicalProperty orderingType = new HierarchicalProperty(name);

            // <D:href>DAV:custom</D:href>

            HierarchicalProperty orderHref = orderingType.addChild(new HierarchicalProperty(new QName("DAV:", "href")));
            orderHref.setValue("DAV:custom");

            return orderingType;
         }
         throw new PathNotFoundException();

      }
      else
      {

         if ("DAV:".equals(name.getNamespaceURI()))
         {
            throw new PathNotFoundException();
         }

         Property property = node.getProperty(WebDavNamespaceContext.createName(name));

         if (property.getDefinition().isMultiple())
         {
            Value[] values = property.getValues();
            return new HierarchicalProperty(name, values[0].getString());
         }
         else
         {
            return new HierarchicalProperty(name, property.getString());
         }

      }
   }
View Full Code Here

         {
            QName name = namespaceContext.createQName(property.getName());

            try
            {
               props.add((namesOnly) ? new HierarchicalProperty(name) : getProperty(name));
            }
            catch (Exception exc)
            {
               if (LOG.isDebugEnabled())
                  LOG.error(exc.getMessage(), exc);
View Full Code Here

   public HierarchicalProperty getProperty(QName name) throws PathNotFoundException, AccessDeniedException,
      RepositoryException
   {
      if (name.equals(DISPLAYNAME))
      {
         return new HierarchicalProperty(name, node.getName());

      }
      else if (name.equals(CHILDCOUNT))
      {
         return new HierarchicalProperty(name, "" + node.getNodes().getSize());

      }
      else if (name.equals(CREATIONDATE))
      {
         if (node.isNodeType("nt:hierarchyNode"))
         {
            Calendar created = node.getProperty("jcr:created").getDate();
            HierarchicalProperty creationDate = new HierarchicalProperty(name, created, CREATION_PATTERN);
            creationDate.setAttribute("b:dt", "dateTime.tz");
            return creationDate;

         }
         else
         {
            throw new PathNotFoundException("Property not found " + CREATIONDATE);
         }

      }
      else if (name.equals(HASCHILDREN))
      {
         if (node.getNodes().getSize() > 0)
         {
            return new HierarchicalProperty(name, "1");
         }
         else
         {
            return new HierarchicalProperty(name, "0");
         }

      }
      else if (name.equals(ISCOLLECTION))
      {
         return new HierarchicalProperty(name, "1");

      }
      else if (name.equals(ISFOLDER))
      {
         return new HierarchicalProperty(name, "1");

      }
      else if (name.equals(ISROOT))
      {
         return new HierarchicalProperty(name, (node.getDepth() == 0) ? "1" : "0");

      }
      else if (name.equals(PARENTNAME))
      {
         if (node.getDepth() == 0)
         {
            throw new PathNotFoundException();
         }
         return new HierarchicalProperty(name, node.getParent().getName());

      }
      else if (name.equals(RESOURCETYPE))
      {
         HierarchicalProperty collectionProp = new HierarchicalProperty(new QName("DAV:", "collection"));
         HierarchicalProperty resourceType = new HierarchicalProperty(name);
         resourceType.addChild(collectionProp);
         return resourceType;

      }
      else if (name.equals(SUPPORTEDLOCK))
      {
         if (!node.canAddMixin("mix:lockable"))
         {
            throw new PathNotFoundException();
         }
         return supportedLock();

      }
      else if (name.equals(LOCKDISCOVERY))
      {
         if (node.isLocked())
         {
            String token = node.getLock().getLockToken();
            String owner = node.getLock().getLockOwner();

            return lockDiscovery(token, owner, "86400");
         }
         throw new PathNotFoundException();

      }
      else if (name.equals(ISVERSIONED))
      {
         return new HierarchicalProperty(name, "0");

      }
      else if (name.equals(SUPPORTEDMETHODSET))
      {
         return supportedMethodSet();

      }
      else if (name.equals(ORDERING_TYPE))
      {
         if (node.getPrimaryNodeType().hasOrderableChildNodes())
         {
            HierarchicalProperty orderingType = new HierarchicalProperty(name);

            // <D:href>DAV:custom</D:href>

            HierarchicalProperty orderHref = orderingType.addChild(new HierarchicalProperty(new QName("DAV:", "href")));
            orderHref.setValue("DAV:custom");

            return orderingType;
         }
         throw new PathNotFoundException();

      }
      else if (name.equals(ACLProperties.ACL))
      {
         return ACLProperties.getACL((NodeImpl)node);
      }
      else if (name.equals(OWNER))
      {
         return ACLProperties.getOwner((NodeImpl)node);
      }
      else
      {

         if ("DAV:".equals(name.getNamespaceURI()))
         {
            throw new PathNotFoundException();
         }

         Property property = node.getProperty(WebDavNamespaceContext.createName(name));

         if (property.getDefinition().isMultiple())
         {
            Value[] values = property.getValues();
            return new HierarchicalProperty(name, values[0].getString());
         }
         else
         {
            return new HierarchicalProperty(name, property.getString());
         }

      }
   }
View Full Code Here

            writeAttributes(xmlStreamWriter, prop);

            for (int i = 0; i < prop.getChildren().size(); i++)
            {
               HierarchicalProperty property = prop.getChildren().get(i);
               writeProperty(xmlStreamWriter, property);
            }
            xmlStreamWriter.writeEndElement();
         }
         else
View Full Code Here

   public Set<HierarchicalProperty> getProperties(boolean namesOnly) throws PathNotFoundException,
      AccessDeniedException, RepositoryException
   {
      Set<HierarchicalProperty> props = super.getProperties(namesOnly);

      props.add(namesOnly ? new HierarchicalProperty(GETLASTMODIFIED) : getProperty(GETLASTMODIFIED));
      props.add(namesOnly ? new HierarchicalProperty(GETCONTENTLENGTH) : getProperty(GETCONTENTLENGTH));
      props.add(namesOnly ? new HierarchicalProperty(GETCONTENTTYPE) : getProperty(GETCONTENTTYPE));

      QName nodeTypeName = namespaceContext.createQName("jcr:nodeType");
      HierarchicalProperty noneTypeProp =
         new HierarchicalProperty(nodeTypeName, contentNode().getPrimaryNodeType().getName());
      props.add(noneTypeProp);

      Set<QName> presents = new HashSet<QName>();

      PropertyIterator jcrProps = node.getProperties();
      while (jcrProps.hasNext())
      {
         Property property = jcrProps.nextProperty();
         if (!FILE_SKIP.contains(property.getName()))
         {
            QName name = namespaceContext.createQName(property.getName());
            presents.add(name);
            props.add((namesOnly) ? new HierarchicalProperty(name) : getProperty(name));
            if (name.getLocalPart().equals("isCheckedOut"))
            {
               QName qname = namespaceContext.createQName("D:checked-in");
               presents.add(qname);
               props.add(new HierarchicalProperty(qname));
            }
         }
      }

      jcrProps = contentNode().getProperties();
      HierarchicalProperty jcrContentProp =
         new HierarchicalProperty(namespaceContext.createQName(WebDavConst.NodeTypes.JCR_CONTENT));

      while (jcrProps.hasNext())
      {
         Property property = jcrProps.nextProperty();
         if (!CONTENT_SKIP.contains(property.getName()))
         {
            QName name = namespaceContext.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;
   }
View Full Code Here

   public HierarchicalProperty getProperty(QName name) throws PathNotFoundException, AccessDeniedException,
      RepositoryException
   {
      if (name.equals(DISPLAYNAME))
      {
         return new HierarchicalProperty(name, node.getName());
      }
      else if (name.equals(CREATIONDATE))
      {
         Calendar created = node.getProperty("jcr:created").getDate();

         HierarchicalProperty creationDate = new HierarchicalProperty(name, created, CREATION_PATTERN);
         creationDate.setAttribute("b:dt", "dateTime.tz");
         return creationDate;
      }
      else if (name.equals(CHILDCOUNT))
      {
         return new HierarchicalProperty(name, "0");
      }
      else if (name.equals(GETCONTENTLENGTH))
      {
         return new HierarchicalProperty(name, String.valueOf(dataProperty().getLength()));
      }
      else if (name.equals(GETCONTENTTYPE))
      {
         return new HierarchicalProperty(name, contentNode().getProperty("jcr:mimeType").getString());
      }
      else if (name.equals(GETLASTMODIFIED))
      {
         Calendar modified;
         try
         {
            modified = contentNode().getProperty("jcr:lastModified").getDate();
         }
         catch (PathNotFoundException e)
         {
            modified = node.getProperty("jcr:created").getDate();
         }
         HierarchicalProperty lastModified = new HierarchicalProperty(name, modified, MODIFICATION_PATTERN);
         lastModified.setAttribute("b:dt", "dateTime.rfc1123");
         return lastModified;
      }
      else if (name.equals(HASCHILDREN))
      {
         return new HierarchicalProperty(name, "0");
      }
      else if (name.equals(ISCOLLECTION))
      {
         return new HierarchicalProperty(name, "0");
      }
      else if (name.equals(ISFOLDER))
      {
         return new HierarchicalProperty(name, "0");
      }
      else if (name.equals(ISROOT))
      {
         return new HierarchicalProperty(name, "0");
      }
      else if (name.equals(PARENTNAME))
      {
         return new HierarchicalProperty(name, node.getParent().getName());
      }
      else if (name.equals(RESOURCETYPE))
      {
         return new HierarchicalProperty(name);
      }
      else if (name.equals(SUPPORTEDLOCK))
      {
         if (!node.canAddMixin("mix:lockable"))
         {
            throw new PathNotFoundException();
         }
         return supportedLock();
      }
      else if (name.equals(LOCKDISCOVERY))
      {
         if (node.isLocked())
         {
            String token = node.getLock().getLockToken();
            String owner = node.getLock().getLockOwner();
            return lockDiscovery(token, owner, "86400");
         }
         else
         {
            throw new PathNotFoundException();
         }
      }
      else if (name.equals(ISVERSIONED))
      {
         return new HierarchicalProperty(name, "0");
      }
      else if (name.equals(SUPPORTEDMETHODSET))
      {
         return supportedMethodSet();
      }
View Full Code Here

TOP

Related Classes of org.exoplatform.common.util.HierarchicalProperty

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.